Skip to content

Commit a5d10e7

Browse files
committed
tidy up
1 parent b94f4f0 commit a5d10e7

File tree

9 files changed

+156
-11
lines changed

9 files changed

+156
-11
lines changed

src/virtualship/instruments/adcp.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
register_instrument,
1212
)
1313

14+
# =====================================================
15+
# SECTION: Dataclass
16+
# =====================================================
17+
1418

1519
@dataclass
1620
class ADCP:
@@ -19,22 +23,34 @@ class ADCP:
1923
name: ClassVar[str] = "ADCP"
2024

2125

22-
# we specifically use ScipyParticle because we have many small calls to execute
23-
# there is some overhead with JITParticle and this ends up being significantly faster
26+
# =====================================================
27+
# SECTION: Particle Class
28+
# =====================================================
29+
30+
2431
_ADCPParticle = ScipyParticle.add_variables(
2532
[
2633
Variable("U", dtype=np.float32, initial=np.nan),
2734
Variable("V", dtype=np.float32, initial=np.nan),
2835
]
2936
)
3037

38+
# =====================================================
39+
# SECTION: Kernels
40+
# =====================================================
41+
3142

3243
def _sample_velocity(particle, fieldset, time):
3344
particle.U, particle.V = fieldset.UV.eval(
3445
time, particle.depth, particle.lat, particle.lon, applyConversion=False
3546
)
3647

3748

49+
# =====================================================
50+
# SECTION: InputDataset Class
51+
# =====================================================
52+
53+
3854
@register_input_dataset(InstrumentType.ADCP)
3955
class ADCPInputDataset(InputDataset):
4056
"""Input dataset for ADCP instrument."""
@@ -70,6 +86,11 @@ def get_datasets_dict(self) -> dict:
7086
}
7187

7288

89+
# =====================================================
90+
# SECTION: Instrument Class
91+
# =====================================================
92+
93+
7394
@register_instrument(InstrumentType.ADCP)
7495
class ADCPInstrument(Instrument):
7596
"""ADCP instrument class."""

src/virtualship/instruments/argo_float.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
from virtualship.models.spacetime import Spacetime
1818
from virtualship.utils import register_input_dataset, register_instrument
1919

20+
# =====================================================
21+
# SECTION: Dataclass
22+
# =====================================================
23+
2024

2125
@dataclass
2226
class ArgoFloat:
@@ -32,6 +36,10 @@ class ArgoFloat:
3236
drift_days: float
3337

3438

39+
# =====================================================
40+
# SECTION: Particle Class
41+
# =====================================================
42+
3543
_ArgoParticle = JITParticle.add_variables(
3644
[
3745
Variable("cycle_phase", dtype=np.int32, initial=0.0),
@@ -48,6 +56,10 @@ class ArgoFloat:
4856
]
4957
)
5058

59+
# =====================================================
60+
# SECTION: Kernels
61+
# =====================================================
62+
5163

5264
def _argo_float_vertical_movement(particle, fieldset, time):
5365
if particle.cycle_phase == 0:
@@ -116,6 +128,11 @@ def _check_error(particle, fieldset, time):
116128
particle.delete()
117129

118130

131+
# =====================================================
132+
# SECTION: InputDataset Class
133+
# =====================================================
134+
135+
119136
@register_input_dataset(InstrumentType.ARGO_FLOAT)
120137
class ArgoFloatInputDataset(InputDataset):
121138
"""Input dataset for ArgoFloat instrument."""
@@ -161,6 +178,11 @@ def get_datasets_dict(self) -> dict:
161178
}
162179

163180

181+
# =====================================================
182+
# SECTION: Instrument Class
183+
# =====================================================
184+
185+
164186
@register_instrument(InstrumentType.ARGO_FLOAT)
165187
class ArgoFloatInstrument(Instrument):
166188
"""ArgoFloat instrument class."""

