Skip to content
Merged
6 changes: 3 additions & 3 deletions plasticparcels/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ def create_particleset(fieldset, settings, release_locations):
"""

# Set the longitude, latitude, and plastic amount per particle
lons = release_locations['lons']
lats = release_locations['lats']
lons = np.array(release_locations['lons'])
lats = np.array(release_locations['lats'])
if 'plastic_amount' in release_locations.keys():
plastic_amounts = release_locations['plastic_amount']
else:
plastic_amounts = np.nan_like(lons)
plastic_amounts = np.full_like(lons, np.nan)

# Set particle properties
plastic_densities = np.full(lons.shape, settings['plastictype']['plastic_density'])
Expand Down
22 changes: 22 additions & 0 deletions tests/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ def test_create_fieldset(use_3D, use_biofouling, use_stokes, use_wind, use_mixin
assert isinstance(fieldset, parcels.FieldSet)


# Test the base create_particleset() function
@pytest.mark.parametrize('plastic_amount', [None, 1])
def test_create_particleset(plastic_amount):
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()

if plastic_amount is None:
release_locations = {'lons': [18], 'lats': [35]}
else:
release_locations = {'lons': [18], 'lats': [35], 'plastic_amount': [plastic_amount]}

fieldset = make_simple_fieldset()
pset = pp.constructors.create_particleset(fieldset, settings, release_locations)

assert isinstance(pset, parcels.ParticleSet)


# Test three different initialisation maps
@pytest.mark.parametrize('initialisation_map', ['coastal', 'fisheries', 'rivers'])
def test_create_particleset_from_map(initialisation_map):
Expand Down
19 changes: 8 additions & 11 deletions tests/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ def make_standard_plastictype_settings():

def make_standard_particleset(fieldset, settings):
# Generate a particleset that has particles in the test domain
settings['release'] = {'initialisation_type': 'fisheries', 'country': 'Malta'}
pset = pp.constructors.create_particleset_from_map(fieldset, settings)

# Only keep particles in the test domain
keep_particles = (pset.lon > 17) & (pset.lon < 20) & (pset.lat < 36) & (pset.lat > 34)
pset.remove_booleanvector(~keep_particles)
release_locations = {'lons': [18, 18.25, 18.5], 'lats': [35, 35, 35],
'plastic_amount': [1, 1, 1]}
pset = pp.constructors.create_particleset(fieldset, settings, release_locations)

return pset

Expand All @@ -40,7 +37,6 @@ def make_standard_particleset(fieldset, settings):
def test_advection_only(use_3D):
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()
Expand Down Expand Up @@ -75,7 +71,6 @@ def test_advection_only(use_3D):
def test_settling_velocity():
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()
Expand Down Expand Up @@ -108,7 +103,6 @@ def test_settling_velocity():
def test_biofouling():
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()
Expand Down Expand Up @@ -141,6 +135,8 @@ def test_biofouling():
def test_Stokes():
settings_file = 'tests/test_data/test_settings.json'
settings = pp.utils.load_settings(settings_file)

# Required for the unbeaching kernel
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')

settings['simulation'] = make_standard_simulation_settings()
Expand All @@ -157,7 +153,7 @@ def test_Stokes():

fieldset = pp.constructors.create_fieldset(settings)

kernels = [pp.kernels.StokesDrift, pp.kernels.deleteParticle]
kernels = [pp.kernels.StokesDrift, pp.kernels.unbeaching, pp.kernels.periodicBC, pp.kernels.deleteParticle]

pset = make_standard_particleset(fieldset, settings)

Expand All @@ -173,6 +169,8 @@ def test_Stokes():
def test_wind():
settings_file = 'tests/test_data/test_settings.json'
settings = pp.utils.load_settings(settings_file)

# Required for the unbeaching kernel
settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')

settings['simulation'] = make_standard_simulation_settings()
Expand Down Expand Up @@ -205,7 +203,6 @@ def test_wind():
def test_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['plastictype'] = make_standard_plastictype_settings()
Expand Down