Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ input_data/
**.code-workspace*
**.DS_store**
**.pyc**
**.nc
**.zarr
docs/_build/*
docs/_downloads
4 changes: 2 additions & 2 deletions docs/examples/example_Croatian_fisheries_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"lon": "nav_lon",
"lat": "nav_lat"
},
"mixing_variables": {
"vertical_mixing_variables": {
"mixing_kz": "votkeavt"
},
"mixing_dimensions": {
"vertical_mixing_dimensions": {
"lon": "glamf",
"lat": "gphif",
"depth": "depthw",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/example_Greece_coast_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"lon": "nav_lon",
"lat": "nav_lat"
},
"mixing_variables": {
"vertical_mixing_variables": {
"mixing_kz": "votkeavt"
},
"mixing_dimensions": {
"vertical_mixing_dimensions": {
"lon": "glamf",
"lat": "gphif",
"depth": "depthw",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/example_Italy_coast_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"lon": "nav_lon",
"lat": "nav_lat"
},
"mixing_variables": {
"vertical_mixing_variables": {
"mixing_kz": "votkeavt"
},
"mixing_dimensions": {
"vertical_mixing_dimensions": {
"lon": "glamf",
"lat": "gphif",
"depth": "depthw",
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/example_add_your_own_kernel_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
"lon": "nav_lon",
"lat": "nav_lat"
},
"mixing_variables": {
"vertical_mixing_variables": {
"mixing_kz": "votkeavt"
},
"mixing_dimensions": {
"vertical_mixing_dimensions": {
"lon": "glamf",
"lat": "gphif",
"depth": "depthw",
Expand Down
156 changes: 156 additions & 0 deletions tests/test_constructors.py
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):
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 added tests/test_data/test_KZ_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_S_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_T_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_U_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_V_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_W_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_bathymetry_mesh_zgr.nc
Binary file not shown.
Binary file added tests/test_data/test_bgc_mesh_hgr.nc
Binary file not shown.
Binary file added tests/test_data/test_nppv_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_ocean_mesh_hgr.nc
Binary file not shown.
Binary file added tests/test_data/test_phy2_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_phy_2020-01-04.nc
Binary file not shown.
167 changes: 167 additions & 0 deletions tests/test_data/test_settings.json
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 added tests/test_data/test_waves_2020-01-04.nc
Binary file not shown.
Binary file added tests/test_data/test_wind_2020-01-04.nc
Binary file not shown.
Loading