Skip to content

Commit da86613

Browse files
committed
Revert "move to positive down API throughout virtualship"
This reverts commit 003f79f.
1 parent 003f79f commit da86613

10 files changed

Lines changed: 42 additions & 42 deletions

File tree

src/virtualship/instruments/adcp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ def simulate(self, measurements, out_path) -> None:
8282
self.expedition.instruments_config.adcp_config.max_depth_meter
8383
)
8484

85-
if config_max_depth > 1600.0:
85+
if config_max_depth < -1600.0:
8686
print(
8787
f"\n\n⚠️ Warning: The configured ADCP max depth of {abs(config_max_depth)} m exceeds the 1600 m limit for the technology (e.g. https://www.geomar.de/en/research/fb1/fb1-po/observing-systems/adcp)."
8888
"\n\n This expedition will continue using the prescribed configuration. However, note, the results will not necessarily represent authentic ADCP instrument readings and could also lead to slower simulations ."
8989
"\n\n If this was unintented, consider re-adjusting your ADCP configuration in your expedition.yaml or via `virtualship plan`.\n\n"
9090
)
9191

9292
MAX_DEPTH = config_max_depth
93-
MIN_DEPTH = 5.0
93+
MIN_DEPTH = -5.0
9494
NUM_BINS = self.expedition.instruments_config.adcp_config.num_bins
9595

9696
measurements.sort(key=lambda p: p.time)

