Skip to content

Commit 0997d08

Browse files
authored
New variables for CTD_BGC (#201)
The CTD_BGC instrument now supports measurements of additional variables: nutrients (nitrate, phosphate), pH, phytoplankton, zooplankton and primary production (on top of the pre-existing o2 and chlorophyll variables).
1 parent 6d915c7 commit 0997d08

13 files changed

Lines changed: 186 additions & 9 deletions

File tree

src/virtualship/cli/_fetch.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,37 @@ def _fetch(path: str | Path, username: str | None, password: str | None) -> None
248248
"chlorodata": {
249249
"dataset_id": "cmems_mod_glo_bgc-pft_anfc_0.25deg_P1D-m",
250250
"variables": ["chl"],
251-
"output_filename": "ctd_bgc_chloro.nc",
251+
"output_filename": "ctd_bgc_chl.nc",
252+
},
253+
"nitratedata": {
254+
"dataset_id": "cmems_mod_glo_bgc-nut_anfc_0.25deg_P1D-m",
255+
"variables": ["no3"],
256+
"output_filename": "ctd_bgc_no3.nc",
257+
},
258+
"phosphatedata": {
259+
"dataset_id": "cmems_mod_glo_bgc-nut_anfc_0.25deg_P1D-m",
260+
"variables": ["po4"],
261+
"output_filename": "ctd_bgc_po4.nc",
262+
},
263+
"phdata": {
264+
"dataset_id": "cmems_mod_glo_bgc-car_anfc_0.25deg_P1D-m",
265+
"variables": ["ph"],
266+
"output_filename": "ctd_bgc_ph.nc",
267+
},
268+
"phytoplanktondata": {
269+
"dataset_id": "cmems_mod_glo_bgc-pft_anfc_0.25deg_P1D-m",
270+
"variables": ["phyc"],
271+
"output_filename": "ctd_bgc_phyc.nc",
272+
},
273+
"zooplanktondata": {
274+
"dataset_id": "cmems_mod_glo_bgc-plankton_anfc_0.25deg_P1D-m",
275+
"variables": ["zooc"],
276+
"output_filename": "ctd_bgc_zooc.nc",
277+
},
278+
"primaryproductiondata": {
279+
"dataset_id": "cmems_mod_glo_bgc-bio_anfc_0.25deg_P1D-m",
280+
"variables": ["nppv"],
281+
"output_filename": "ctd_bgc_nppv.nc",
252282
},
253283
}
254284

src/virtualship/expedition/input_data.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,26 @@ def _load_ctd_bgc_fieldset(cls, directory: Path) -> FieldSet:
137137
"U": directory.joinpath("ship_uv.nc"),
138138
"V": directory.joinpath("ship_uv.nc"),
139139
"o2": directory.joinpath("ctd_bgc_o2.nc"),
140-
"chl": directory.joinpath("ctd_bgc_chloro.nc"),
140+
"chl": directory.joinpath("ctd_bgc_chl.nc"),
141+
"no3": directory.joinpath("ctd_bgc_no3.nc"),
142+
"po4": directory.joinpath("ctd_bgc_po4.nc"),
143+
"ph": directory.joinpath("ctd_bgc_ph.nc"),
144+
"phyc": directory.joinpath("ctd_bgc_phyc.nc"),
145+
"zooc": directory.joinpath("ctd_bgc_zooc.nc"),
146+
"nppv": directory.joinpath("ctd_bgc_nppv.nc"),
147+
}
148+
variables = {
149+
"U": "uo",
150+
"V": "vo",
151+
"o2": "o2",
152+
"chl": "chl",
153+
"no3": "no3",
154+
"po4": "po4",
155+
"ph": "ph",
156+
"phyc": "phyc",
157+
"zooc": "zooc",
158+
"nppv": "nppv",
141159
}
142-
variables = {"U": "uo", "V": "vo", "o2": "o2", "chl": "chl"}
143160
dimensions = {
144161
"lon": "longitude",
145162
"lat": "latitude",
@@ -152,6 +169,12 @@ def _load_ctd_bgc_fieldset(cls, directory: Path) -> FieldSet:
152169
)
153170
fieldset.o2.interp_method = "linear_invdist_land_tracer"
154171
fieldset.chl.interp_method = "linear_invdist_land_tracer"
172+
fieldset.no3.interp_method = "linear_invdist_land_tracer"
173+
fieldset.po4.interp_method = "linear_invdist_land_tracer"
174+
fieldset.ph.interp_method = "linear_invdist_land_tracer"
175+
fieldset.phyc.interp_method = "linear_invdist_land_tracer"
176+
fieldset.zooc.interp_method = "linear_invdist_land_tracer"
177+
fieldset.nppv.interp_method = "linear_invdist_land_tracer"
155178

