@@ -408,15 +408,14 @@ def _discover_copernicusmarine_U_and_V(ds: xr.Dataset) -> xr.Dataset:
408408
409409
410410def _discover_fesom2_U_and_V (ds : ux .UxDataset ) -> ux .UxDataset :
411- # Assumes that the dataset has U and V data
412-
413- ux_UV_standard_name_fallbacks = [("unod" , "vnod" ), ("u" , "v" )]
414- ux_W_standard_name_fallbacks = ["w" ]
411+ # Common variable names for U and V found in UxDatasets
412+ common_fesom_UV = [("unod" , "vnod" ), ("u" , "v" )]
413+ common_fesom_W = ["w" ]
415414
416415 if "W" not in ds :
417- for ux_standard_name_W in ux_W_standard_name_fallbacks :
418- if ux_standard_name_W in ds . ux . standard_names :
419- ds = _ds_rename_using_standard_names (ds , {ux_standard_name_W : "W" })
416+ for common_W in common_fesom_W :
417+ if common_W in ds :
418+ ds = _ds_rename_using_standard_names (ds , {common_W : "W" })
420419 break
421420
422421 if "U" in ds and "V" in ds :
@@ -426,19 +425,33 @@ def _discover_fesom2_U_and_V(ds: ux.UxDataset) -> ux.UxDataset:
426425 "Dataset has only one of the two variables 'U' and 'V'. Please rename the appropriate variable in your dataset to have both 'U' and 'V' for Parcels simulation."
427426 )
428427
429- for ux_standard_name_U , ux_standard_name_V in ux_UV_standard_name_fallbacks :
430- if ux_standard_name_U in ds .ux .standard_names :
431- if ux_standard_name_V not in ds .ux .standard_names :
428+ uv_found = False
429+ for common_U , common_V in common_fesom_UV :
430+ if common_U in ds :
431+ if common_V not in ds :
432432 raise ValueError (
433- f"Dataset has variable with standard name { ux_standard_name_U !r} , "
434- f"but not the matching variable with standard name { ux_standard_name_V !r} . "
433+ f"Dataset has variable with standard name { common_U !r} , "
434+ f"but not the matching variable with standard name { common_V !r} . "
435435 "Please rename the appropriate variables in your dataset to have both 'U' and 'V' for Parcels simulation."
436436 )
437+ else :
438+ ds = _ds_rename_using_standard_names (ds , {common_U : "U" , common_V : "V" })
439+ uv_found = True
440+ break
441+
437442 else :
443+ if common_V in ds :
444+ raise ValueError (
445+ f"Dataset has variable with standard name { common_V !r} , "
446+ f"but not the matching variable with standard name { common_U !r} . "
447+ "Please rename the appropriate variables in your dataset to have both 'U' and 'V' for Parcels simulation."
448+ )
438449 continue
439-
440- ds = _ds_rename_using_standard_names (ds , {ux_standard_name_U : "U" , ux_standard_name_V : "V" })
441- break
450+ if not uv_found :
451+ raise ValueError (
452+ f"Dataset has neither 'U' nor 'V' in potential options { common_fesom_UV !r} , "
453+ f"Please provide a dataset that has both 'U' and 'V' for Parcels simulation."
454+ )
442455 return ds
443456
444457
0 commit comments