Skip to content

Commit 9ac08fc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f781eeb commit 9ac08fc

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

src/parcels/_core/uxgrid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from parcels._core.basegrid import BaseGrid
99
from parcels._core.index_search import GRID_SEARCH_ERROR, _search_1d_array, uxgrid_point_in_cell
10-
from parcels._core.mesh import SphericalMesh, EARTH_RADIUS
10+
from parcels._core.mesh import EARTH_RADIUS, SphericalMesh
1111
from parcels._typing import assert_valid_mesh
1212

1313
_UXGRID_AXES = Literal["Z", "FACE"]
@@ -82,7 +82,7 @@ def get_axis_dim(self, axis: _UXGRID_AXES) -> int:
8282
@property
8383
def deg2m(self) -> float:
8484
"""Metres per arcdegree for this grid's mesh."""
85-
if self._radius is None: # flat mesh; None causes crash in advection
85+
if self._radius is None: # flat mesh; None causes crash in advection
8686
return 1.0
8787
return self._radius * np.pi / 180.0
8888

src/parcels/_core/xgrid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import parcels._typing as ptyping
1313
from parcels._core.basegrid import BaseGrid
1414
from parcels._core.index_search import _search_1d_array, _search_indices_curvilinear_2d
15-
from parcels._core.mesh import SphericalMesh, EARTH_RADIUS
15+
from parcels._core.mesh import EARTH_RADIUS, SphericalMesh
1616
from parcels._sgrid.accessor import _get_dim_to_axis_mapping
1717
from parcels._sgrid.core import SGRID_PADDING_TO_XGCM_POSITION
1818

@@ -258,7 +258,7 @@ def time(self):
258258
@property
259259
def deg2m(self) -> float:
260260
"""Metres per degree of arc for this grid's mesh."""
261-
if self._radius is None: # flat mesh; None causes crash in advection
261+
if self._radius is None: # flat mesh; None causes crash in advection
262262
return 1.0
263263
return self._radius * np.pi / 180.0
264264

tests/test_mesh.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
EARTH_DEG2M = EARTH_RADIUS * np.pi / 180
1010

11+
1112
def test_spherical_mesh_deg2m():
1213
assert SphericalMesh().radius == EARTH_RADIUS
1314
assert SphericalMesh().deg2m == EARTH_DEG2M
1415
r = 3389500.0 # Mars radius
1516
assert SphericalMesh(radius=r).deg2m == pytest.approx(r * np.pi / 180)
1617

18+
1719
@pytest.mark.parametrize(
1820
"mesh, exp_radius, exp_deg2m",
1921
[
@@ -28,14 +30,16 @@ def test_xgrid_radius_and_deg2m(mesh, exp_radius, exp_deg2m):
2830
assert grid._radius == exp_radius
2931
assert grid.deg2m == pytest.approx(exp_deg2m)
3032

31-
@pytest.mark.parametrize("mesh, deg2m",
32-
[
33-
(SphericalMesh(), EARTH_DEG2M), # No radius entered
34-
(SphericalMesh(radius=3389500.0), 3389500.0 * np.pi / 180), # Mars
35-
(SphericalMesh(radius=6051800.0), 6051800.0 * np.pi / 180), # Venus
36-
(SphericalMesh(radius=EARTH_RADIUS), EARTH_DEG2M), # Explicit Earth
37-
],
38-
)
33+
34+
@pytest.mark.parametrize(
35+
"mesh, deg2m",
36+
[
37+
(SphericalMesh(), EARTH_DEG2M), # No radius entered
38+
(SphericalMesh(radius=3389500.0), 3389500.0 * np.pi / 180), # Mars
39+
(SphericalMesh(radius=6051800.0), 6051800.0 * np.pi / 180), # Venus
40+
(SphericalMesh(radius=EARTH_RADIUS), EARTH_DEG2M), # Explicit Earth
41+
],
42+
)
3943
def test_advection_uses_custom_radius(mesh, deg2m, npart=10):
4044
ds = simple_UV_dataset()
4145
ds["U"].data[:] = 1.0
@@ -51,26 +55,29 @@ def test_advection_uses_custom_radius(mesh, deg2m, npart=10):
5155
np.testing.assert_allclose(pset.x - startlon, expected_dlon, atol=1e-5)
5256
np.testing.assert_allclose(pset.y, startlat, atol=1e-5)
5357

58+
5459
def test_advection_flat_mesh(npart=10):
5560
ds = simple_UV_dataset(mesh="flat")
5661
ds["U"].data[:] = 1.0
5762
fieldset = FieldSet.from_sgrid_conventions(ds, mesh="flat")
58-
63+
5964
runtime = 7200
6065
startlat = np.linspace(0, 80, npart)
6166
startlon = 20.0 + np.zeros(npart)
6267
pset = ParticleSet(fieldset, x=startlon, y=startlat)
6368
pset.execute(AdvectionRK4, runtime=runtime, dt=np.timedelta64(15, "m"))
6469

65-
assert fieldset.U.grid.deg2m == 1.0 # flat mesh deg2m
70+
assert fieldset.U.grid.deg2m == 1.0 # flat mesh deg2m
6671
np.testing.assert_allclose(pset.x - startlon, runtime, atol=1e-5)
6772
np.testing.assert_allclose(pset.y, startlat, atol=1e-5)
6873

74+
6975
@pytest.mark.parametrize("bad_radius", ["6371000", [6371000], (1, 2), {}])
7076
def test_spherical_mesh_rejects_non_numeric_radius(bad_radius):
7177
with pytest.raises(TypeError):
7278
SphericalMesh(radius=bad_radius)
7379

80+
7481
@pytest.mark.parametrize("bad_radius", [0, -1.0, -6371000])
7582
def test_spherical_mesh_rejects_nonpos_radius(bad_radius):
7683
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)