88
99EARTH_DEG2M = EARTH_RADIUS * np .pi / 180
1010
11+
1112def 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+ )
3943def 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+
5459def 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 ), {}])
7076def 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 ])
7582def test_spherical_mesh_rejects_nonpos_radius (bad_radius ):
7683 with pytest .raises (ValueError ):
0 commit comments