src/virtualship/instruments/argo_float.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _check_error(particles, fieldset):
162162
def _argo_sample_temperature(particles, fieldset):
163163
# Phase 3: ascending — sample temperature; NaN otherwise
164164
phase_mask = particles.cycle_phase == 3
165-
depth_mask = particles.z > particles.min_depth
165+
depth_mask = particles.z < particles.min_depth
166166
sampling_particles = particles[np.logical_and(phase_mask, depth_mask)]
167167
sampling_particles.temperature = fieldset.T[
168168
sampling_particles.time,
@@ -175,7 +175,7 @@ def _argo_sample_temperature(particles, fieldset):
175175
def _argo_sample_salinity(particles, fieldset):
176176
# Phase 3: ascending — sample salinity; NaN otherwise
177177
phase_mask = particles.cycle_phase == 3
178-
depth_mask = particles.z > particles.min_depth
178+
depth_mask = particles.z < particles.min_depth
179179
sampling_particles = particles[np.logical_and(phase_mask, depth_mask)]
180180
sampling_particles.salinity = fieldset.S[
181181
sampling_particles.time,

src/virtualship/instruments/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def load_input_data(self) -> parcels.FieldSet:
104104
# bathymetry data
105105
if self.add_bathymetry:
106106
bathymetry_field = _get_bathy_data(from_data=self.from_data).bathymetry
107+
bathymetry_field.data = -bathymetry_field.data
107108
fieldset.add_field(bathymetry_field)
108109

109110
return fieldset

src/virtualship/instruments/ctd.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ def _ctd_cast(particles, fieldset):
118118
particles_raising = particles[particles.raising == 1]
119119

120120
# lowering
121-
particles_lowering.dz += particles_lowering.winch_speed * particles_lowering.dt
121+
particles_lowering.dz += -particles_lowering.winch_speed * particles_lowering.dt
122122
particles_lowering.raising = np.where(
123-
particles_lowering.z + particles_lowering.dz > particles_lowering.max_depth,
123+
particles_lowering.z + particles_lowering.dz < particles_lowering.max_depth,
124124
1,
125125
particles_lowering.raising,
126126
)
127127

128128
# raising
129-
particles_raising.dz += -particles_raising.winch_speed * particles_raising.dt
129+
particles_raising.dz += particles_raising.winch_speed * particles_raising.dt
130130
particles_raising.state = np.where(
131-
particles_raising.z + particles_raising.dz < particles_raising.min_depth,
131+
particles_raising.z + particles_raising.dz > particles_raising.min_depth,
132132
StatusCode.Delete,
133133
particles_raising.state,
134134
)
@@ -209,10 +209,9 @@ def simulate(self, measurements, out_path) -> None:
209209

210210
# CTD depth can not be too shallow, because kernel would break.
211211
# This shallow is not useful anyway, no need to support.
212-
# TODO: should make this say which CTD(s) are the issue, and which max depth(s) are the issue, to make it easier for users to fix
213-
if not all([max_depth >= DT * WINCH_SPEED for max_depth in max_depths]):
212+
if not all([max_depth <= -DT * WINCH_SPEED for max_depth in max_depths]):
214213
raise ValueError(
215-
f"CTD max_depth or bathymetry shallower than maximum {DT * WINCH_SPEED}"
214+
f"CTD max_depth or bathymetry shallower than maximum {-DT * WINCH_SPEED}"
216215
)
217216

218217
# build dynamic particle class from the active sensors

src/virtualship/instruments/ship_underwater_st.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(self, expedition, from_data):
8888

8989
def simulate(self, measurements, out_path) -> None:
9090
"""Simulate underway salinity and temperature measurements."""
91-
DEPTH = 2.0
91+
DEPTH = -2.0
9292

9393
measurements.sort(key=lambda p: p.time)
9494

src/virtualship/instruments/xbt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _sample_temperature(particles, fieldset):
5858

5959

6060
def _xbt_cast(particles, fieldset):
61-
particles.dz = particles.fall_speed * particles.dt
61+
particles.dz = -particles.fall_speed * particles.dt
6262

6363
# update the fall speed from the quadractic fall-rate equation
6464
# check https://doi.org/10.5194/os-7-231-2011
@@ -73,9 +73,9 @@ def _xbt_cast(particles, fieldset):
7373

7474
# set particle depth to max depth if it's too deep
7575
particles.dz = np.where(
76-
particles.z + particles.dz > particles.max_depth,
76+
particles.z + particles.dz < particles.max_depth,
7777
particles.max_depth - particles.z,
78-
particles.dz,
78+
particles.z,
7979
)
8080

8181

src/virtualship/models/expedition.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ class ArgoFloatConfig(_InstrumentConfigMixin, pydantic.BaseModel):
255255
_instrument_type: ClassVar[InstrumentType] = InstrumentType.ARGO_FLOAT
256256
_instrument_name: ClassVar[str] = "ArgoFloat"
257257

258-
min_depth_meter: float = pydantic.Field(ge=0.0)
259-
max_depth_meter: float = pydantic.Field(ge=0.0)
260-
drift_depth_meter: float = pydantic.Field(ge=0.0)
261-
vertical_speed_meter_per_second: float = pydantic.Field(gt=0.0)
258+
min_depth_meter: float = pydantic.Field(le=0.0)
259+
max_depth_meter: float = pydantic.Field(le=0.0)
260+
drift_depth_meter: float = pydantic.Field(le=0.0)
261+
vertical_speed_meter_per_second: float = pydantic.Field(lt=0.0)
262262
cycle_days: float = pydantic.Field(gt=0.0)
263263
drift_days: float = pydantic.Field(gt=0.0)
264264
lifetime: timedelta = pydantic.Field(
@@ -302,7 +302,7 @@ class ADCPConfig(_InstrumentConfigMixin, pydantic.BaseModel):
302302
_instrument_type: ClassVar[InstrumentType] = InstrumentType.ADCP
303303
_instrument_name: ClassVar[str] = "ADCP"
304304

305-
max_depth_meter: float = pydantic.Field(ge=0.0)
305+
max_depth_meter: float = pydantic.Field(le=0.0)
306306
num_bins: int = pydantic.Field(gt=0.0)
307307
period: timedelta = pydantic.Field(
308308
serialization_alias="period_minutes",
@@ -346,8 +346,8 @@ class CTDConfig(_InstrumentConfigMixin, pydantic.BaseModel):
346346
validation_alias="stationkeeping_time_minutes",
347347
gt=timedelta(),
348348
)
349-
min_depth_meter: float = pydantic.Field(ge=0.0)
350-
max_depth_meter: float = pydantic.Field(ge=0.0)
349+
min_depth_meter: float = pydantic.Field(le=0.0)
350+
max_depth_meter: float = pydantic.Field(le=0.0)
351351

352352
sensors: list[SensorConfig] = pydantic.Field(
353353
default_factory=lambda: [
@@ -402,7 +402,7 @@ class DrifterConfig(_InstrumentConfigMixin, pydantic.BaseModel):
402402
_instrument_type: ClassVar[InstrumentType] = InstrumentType.DRIFTER
403403
_instrument_name: ClassVar[str] = "Drifter"
404404

405-
depth_meter: float = pydantic.Field(ge=0.0)
405+
depth_meter: float = pydantic.Field(le=0.0)
406406
lifetime: timedelta = pydantic.Field(
407407
serialization_alias="lifetime_days",
408408
validation_alias="lifetime_days",
@@ -429,8 +429,8 @@ class XBTConfig(_InstrumentConfigMixin, pydantic.BaseModel):
429429
_instrument_type: ClassVar[InstrumentType] = InstrumentType.XBT
430430
_instrument_name: ClassVar[str] = "XBT"
431431

432-
min_depth_meter: float = pydantic.Field(ge=0.0)
433-
max_depth_meter: float = pydantic.Field(ge=0.0)
432+
min_depth_meter: float = pydantic.Field(le=0.0)
433+
max_depth_meter: float = pydantic.Field(le=0.0)
434434
fall_speed_meter_per_second: float = pydantic.Field(gt=0.0)
435435
deceleration_coefficient: float = pydantic.Field(gt=0.0)
436436

src/virtualship/static/expedition.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ schedule:
3434
instruments_config:
3535
adcp_config:
3636
num_bins: 40
37-
max_depth_meter: 1000.0
37+
max_depth_meter: -1000.0
3838
period_minutes: 5.0
3939
sensors:
4040
- VELOCITY
4141
argo_float_config:
4242
cycle_days: 10.0
4343
drift_days: 9.0
44-
drift_depth_meter: 1000.0
45-
max_depth_meter: 2000.0
44+
drift_depth_meter: -1000.0
45+
max_depth_meter: -2000.0
4646
min_depth_meter: 0.0
47-
vertical_speed_meter_per_second: 0.1
47+
vertical_speed_meter_per_second: -0.1
4848
stationkeeping_time_minutes: 20.0
4949
lifetime_days: 63.0
5050
sensors:
5151
- TEMPERATURE
5252
- SALINITY
5353
ctd_config:
54-
max_depth_meter: 2000.0
55-
min_depth_meter: 11.0
54+
max_depth_meter: -2000.0
55+
min_depth_meter: -11.0
5656
stationkeeping_time_minutes: 50.0
5757
sensors:
5858
- TEMPERATURE
@@ -65,14 +65,14 @@ instruments_config:
6565
- PHYTOPLANKTON
6666
- PRIMARY_PRODUCTION
6767
drifter_config:
68-
depth_meter: 1.0
68+
depth_meter: -1.0
6969
lifetime_days: 42.0
7070
stationkeeping_time_minutes: 20.0
7171
sensors:
7272
- TEMPERATURE
7373
xbt_config:
74-
max_depth_meter: 285.0
75-
min_depth_meter: 2.0
74+
max_depth_meter: -285.0
75+
min_depth_meter: -2.0
7676
fall_speed_meter_per_second: 6.7
7777
deceleration_coefficient: 0.00225
7878
sensors:

src/virtualship/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def _find_files_in_timerange(
563563
def _compute_max_depths(measurements, fieldset) -> list[float]:
564564
"""Compute the effective max depth for each measurement, capped by bathymetry."""
565565
return [
566-
min( # min because depth is positive down
566+
max(
567567
m.max_depth,
568568
fieldset.bathymetry.eval(
569569
z=0,

tests/expedition/expedition_dir/expedition.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ schedule:
2222
instruments_config:
2323
adcp_config:
2424
num_bins: 40
25-
max_depth_meter: 1000.0
25+
max_depth_meter: -1000.0
2626
period_minutes: 5.0
2727
argo_float_config:
2828
cycle_days: 10.0
2929
drift_days: 9.0
30-
drift_depth_meter: 1000.0
31-
max_depth_meter: 2000.0
30+
drift_depth_meter: -1000.0
31+
max_depth_meter: -2000.0
3232
min_depth_meter: 0.0
33-
vertical_speed_meter_per_second: 0.1
33+
vertical_speed_meter_per_second: -0.1
3434
stationkeeping_time_minutes: 20.0
3535
lifetime_days: 63.0
3636
ctd_config:
37-
max_depth_meter: 2000.0
38-
min_depth_meter: 11.0
37+
max_depth_meter: -2000.0
38+
min_depth_meter: -11.0
3939
stationkeeping_time_minutes: 50.0
4040
drifter_config:
41-
depth_meter: 1.0
41+
depth_meter: -1.0
4242
lifetime_days: 28.0
4343
stationkeeping_time_minutes: 20.0
4444
ship_underwater_st_config:

0 commit comments

Comments
 (0)