Skip to content

Commit bd60c7c

Browse files
Merge pull request #2505 from Parcels-code/patch/ux-uv-uvw
Ensure (ux)fieldset has both UV and UVW for datasets with U, V, and W
2 parents 1461837 + bada421 commit bd60c7c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/parcels/_core/fieldset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,13 @@ def from_ugrid_conventions(cls, ds: ux.UxDataset, mesh: str = "spherical"):
214214
if "U" in ds.data_vars and "V" in ds.data_vars:
215215
fields["U"] = Field("U", ds["U"], grid, _select_uxinterpolator(ds["U"]))
216216
fields["V"] = Field("V", ds["V"], grid, _select_uxinterpolator(ds["V"]))
217+
fields["UV"] = VectorField("UV", fields["U"], fields["V"], vector_interp_method=Ux_Velocity)
217218

218219
if "W" in ds.data_vars:
219220
fields["W"] = Field("W", ds["W"], grid, _select_uxinterpolator(ds["W"]))
220221
fields["UVW"] = VectorField(
221222
"UVW", fields["U"], fields["V"], fields["W"], vector_interp_method=Ux_Velocity
222223
)
223-
else:
224-
fields["UV"] = VectorField("UV", fields["U"], fields["V"], vector_interp_method=Ux_Velocity)
225224

226225
for varname in set(ds.data_vars) - set(fields.keys()):
227226
fields[varname] = Field(varname, ds[varname], grid, _select_uxinterpolator(ds[varname]))

tests/test_fieldset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def test_fieldset_from_fesom2():
255255
fieldset = FieldSet.from_ugrid_conventions(ds)
256256
assert "U" in fieldset.fields
257257
assert "V" in fieldset.fields
258+
assert "UV" in fieldset.fields
258259
assert "UVW" in fieldset.fields
259260

260261

0 commit comments

Comments
 (0)