Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Latest commit

 

History

History
214 lines (116 loc) · 7.81 KB

File metadata and controls

214 lines (116 loc) · 7.81 KB

ENMOD

Ecological Niche Modeling on Docker

Tutorial

Getting started

For this project we'll work with 4 species in the Genus Mammillaria, a group of small cacti mostly restricted to Mexico.

Mammillaria haageana

  • We will use the working directory Mammillaria :

home/user/documents/Mammillaria

Containing:

Working Directory

  • An empty subdirectory data_out:

  • A subdirectory data_in with the following data:

Data_In

  • An input file, species.csv

Species.csv

Required only for Records.R

  • Raster files from WorldClim Database in .bil format in a directory named "rasters". Required for Vars.R and Maxent.R

asc_files

Raster files must be clipped to coincide with your species distribution. If species records fall outside your raster coordinates you will get NA data.

Docker

https://upload.wikimedia.org/wikipedia/commons/7/79/Docker_(container_engine)_logo.png

Docker is a software container platform. It is used to eliminate compatibility problems when working with different operating systems. It is based on the idea of that you can package your code with dependencies into a deployable unit called a container. Images are essentially a snapshot of the contents a container is meant to run.

ENMOD is a Docker image designed to download data from Global Biodiversity Information Facility (GBIF), generate ocurrence files, ocurrence maps, and generate ENMs on batch mode.

All the scripts, libraries and packages necessary to use ENMOD come pre-installed. In order to use ENMOD you'll need to install Docker on your operating system

Visit Docker Website For an installation and basic walkthrough.

You need to make sure Docker is properly working by writing a command like docker ps -a, if an error like the following appears:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

You must start the docker service by writing:

sudo service docker start or sudo dockerd

Once everything is in order, you can dowload the latest ENMOD image using the following command:

docker pull ghuertaramos/enmod

Running ENMOD

Once the image is pulled from docker cloud.

  • We will set a shortname for the path of our working directory

mydatapath=/home/user/Documents/Mammillaria/

Records.R


  • We can begin our work by downloading the records for the species in species.csv using Records.R with the following command:
docker run --rm -v $mydatapath:/ENMOD/data ghuertaramos/enmod Rscript Records.R

Records.R

We have now obtained a record file for each species:

Records_Files

Records.R by default deletes columns which are redundant or rarely relevant. This script selects the information on the fields: lon, lat, locality, gbifID, elevation, identifiedBy, identifier, recordNumber and occurrenceRemarks.

Record files generated by Records.R can be quite messy, many records are repeated (yellow) and some records may not have geographic coordinates (green)

Records.RAW

Clean.R


To improve these results we can use the Clean.R function in ENMOD:

docker run --rm -v $mydatapath:/ENMOD/data enmod Rscript Clean.R

Clean.R

Now the files contains only unique records with geographic coordinates. It is important to notice that for now, this script also deletes records outside the americas. The exact ranges are. Longitude: -131,-38 Latitude: -49,55

Clean.RAW

The maps generated by this script show each record on a simple map, we may now check for inconsistencies and probable errors.

CleanMaps

Rarf.R


Some records aren’t evenly distributed, probably due to sampling effort. To compensate for that, The function `Rarf.R divides the map up into a grid and randomly draw a single point from each grid square.

This script is disabled for species with less than 30 records by default.

docker run --rm -v $mydatapath:/ENMOD/data enmod Rscript Rarf.R

Rarf.R

RarfMaps

The number of records is reduced, for example M. haageana had 500 records but after rarefaction we obtained 130 records.

Pseudo.R


We also need some points that define regions our species aren’t found. One option is to define a “background” region to sample at random, which (we hope) captures environmental conditions that our species could disperse to, but haven’t.

docker run --rm -v $mydatapath:/ENMOD/data enmod Rscript Pseudo.R

Pseudo.R

We have defined circles with a radius of 50km, centered on each point in our presence list, then draw random points that fall within those circles.

Pseudomaps

Vars.R


The following scripts are necessary to diminish the effect of variable autocorrelation in the models, since they mean the same thing (in terms of inference).

First Vars.R enables us to extract climatic data from rasters based on our species records.

docker run --rm -v $mydatapath:/ENMOD/data enmod Rscript Vars.R

Vars.R

Vars.RAW

Corrls.R


From the extracted data we can use Corrls.Rto generate correlation coefficients, significancies and plots from climatic data.

docker run --rm -v $mydatapath:/ENMOD/data enmod Rscript Corrls.R

Corrls.R

Correlation files include correlation values and significancies, but we can conveniently analyse the data thorugh the generated plots for each species.

CorrlsPlot

In this plot the values represent significant correlation coefficients, negative coefficientes are in red and positive are blue. This graph allows us to select non correlated bioclimatic variables to include in the model.

Maxent.R


Using Maxent.R we can generate ENMs for input species, this function also generates output data and graphs for model evaluation.

This function uses data originated from Rarf.R , Pseudo.R and the raster files needed in data_in.

Use the command:

docker run --rm -v $mydatapath:/ENMOD/data enmod Rscript Maxent.R

This scrip generatesa new directory named after each species input and also includes the following directories:

MaxentOutput

The output directory contains the standar maxent output which contains useful data and graphs that allow us to assess performance.

Most data are condensed in the html file

MAxentModel

The directory evaluation contains a graph that cross-validates models with presence/absence data.

Finally in the directory prediction we can find a grid files that contains a visualization of the predictions from our model, it is an estimation of the probability of presence for every cell in our raster data set.

MaxentPred

Known issues

In Records.R if query species has no records on gbif database, the script will fail. This can also ocurr if the species name is misspelled.

Rarf.R Vars.R and Maxent.R may take a long time to finish.

It is also very important to notice that Clean.Rand Rarf.R scripts only works for records in the americas. The exact ranges are: Longitude: -131,-38 Latitude: -49,55