Applying deep learning to quantify drivers of long-term ecological change in a Swedish marine protected area — GitHub repository
This is the official GitHub repository for the scientific publication, "Applying deep learning to quantify drivers of long-term ecological change in a Swedish marine protected area" by Nilsson et al., currently available as a preprint. This repository details the data, processing workflows, and statistical analyses utilized to generate results shown in this article. While the primary objective of this repository is to enhance the reproducibility of the study, code here can be highly useful in analyses of data from the Swedish platform for subsea image analysis (SUBSIM) and may also be used for unrelated purposes as well.
Nilsson et al. trained a YOLOv8 object-detection model to annotate prominent benthic invertebrate fauna from ROV footage spanning across 26 years (1997-2023) along a depth gradient in Kosterhavets national park (situated in the northernmost part of Sweden's west coast).
Analysis of the data produced by the object-detection model highlighted changes in community structure along the depth gradient as well as significant temporal trends in community structure and ecosystem function. Temporal trends in community structure were primarily driven by size and temperature preference of the investigated taxa, with large, cold-loving taxa declining. However, the area's designation as a national park appears to benefit the remaining community.
The repository is divided into four chapters, following the order of methodology utilized by Nilsson et al. (2025). Each chapter contains a script to carry out the chapter's tasks, example data, and instructions for use (in a README file and the script).
/ (root)
|-- /chapter1 # Depth Extraction
|-- /chapter2 # Annotations to GBIF data
|-- /chapter3 # Depth exploration and temperature assignments
|-- /chapter4 # GLMs and trait analyses
|-- README.md # Main repository README
|-- LICENSE # License file
The primary idea of the repository is to follow scripts 1-4 using example data to follow data processing/analysis steps of Nilsson et al. (2025), but users may use any chapter irregardless of order to perform their own analyses if deemed relevant. Chapters include:
-
Using OCR software to extract depth values from a folder of image frames taken from ROV footage (with overlay visible).
-
Tying YOLOv8 annotations to depth values from chapter 1, gather abundance data for each investigated taxon and formatting data for GBIF publication.
-
Extracting depth ranges of investigated taxa from data generated in chapter 2 and a GBIF occurrence download for comparison. Finding temperature preferences of investigated taxa using GBIF occurrences and seafloor temperature data packages.
-
Investigating trends in community structure and ecosystem functioning using data generated in chapter 2 and temperature preferences from chapter 3. Investigating the impact of traits on abundance trends of individual taxa.
For further details on what is done in the different chapters, check chapter READMEs and scripts.
The original workflow was executed using the programming languages Python (Jupyter Notebooks) and R (RStudio).
Python packages required:
- os
- csv
- PIL
- numpy
- pandas
- easyocr
- matplotlib.pyplot
R packages required:
- zoo
- dplyr
- tidyr
- ggplot2
- terra
- raster
- biooracler
- geosphere
For more information on chapter-specific dependencies, check chapter READMEs.
Please use the following citation for use of any data or code provided in this repository:
- Christian Nilsson. (2025). ShrimpFather7/Koster-Deep-Learning-Ecology. Zenodo. https://doi.org/10.5281/zenodo.15249144
Associated article citation:
- Nilsson CL, Faurby S, Burman E, Germishuys J, and Obst M. 2025. “ Applying Deep Learning to Quantify Drivers of Long-Term Ecological Change in a Swedish Marine Protected Area.” Ecology and Evolution 15, no. 9: e72091. https://doi.org/10.1002/ece3.72091
Associated dataset citation:
- Nilsson CL, Anton V, Burman E, Germishuys J, Obst M. (2025). Koster historical biodiversity assessment. Version 1.7. Wildlife.ai. Occurrence dataset. https://ipt.gbif.org.nz/resource?r=koster_historical_assessment&v=1.8 https://doi.org/10.15468/rzhmef.
Associated YOLOv8 model citation:
- Nilsson, CL, Germishuys, J, Burman, E, Anton, V, White, J, Obst, M (2024). Koster historical invertebrate model - SUBSIM 17tx. Zenodo. https://doi.org/10.5281/zenodo.13589902
Questions, bugs, and suggestions can be submitted via email to christian.nilsson7@outlook.com.
All scripts and data are available under the MIT license, please cite any use or derivatives of this work.