@@ -230,21 +230,25 @@ def from_copernicusmarine(ds: xr.Dataset):
230230 )
231231 )
232232
233- U = Field ("U" , ds ["U" ], grid )
234- V = Field ("V" , ds ["V" ], grid )
235-
236- U .units = GeographicPolar ()
237- V .units = Geographic ()
233+ fields = {}
234+ if "U" in ds .data_vars and "V" in ds .data_vars :
235+ fields ["U" ] = Field ("U" , ds ["U" ], grid )
236+ fields ["V" ] = Field ("V" , ds ["V" ], grid )
237+ fields ["U" ].units = GeographicPolar ()
238+ fields ["V" ].units = Geographic ()
239+
240+ if "W" in ds .data_vars :
241+ ds ["W" ] -= ds [
242+ "W"
243+ ] # Negate W to convert from up positive to down positive (as that's the direction of positive depth)
244+ fields ["W" ] = Field ("W" , ds ["W" ], grid )
245+ fields ["UVW" ] = VectorField ("UVW" , fields ["U" ], fields ["V" ], fields ["W" ])
246+ else :
247+ fields ["UV" ] = VectorField ("UV" , fields ["U" ], fields ["V" ])
238248
239- fields = {"U" : U , "V" : V }
240249 for varname in set (ds .data_vars ) - set (fields .keys ()):
241250 fields [varname ] = Field (varname , ds [varname ], grid )
242251
243- if "U" in fields and "V" in fields :
244- if "W" in fields :
245- fields ["UVW" ] = VectorField ("UVW" , fields ["U" ], fields ["V" ], fields ["W" ])
246- else :
247- fields ["UV" ] = VectorField ("UV" , fields ["U" ], fields ["V" ])
248252 return FieldSet (list (fields .values ()))
249253
250254
@@ -324,6 +328,13 @@ def _discover_copernicusmarine_U_and_V(ds: xr.Dataset) -> xr.Dataset:
324328 "northward_sea_water_velocity_vertical_mean_over_pelagic_layer" ,
325329 ), # GLOBAL_MULTIYEAR_BGC_001_033
326330 ]
331+ cf_W_standard_name_fallbacks = ["upward_sea_water_velocity" , "vertical_sea_water_velocity" ]
332+
333+ if "W" not in ds :
334+ for cf_standard_name_W in cf_W_standard_name_fallbacks :
335+ if cf_standard_name_W in ds .cf .standard_names :
336+ ds = _ds_rename_using_standard_names (ds , {cf_standard_name_W : "W" })
337+ break
327338
328339 if "U" in ds and "V" in ds :
329340 return ds # U and V already present
@@ -345,12 +356,6 @@ def _discover_copernicusmarine_U_and_V(ds: xr.Dataset) -> xr.Dataset:
345356
346357 ds = _ds_rename_using_standard_names (ds , {cf_standard_name_U : "U" , cf_standard_name_V : "V" })
347358 break
348- else :
349- raise ValueError (
350- f"Could not find variables 'U' and 'V' in dataset, nor any of the fallback CF standard names "
351- f"{ cf_UV_standard_name_fallbacks } . Please rename the appropriate variables to 'U' and 'V' in "
352- "your dataset for the Parcels simulation."
353- )
354359 return ds
355360
356361
0 commit comments