|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# PlasticParcels Example\n", |
| 8 | + "## The pathways and fate of existing plastic pollution along Greek coastlines\n", |
| 9 | + "In this example, we will use `plasticparcels` to run a basic simulation of microplastic pollution along the Greek coastline." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "# Library imports\n", |
| 19 | + "from datetime import datetime, timedelta\n", |
| 20 | + "\n", |
| 21 | + "# Parcels and PlasticParcels imports\n", |
| 22 | + "import os\n", |
| 23 | + "os.chdir('../../')\n", |
| 24 | + "import plasticparcels as pp\n", |
| 25 | + "\n", |
| 26 | + "# Plotting imports\n", |
| 27 | + "import matplotlib.pyplot as plt\n", |
| 28 | + "import cartopy.crs as ccrs\n", |
| 29 | + "import xarray as xr" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "code", |
| 34 | + "execution_count": null, |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "# Load the model settings\n", |
| 39 | + "settings_file = 'docs/examples/example_Greece_coast_settings.json'\n", |
| 40 | + "settings = pp.utils.load_settings(settings_file)" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [], |
| 48 | + "source": [ |
| 49 | + "# Create the simulation settings\n", |
| 50 | + "settings['simulation'] = {\n", |
| 51 | + " 'start_date': datetime.strptime('2019-01-10-00:00:00', '%Y-%m-%d-%H:%M:%S'), # Start date of simulation\n", |
| 52 | + " 'runtime': timedelta(days=30), # Runtime of simulation, use negative if releasing particles backwards in time\n", |
| 53 | + " 'dt_write': timedelta(hours=12), # Timestep of output\n", |
| 54 | + " 'dt_timestep': timedelta(minutes=20), # Timestep of advection\n", |
| 55 | + " }\n", |
| 56 | + "\n", |
| 57 | + "# Overwrite some settings\n", |
| 58 | + "settings['use_3D'] = False\n", |
| 59 | + "settings['use_biofouling'] = False\n", |
| 60 | + "settings['use_stokes'] = True\n", |
| 61 | + "settings['use_wind'] = True\n" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "code", |
| 66 | + "execution_count": null, |
| 67 | + "metadata": {}, |
| 68 | + "outputs": [], |
| 69 | + "source": [ |
| 70 | + "# Create the particle release settings\n", |
| 71 | + "settings['release'] = {\n", |
| 72 | + " 'initialisation_type': 'global_concentrations',\n", |
| 73 | + " 'concentration_type': 'Beach',\n", |
| 74 | + " 'country': 'Greece',\n", |
| 75 | + "}" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": null, |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [], |
| 83 | + "source": [ |
| 84 | + "# Create the plastic type settings\n", |
| 85 | + "settings['plastictype'] = {\n", |
| 86 | + " 'wind_coefficient' : 0.01, # Percentage of wind to apply to particles\n", |
| 87 | + " 'plastic_diameter' : 0.001, # Plastic particle diameter (m)\n", |
| 88 | + " 'plastic_density' : 1030., # Plastic particle density (kg/m^3)\n", |
| 89 | + "}" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [], |
| 97 | + "source": [ |
| 98 | + "settings['ocean']['indices'] = {'lon':range(3300, 4000), 'lat':range(1850, 2400)}#, 'depth':range(0,2)}" |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + "cell_type": "code", |
| 103 | + "execution_count": null, |
| 104 | + "metadata": {}, |
| 105 | + "outputs": [], |
| 106 | + "source": [ |
| 107 | + "# Download the mask and release data\n", |
| 108 | + "#settings = pp.utils.download_plasticparcels_dataset('NEMO0083', settings, 'input_data')" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "execution_count": null, |
| 114 | + "metadata": {}, |
| 115 | + "outputs": [], |
| 116 | + "source": [ |
| 117 | + "# Create the fieldset\n", |
| 118 | + "fieldset = pp.constructors.create_fieldset(settings)" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "code", |
| 123 | + "execution_count": null, |
| 124 | + "metadata": {}, |
| 125 | + "outputs": [], |
| 126 | + "source": [ |
| 127 | + "# Create the particleset\n", |
| 128 | + "pset = pp.constructors.create_particleset_from_map(fieldset, settings)" |
| 129 | + ] |
| 130 | + }, |
| 131 | + { |
| 132 | + "cell_type": "code", |
| 133 | + "execution_count": null, |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [], |
| 136 | + "source": [ |
| 137 | + "# Create the applicable kernels to the plastic particles\n", |
| 138 | + "kernels = pp.constructors.create_kernel(fieldset)" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": null, |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "# Define the runtime, the timestepping, and the output frequency of the simulation from the settings\n", |
| 148 | + "runtime = settings['simulation']['runtime']\n", |
| 149 | + "dt_timestep = settings['simulation']['dt_timestep']\n", |
| 150 | + "dt_write = settings['simulation']['dt_write']" |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + "cell_type": "code", |
| 155 | + "execution_count": null, |
| 156 | + "metadata": {}, |
| 157 | + "outputs": [], |
| 158 | + "source": [ |
| 159 | + "# Create the particle file where output will be stored\n", |
| 160 | + "pfile = pp.ParticleFile('example_Italy_coast.zarr', pset, settings=settings, outputdt=dt_write)" |
| 161 | + ] |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "code", |
| 165 | + "execution_count": null, |
| 166 | + "metadata": {}, |
| 167 | + "outputs": [], |
| 168 | + "source": [ |
| 169 | + "# Execute the simulation\n", |
| 170 | + "pset.execute(kernels, runtime=runtime, dt=dt_timestep, output_file=pfile)" |
| 171 | + ] |
| 172 | + }, |
| 173 | + { |
| 174 | + "cell_type": "code", |
| 175 | + "execution_count": null, |
| 176 | + "metadata": {}, |
| 177 | + "outputs": [], |
| 178 | + "source": [ |
| 179 | + "# Plot the trajectories\n", |
| 180 | + "ds = xr.open_zarr('example_Italy_coast.zarr')\n", |
| 181 | + "\n", |
| 182 | + "ax = plt.subplot(111, projection=ccrs.PlateCarree())\n", |
| 183 | + "ax.coastlines(zorder=20)\n", |
| 184 | + "ax.plot(ds['lon'].T, ds['lat'].T, transform=ccrs.PlateCarree())\n", |
| 185 | + "\n", |
| 186 | + "plt.show()" |
| 187 | + ] |
| 188 | + } |
| 189 | + ], |
| 190 | + "metadata": { |
| 191 | + "kernelspec": { |
| 192 | + "display_name": "py3_parcels", |
| 193 | + "language": "python", |
| 194 | + "name": "python3" |
| 195 | + }, |
| 196 | + "language_info": { |
| 197 | + "codemirror_mode": { |
| 198 | + "name": "ipython", |
| 199 | + "version": 3 |
| 200 | + }, |
| 201 | + "file_extension": ".py", |
| 202 | + "mimetype": "text/x-python", |
| 203 | + "name": "python", |
| 204 | + "nbconvert_exporter": "python", |
| 205 | + "pygments_lexer": "ipython3", |
| 206 | + "version": "3.11.4" |
| 207 | + } |
| 208 | + }, |
| 209 | + "nbformat": 4, |
| 210 | + "nbformat_minor": 2 |
| 211 | +} |
0 commit comments