PelagiaIBM OpenDrift module for simulation of jellyfish population dynamics using dispersal, growth and mortaliy.


Repository structure:
opendrift/ - pelagia_IBM.py module file, should be included in the opendrift/models/ folder.
PelagiaMFS09/ - run scripts
IMG/ - images of results
MED-MFC_006_004_mask_bathy_copy3.nc - mask netCDF file for Med MFS. A land-proximity variable was added (nearshore_mask).


The "How to use" guide provides pointers how to run the code and how to reproduce Figures from the "Spatially explicit individual-based model reveals the mauve stinger jellyfish distribution in the Mediterranean Sea" manuscript.


How to use:

1) Install OpenDrift (https://opendrift.github.io/index.html).
2) Copy the pelagia_IBM.py module file into the opendrift/models/ folder.
3) Prepare the files with environmental variables (currents, primary production). NetCDF files from Copernicus Marine Service were used by the scripts included in the repository. Specificaly, Mediterranean Sea Physics Reanalysis daly values (https://doi.org/10.25423/CMCC/MEDSEA_MULTIYEAR_PHY_006_004_E3R1) were used for the currents and Mediterranean Sea biogeochemical reanalysis (https://doi.org/10.25423/cmcc/medsea_multiyear_bgc_006_008_medbfm3) monthly values were used for primary production.


Initital 4-year run (not neccessary) 
1) Open Run_baserun.py and set the right paths for the readers (environmental parameters files). Set the right path to the 3d7053bc-f72d-11ee-bfa3-6b8e5cabd000.shp file which defines the initial release polygon. You can also set the timestep, length of the simulation, number of particles etc.
2) Run the Run_baserun.py script: 
> python Run_baserun.py
3) Run the MATLAB version of the ABM/IBM using the Pelagia_IBM5_par.m. This script will run multiple simulations, using slighthly different parameters each time. The script takes a long time to run. It uses the parfor loop and makes use of multiple CPU cores.
4) Use the MATLAB sctipt Parameter_clustering2.m to plot the results in the parameter space and search for clusters- Figures 1 and 2 in the manuscript.


Long multi-year runs 
1) Set the paths to the current and primary production files (in this case NetCDFs from CMEMS) in the Run_pelagia.py and Restart_pelagia.py scripts. The former runs the first year of the simulation and the latter all the other years.
2) Set the growth-mortality coefficients in the Longrun.sh shell script or use those provided in the first lines of the script. The script can run multiple coefficient combinations for multiple years.
3) Run rhe Longrun.sh script
> ./Longrun.sh
This will also run for several hours. The time depends on the number of years and number of parameter combinations you want to run.
4) To plot the biomass distribution, use the Pelagia_biomass_density_plot2.m MATLAB script (Figures 5 to 8). To plot yearly biomass distribution, use the Pelagia_biomass_density_plot_yearly.m script.
5) Use the count_Area_density_multiyear.m script to evaluate the biomass inside a predefined area - Figure 9 in the manuscript.  
6) To plot the total biomass in the model, use the count_jelly_multiyear.m script. This will plot a graph as in Figure 4.



