@@ -25,9 +25,7 @@ class Instrument(abc.ABC):
2525 """Base class for instruments and their simulation."""
2626
2727 #! TODO List:
28- # TODO: update documentation/quickstart
29- # TODO: update tests
30- #! TODO: how is this handling credentials?! Seems to work already, are these set up from my previous instances of using copernicusmarine? Therefore users will only have to do it once too?
28+ # TODO: how is this handling credentials?! Seems to work already, are these set up from my previous instances of using copernicusmarine? Therefore users will only have to do it once too?
3129
3230 def __init__ (
3331 self ,
@@ -39,7 +37,8 @@ def __init__(
3937 add_bathymetry : bool ,
4038 allow_time_extrapolation : bool ,
4139 verbose_progress : bool ,
42- bathymetry_file : str = "bathymetry.nc" ,
40+ buffer_spec : dict | None = None ,
41+ limit_spec : dict | None = None ,
4342 ):
4443 """Initialise instrument."""
4544 self .name = name
@@ -53,31 +52,23 @@ def __init__(
5352 "time" : "time" ,
5453 "depth" : "depth" ,
5554 } # same dimensions for all instruments
56- self .bathymetry_file = bathymetry_file
5755 self .add_bathymetry = add_bathymetry
5856 self .allow_time_extrapolation = allow_time_extrapolation
5957 self .verbose_progress = verbose_progress
58+ self .buffer_spec = buffer_spec
59+ self .limit_spec = limit_spec
6060
6161 def load_input_data (self ) -> FieldSet :
6262 """Load and return the input data as a FieldSet for the instrument."""
6363 try :
6464 datasets = []
6565 for var in self .variables .values ():
6666 physical = True if var in COPERNICUSMARINE_PHYS_VARIABLES else False
67-
68- # TODO: TEMPORARY BODGE FOR DRIFTER INSTRUMENT - REMOVE WHEN ABLE TO!
69- if self .name == "Drifter" :
70- ds = self ._get_copernicus_ds_DRIFTER (physical = physical , var = var )
71- else :
72- ds = self ._get_copernicus_ds (physical = physical , var = var )
73- datasets .append (ds )
67+ datasets .append (self ._get_copernicus_ds (physical = physical , var = var ))
7468
7569 # make sure time dims are matched if BGC variables are present (different monthly/daily resolutions can impact fieldset_endtime in simulate)
76- if any (
77- key in COPERNICUSMARINE_BGC_VARIABLES
78- for key in ds .keys ()
79- for ds in datasets
80- ):
70+ all_keys = set ().union (* (ds .keys () for ds in datasets ))
71+ if all_keys & set (COPERNICUSMARINE_BGC_VARIABLES ):
8172 datasets = self ._align_temporal (datasets )
8273
8374 ds_concat = xr .merge (datasets ) # TODO: deal with WARNINGS?
@@ -100,11 +91,15 @@ def load_input_data(self) -> FieldSet:
10091 g .negate_depth ()
10192
10293 # bathymetry data
103- bathymetry_field = _get_bathy_data (
104- self .expedition .schedule .space_time_region
105- ).bathymetry
106- bathymetry_field .data = - bathymetry_field .data
107- fieldset .add_field (bathymetry_field )
94+ if self .add_bathymetry :
95+ bathymetry_field = _get_bathy_data (
96+ self .expedition .schedule .space_time_region ,
97+ latlon_buffer = self .buffer_spec .get ("latlon" )
98+ if self .buffer_spec
99+ else None ,
100+ ).bathymetry
101+ bathymetry_field .data = - bathymetry_field .data
102+ fieldset .add_field (bathymetry_field )
108103
109104 return fieldset
110105
@@ -127,8 +122,6 @@ def execute(self, measurements: list, out_path: str | Path) -> None:
127122 self .simulate (measurements , out_path )
128123 print ("\n " )
129124
130- # self.simulate(measurements, out_path)
131-
132125 def _get_copernicus_ds (
133126 self ,
134127 physical : bool ,
@@ -142,50 +135,28 @@ def _get_copernicus_ds(
142135 variable = var if not physical else None ,
143136 )
144137
145- return copernicusmarine .open_dataset (
146- dataset_id = product_id ,
147- dataset_part = "default" ,
148- minimum_longitude = self .expedition .schedule .space_time_region .spatial_range .minimum_longitude ,
149- maximum_longitude = self .expedition .schedule .space_time_region .spatial_range .maximum_longitude ,
150- minimum_latitude = self .expedition .schedule .space_time_region .spatial_range .minimum_latitude ,
151- maximum_latitude = self .expedition .schedule .space_time_region .spatial_range .maximum_latitude ,
152- variables = [var ],
153- start_datetime = self .expedition .schedule .space_time_region .time_range .start_time ,
154- end_datetime = self .expedition .schedule .space_time_region .time_range .end_time ,
155- coordinates_selection_method = "outside" ,
156- )
138+ latlon_buffer = self .buffer_spec .get ("latlon" ) if self .buffer_spec else 0.0
139+ time_buffer = self .buffer_spec .get ("time" ) if self .buffer_spec else 0.0
157140
158- # TODO: TEMPORARY BODGE FOR DRIFTER INSTRUMENT - REMOVE WHEN ABLE TO!
159- def _get_copernicus_ds_DRIFTER (
160- self ,
161- physical : bool ,
162- var : str ,
163- ) -> xr .Dataset :
164- """Get Copernicus Marine dataset for direct ingestion."""
165- product_id = _select_product_id (
166- physical = physical ,
167- schedule_start = self .expedition .schedule .space_time_region .time_range .start_time ,
168- schedule_end = self .expedition .schedule .space_time_region .time_range .end_time ,
169- variable = var if not physical else None ,
170- )
141+ depth_min = self .limit_spec .get ("depth_min" ) if self .limit_spec else None
142+ depth_max = self .limit_spec .get ("depth_max" ) if self .limit_spec else None
171143
172144 return copernicusmarine .open_dataset (
173145 dataset_id = product_id ,
174- dataset_part = "default" ,
175146 minimum_longitude = self .expedition .schedule .space_time_region .spatial_range .minimum_longitude
176- - 3.0 ,
147+ - latlon_buffer ,
177148 maximum_longitude = self .expedition .schedule .space_time_region .spatial_range .maximum_longitude
178- + 3.0 ,
149+ + latlon_buffer ,
179150 minimum_latitude = self .expedition .schedule .space_time_region .spatial_range .minimum_latitude
180- - 3.0 ,
151+ - latlon_buffer ,
181152 maximum_latitude = self .expedition .schedule .space_time_region .spatial_range .maximum_latitude
182- + 3.0 ,
183- maximum_depth = 1.0 ,
184- minimum_depth = 1.0 ,
153+ + latlon_buffer ,
185154 variables = [var ],
186155 start_datetime = self .expedition .schedule .space_time_region .time_range .start_time ,
187156 end_datetime = self .expedition .schedule .space_time_region .time_range .end_time
188- + timedelta (days = 21.0 ),
157+ + timedelta (days = time_buffer ),
158+ minimum_depth = depth_min ,
159+ maximum_depth = depth_max ,
189160 coordinates_selection_method = "outside" ,
190161 )
191162
0 commit comments