Skip to content

Commit 47a7ecc

Browse files
committed
Updates to google collab files
1 parent cf78365 commit 47a7ecc

4 files changed

Lines changed: 635 additions & 583 deletions

File tree

src/DRAKKAR workshop code/PlasticParcels/helper.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import xarray as xr
44

55

6+
import pandas as pd
67
from parcels import FieldSet, Field, ParticleSet, JITParticle, Variable, AdvectionRK4, AdvectionRK4_3D
78
from parcels.tools.converters import Geographic, GeographicPolar
89
from datetime import datetime, timedelta
@@ -354,7 +355,63 @@ def create_particleset(fieldset, particle_settings):
354355
windage_coefficient=windage_coefficients
355356
)
356357
return pset
357-
358+
359+
def create_particleset_from_file(fieldset, particle_settings):
360+
""" Helper function to create a Parcels.ParicleSet
361+
362+
Parameters
363+
----------
364+
model_settings :
365+
A dictionary of model settings used to create the fieldset
366+
particle_settings :
367+
A dictionary of particle settings used to define some ....
368+
369+
Returns
370+
-------
371+
fieldset
372+
A parcels.FieldSet object
373+
"""
374+
375+
# Load release type information
376+
release_type = particle_settings['release_type']
377+
if release_type == 'coastal':
378+
release_file = './data/coastal_population_MPW_NEMO0083.csv'
379+
release_quantity_name = 'MPW_Cell'
380+
elif release_type == 'rivers':
381+
release_file = './data/river_emissions_NEMO0083.csv'
382+
release_quantity_name = 'Emissions'
383+
elif release_type == 'fisheries':
384+
release_file = './data/agg_data_fisheries_info.csv'
385+
release_quantity_name = 'fishing_hours'
386+
387+
particle_locations = pd.read_csv(release_file)
388+
389+
390+
# Select specific continent/region/subregion/country/economic status if applicable:
391+
if 'continent' in particle_settings.keys():
392+
particle_locations = particle_locations[particle_locations['Continent'] == particle_settings['continent']]
393+
if 'region' in particle_settings.keys():
394+
particle_locations = particle_locations[particle_locations['Region'] == particle_settings['region']]
395+
if 'subregion' in particle_settings.keys():
396+
particle_locations = particle_locations[particle_locations['Subregion'] == particle_settings['subregion']]
397+
if 'country' in particle_settings.keys():
398+
particle_locations = particle_locations[particle_locations['Country'] == particle_settings['country']]
399+
if 'economicstatus' in particle_settings.keys():
400+
particle_locations = particle_locations[particle_locations['Economic status'] == particle_settings['economicstatus']]
401+
402+
particle_locations = particle_locations.groupby(['Longitude', 'Latitude'])[release_quantity_name].agg('sum').reset_index()
403+
particle_locations = particle_locations[particle_locations[release_quantity_name]>0]
404+
405+
release_locations = {'lons': particle_locations['Longitude'],
406+
'lats': particle_locations['Latitude']}
407+
408+
particle_settings['release_locations'] = release_locations
409+
410+
411+
return create_particleset(fieldset, particle_settings)
412+
413+
414+
358415
def create_kernel(fieldset, pset):
359416
"""_summary_
360417

src/DRAKKAR workshop code/PlasticParcels/kernels.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,12 @@ def biofouling(particle, fieldset, time):
455455
a_grazing = fieldset.algae_mortality_rate * particle.algae_amount
456456

457457
### ------ Compute the final algal amount ------
458-
particle.algae_amount += (a_collision + algae_growth - a_grazing - a_respiration) * particle.dt
458+
algae_amount_change = (a_collision + algae_growth - a_grazing - a_respiration) * particle.dt
459+
if particle.algae_amount + algae_amount_change < 0.:
460+
particle.algae_amount = 0.
461+
else:
462+
particle.algae_amount += algae_amount_change
463+
459464

460465
### ------ Compute the new settling velocity
461466
particle_diameter = 2. * (total_radius) # equivalent spherical diameter [m], calculated from Dietrich (1982) from A = pi/4 * dn**2
@@ -757,23 +762,24 @@ def unbeaching(particle, fieldset, time):
757762

758763

759764
def checkThroughBathymetry(particle, fieldset, time):
760-
bathym = fieldset.bathymetry[time, particle.depth + particle_ddepth, particle.lat + particle_dlat, particle.lon + particle_dlon]
761-
762-
# If the particle is below the bathymetry
763-
if particle.depth + particle_ddepth > bathym:
764-
particle_ddepth = bathym - particle.depth - 5 # Move the particle 5 metres above the model bathymetry
765-
765+
bathymetry_local = fieldset.bathymetry[time, particle.depth + particle_ddepth, particle.lat + particle_dlat, particle.lon + particle_dlon]
766+
potential_depth = particle.depth + particle_ddepth
767+
min_depth = 0.5 #meters - maybe set this as a fieldset variable?
766768

767-
768-
769-
769+
if potential_depth < min_depth:
770+
particle_ddepth = fieldset.z_start - particle.depth # Stick particle to surface
771+
elif potential_depth > bathymetry_local:
772+
particle_ddepth = bathymetry_local - particle.depth # Stick particle at bottom of ocean
773+
elif particle.depth > 100 and potential_depth > (bathymetry_local*0.99): # for deeper particles; since bathymetry can be quite rough (and is interpolated linearly) look at the 99% value instead
774+
particle_ddepth = bathymetry_local*0.99 - particle.depth # Stick particle at the 99% point
775+
776+
elif potential_depth > 3900: # If particle >3.9km deep, stick it there
777+
particle_ddepth = 3900 - particle.depth
770778

771779

772780

773781

774-
775-
776-
782+
777783

778784

779785

0 commit comments

Comments
 (0)