Skip to content

Commit a0da379

Browse files
committed
add rotating dial to instrument progress monitoring
1 parent 0b08bc6 commit a0da379

8 files changed

Lines changed: 42 additions & 13 deletions

File tree

src/virtualship/expedition/simulate_measurements.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def simulate_measurements(
3636
expedition_dir = Path(expedition_dir)
3737

3838
if len(measurements.ship_underwater_sts) > 0:
39-
print("Simulating onboard salinity and temperature measurements.")
4039
if ship_config.ship_underwater_st_config is None:
4140
raise RuntimeError("No configuration for ship underwater ST provided.")
4241
if input_data.ship_underwater_st_fieldset is None:
@@ -49,7 +48,6 @@ def simulate_measurements(
4948
)
5049

5150
if len(measurements.adcps) > 0:
52-
print("Simulating onboard ADCP.")
5351
if ship_config.adcp_config is None:
5452
raise RuntimeError("No configuration for ADCP provided.")
5553
if input_data.adcp_fieldset is None:
@@ -64,7 +62,6 @@ def simulate_measurements(
6462
)
6563

6664
if len(measurements.ctds) > 0:
67-
print("Simulating CTD casts.")
6865
if ship_config.ctd_config is None:
6966
raise RuntimeError("No configuration for CTD provided.")
7067
if input_data.ctd_fieldset is None:
@@ -77,7 +74,6 @@ def simulate_measurements(
7774
)
7875

7976
if len(measurements.ctd_bgcs) > 0:
80-
print("Simulating BGC CTD casts.")
8177
if ship_config.ctd_bgc_config is None:
8278
raise RuntimeError("No configuration for CTD_BGC provided.")
8379
if input_data.ctd_bgc_fieldset is None:
@@ -90,7 +86,6 @@ def simulate_measurements(
9086
)
9187

9288
if len(measurements.drifters) > 0:
93-
print("Simulating drifters")
9489
if ship_config.drifter_config is None:
9590
raise RuntimeError("No configuration for drifters provided.")
9691
if input_data.drifter_fieldset is None:
@@ -105,7 +100,6 @@ def simulate_measurements(
105100
)
106101

107102
if len(measurements.argo_floats) > 0:
108-
print("Simulating argo floats")
109103
if ship_config.argo_float_config is None:
110104
raise RuntimeError("No configuration for argo floats provided.")
111105
if input_data.argo_float_fieldset is None:
@@ -119,7 +113,6 @@ def simulate_measurements(
119113
)
120114

121115
if len(measurements.xbts) > 0:
122-
print("Simulating XBTs")
123116
if ship_config.xbt_config is None:
124117
raise RuntimeError("No configuration for XBTs provided.")
125118
if input_data.xbt_fieldset is None:

src/virtualship/instruments/adcp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from ..log_filter import Filter, external_logger
99
from ..spacetime import Spacetime
10+
from ..utils import RotatePrint
1011

1112
# we specifically use ScipyParticle because we have many small calls to execute
1213
# there is some overhead with JITParticle and this ends up being significantly faster
@@ -42,6 +43,8 @@ def simulate_adcp(
4243
:param num_bins: How many samples to take in the complete range between max_depth and min_depth.
4344
:param sample_points: The places and times to sample at.
4445
"""
46+
rotator = RotatePrint("Simulating onboard ADCP...")
47+
4548
sample_points.sort(key=lambda p: p.time)
4649

4750
bins = np.linspace(max_depth, min_depth, num_bins)
@@ -66,7 +69,10 @@ def simulate_adcp(
6669
handler.addFilter(Filter())
6770

6871
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
72+
# also suits starting and ending the rotator for custom log message
6973
try:
74+
rotator.start()
75+
7076
for point in sample_points:
7177
particleset.lon_nextloop[:] = point.location.lon
7278
particleset.lat_nextloop[:] = point.location.lat
@@ -85,5 +91,6 @@ def simulate_adcp(
8591
)
8692

8793
finally:
94+
rotator.stop()
8895
for handler in external_logger.handlers:
8996
handler.removeFilter(handler.filters[0])

src/virtualship/instruments/argo_float.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def simulate_argo_floats(
132132
:param outputdt: Interval which dictates the update frequency of file output during simulation
133133
:param endtime: Stop at this time, or if None, continue until the end of the fieldset.
134134
"""
135+
print("Simulating argo floats...")
135136
DT = 10.0 # dt of Argo float simulation integrator
136137

137138
if len(argo_floats) == 0:
@@ -178,7 +179,6 @@ def simulate_argo_floats(
178179

179180
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
180181
try:
181-
# execute simulation
182182
argo_float_particleset.execute(
183183
[
184184
_argo_float_vertical_movement,
@@ -189,9 +189,10 @@ def simulate_argo_floats(
189189
endtime=actual_endtime,
190190
dt=DT,
191191
output_file=out_file,
192-
verbose_progress=False,
192+
verbose_progress=True,
193193
)
194194

195195
finally:
196+
print("... [COMPLETED]")
196197
for handler in external_logger.handlers:
197198
handler.removeFilter(handler.filters[0])

src/virtualship/instruments/ctd.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from ..log_filter import Filter, external_logger
1111
from ..spacetime import Spacetime
12+
from ..utils import RotatePrint
1213

1314

1415
@dataclass
@@ -69,6 +70,8 @@ def simulate_ctd(
6970
:param outputdt: Interval which dictates the update frequency of file output during simulation
7071
:raises ValueError: Whenever provided CTDs, fieldset, are not compatible with this function.
7172
"""
73+
rotator = RotatePrint("Simulating CTD casts...")
74+
7275
WINCH_SPEED = 1.0 # sink and rise speed in m/s
7376
DT = 10.0 # dt of CTD simulation integrator
7477

@@ -127,7 +130,10 @@ def simulate_ctd(
127130
handler.addFilter(Filter())
128131

129132
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
133+
# also suits starting and ending the rotator for custom log message
130134
try:
135+
rotator.start()
136+
131137
ctd_particleset.execute(
132138
[_sample_salinity, _sample_temperature, _ctd_cast],
133139
endtime=fieldset_endtime,
@@ -137,6 +143,7 @@ def simulate_ctd(
137143
)
138144

139145
finally:
146+
rotator.stop()
140147
for handler in external_logger.handlers:
141148
handler.removeFilter(handler.filters[0])
142149

src/virtualship/instruments/ctd_bgc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from ..log_filter import Filter, external_logger
1111
from ..spacetime import Spacetime
12+
from ..utils import RotatePrint
1213

1314

1415
@dataclass
@@ -69,6 +70,8 @@ def simulate_ctd_bgc(
6970
:param outputdt: Interval which dictates the update frequency of file output during simulation
7071
:raises ValueError: Whenever provided BGC CTDs, fieldset, are not compatible with this function.
7172
"""
73+
rotator = RotatePrint("Simulating BGC CTD casts...")
74+
7275
WINCH_SPEED = 1.0 # sink and rise speed in m/s
7376
DT = 10.0 # dt of CTD simulation integrator
7477

@@ -133,7 +136,10 @@ def simulate_ctd_bgc(
133136
handler.addFilter(Filter())
134137

135138
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
139+
# also suits starting and ending the rotator for custom log message
136140
try:
141+
rotator.start()
142+
137143
ctd_bgc_particleset.execute(
138144
[_sample_o2, _sample_chlorophyll, _ctd_bgc_cast],
139145
endtime=fieldset_endtime,
@@ -143,6 +149,7 @@ def simulate_ctd_bgc(
143149
)
144150

145151
finally:
152+
rotator.stop()
146153
for handler in external_logger.handlers:
147154
handler.removeFilter(handler.filters[0])
148155

src/virtualship/instruments/drifter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def simulate_drifters(
5959
:param dt: Dt for integration.
6060
:param endtime: Stop at this time, or if None, continue until the end of the fieldset or until all drifters ended. If this is earlier than the last drifter ended or later than the end of the fieldset, a warning will be printed.
6161
"""
62+
print("Simulating drifters...")
63+
6264
if len(drifters) == 0:
6365
print(
6466
"No drifters provided. Parcels currently crashes when providing an empty particle set, so no drifter simulation will be done and no files will be created."
@@ -102,16 +104,16 @@ def simulate_drifters(
102104

103105
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
104106
try:
105-
# execute simulation
106107
drifter_particleset.execute(
107108
[AdvectionRK4, _sample_temperature, _check_lifetime],
108109
endtime=actual_endtime,
109110
dt=dt,
110111
output_file=out_file,
111-
verbose_progress=False,
112+
verbose_progress=True,
112113
)
113114

114115
finally:
116+
print("... [COMPLETED]")
115117
for handler in external_logger.handlers:
116118
handler.removeFilter(handler.filters[0])
117119

src/virtualship/instruments/ship_underwater_st.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from ..log_filter import Filter, external_logger
99
from ..spacetime import Spacetime
10+
from ..utils import RotatePrint
1011

1112
# we specifically use ScipyParticle because we have many small calls to execute
1213
# there is some overhead with JITParticle and this ends up being significantly faster
@@ -42,6 +43,8 @@ def simulate_ship_underwater_st(
4243
:param depth: The depth at which to measure. 0 is water surface, negative is into the water.
4344
:param sample_points: The places and times to sample at.
4445
"""
46+
rotator = RotatePrint("Simulating onboard salinity and temperature measurements...")
47+
4548
sample_points.sort(key=lambda p: p.time)
4649

4750
particleset = ParticleSet.from_list(
@@ -53,7 +56,6 @@ def simulate_ship_underwater_st(
5356
time=0, # same for time
5457
)
5558

56-
# define output file for the simulation
5759
# outputdt set to infinie as we want to just want to write at the end of every call to 'execute'
5860
out_file = particleset.ParticleFile(name=out_path, outputdt=np.inf)
5961

@@ -62,7 +64,10 @@ def simulate_ship_underwater_st(
6264
handler.addFilter(Filter())
6365

6466
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
67+
# also suits starting and ending the rotator for custom log message
6568
try:
69+
rotator.start()
70+
6671
# iterate over each point, manually set lat lon time, then
6772
# execute the particle set for one step, performing one set of measurement
6873
for point in sample_points:
@@ -83,5 +88,6 @@ def simulate_ship_underwater_st(
8388
)
8489

8590
finally:
91+
rotator.stop()
8692
for handler in external_logger.handlers:
8793
handler.removeFilter(handler.filters[0])

src/virtualship/instruments/xbt.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from ..log_filter import Filter, external_logger
1111
from ..spacetime import Spacetime
12+
from ..utils import RotatePrint
1213

1314

1415
@dataclass
@@ -70,6 +71,8 @@ def simulate_xbt(
7071
:param outputdt: Interval which dictates the update frequency of file output during simulation
7172
:raises ValueError: Whenever provided XBTs, fieldset, are not compatible with this function.
7273
"""
74+
rotator = RotatePrint("Simulating XBTs")
75+
7376
DT = 10.0 # dt of XBT simulation integrator
7477

7578
if len(xbts) == 0:
@@ -131,8 +134,10 @@ def simulate_xbt(
131134
handler.addFilter(Filter())
132135

133136
# try/finally to ensure filter is always removed even if .execute fails (to avoid filter being appled universally)
137+
# also suits starting and ending the rotator for custom log message
134138
try:
135-
# execute simulation
139+
rotator.start()
140+
136141
xbt_particleset.execute(
137142
[_sample_temperature, _xbt_cast],
138143
endtime=fieldset_endtime,
@@ -142,6 +147,7 @@ def simulate_xbt(
142147
)
143148

144149
finally:
150+
rotator.stop()
145151
for handler in external_logger.handlers:
146152
handler.removeFilter(handler.filters[0])
147153

0 commit comments

Comments
 (0)