-
Notifications
You must be signed in to change notification settings - Fork 7
Broadening the unit tests #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1f7d4b7
Near-complete draft of the paper. Needs an updated initialisation_map…
michaeldenes 0e7ac60
Updates to paper based on Erik's suggestions in github
michaeldenes 17b208f
Adding wind and wave test datasets
michaeldenes 6d87169
Change to the test_settings script to use a standalone .json file for…
michaeldenes 45654c3
Changing test_settings to turn on all kernels
michaeldenes 90716a5
Fixing small bug in .json files that provide 'mixing_variables' and '…
michaeldenes e472ff0
Creating a test for fieldset creation
michaeldenes ea48925
Adding new testing for functions in the constructors module
michaeldenes 3d947ec
Adding all combinations of fields in fieldset testing
michaeldenes d44c04b
Simplifying the test_constructors unit tests
michaeldenes 783cb4b
Removing some blank lines
michaeldenes f7aca6e
Unit tests for all of the different kernels.
michaeldenes ed1ce9d
Making files flake8 compliant
michaeldenes 7824ed4
Hopefully fixing all flake8 compliance problems
michaeldenes 32acc33
A small whitespace issue and missing blank EOF line
michaeldenes 7e8006b
Adding a newline to a list to make it easier to read
michaeldenes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ input_data/ | |
| **.code-workspace* | ||
| **.DS_store** | ||
| **.pyc** | ||
| **.nc | ||
| **.zarr | ||
| docs/_build/* | ||
| docs/_downloads | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import parcels.application_kernels | ||
| import plasticparcels as pp | ||
| import parcels | ||
| from datetime import datetime, timedelta | ||
| import pytest | ||
|
|
||
|
|
||
| def make_simple_fieldset(): | ||
| fieldset = parcels.FieldSet.from_data({'U': 0, 'V': 0}, | ||
| {'lon': 0, 'lat': 0}, | ||
| mesh='spherical') | ||
| return fieldset | ||
|
|
||
|
|
||
| def make_standard_simulation_settings(): | ||
| simulation_settings = {'startdate': datetime.strptime('2020-01-04-00:00:00', '%Y-%m-%d-%H:%M:%S'), | ||
| 'runtime': timedelta(days=2), | ||
| 'outputdt': timedelta(hours=1), | ||
| 'dt': timedelta(minutes=20), | ||
| } | ||
| return simulation_settings | ||
|
|
||
|
|
||
| def make_standard_plastictype_settings(): | ||
| plastictype_settings = {'wind_coefficient': 0.01, # Percentage of wind to apply to particles | ||
| 'plastic_diameter': 0.01, # Plastic particle diameter (m) | ||
| 'plastic_density': 1030., # Plastic particle density (kg/m^3) | ||
| } | ||
| return plastictype_settings | ||
|
|
||
|
|
||
| # Test the create_hydrodynamic_fieldset() function | ||
| def test_create_hydrodynamic_fieldset(): | ||
| settings_file = 'tests/test_data/test_settings.json' | ||
| settings = pp.utils.load_settings(settings_file) | ||
| settings['simulation'] = make_standard_simulation_settings() | ||
|
|
||
| fieldset = pp.constructors.create_hydrodynamic_fieldset(settings) | ||
|
|
||
| assert isinstance(fieldset, parcels.FieldSet) | ||
|
|
||
|
|
||
| # Test the create_fieldset() function | ||
| @pytest.mark.parametrize('use_3D', [True, False]) | ||
| @pytest.mark.parametrize('use_biofouling', [True, False]) | ||
| @pytest.mark.parametrize('use_stokes', [True, False]) | ||
| @pytest.mark.parametrize('use_wind', [True, False]) | ||
| @pytest.mark.parametrize('use_mixing', [True, False]) | ||
| def test_create_fieldset(use_3D, use_biofouling, use_stokes, use_wind, use_mixing): | ||
| settings_file = 'tests/test_data/test_settings.json' | ||
| settings = pp.utils.load_settings(settings_file) | ||
| settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data') | ||
|
|
||
| settings['simulation'] = make_standard_simulation_settings() | ||
|
|
||
| settings['use_3D'] = use_3D | ||
| settings['use_biofouling'] = use_biofouling | ||
| settings['use_stokes'] = use_stokes | ||
| settings['use_wind'] = use_wind | ||
| settings['use_mixing'] = use_mixing | ||
|
|
||
| fieldset = pp.constructors.create_fieldset(settings) | ||
|
|
||
| assert isinstance(fieldset, parcels.FieldSet) | ||
|
|
||
|
|
||
| # Test three different initialisation maps | ||
| @pytest.mark.parametrize('initialisation_map', ['coastal', 'fisheries', 'rivers']) | ||
| def test_create_particleset_from_map(initialisation_map): | ||
| settings_file = 'tests/test_data/test_settings.json' | ||
| settings = pp.utils.load_settings(settings_file) | ||
| settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data') | ||
|
|
||
| settings['simulation'] = make_standard_simulation_settings() | ||
|
|
||
| settings['plastictype'] = make_standard_plastictype_settings() | ||
|
|
||
| settings['release'] = {'initialisation_type': initialisation_map, | ||
| 'country': 'Italy', | ||
| } | ||
|
|
||
| fieldset = make_simple_fieldset() | ||
| pset = pp.constructors.create_particleset_from_map(fieldset, settings) | ||
|
|
||
| assert isinstance(pset, parcels.ParticleSet) | ||
|
|
||
|
|
||
| # Test the two global concentration release map types | ||
| @pytest.mark.parametrize('concentration_type', ['Beach', 'Ocean']) | ||
| def test_create_particleset_from_map_concentrations(concentration_type): | ||
| settings_file = 'tests/test_data/test_settings.json' | ||
| settings = pp.utils.load_settings(settings_file) | ||
| settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data') | ||
|
|
||
| settings['simulation'] = make_standard_simulation_settings() | ||
|
|
||
| settings['plastictype'] = make_standard_plastictype_settings() | ||
|
|
||
| settings['release'] = {'initialisation_type': 'global_concentrations', | ||
| 'concentration_type': concentration_type, | ||
| } | ||
|
|
||
| fieldset = make_simple_fieldset() | ||
| pset = pp.constructors.create_particleset_from_map(fieldset, settings) | ||
|
|
||
| assert isinstance(pset, parcels.ParticleSet) | ||
|
|
||
|
|
||
| # Test three different initialisation maps | ||
| @pytest.mark.parametrize('use_3D', [True, False]) | ||
| @pytest.mark.parametrize('use_biofouling', [True, False]) | ||
| @pytest.mark.parametrize('use_stokes', [True, False]) | ||
| @pytest.mark.parametrize('use_wind', [True, False]) | ||
| @pytest.mark.parametrize('use_mixing', [True, False]) | ||
| def test_create_kernel(use_3D, use_biofouling, use_stokes, use_wind, use_mixing): | ||
erikvansebille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| settings_file = 'tests/test_data/test_settings.json' | ||
| settings = pp.utils.load_settings(settings_file) | ||
| settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data') | ||
|
|
||
| settings['simulation'] = make_standard_simulation_settings() | ||
|
|
||
| settings['use_3D'] = use_3D | ||
| settings['use_biofouling'] = use_biofouling | ||
| settings['use_stokes'] = use_stokes | ||
| settings['use_wind'] = use_wind | ||
| settings['use_mixing'] = use_mixing | ||
|
|
||
| fieldset = pp.constructors.create_fieldset(settings) | ||
| kernels = pp.constructors.create_kernel(fieldset) | ||
|
|
||
| if use_3D: | ||
| assert parcels.application_kernels.AdvectionRK4_3D in kernels | ||
| assert pp.kernels.checkThroughBathymetry in kernels | ||
| assert pp.kernels.checkErrorThroughSurface in kernels | ||
| else: | ||
| assert parcels.application_kernels.AdvectionRK4 in kernels | ||
|
|
||
| if use_3D and use_biofouling: | ||
| assert pp.kernels.Biofouling in kernels | ||
| elif use_3D and not use_biofouling: | ||
| assert pp.kernels.SettlingVelocity in kernels | ||
|
|
||
| if use_mixing: | ||
| assert pp.kernels.VerticalMixing in kernels | ||
|
|
||
| if use_stokes: | ||
| assert pp.kernels.StokesDrift in kernels | ||
| assert pp.kernels.unbeaching in kernels | ||
|
|
||
| if use_wind: | ||
| assert pp.kernels.WindageDrift in kernels | ||
| assert pp.kernels.unbeaching in kernels | ||
|
|
||
| assert pp.kernels.deleteParticle in kernels | ||
| assert pp.kernels.periodicBC in kernels | ||
| assert pp.kernels.PolyTEOS10_bsq in kernels | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| { | ||
| "use_3D": true, | ||
| "allow_time_extrapolation": true, | ||
| "verbose_delete": false, | ||
| "use_mixing": true, | ||
| "use_biofouling": true, | ||
| "use_stokes": true, | ||
| "use_wind": true, | ||
| "ocean": { | ||
| "modelname": "NEMO0083", | ||
| "directory": "tests/test_data/", | ||
| "filename_style": "test_", | ||
| "ocean_mesh": "test_ocean_mesh_hgr.nc", | ||
| "bathymetry_mesh": "test_bathymetry_mesh_zgr.nc", | ||
| "variables": { | ||
| "U": "vozocrtx", | ||
| "V": "vomecrty", | ||
| "W": "vovecrtz", | ||
| "conservative_temperature": "votemper", | ||
| "absolute_salinity": "vosaline" | ||
| }, | ||
| "dimensions": { | ||
| "U": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| }, | ||
| "V": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| }, | ||
| "W": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| }, | ||
| "conservative_temperature": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| }, | ||
| "absolute_salinity": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| } | ||
| }, | ||
| "indices": {}, | ||
| "bathymetry_variables": { | ||
| "bathymetry": "mbathy" | ||
| }, | ||
| "bathymetry_dimensions": { | ||
| "lon": "nav_lon", | ||
| "lat": "nav_lat" | ||
| }, | ||
| "vertical_mixing_variables": { | ||
| "mixing_kz": "votkeavt" | ||
| }, | ||
| "vertical_mixing_dimensions": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| } | ||
| }, | ||
| "bgc": { | ||
| "directory": "tests/test_data/", | ||
| "filename_style": "test_", | ||
| "bgc_mesh": "test_bgc_mesh_hgr.nc", | ||
| "variables": { | ||
| "pp_phyto": "nppv", | ||
| "bio_nanophy": "phy", | ||
| "bio_diatom": "phy2" | ||
| }, | ||
| "dimensions": { | ||
| "pp_phyto": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| }, | ||
| "bio_nanophy": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| }, | ||
| "bio_diatom": { | ||
| "lon": "glamf", | ||
| "lat": "gphif", | ||
| "depth": "depthw", | ||
| "time": "time_counter" | ||
| } | ||
| }, | ||
| "indices": {}, | ||
| "constants": { | ||
| "biofilm_density": 1388.0, | ||
| "algae_cell_volume": 2e-16, | ||
| "K": 1.3805834190672156e-23, | ||
| "R20": 1.1574074074074074e-06, | ||
| "Q10": 2.13, | ||
| "Gamma": 2.0, | ||
| "carbon_molecular_weight": 12.0, | ||
| "collision_probability": 1.0, | ||
| "algae_mortality_rate": 1.0, | ||
| "algae_respiration_f": 1.0 | ||
| } | ||
| }, | ||
| "stokes": { | ||
| "directory": "tests/test_data/", | ||
| "filename_style": "test_waves_", | ||
| "variables": { | ||
| "Stokes_U": "ust", | ||
| "Stokes_V": "vst", | ||
| "wave_Tp": "pp1d" | ||
| }, | ||
| "dimensions": { | ||
| "lat": "latitude", | ||
| "lon": "longitude", | ||
| "time": "time" | ||
| }, | ||
| "indices": {} | ||
| }, | ||
| "wind": { | ||
| "directory": "tests/test_data/", | ||
| "filename_style": "test_wind_", | ||
| "variables": { | ||
| "Wind_U": "u10", | ||
| "Wind_V": "v10" | ||
| }, | ||
| "dimensions": { | ||
| "lat": "latitude", | ||
| "lon": "longitude", | ||
| "time": "time" | ||
| }, | ||
| "indices": {} | ||
| }, | ||
| "unbeaching": { | ||
| "filename": "input_data/NEMO0083/land_current_NEMO0083.nc", | ||
| "variables": { | ||
| "unbeach_U": "land_current_u", | ||
| "unbeach_V": "land_current_v" | ||
| }, | ||
| "dimensions": { | ||
| "lat": "lat", | ||
| "lon": "lon" | ||
| } | ||
| }, | ||
| "simulation": { | ||
| "start_date": null, | ||
| "runtime": null, | ||
| "dt_write": null, | ||
| "dt_timestep": null | ||
| }, | ||
| "release_maps": { | ||
| "coastal": "input_data/NEMO0083/coastal_population_MPW_NEMO0083.csv", | ||
| "rivers": "input_data/NEMO0083/river_emissions_NEMO0083.csv", | ||
| "fisheries": "input_data/NEMO0083/agg_data_fisheries_info_NEMO0083.csv", | ||
| "global_concentrations": "input_data/NEMO0083/global_concentrations_NEMO0083.csv" | ||
| } | ||
| } |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.