156179
# make depth negative
157180
for g in fieldset.gridset.grids:

src/virtualship/instruments/ctd_bgc.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class CTD_BGC:
2323
[
2424
Variable("o2", dtype=np.float32, initial=np.nan),
2525
Variable("chl", dtype=np.float32, initial=np.nan),
26+
Variable("no3", dtype=np.float32, initial=np.nan),
27+
Variable("po4", dtype=np.float32, initial=np.nan),
28+
Variable("ph", dtype=np.float32, initial=np.nan),
29+
Variable("phyc", dtype=np.float32, initial=np.nan),
30+
Variable("zooc", dtype=np.float32, initial=np.nan),
31+
Variable("nppv", dtype=np.float32, initial=np.nan),
2632
Variable("raising", dtype=np.int8, initial=0.0), # bool. 0 is False, 1 is True.
2733
Variable("max_depth", dtype=np.float32),
2834
Variable("min_depth", dtype=np.float32),
@@ -39,6 +45,30 @@ def _sample_chlorophyll(particle, fieldset, time):
3945
particle.chl = fieldset.chl[time, particle.depth, particle.lat, particle.lon]
4046

4147

48+
def _sample_nitrate(particle, fieldset, time):
49+
particle.no3 = fieldset.no3[time, particle.depth, particle.lat, particle.lon]
50+
51+
52+
def _sample_phosphate(particle, fieldset, time):
53+
particle.po4 = fieldset.po4[time, particle.depth, particle.lat, particle.lon]
54+
55+
56+
def _sample_ph(particle, fieldset, time):
57+
particle.ph = fieldset.ph[time, particle.depth, particle.lat, particle.lon]
58+
59+
60+
def _sample_phytoplankton(particle, fieldset, time):
61+
particle.phyc = fieldset.phyc[time, particle.depth, particle.lat, particle.lon]
62+
63+
64+
def _sample_zooplankton(particle, fieldset, time):
65+
particle.zooc = fieldset.zooc[time, particle.depth, particle.lat, particle.lon]
66+
67+
68+
def _sample_primary_production(particle, fieldset, time):
69+
particle.nppv = fieldset.nppv[time, particle.depth, particle.lat, particle.lon]
70+
71+
4272
def _ctd_bgc_cast(particle, fieldset, time):
4373
# lowering
4474
if particle.raising == 0:
@@ -129,7 +159,17 @@ def simulate_ctd_bgc(
129159

130160
# execute simulation
131161
ctd_bgc_particleset.execute(
132-
[_sample_o2, _sample_chlorophyll, _ctd_bgc_cast],
162+
[
163+
_sample_o2,
164+
_sample_chlorophyll,
165+
_sample_nitrate,
166+
_sample_phosphate,
167+
_sample_ph,
168+
_sample_phytoplankton,
169+
_sample_zooplankton,
170+
_sample_primary_production,
171+
_ctd_bgc_cast,
172+
],
133173
endtime=fieldset_endtime,
134174
dt=DT,
135175
verbose_progress=False,

tests/expedition/expedition_dir/input_data/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
!ship_uv.nc
88
!drifter_t.nc
99
!drifter_uv.nc
10+
!ctd_bgc_*.nc

tests/expedition/expedition_dir/input_data/ctd_bgc_chloro.nc renamed to tests/expedition/expedition_dir/input_data/ctd_bgc_chl.nc

22.8 KB
Binary file not shown.
22.8 KB
Binary file not shown.
22.9 KB
Binary file not shown.
51 Bytes
Binary file not shown.
22.7 KB
Binary file not shown.
22.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)