Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/virtualship/instruments/argo_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ def simulate(self, measurements, out_path) -> None:
drift_days=[argo.drift_days for argo in measurements],
)

# add initial conditions to sampling variables
self._sample_initial(
argo_float_particleset, fieldset, argo_float_config.sensors
)

# define output file for the simulation
out_file = ParticleFile(
path=out_path,
Expand Down
20 changes: 20 additions & 0 deletions src/virtualship/instruments/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ def execute(self, measurements: list, out_path: str | Path) -> None:
self.simulate(measurements, out_path)
print("\n")

def _sample_initial(
self,
pset: parcels.ParticleSet,
fieldset: parcels.FieldSet,
sensors_config: object,
) -> None:
"""Perform initial Field sampling with ParticleSet."""
for sensor in sensors_config:
if not (sensor.enabled and sensor.sensor_type in self.sensor_kernels):
raise ValueError(
f"Attempted to initialise sensor '{sensor.sensor_type}' but it is not enabled or not in sensor_kernels."
)

fs_key = sensor.meta.fs_key
field = getattr(fieldset, fs_key)
particle_vars = [pv.name for pv in sensor.meta.particle_vars]

for var in particle_vars:
setattr(pset, var, field[pset.t, pset.z, pset.y, pset.x])

def _get_copernicus_ds(
self,
time_buffer: float | None,
Expand Down
3 changes: 3 additions & 0 deletions src/virtualship/instruments/ctd.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def simulate(self, measurements, out_path) -> None:
winch_speed=[WINCH_SPEED for _ in measurements],
)

# add initial conditions to sampling variables
self._sample_initial(ctd_particleset, fieldset, ctd_config.sensors)

# define output file for the simulation
out_file = ParticleFile(path=out_path, outputdt=OUTPUT_DT)

Expand Down
3 changes: 3 additions & 0 deletions src/virtualship/instruments/drifter.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def simulate(self, measurements, out_path) -> None:
],
)

# add initial conditions to sampling variables
self._sample_initial(drifter_particleset, fieldset, drifter_config.sensors)

# define output file for the simulation
out_file = ParticleFile(
path=out_path,
Expand Down
3 changes: 3 additions & 0 deletions src/virtualship/instruments/xbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ def simulate(self, measurements, out_path) -> None:
fall_speed=[xbt.fall_speed for xbt in measurements],
)

# add initial conditions to sampling variables
self._sample_initial(xbt_particleset, fieldset, xbt_config.sensors)

out_file = ParticleFile(path=out_path, outputdt=OUTPUT_DT)

# build kernel list from active sensors only
Expand Down
Loading