2121
2222GDP_VERSION = "September 2023"
2323
24- GDP_DATA_URL = "https://www.aoml.noaa.gov/ftp/pub/phod/buoydata/6h/ "
24+ GDP_DATA_URL = "https://www.aoml.noaa.gov/ftp/pub/phod/buoydata/6h"
2525GDP_TMP_PATH = os .path .join (tempfile .gettempdir (), "clouddrift" , "gdp6h" )
2626GDP_DATA = [
2727 "lon" ,
@@ -82,7 +82,7 @@ def download(
8282 string = urlpath .read ().decode ("utf-8" )
8383 filelist = list (set (re .compile (pattern ).findall (string )))
8484 for f in filelist :
85- did = int (f [: - 3 ] .split ("_" )[2 ])
85+ did = int (f .split ("_" )[2 ]. removesuffix ( ".nc" ) )
8686 if (drifter_ids is None or did in drifter_ids ) and did not in added :
8787 drifter_urls .append (f"{ url } /{ dir } /{ f } " )
8888 added .add (did )
@@ -187,7 +187,10 @@ def preprocess(index: int, **kwargs) -> xr.Dataset:
187187 warnings .warn (f"Variable { var } not found in upstream data; skipping." )
188188
189189 # new variables
190- ds ["ids" ] = (["traj" , "obs" ], [np .repeat (ds .ID .values , ds .sizes ["obs" ])])
190+ ds ["ids" ] = (
191+ ["traj" , "obs" ],
192+ [np .repeat (ds .ID .values , ds .sizes ["obs" ])],
193+ )
191194 ds ["drogue_status" ] = (
192195 ["traj" , "obs" ],
193196 [gdp .drogue_presence (ds .drogue_lost_date .data , ds .time .data [0 ])],
@@ -199,17 +202,32 @@ def preprocess(index: int, **kwargs) -> xr.Dataset:
199202 [False if ds .get ("location_type" ) == "Argos" else True ],
200203 ) # 0 for Argos, 1 for GPS
201204 ds ["DeployingShip" ] = (("traj" ), gdp .cut_str (ds .DeployingShip , 20 ))
202- ds ["DeploymentStatus" ] = (("traj" ), gdp .cut_str (ds .DeploymentStatus , 20 ))
203- ds ["BuoyTypeManufacturer" ] = (("traj" ), gdp .cut_str (ds .BuoyTypeManufacturer , 20 ))
204- ds ["BuoyTypeSensorArray" ] = (("traj" ), gdp .cut_str (ds .BuoyTypeSensorArray , 20 ))
205+ ds ["DeploymentStatus" ] = (
206+ ("traj" ),
207+ gdp .cut_str (ds .DeploymentStatus , 20 ),
208+ )
209+ ds ["BuoyTypeManufacturer" ] = (
210+ ("traj" ),
211+ gdp .cut_str (ds .BuoyTypeManufacturer , 20 ),
212+ )
213+ ds ["BuoyTypeSensorArray" ] = (
214+ ("traj" ),
215+ gdp .cut_str (ds .BuoyTypeSensorArray , 20 ),
216+ )
205217 ds ["CurrentProgram" ] = (
206218 ("traj" ),
207219 [np .int32 (gdp .str_to_float (ds .CurrentProgram , - 1 ))],
208220 )
209- ds ["PurchaserFunding" ] = (("traj" ), gdp .cut_str (ds .PurchaserFunding , 20 ))
221+ ds ["PurchaserFunding" ] = (
222+ ("traj" ),
223+ gdp .cut_str (ds .PurchaserFunding , 20 ),
224+ )
210225 ds ["SensorUpgrade" ] = (("traj" ), gdp .cut_str (ds .SensorUpgrade , 20 ))
211226 ds ["Transmissions" ] = (("traj" ), gdp .cut_str (ds .Transmissions , 20 ))
212- ds ["DeployingCountry" ] = (("traj" ), gdp .cut_str (ds .DeployingCountry , 20 ))
227+ ds ["DeployingCountry" ] = (
228+ ("traj" ),
229+ gdp .cut_str (ds .DeployingCountry , 20 ),
230+ )
213231 ds ["DeploymentComments" ] = (
214232 ("traj" ),
215233 gdp .cut_str (
@@ -224,10 +242,13 @@ def preprocess(index: int, **kwargs) -> xr.Dataset:
224242 ("traj" ),
225243 [np .int16 (gdp .str_to_float (ds .ManufactureMonth , - 1 ))],
226244 )
227- ds ["ManufactureSensorType" ] = (("traj" ), gdp .cut_str (ds .ManufactureSensorType , 20 ))
245+ ds ["ManufactureSensorType" ] = (
246+ ("traj" ),
247+ gdp .cut_str (ds .ManufactureSensorType , 20 ),
248+ )
228249 ds ["ManufactureVoltage" ] = (
229250 ("traj" ),
230- [np .int16 (gdp .str_to_float (ds .ManufactureVoltage [:- 6 ], - 1 ))],
251+ [np .int16 (gdp .str_to_float (ds .ManufactureVoltage [:- 2 ], - 1 ))],
231252 ) # e.g. 56 V
232253 ds ["FloatDiameter" ] = (
233254 ("traj" ),
@@ -254,12 +275,18 @@ def preprocess(index: int, **kwargs) -> xr.Dataset:
254275 ("traj" ),
255276 [gdp .str_to_float (ds .DragAreaOfDrogue [:- 4 ])],
256277 ) # e.g. 416.6 m^2
257- ds ["DragAreaRatio" ] = (("traj" ), [gdp .str_to_float (ds .DragAreaRatio )]) # e.g. 39.08
278+ ds ["DragAreaRatio" ] = (
279+ ("traj" ),
280+ [gdp .str_to_float (ds .DragAreaRatio )],
281+ ) # e.g. 39.08
258282 ds ["DrogueCenterDepth" ] = (
259283 ("traj" ),
260284 [gdp .str_to_float (ds .DrogueCenterDepth [:- 2 ])],
261285 ) # e.g. 20.0 m
262- ds ["DrogueDetectSensor" ] = (("traj" ), gdp .cut_str (ds .DrogueDetectSensor , 20 ))
286+ ds ["DrogueDetectSensor" ] = (
287+ ("traj" ),
288+ gdp .cut_str (ds .DrogueDetectSensor , 20 ),
289+ )
263290
264291 # vars attributes
265292 vars_attrs = {
@@ -481,20 +508,21 @@ def to_raggedarray(
481508 ra = RaggedArray .from_files (
482509 indices = ids ,
483510 preprocess_func = preprocess ,
484- coord_dim_map = gdp .GDP_COORDS ,
511+ name_coords = gdp .GDP_COORDS ,
485512 name_meta = gdp .GDP_METADATA ,
486513 name_data = GDP_DATA ,
514+ name_dims = gdp .GDP_DIMS ,
487515 rowsize_func = gdp .rowsize ,
488516 filename_pattern = "drifter_6h_{id}.nc" ,
489517 tmp_path = tmp_path ,
490518 )
491519
492520 # update dynamic global attributes
493- ra .attrs_global [
494- "time_coverage_start "
495- ] = f" { datetime . datetime ( 1970 , 1 , 1 ) + datetime . timedelta ( seconds = int ( np . min ( ra . coords [ 'time' ]))):%Y-%m-%d:%H:%M:%SZ } "
496- ra .attrs_global [
497- "time_coverage_end "
498- ] = f" { datetime . datetime ( 1970 , 1 , 1 ) + datetime . timedelta ( seconds = int ( np . max ( ra . coords [ 'time' ]))):%Y-%m-%d:%H:%M:%SZ } "
521+ ra .attrs_global ["time_coverage_start" ] = (
522+ f" { datetime . datetime ( 1970 , 1 , 1 ) + datetime . timedelta ( seconds = int ( np . min ( ra . coords [ 'time' ]))):%Y-%m-%d:%H:%M:%SZ } "
523+ )
524+ ra .attrs_global ["time_coverage_end" ] = (
525+ f" { datetime . datetime ( 1970 , 1 , 1 ) + datetime . timedelta ( seconds = int ( np . max ( ra . coords [ 'time' ]))):%Y-%m-%d:%H:%M:%SZ } "
526+ )
499527
500528 return ra
0 commit comments