Skip to content

Commit f726363

Browse files
committed
Select vector_interp_method based on U and V
1 parent 9febb6a commit f726363

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/parcels/_core/fieldset.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from parcels._typing import Mesh
2323
from parcels.convert import _discover_U_and_V, _ds_rename_using_standard_names, _maybe_rename_coords
2424
from parcels.interpolators import (
25+
CGrid_Velocity,
2526
Ux_Velocity,
2627
UxPiecewiseConstantFace,
2728
UxPiecewiseLinearNode,
@@ -365,14 +366,15 @@ def from_sgrid_conventions(
365366

366367
fields = {}
367368
if "U" in ds.data_vars and "V" in ds.data_vars:
369+
vector_interp_method = XLinear_Velocity if _is_agrid(ds) else CGrid_Velocity
368370
fields["U"] = Field("U", ds["U"], grid, XLinear)
369371
fields["V"] = Field("V", ds["V"], grid, XLinear)
370-
fields["UV"] = VectorField("UV", fields["U"], fields["V"], vector_interp_method=XLinear_Velocity)
372+
fields["UV"] = VectorField("UV", fields["U"], fields["V"], vector_interp_method=vector_interp_method)
371373

372374
if "W" in ds.data_vars:
373375
fields["W"] = Field("W", ds["W"], grid, XLinear)
374376
fields["UVW"] = VectorField(
375-
"UVW", fields["U"], fields["V"], fields["W"], vector_interp_method=XLinear_Velocity
377+
"UVW", fields["U"], fields["V"], fields["W"], vector_interp_method=vector_interp_method
376378
)
377379

378380
for varname in set(ds.data_vars) - set(fields.keys()) - skip_vars:
@@ -548,6 +550,12 @@ def _get_mesh_type_from_sgrid_dataset(ds_sgrid: xr.Dataset) -> Mesh:
548550
return "spherical" if _is_coordinate_in_degrees(ds_sgrid[fpoint_x]) else "flat"
549551

550552

553+
def _is_agrid(ds: xr.Dataset) -> bool:
554+
# check if U and V are defined on the same dimensions
555+
# if yes, interpret as A grid
556+
return set(ds["U"].dims) == set(ds["V"].dims)
557+
558+
551559
def _is_coordinate_in_degrees(da: xr.DataArray) -> bool:
552560
match da.attrs.get("units"):
553561
case None:

0 commit comments

Comments
 (0)