-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapps.html
More file actions
1030 lines (997 loc) · 57.3 KB
/
apps.html
File metadata and controls
1030 lines (997 loc) · 57.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.8.25">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="description" content="Documentation for open-Source products at CalCOFI.io developed for California Cooperative Oceanic Fisheries Investigations (CalCOFI.org)">
<title>3 Applications – CalCOFI.io</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="site_libs/quarto-nav/quarto-nav.js"></script>
<script src="site_libs/quarto-nav/headroom.min.js"></script>
<script src="site_libs/clipboard/clipboard.min.js"></script>
<script src="site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="site_libs/quarto-search/fuse.min.js"></script>
<script src="site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="./">
<link href="./maps.html" rel="next">
<link href="./reports.html" rel="prev">
<script src="site_libs/quarto-html/quarto.js" type="module"></script>
<script src="site_libs/quarto-html/tabsets/tabsets.js" type="module"></script>
<script src="site_libs/quarto-html/axe/axe-check.js" type="module"></script>
<script src="site_libs/quarto-html/popper.min.js"></script>
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="site_libs/quarto-html/anchor.min.js"></script>
<link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="site_libs/quarto-html/quarto-syntax-highlighting-7b89279ff1a6dce999919e0e67d4d9ec.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="site_libs/bootstrap/bootstrap.min.js"></script>
<link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="site_libs/bootstrap/bootstrap-27c261d06b905028a18691de25d09dde.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "sidebar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "start",
"type": "textbox",
"limit": 50,
"keyboard-shortcut": [
"f",
"/",
"s"
],
"show-item-context": false,
"language": {
"search-no-results-text": "No results",
"search-matching-documents-text": "matching documents",
"search-copy-link-title": "Copy link to search",
"search-hide-matches-text": "Hide additional matches",
"search-more-match-text": "more match in this document",
"search-more-matches-text": "more matches in this document",
"search-clear-button-title": "Clear",
"search-text-placeholder": "",
"search-detached-cancel-button-title": "Cancel",
"search-submit-button-title": "Submit",
"search-label": "Search"
}
}</script>
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-0HVK8TDMCF"></script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-0HVK8TDMCF', { 'anonymize_ip': true});
</script>
</head>
<body class="nav-sidebar floating quarto-light">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top">
<nav class="quarto-secondary-nav">
<div class="container-fluid d-flex">
<button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<i class="bi bi-layout-text-sidebar-reverse"></i>
</button>
<nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./apps.html"><span class="chapter-number">3</span> <span class="chapter-title">Applications</span></a></li></ol></nav>
<a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
</a>
<button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
<i class="bi bi-search"></i>
</button>
</div>
</nav>
</header>
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
<!-- sidebar -->
<nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto">
<div class="pt-lg-2 mt-2 text-left sidebar-header sidebar-header-stacked">
<a href="./index.html" class="sidebar-logo-link">
</a>
<div class="sidebar-title mb-0 py-0">
<a href="./">CalCOFI.io</a>
<div class="sidebar-tools-main tools-wide">
<a href="https://github.com/CalCOFI/docs/" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-github"></i></a>
<div class="dropdown">
<a href="" title="Download" id="quarto-navigation-tool-dropdown-0" class="quarto-navigation-tool dropdown-toggle px-1" data-bs-toggle="dropdown" aria-expanded="false" role="link" aria-label="Download"><i class="bi bi-download"></i></a>
<ul class="dropdown-menu" aria-labelledby="quarto-navigation-tool-dropdown-0">
<li>
<a class="dropdown-item sidebar-tools-main-item" href="./CalCOFI.io.pdf">
<i class="bi bi-file-pdf pe-1"></i>
Download PDF
</a>
</li>
<li>
<a class="dropdown-item sidebar-tools-main-item" href="./CalCOFI.io.docx">
<i class="bi bi-file-word pe-1"></i>
Download Docx
</a>
</li>
<li>
<a class="dropdown-item sidebar-tools-main-item" href="./CalCOFI.io.epub">
<i class="bi bi-journal pe-1"></i>
Download ePub
</a>
</li>
</ul>
</div>
<div class="dropdown">
<a href="" title="Share" id="quarto-navigation-tool-dropdown-1" class="quarto-navigation-tool dropdown-toggle px-1" data-bs-toggle="dropdown" aria-expanded="false" role="link" aria-label="Share"><i class="bi bi-share"></i></a>
<ul class="dropdown-menu" aria-labelledby="quarto-navigation-tool-dropdown-1">
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://twitter.com/intent/tweet?url=|url|">
<i class="bi bi-twitter pe-1"></i>
Twitter
</a>
</li>
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://www.facebook.com/sharer/sharer.php?u=|url|">
<i class="bi bi-facebook pe-1"></i>
Facebook
</a>
</li>
<li>
<a class="dropdown-item sidebar-tools-main-item" href="https://www.linkedin.com/sharing/share-offsite/?url=|url|">
<i class="bi bi-linkedin pe-1"></i>
LinkedIn
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="mt-2 flex-shrink-0 align-items-center">
<div class="sidebar-search">
<div id="quarto-search" class="" title="Search"></div>
</div>
</div>
<div class="sidebar-menu-container">
<ul class="list-unstyled mt-1">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">1</span> <span class="chapter-title">Process</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./reports.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span> <span class="chapter-title">Reports</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./apps.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">3</span> <span class="chapter-title">Applications</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./maps.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">4</span> <span class="chapter-title">Maps</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./db.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span> <span class="chapter-title">Database</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./data-access.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">6</span> <span class="chapter-title">Data Access</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./helpers.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">7</span> <span class="chapter-title">Matching Helpers</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./api.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span> <span class="chapter-title">API</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./portals.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">9</span> <span class="chapter-title">Portals</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./status.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">10</span> <span class="chapter-title">Status</span></span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./refs.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span> <span class="chapter-title">References</span></span></a>
</div>
</li>
</ul>
</div>
</nav>
<div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#matching-helpers" id="toc-matching-helpers" class="nav-link active" data-scroll-target="#matching-helpers"><span class="header-section-number">4</span> Matching Helpers</a>
<ul class="collapse">
<li><a href="#install" id="toc-install" class="nav-link" data-scroll-target="#install"><span class="header-section-number">4.1</span> Install</a></li>
<li><a href="#the-wrappers" id="toc-the-wrappers" class="nav-link" data-scroll-target="#the-wrappers"><span class="header-section-number">4.2</span> The wrappers</a></li>
<li><a href="#worked-example-sardine-larvae-temperature" id="toc-worked-example-sardine-larvae-temperature" class="nav-link" data-scroll-target="#worked-example-sardine-larvae-temperature"><span class="header-section-number">4.3</span> Worked example: sardine larvae + temperature</a></li>
<li><a href="#reproducible-sql" id="toc-reproducible-sql" class="nav-link" data-scroll-target="#reproducible-sql"><span class="header-section-number">4.4</span> Reproducible SQL</a></li>
<li><a href="#the-core-engine-cc_match_bio_env" id="toc-the-core-engine-cc_match_bio_env" class="nav-link" data-scroll-target="#the-core-engine-cc_match_bio_env"><span class="header-section-number">4.5</span> The core engine: <code>cc_match_bio_env()</code></a></li>
<li><a href="#parameters" id="toc-parameters" class="nav-link" data-scroll-target="#parameters"><span class="header-section-number">4.6</span> Parameters</a></li>
<li><a href="#migrating-from-the-api" id="toc-migrating-from-the-api" class="nav-link" data-scroll-target="#migrating-from-the-api"><span class="header-section-number">4.7</span> Migrating from the API</a></li>
</ul></li>
<li><a href="#api" id="toc-api" class="nav-link" data-scroll-target="#api"><span class="header-section-number">5</span> API</a>
<ul class="collapse">
<li><a href="#endpoint-replacement" id="toc-endpoint-replacement" class="nav-link" data-scroll-target="#endpoint-replacement"><span class="header-section-number">5.1</span> Endpoint → replacement</a></li>
<li><a href="#legacy-endpoint-reference" id="toc-legacy-endpoint-reference" class="nav-link" data-scroll-target="#legacy-endpoint-reference"><span class="header-section-number">5.2</span> Legacy endpoint reference</a>
<ul class="collapse">
<li><a href="#variables-get-list-of-variables-for-timeseries" id="toc-variables-get-list-of-variables-for-timeseries" class="nav-link" data-scroll-target="#variables-get-list-of-variables-for-timeseries"><span class="header-section-number">5.2.1</span> <code>/variables</code>: get list of variables for timeseries</a></li>
<li><a href="#species_groups-get-species-groups-for-larvae" id="toc-species_groups-get-species-groups-for-larvae" class="nav-link" data-scroll-target="#species_groups-get-species-groups-for-larvae"><span class="header-section-number">5.2.2</span> <code>/species_groups</code>: get species groups for larvae</a></li>
<li><a href="#timeseries-get-time-series-data" id="toc-timeseries-get-time-series-data" class="nav-link" data-scroll-target="#timeseries-get-time-series-data"><span class="header-section-number">5.2.3</span> <code>/timeseries</code>: get time series data</a></li>
<li><a href="#cruises-get-list-of-cruises" id="toc-cruises-get-list-of-cruises" class="nav-link" data-scroll-target="#cruises-get-list-of-cruises"><span class="header-section-number">5.2.4</span> <code>/cruises</code>: get list of cruises</a></li>
<li><a href="#raster-get-raster-map-of-variable" id="toc-raster-get-raster-map-of-variable" class="nav-link" data-scroll-target="#raster-get-raster-map-of-variable"><span class="header-section-number">5.2.5</span> <code>/raster</code>: get raster map of variable</a></li>
<li><a href="#cruise_lines-get-station-lines-from-cruises" id="toc-cruise_lines-get-station-lines-from-cruises" class="nav-link" data-scroll-target="#cruise_lines-get-station-lines-from-cruises"><span class="header-section-number">5.2.6</span> <code>/cruise_lines</code>: get station lines from cruises</a></li>
<li><a href="#cruise_line_profile" id="toc-cruise_line_profile" class="nav-link" data-scroll-target="#cruise_line_profile"><span class="header-section-number">5.2.7</span> <code>/cruise_line_profile</code></a></li>
</ul></li>
</ul></li>
</ul>
<div class="toc-actions"><ul><li><a href="https://github.com/CalCOFI/docs/edit/main/apps.qmd" class="toc-action"><i class="bi bi-github"></i>Edit this page</a></li></ul></div></nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title"><span class="chapter-number">3</span> <span class="chapter-title">Applications</span></h1>
</div>
<div class="quarto-title-meta">
</div>
</header>
<ul>
<li><a href="https://shiny.calcofi.io/oceano">CalCOFI Oceanography</a><br>
oceanographic summarization by arbitrary area of interest and sampling period</li>
<li><a href="https://shiny.calcofi.io/capstone">UCSB Student Capstone</a></li>
</ul>
<section id="matching-helpers" class="level1" data-number="4">
<h1 data-number="4"><span class="header-section-number">4</span> Matching Helpers</h1>
<p>The <a href="https://calcofi.io/calcofi4r"><code>calcofi4r</code></a> package provides helper functions that relate <strong>biological</strong> observations (net-tow ichthyoplankton or zooplankton biomass) to <strong>environmental</strong> observations (CTD-bottle measurements) by matching them in time and space — on the fly, against the public release <a href="./data-access.html">Parquet on GCS</a>.</p>
<p>These supersede the retired Postgres Plumber <a href="./api.html">API</a> endpoints <code>zooplankton_biomass</code>, <code>itis_ichthyodata</code> and <code>ichthyodata</code>, which depended on pre-built <code>uunet2ctd*</code> match tables that are no longer part of releases.</p>
<section id="install" class="level2" data-number="4.1">
<h2 data-number="4.1" class="anchored" data-anchor-id="install"><span class="header-section-number">4.1</span> Install</h2>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># remotes::install_github("calcofi/calcofi4r")</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(calcofi4r)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<p>The matching helpers need <code>calcofi4r</code> ≥ 1.2.0 and DuckDB with the <code>httpfs</code> and <code>spatial</code> extensions (the functions install/load these for you).</p>
</section>
<section id="the-wrappers" class="level2" data-number="4.2">
<h2 data-number="4.2" class="anchored" data-anchor-id="the-wrappers"><span class="header-section-number">4.2</span> The wrappers</h2>
<p>Three wrappers cover the common cases. Each builds the matching SQL, runs it, and returns a tibble of <strong>one row per biological observation</strong> with the matched environmental value:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">
</colgroup>
<thead>
<tr class="header">
<th>Function</th>
<th>Biological side</th>
<th>Replaces</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>cc_match_ichthyo_by_name()</code></td>
<td>ichthyoplankton, filtered by scientific name</td>
<td><code>/ichthyodata</code></td>
</tr>
<tr class="even">
<td><code>cc_match_ichthyo_by_taxon()</code></td>
<td>ichthyoplankton, filtered by a WoRMS taxon <strong>and all its descendants</strong></td>
<td><code>/itis_ichthyodata</code></td>
</tr>
<tr class="odd">
<td><code>cc_match_zooplankton_biomass()</code></td>
<td>net-tow displacement-volume biomass (<code>totalplankton</code> / <code>smallplankton</code>)</td>
<td><code>/zooplankton_biomass</code></td>
</tr>
</tbody>
</table>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co"># ichthyoplankton by scientific name</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> <span class="fu">cc_match_ichthyo_by_name</span>(</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"Sardinops sagax"</span>, <span class="at">env_var =</span> <span class="st">"temperature"</span>)</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="co"># every descendant of a WoRMS taxon (recursive parentNameUsageID walk)</span></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> <span class="fu">cc_match_ichthyo_by_taxon</span>(</span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a> <span class="at">worms_id =</span> <span class="dv">125620</span>, <span class="at">env_var =</span> <span class="st">"salinity"</span>) <span class="co"># 125620 = genus Engraulis</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a><span class="co"># zooplankton biomass</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> <span class="fu">cc_match_zooplankton_biomass</span>(</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a> <span class="at">env_var =</span> <span class="st">"temperature"</span>, <span class="at">biomass_type =</span> <span class="st">"totalplankton"</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</section>
<section id="worked-example-sardine-larvae-temperature" class="level2" data-number="4.3">
<h2 data-number="4.3" class="anchored" data-anchor-id="worked-example-sardine-larvae-temperature"><span class="header-section-number">4.3</span> Worked example: sardine larvae + temperature</h2>
<p>The recurring example through these pages — <em>Pacific sardine (<code>Sardinops sagax</code>) larvae matched to CTD-bottle temperature, Q1 2018, with relaxed (5 km / 72 hr) matching</em> — is a single call:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>d <span class="ot"><-</span> <span class="fu">cc_match_ichthyo_by_name</span>(</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="st">"Sardinops sagax"</span>,</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="at">env_var =</span> <span class="st">"temperature"</span>,</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="at">life_stage =</span> <span class="st">"larva"</span>,</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="at">date_min =</span> <span class="st">"2018-01-01"</span>,</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="at">date_max =</span> <span class="st">"2018-03-31"</span>,</span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="at">relax_matching =</span> <span class="cn">TRUE</span>)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>d[, <span class="fu">c</span>(<span class="st">"scientific_name"</span>, <span class="st">"life_stage"</span>, <span class="st">"bio_datetime"</span>,</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="st">"bio_value"</span>, <span class="st">"n_env"</span>, <span class="st">"env_value"</span>, <span class="st">"dist_km"</span>, <span class="st">"time_diff_hr"</span>)]</span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co">#> # A tibble: 13 × 8</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="co">#> scientific_name life_stage bio_datetime bio_value n_env env_value dist_km time_diff_hr</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a><span class="co">#> <chr> <chr> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl></span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a><span class="co">#> 1 Sardinops sagax larva 2018-02-05 00:44:00 116. 34 11.4 0.167 1.39</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a><span class="co">#> 2 Sardinops sagax larva 2018-02-05 06:03:00 17.8 30 10.5 0.225 1.21</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a><span class="co">#> 3 Sardinops sagax larva 2018-02-07 09:56:00 120. 33 10.4 … …</span></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a><span class="co">#> # … 10 more rows</span></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<p><code>bio_value</code> is the standardized larval tally; <code>env_value</code> is the matched mean temperature (°C); <code>n_env</code> is how many bottle measurements were averaged; <code>dist_km</code> / <code>time_diff_hr</code> are the realized match offsets (within the 5 km / 72 hr window). This returns the <strong>same 13 rows</strong> as the <a href="./data-access.html#sec-worked-example">direct SQL</a> and the <a href="https://calcofi.io/int-app">Interactive App</a> download bundle.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Note
</div>
</div>
<div class="callout-body-container callout-body">
<p>Q1 <strong>2018</strong>, not a more recent year: CTD-bottle environmental data in the current release ends 2021-05, while net-tow biological data runs later. Q1 2018 has ample overlap.</p>
</div>
</div>
</section>
<section id="reproducible-sql" class="level2" data-number="4.4">
<h2 data-number="4.4" class="anchored" data-anchor-id="reproducible-sql"><span class="header-section-number">4.4</span> Reproducible SQL</h2>
<p>Every helper attaches the <strong>exact, portable SQL</strong> that produced the result, plus query metadata, as attributes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span>(<span class="fu">attr</span>(d, <span class="st">"sql"</span>)) <span class="co"># the fully-interpolated, GCS-URL-based query</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="fu">str</span>(<span class="fu">attr</span>(d, <span class="st">"query_meta"</span>)) <span class="co"># package + release version, params, source URLs</span></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<p><code>attr(d, "sql")</code> is character-for-character the query shown on the <a href="./data-access.html#sec-worked-example">Data Access</a> page — copy-paste it into the DuckDB CLI, Python, or a colleague’s R session and it returns identical rows. That is the contract behind the <a href="https://calcofi.io/int-app">Interactive App</a> download bundle’s <code>query/</code> folder.</p>
<p>To get the SQL <strong>without running it</strong> — e.g. to serialize or inspect it — pass <code>return_sql = TRUE</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>sql <span class="ot"><-</span> <span class="fu">cc_match_ichthyo_by_name</span>(<span class="st">"Sardinops sagax"</span>, <span class="at">return_sql =</span> <span class="cn">TRUE</span>)</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span>(sql)</span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
</section>
<section id="the-core-engine-cc_match_bio_env" class="level2" data-number="4.5">
<h2 data-number="4.5" class="anchored" data-anchor-id="the-core-engine-cc_match_bio_env"><span class="header-section-number">4.5</span> The core engine: <code>cc_match_bio_env()</code></h2>
<p>The wrappers are thin shells over <code>cc_match_bio_env()</code>, which takes a <code>bio</code> and an <code>env</code> SQL <code>SELECT</code> string and performs the match. Call it directly when you need a biological or environmental side the wrappers don’t cover (custom filters, a different grouping, joining <code>bottle</code> to <code>cast_condition</code>, …):</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cc_match_bio_env</span>(</span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> bio, env, <span class="co"># SELECT strings (see contract below)</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="at">max_dist_km =</span> <span class="dv">2</span>, <span class="at">max_time_hr =</span> <span class="dv">6</span>, <span class="co"># match tolerances</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> <span class="at">join_method =</span> <span class="st">"nearest_time"</span>, <span class="co"># or "nearest_dist", "average"</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="at">version =</span> <span class="st">"latest"</span>,</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="at">collect =</span> <span class="cn">TRUE</span>, <span class="co"># FALSE → lazy dplyr::tbl</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="at">return_sql =</span> <span class="cn">FALSE</span>) <span class="co"># TRUE → just the SQL string</span></span></code></pre></div><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></div>
<p><strong>Contract.</strong> <code>bio</code> must yield <code>bio_id</code>, <code>bio_datetime</code>, <code>bio_lon</code>, <code>bio_lat</code>, <code>bio_value</code> (plus any descriptive columns, carried through as grouping keys). <code>env</code> must yield exactly <code>env_id</code>, <code>env_datetime</code>, <code>env_lon</code>, <code>env_lat</code>, <code>env_value</code>, <code>env_depth_m</code>, <code>measurement_type</code>. Both typically <code>FROM read_parquet('https://…/{table}.parquet')</code> so the emitted SQL stays portable.</p>
</section>
<section id="parameters" class="level2" data-number="4.6">
<h2 data-number="4.6" class="anchored" data-anchor-id="parameters"><span class="header-section-number">4.6</span> Parameters</h2>
<ul>
<li><strong><code>max_dist_km</code>, <code>max_time_hr</code></strong> — the spatial and temporal match windows. Defaults are 2 km / 6 hr; <code>relax_matching = TRUE</code> widens them to 5 km / 72 hr (an explicit value always wins). This replaces the old API’s <code>relax_matching</code> boolean.</li>
<li><strong><code>join_method</code></strong> — how the environmental observations inside the window are reduced to one value per biological observation:
<ul>
<li><code>"nearest_time"</code> (default) — keep the closest in time, average ties;</li>
<li><code>"nearest_dist"</code> — keep the closest in space, average ties;</li>
<li><code>"average"</code> — average every observation in the window.</li>
</ul>
CalCOFI co-locates net tows and CTD casts, so in practice <code>nearest_time</code> and <code>nearest_dist</code> usually agree and <code>average</code> differs only slightly.</li>
<li><strong><code>life_stage</code></strong> (ichthyo wrappers) — restrict to e.g. <code>"larva"</code> or <code>"egg"</code>.</li>
<li><strong><code>date_min</code>, <code>date_max</code></strong> — bound the biological side by tow start date.</li>
<li><strong><code>depth_m_min</code>, <code>depth_m_max</code></strong> — bound the environmental bottle depths.</li>
<li><strong><code>version</code></strong> — a release string like <code>"v2026.05.14"</code>, or <code>"latest"</code>.</li>
</ul>
</section>
<section id="migrating-from-the-api" class="level2" data-number="4.7">
<h2 data-number="4.7" class="anchored" data-anchor-id="migrating-from-the-api"><span class="header-section-number">4.7</span> Migrating from the API</h2>
<table class="caption-top table">
<colgroup>
<col style="width: 50%">
<col style="width: 50%">
</colgroup>
<thead>
<tr class="header">
<th>Old API</th>
<th>New helper</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>/ichthyodata</code> (<code>species</code>, <code>exact_match</code>)</td>
<td><code>cc_match_ichthyo_by_name(scientific_name, exact_match=)</code></td>
</tr>
<tr class="even">
<td><code>/itis_ichthyodata</code> (<code>ITISid</code>)</td>
<td><code>cc_match_ichthyo_by_taxon(worms_id)</code> — WoRMS, recursive subtree</td>
</tr>
<tr class="odd">
<td><code>/zooplankton_biomass</code></td>
<td><code>cc_match_zooplankton_biomass()</code></td>
</tr>
<tr class="even">
<td><code>relax_matching = TRUE</code></td>
<td><code>relax_matching = TRUE</code> (5 km / 72 hr) or explicit <code>max_dist_km</code> / <code>max_time_hr</code></td>
</tr>
<tr class="odd">
<td><code>cruiseymd_min</code> / <code>cruiseymd_max</code></td>
<td><code>date_min</code> / <code>date_max</code></td>
</tr>
<tr class="even">
<td><code>stage</code></td>
<td><code>life_stage</code></td>
</tr>
</tbody>
</table>
<p>The taxon wrapper is the one real change: ITIS <code>path</code>-regex matching is gone; descendants are now resolved by a recursive walk of WoRMS <code>taxon.parentNameUsageID</code> against the release <code>taxon</code> table.</p>
</section>
</section>
<section id="api" class="level1" data-number="5">
<h1 data-number="5"><span class="header-section-number">5</span> API</h1>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Important</span>Superseded by direct querying + <code>calcofi4r</code> helpers
</div>
</div>
<div class="callout-body-container callout-body">
<p>The Postgres-backed Plumber API at <a href="https://api.calcofi.io">api.calcofi.io</a> is <strong>being phased out</strong>. CalCOFI data is now published as versioned, public <strong>Parquet</strong> files that you query directly with DuckDB — no API server, no credentials, no rate limits.</p>
<ul>
<li>To query the data directly (SQL, R, Python), see <strong><a href="./data-access.html">Data Access</a></strong>.</li>
<li>For biological ↔︎ environmental matching (the old <code>zooplankton_biomass</code>, <code>itis_ichthyodata</code> and <code>ichthyodata</code> endpoints), see <strong><a href="./helpers.html">Matching Helpers</a></strong> — the <code>calcofi4r</code> functions <code>cc_match_zooplankton_biomass()</code>, <code>cc_match_ichthyo_by_taxon()</code> and <code>cc_match_ichthyo_by_name()</code>.</li>
</ul>
<p>The endpoint notes below are retained as a historical reference and a map from each API endpoint to its replacement.</p>
</div>
</div>
<p>The raw interface to the legacy Application Programming Interface (API) is available at:</p>
<ul>
<li><a href="https://api.calcofi.io">api.calcofi.io</a></li>
</ul>
<section id="endpoint-replacement" class="level2" data-number="5.1">
<h2 data-number="5.1" class="anchored" data-anchor-id="endpoint-replacement"><span class="header-section-number">5.1</span> Endpoint → replacement</h2>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Legacy endpoint</th>
<th>Replacement</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>/variables</code></td>
<td><code>calcofi4r::cc_list_measurement_types()</code></td>
</tr>
<tr class="even">
<td><code>/timeseries</code></td>
<td>direct SQL aggregation — see <a href="./data-access.html">Data Access</a></td>
</tr>
<tr class="odd">
<td><code>/cruises</code></td>
<td><code>calcofi4r::cc_read_cruise()</code></td>
</tr>
<tr class="even">
<td><code>/raster</code></td>
<td>direct SQL + <code>calcofi4r::pts_to_rast_idw()</code></td>
</tr>
<tr class="odd">
<td><code>/cruise_lines</code>, <code>/cruise_line_profile</code></td>
<td>direct SQL against <code>ctd_cast</code> / <code>ctd_thin</code></td>
</tr>
<tr class="even">
<td><code>zooplankton_biomass</code></td>
<td><code>calcofi4r::cc_match_zooplankton_biomass()</code> (<a href="./helpers.html">Matching Helpers</a>)</td>
</tr>
<tr class="odd">
<td><code>itis_ichthyodata</code></td>
<td><code>calcofi4r::cc_match_ichthyo_by_taxon()</code> (<a href="./helpers.html">Matching Helpers</a>)</td>
</tr>
<tr class="even">
<td><code>ichthyodata</code></td>
<td><code>calcofi4r::cc_match_ichthyo_by_name()</code> (<a href="./helpers.html">Matching Helpers</a>)</td>
</tr>
</tbody>
</table>
</section>
<section id="legacy-endpoint-reference" class="level2" data-number="5.2">
<h2 data-number="5.2" class="anchored" data-anchor-id="legacy-endpoint-reference"><span class="header-section-number">5.2</span> Legacy endpoint reference</h2>
<section id="variables-get-list-of-variables-for-timeseries" class="level3" data-number="5.2.1">
<h3 data-number="5.2.1" class="anchored" data-anchor-id="variables-get-list-of-variables-for-timeseries"><span class="header-section-number">5.2.1</span> <code>/variables</code>: get list of variables for timeseries</h3>
<p>Get list of variables for use in <code>/timeseries</code>.</p>
</section>
<section id="species_groups-get-species-groups-for-larvae" class="level3" data-number="5.2.2">
<h3 data-number="5.2.2" class="anchored" data-anchor-id="species_groups-get-species-groups-for-larvae"><span class="header-section-number">5.2.2</span> <code>/species_groups</code>: get species groups for larvae</h3>
<p>Not yet working. Get list of species groups for use with variables <code>larvae_counts.count</code> in <code>/timeseries</code>.</p>
</section>
<section id="timeseries-get-time-series-data" class="level3" data-number="5.2.3">
<h3 data-number="5.2.3" class="anchored" data-anchor-id="timeseries-get-time-series-data"><span class="header-section-number">5.2.3</span> <code>/timeseries</code>: get time series data</h3>
</section>
<section id="cruises-get-list-of-cruises" class="level3" data-number="5.2.4">
<h3 data-number="5.2.4" class="anchored" data-anchor-id="cruises-get-list-of-cruises"><span class="header-section-number">5.2.4</span> <code>/cruises</code>: get list of cruises</h3>
<p>Get list of cruises with summary stats as CSV table for time (<code>date_beg</code>).</p>
</section>
<section id="raster-get-raster-map-of-variable" class="level3" data-number="5.2.5">
<h3 data-number="5.2.5" class="anchored" data-anchor-id="raster-get-raster-map-of-variable"><span class="header-section-number">5.2.5</span> <code>/raster</code>: get raster map of variable</h3>
<p>Get raster of variable.</p>
</section>
<section id="cruise_lines-get-station-lines-from-cruises" class="level3" data-number="5.2.6">
<h3 data-number="5.2.6" class="anchored" data-anchor-id="cruise_lines-get-station-lines-from-cruises"><span class="header-section-number">5.2.6</span> <code>/cruise_lines</code>: get station lines from cruises</h3>
<p>Get station lines from cruises (with more than one cast).</p>
</section>
<section id="cruise_line_profile" class="level3" data-number="5.2.7">
<h3 data-number="5.2.7" class="anchored" data-anchor-id="cruise_line_profile"><span class="header-section-number">5.2.7</span> <code>/cruise_line_profile</code></h3>
<p>Get profile at depths for given variable of casts along line of stations.</p>
</section>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const onCopySuccess = function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
}
const getTextToCopy = function(trigger) {
const outerScaffold = trigger.parentElement.cloneNode(true);
const codeEl = outerScaffold.querySelector('code');
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
text: getTextToCopy
});
clipboard.on('success', onCopySuccess);
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
text: getTextToCopy,
container: window.document.getElementById('quarto-embedded-source-code-modal')
});
clipboardModal.on('success', onCopySuccess);
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var mailtoRegex = new RegExp(/^mailto:/);
var filterRegex = new RegExp("https:\/\/calcofi\.io\/docs\/");
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// undo the damage that might have been done by quarto-nav.js in the case of
// links that we want to consider external
if (link.dataset.originalHref !== undefined) {
link.href = link.dataset.originalHref;
}
}
}
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
const config = {
allowHTML: true,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start',
};
if (contentFn) {
config.content = contentFn;
}
if (onTriggerFn) {
config.onTrigger = onTriggerFn;
}
if (onUntriggerFn) {
config.onUntrigger = onUntriggerFn;
}
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note) {
return note.innerHTML;
} else {
return "";
}
});
}
const xrefs = window.document.querySelectorAll('a.quarto-xref');
const processXRef = (id, note) => {
// Strip column container classes
const stripColumnClz = (el) => {
el.classList.remove("page-full", "page-columns");
if (el.children) {
for (const child of el.children) {
stripColumnClz(child);
}
}
}
stripColumnClz(note)
if (id === null || id.startsWith('sec-')) {
// Special case sections, only their first couple elements
const container = document.createElement("div");
if (note.children && note.children.length > 2) {
container.appendChild(note.children[0].cloneNode(true));
for (let i = 1; i < note.children.length; i++) {
const child = note.children[i];
if (child.tagName === "P" && child.innerText === "") {
continue;
} else {
container.appendChild(child.cloneNode(true));
break;
}
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(container);
}
return container.innerHTML
} else {
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
return note.innerHTML;
}
} else {
// Remove any anchor links if they are present
const anchorLink = note.querySelector('a.anchorjs-link');
if (anchorLink) {
anchorLink.remove();
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
if (note.classList.contains("callout")) {
return note.outerHTML;
} else {
return note.innerHTML;
}
}
}
for (var i=0; i<xrefs.length; i++) {
const xref = xrefs[i];
tippyHover(xref, undefined, function(instance) {
instance.disable();
let url = xref.getAttribute('href');
let hash = undefined;
if (url.startsWith('#')) {
hash = url;
} else {
try { hash = new URL(url).hash; } catch {}
}
if (hash) {
const id = hash.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note !== null) {
try {
const html = processXRef(id, note.cloneNode(true));
instance.setContent(html);
} finally {
instance.enable();
instance.show();
}
} else {
// See if we can fetch this
fetch(url.split('#')[0])
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.getElementById(id);
if (note !== null) {
const html = processXRef(id, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
} else {
// See if we can fetch a full url (with no hash to target)
// This is a special case and we should probably do some content thinning / targeting
fetch(url)
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.querySelector('main.content');
if (note !== null) {
// This should only happen for chapter cross references
// (since there is no id in the URL)
// remove the first header
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
note.children[0].remove();
}
const html = processXRef(null, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
}, function(instance) {
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
div.style.left = 0;
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
elRect = undefined;
if (selectedAnnoteEl) {
selectCodeLines(selectedAnnoteEl);
}
}, 10)
);
function throttle(fn, ms) {
let throttle = false;
let timer;
return (...args) => {
if(!throttle) { // first call gets through
fn.apply(this, args);
throttle = true;
} else { // all the others get throttled
if(timer) clearTimeout(timer); // cancel #2
timer = setTimeout(() => {
fn.apply(this, args);
timer = throttle = false;
}, ms);
}
};
}
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');