Skip to content

Commit 7589bde

Browse files
Add fix for spherical uxgrid mesh type
1 parent fa5a352 commit 7589bde

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

parcels/spatialhash.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ def __init__(
138138
_xbound, _ybound, _zbound = _latlon_rad_to_xyz(np.deg2rad(lat), np.deg2rad(lon))
139139

140140
# Compute bounding box of each face
141-
self._xlow = np.min(_xbound, axis=-1)
142-
self._xhigh = np.max(_xbound, axis=-1)
143-
self._ylow = np.min(_ybound, axis=-1)
144-
self._yhigh = np.max(_ybound, axis=-1)
145-
self._zlow = np.min(_zbound, axis=-1)
146-
self._zhigh = np.max(_zbound, axis=-1)
141+
self._xlow = np.atleast_2d(np.min(_xbound, axis=-1))
142+
self._xhigh = np.atleast_2d(np.max(_xbound, axis=-1))
143+
self._ylow = np.atleast_2d(np.min(_ybound, axis=-1))
144+
self._yhigh = np.atleast_2d(np.max(_ybound, axis=-1))
145+
self._zlow = np.atleast_2d(np.min(_zbound, axis=-1))
146+
self._zhigh = np.atleast_2d(np.max(_zbound, axis=-1))
147147

148148
else:
149149
# Boundaries of the hash grid are the bounding box of the source grid

tests/v4/test_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def test_field_constant_in_time():
185185

186186
# Assert that the field can be evaluated at any time, and returns the same value
187187
time = np.datetime64("2000-01-01T00:00:00")
188-
P1 = P.eval(time=time, z=10.0, y=30.0, x=30.0, applyConversion=False)
189-
P2 = P.eval(time=time + np.timedelta64(1, "D"), z=10.0, y=30.0, x=30.0, applyConversion=False)
188+
P1 = P.eval(time=time, z=[10.0], y=[30.0], x=[30.0], applyConversion=False)
189+
P2 = P.eval(time=time + np.timedelta64(1, "D"), z=[10.0], y=[30.0], x=[30.0], applyConversion=False)
190190
assert np.isclose(P1, P2)
191191

192192

tests/v4/test_uxarray_fieldset.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def test_fesom2_square_delaunay_uniform_z_coordinate_eval():
119119
P = Field(name="p", data=ds.p, grid=UxGrid(ds.uxgrid, z=ds.coords["nz"]), interp_method=UXPiecewiseLinearNode)
120120
fieldset = FieldSet([UVW, P, UVW.U, UVW.V, UVW.W])
121121

122-
assert fieldset.U.eval(time=ds.time[0].values, z=1.0, y=30.0, x=30.0, applyConversion=False) == 1.0
123-
assert fieldset.V.eval(time=ds.time[0].values, z=1.0, y=30.0, x=30.0, applyConversion=False) == 1.0
124-
assert fieldset.W.eval(time=ds.time[0].values, z=1.0, y=30.0, x=30.0, applyConversion=False) == 0.0
125-
assert fieldset.p.eval(time=ds.time[0].values, z=1.0, y=30.0, x=30.0, applyConversion=False) == 1.0
122+
assert fieldset.U.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[30.0], applyConversion=False) == 1.0
123+
assert fieldset.V.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[30.0], applyConversion=False) == 1.0
124+
assert fieldset.W.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[30.0], applyConversion=False) == 0.0
125+
assert fieldset.p.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[30.0], applyConversion=False) == 1.0
126126

127127

128128
def test_fesom2_square_delaunay_antimeridian_eval():
@@ -132,10 +132,19 @@ def test_fesom2_square_delaunay_antimeridian_eval():
132132
Since the underlying data is constant, we can check that the values are as expected.
133133
"""
134134
ds = datasets_unstructured["fesom2_square_delaunay_antimeridian"]
135-
P = Field(name="p", data=ds.p, grid=UxGrid(ds.uxgrid, z=ds.coords["nz"]), interp_method=UXPiecewiseLinearNode)
135+
P = Field(
136+
name="p",
137+
data=ds.p,
138+
grid=UxGrid(ds.uxgrid, z=ds.coords["nz"], mesh="spherical"),
139+
interp_method=UXPiecewiseLinearNode,
140+
)
136141
fieldset = FieldSet([P])
137142

138-
assert np.isclose(fieldset.p.eval(time=ds.time[0].values, z=1.0, y=30.0, x=-170.0, applyConversion=False), 1.0)
139-
assert np.isclose(fieldset.p.eval(time=ds.time[0].values, z=1.0, y=30.0, x=-180.0, applyConversion=False), 1.0)
140-
assert np.isclose(fieldset.p.eval(time=ds.time[0].values, z=1.0, y=30.0, x=180.0, applyConversion=False), 1.0)
141-
assert np.isclose(fieldset.p.eval(time=ds.time[0].values, z=1.0, y=30.0, x=170.0, applyConversion=False), 1.0)
143+
assert np.isclose(
144+
fieldset.p.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[-170.0], applyConversion=False), 1.0
145+
)
146+
assert np.isclose(
147+
fieldset.p.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[-180.0], applyConversion=False), 1.0
148+
)
149+
assert np.isclose(fieldset.p.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[180.0], applyConversion=False), 1.0)
150+
assert np.isclose(fieldset.p.eval(time=ds.time[0].values, z=[1.0], y=[30.0], x=[170.0], applyConversion=False), 1.0)

0 commit comments

Comments
 (0)