Skip to content

Commit

Permalink
Merge pull request #65 from OceanParcels/fix_unit_test_failures
Browse files Browse the repository at this point in the history
Minor update to depth- and time-dependent unit testing
  • Loading branch information
michaeldenes authored Dec 5, 2024
2 parents a5a0c63 + fee65c7 commit aaf0871
Show file tree
Hide file tree
Showing 31 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/environment_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ dependencies:
- ipython
- numpydoc
- nbsphinx
- sphinx<6
- pandoc>3,<4
- sphinx
- pandoc
- pydata-sphinx-theme
- sphinx-autobuild
- myst-parser
Binary file added tests/test_data/test_KZ_2020-01-01.nc
Binary file not shown.
Binary file modified tests/test_data/test_KZ_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_KZ_2020-01-05.nc
Binary file not shown.
Binary file added tests/test_data/test_S_2020-01-01.nc
Binary file not shown.
Binary file modified tests/test_data/test_S_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_S_2020-01-05.nc
Binary file not shown.
Binary file added tests/test_data/test_T_2020-01-01.nc
Binary file not shown.
Binary file modified tests/test_data/test_T_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_T_2020-01-05.nc
Binary file not shown.
Binary file added tests/test_data/test_U_2020-01-01.nc
Binary file not shown.
Binary file modified tests/test_data/test_U_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_U_2020-01-05.nc
Binary file not shown.
Binary file added tests/test_data/test_V_2020-01-01.nc
Binary file not shown.
Binary file modified tests/test_data/test_V_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_V_2020-01-05.nc
Binary file not shown.
Binary file added tests/test_data/test_W_2020-01-01.nc
Binary file not shown.
Binary file modified tests/test_data/test_W_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_W_2020-01-05.nc
Binary file not shown.
Binary file modified tests/test_data/test_bathymetry_mesh_zgr.nc
Binary file not shown.
Binary file modified tests/test_data/test_bgc_mesh_hgr.nc
Binary file not shown.
Binary file modified tests/test_data/test_nppv_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_nppv_2020-01-05.nc
Binary file not shown.
Binary file modified tests/test_data/test_ocean_mesh_hgr.nc
Binary file not shown.
Binary file modified tests/test_data/test_phy2_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_phy2_2020-01-05.nc
Binary file not shown.
Binary file modified tests/test_data/test_phy_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_phy_2020-01-05.nc
Binary file not shown.
Binary file modified tests/test_data/test_waves_2020-01-04.nc
Binary file not shown.
Binary file modified tests/test_data/test_wind_2020-01-04.nc
Binary file not shown.
22 changes: 17 additions & 5 deletions tests/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def make_standard_plastictype_settings():
# Use tiny wind percentage because test data set is not large and wind speeds are quick!
plastictype_settings = {'wind_coefficient': 0.0001, # Percentage of wind to apply to particles
'plastic_diameter': 0.001, # Plastic particle diameter (m)
'plastic_density': 1030., # Plastic particle density (kg/m^3)
'plastic_density': 1027.67, # Plastic particle density (kg/m^3)
}
return plastictype_settings

Expand All @@ -32,6 +32,14 @@ def make_standard_particleset(fieldset, settings):

return pset

def checkBelowDataDepth(particle, fieldset, time):
# The vertical mixing kernel can push particles below the test dataset depth, throwing an
# out of bounds error. This kernel will keep particles above the max depth.
if particle.depth + particle_ddepth >= fieldset.max_depth: # noqa
# move a meter above the max depth
particle_ddepth = fieldset.max_depth - particle.depth - 1.0 # noqa
particle.state = parcels.StatusCode.Success


@pytest.mark.parametrize('use_3D', [True, False])
def test_advection_only(use_3D):
Expand Down Expand Up @@ -159,7 +167,6 @@ def test_Stokes():

start_lons = pset.lon.copy()
start_lats = pset.lat.copy()
print(pset[0].dt)
pset.execute(kernels, runtime=settings['simulation']['runtime'], dt=settings['simulation']['dt'])

# Assert that the particles move from their initial location
Expand Down Expand Up @@ -216,18 +223,23 @@ def test_mixing():
settings['use_stokes'] = False

fieldset = pp.constructors.create_fieldset(settings)
fieldset.add_constant('max_depth', fieldset.U.depth[-1])

# Set the simulation runtime to just 1 day so particles aren't kicked around significantly
settings['simulation']['runtime'] = timedelta(days=1)

kernels = [parcels.application_kernels.AdvectionRK4_3D, pp.kernels.checkThroughBathymetry,
pp.kernels.checkErrorThroughSurface, pp.kernels.deleteParticle]

kernels_mixing = [parcels.application_kernels.AdvectionRK4_3D, pp.kernels.VerticalMixing,
pp.kernels.checkThroughBathymetry, pp.kernels.checkErrorThroughSurface,
pp.kernels.deleteParticle]
checkBelowDataDepth, pp.kernels.checkThroughBathymetry,
pp.kernels.checkErrorThroughSurface, pp.kernels.deleteParticle]

pset = make_standard_particleset(fieldset, settings)
pset_mixing = make_standard_particleset(fieldset, settings)

pset.execute(kernels, runtime=settings['simulation']['runtime'], dt=settings['simulation']['dt'])
pset.execute(kernels_mixing, runtime=settings['simulation']['runtime'], dt=settings['simulation']['dt'])
pset_mixing.execute(kernels_mixing, runtime=settings['simulation']['runtime'], dt=settings['simulation']['dt'])

# Assert that the particles move from their initial location
assert (np.sum(np.abs(pset.lon - pset_mixing.lon)) > 0.) & (np.sum(np.abs(pset.lat - pset_mixing.lat)) > 0.)

0 comments on commit aaf0871

Please sign in to comment.