src/virtualship/instruments/base.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,8 @@ def __init__(
246246

247247
def load_input_data(self) -> FieldSet:
248248
"""Load and return the input data as a FieldSet for the instrument."""
249-
# TODO: can simulate_schedule.py be refactored to be contained in base.py and repsective instrument files too...?
250249
# TODO: tests need updating...!
251250

252-
#! TODO: E.g. ADCP is giving too much depth data?!
253-
#! TODO: in fact output from most instruments doesn't look quite right...?
254-
255251
try:
256252
data_dir = self._get_data_dir(self.directory)
257253
joined_filepaths = {
@@ -303,10 +299,11 @@ def run(self, measurements: list, out_path: str | Path) -> None:
303299
spinner=ship_spinner,
304300
) as spinner:
305301
self.simulate(measurements, out_path)
306-
spinner.ok("✅")
302+
spinner.ok("✅\n")
307303
else:
308304
print(f"Simulating {self.name} measurements... ")
309305
self.simulate(measurements, out_path)
306+
print("\n")
310307

311308
def _get_data_dir(self, expedition_dir: Path) -> Path:
312309
space_time_region_hash = get_space_time_region_hash(

src/virtualship/instruments/ctd.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
# TODO: add some kind of check that each instrument has a dataclass, particle class, InputDataset class and Instrument class?
1414
# TODO: probably as a test
1515

16+
# =====================================================
17+
# SECTION: Dataclass
18+
# =====================================================
19+
1620

1721
@dataclass
1822
class CTD:
@@ -24,6 +28,10 @@ class CTD:
2428
max_depth: float
2529

2630

31+
# =====================================================
32+
# SECTION: Particle Class
33+
# =====================================================
34+
2735
_CTDParticle = JITParticle.add_variables(
2836
[
2937
Variable("salinity", dtype=np.float32, initial=np.nan),
@@ -36,7 +44,9 @@ class CTD:
3644
)
3745

3846

39-
# TODO: way to group kernels together, just to make clearer?
47+
# =====================================================
48+
# SECTION: Kernels
49+
# =====================================================
4050

4151

4252
def _sample_temperature(particle, fieldset, time):
@@ -61,6 +71,11 @@ def _ctd_cast(particle, fieldset, time):
6171
particle.delete()
6272

6373

74+
# =====================================================
75+
# SECTION: InputDataset Class
76+
# =====================================================
77+
78+
6479
@register_input_dataset(InstrumentType.CTD)
6580
class CTDInputDataset(InputDataset):
6681
"""Input dataset for CTD instrument."""
@@ -99,14 +114,17 @@ def get_datasets_dict(self) -> dict:
99114
}
100115

101116

117+
# =====================================================
118+
# SECTION: Instrument Class
119+
# =====================================================
120+
121+
102122
@register_instrument(InstrumentType.CTD)
103123
class CTDInstrument(Instrument):
104124
"""CTD instrument class."""
105125

106126
def __init__(self, expedition, directory):
107127
"""Initialize CTDInstrument."""
108-
#! TODO: actually don't need to download U and V for CTD simulation... can instead add mock/duplicate of T and name it U (also don't need V)!
109-
110128
filenames = {
111129
"S": f"{CTD.name}_s.nc",
112130
"T": f"{CTD.name}_t.nc",

src/virtualship/instruments/ctd_bgc.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from virtualship.models.spacetime import Spacetime
1111
from virtualship.utils import add_dummy_UV, register_input_dataset, register_instrument
1212

13+
# =====================================================
14+
# SECTION: Dataclass
15+
# =====================================================
16+
1317

1418
@dataclass
1519
class CTD_BGC:
@@ -21,6 +25,10 @@ class CTD_BGC:
2125
max_depth: float
2226

2327

28+
# =====================================================
29+
# SECTION: Particle Class
30+
# =====================================================
31+
2432
_CTD_BGCParticle = JITParticle.add_variables(
2533
[
2634
Variable("o2", dtype=np.float32, initial=np.nan),
@@ -37,6 +45,10 @@ class CTD_BGC:
3745
]
3846
)
3947

48+
# =====================================================
49+
# SECTION: Kernels
50+
# =====================================================
51+
4052

4153
def _sample_o2(particle, fieldset, time):
4254
particle.o2 = fieldset.o2[time, particle.depth, particle.lat, particle.lon]
@@ -80,6 +92,11 @@ def _ctd_bgc_cast(particle, fieldset, time):
8092
particle.delete()
8193

8294

95+
# =====================================================
96+
# SECTION: InputDataset Class
97+
# =====================================================
98+
99+
83100
@register_input_dataset(InstrumentType.CTD_BGC)
84101
class CTD_BGCInputDataset(InputDataset):
85102
"""Input dataset object for CTD_BGC instrument."""
@@ -143,6 +160,11 @@ def get_datasets_dict(self) -> dict:
143160
}
144161

145162

163+
# =====================================================
164+
# SECTION: Instrument Class
165+
# =====================================================
166+
167+
146168
@register_instrument(InstrumentType.CTD_BGC)
147169
class CTD_BGCInstrument(Instrument):
148170
"""CTD_BGC instrument class."""

src/virtualship/instruments/drifter.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from virtualship.models.spacetime import Spacetime
1111
from virtualship.utils import register_input_dataset, register_instrument
1212

13+
# =====================================================
14+
# SECTION: Dataclass
15+
# =====================================================
16+
1317

1418
@dataclass
1519
class Drifter:
@@ -21,6 +25,10 @@ class Drifter:
2125
lifetime: timedelta | None # if none, lifetime is infinite
2226

2327

28+
# =====================================================
29+
# SECTION: Particle Class
30+
# =====================================================
31+
2432
_DrifterParticle = JITParticle.add_variables(
2533
[
2634
Variable("temperature", dtype=np.float32, initial=np.nan),
@@ -30,6 +38,10 @@ class Drifter:
3038
]
3139
)
3240

41+
# =====================================================
42+
# SECTION: Kernels
43+
# =====================================================
44+
3345

3446
def _sample_temperature(particle, fieldset, time):
3547
particle.temperature = fieldset.T[time, particle.depth, particle.lat, particle.lon]
@@ -42,6 +54,11 @@ def _check_lifetime(particle, fieldset, time):
4254
particle.delete()
4355

4456

57+
# =====================================================
58+
# SECTION: InputDataset Class
59+
# =====================================================
60+
61+
4562
@register_input_dataset(InstrumentType.DRIFTER)
4663
class DrifterInputDataset(InputDataset):
4764
"""Input dataset for Drifter instrument."""
@@ -82,6 +99,11 @@ def get_datasets_dict(self) -> dict:
8299
}
83100

84101

102+
# =====================================================
103+
# SECTION: Instrument Class
104+
# =====================================================
105+
106+
85107
@register_instrument(InstrumentType.DRIFTER)
86108
class DrifterInstrument(Instrument):
87109
"""Drifter instrument class."""

src/virtualship/instruments/ship_underwater_st.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from virtualship.instruments.types import InstrumentType
99
from virtualship.utils import add_dummy_UV, register_input_dataset, register_instrument
1010

11+
# =====================================================
12+
# SECTION: Dataclass
13+
# =====================================================
14+
1115

1216
@dataclass
1317
class Underwater_ST:
@@ -16,13 +20,21 @@ class Underwater_ST:
1620
name: ClassVar[str] = "Underwater_ST"
1721

1822

23+
# =====================================================
24+
# SECTION: Particle Class
25+
# =====================================================
26+
1927
_ShipSTParticle = ScipyParticle.add_variables(
2028
[
2129
Variable("S", dtype=np.float32, initial=np.nan),
2230
Variable("T", dtype=np.float32, initial=np.nan),
2331
]
2432
)
2533

34+
# =====================================================
35+
# SECTION: Kernels
36+
# =====================================================
37+
2638

2739
# define function sampling Salinity
2840
def _sample_salinity(particle, fieldset, time):
@@ -34,6 +46,11 @@ def _sample_temperature(particle, fieldset, time):
3446
particle.T = fieldset.T[time, particle.depth, particle.lat, particle.lon]
3547

3648

49+
# =====================================================
50+
# SECTION: InputDataset Class
51+
# =====================================================
52+
53+
3754
@register_input_dataset(InstrumentType.UNDERWATER_ST)
3855
class Underwater_STInputDataset(InputDataset):
3956
"""Input dataset for Underwater_ST instrument."""
@@ -74,6 +91,11 @@ def get_datasets_dict(self) -> dict:
7491
}
7592

7693

94+
# =====================================================
95+
# SECTION: Instrument Class
96+
# =====================================================
97+
98+
7799
@register_instrument(InstrumentType.UNDERWATER_ST)
78100
class Underwater_STInstrument(Instrument):
79101
"""Underwater_ST instrument class."""

0 commit comments

Comments
 (0)