From 1a5252272b079a8ebdf96725db2b2e5355b63a38 Mon Sep 17 00:00:00 2001 From: Biorey Date: Wed, 23 Oct 2024 11:34:46 -0500 Subject: [PATCH] se agrego paquete Se agrego mvtnorm en el step de camptrap_format --- .gitignore | 5 ++- runners/conda-dockerfile | 50 +++++++++++++++++++++++ runners/r-environment.yml | 34 +++++++++++++++ scripts/CamTrap_format2/CamTrap_format2.R | 2 +- scripts/SHI/scpSHI_Jetz_complete.R | 15 +++++++ scripts/data/loadFromStac.yml | 15 +++++++ 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 runners/conda-dockerfile create mode 100644 runners/r-environment.yml diff --git a/.gitignore b/.gitignore index e57754105..c4f24e1c4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ runner.env **/.cache **/.config .server +<<<<<<< Updated upstream /output/ /scripts/00_auk_filter/input/original/ -scripts/00_auk_filter_v2/input/original/ \ No newline at end of file +scripts/00_auk_filter_v2/input/original/ +======= +>>>>>>> Stashed changes diff --git a/runners/conda-dockerfile b/runners/conda-dockerfile new file mode 100644 index 000000000..60e4650b6 --- /dev/null +++ b/runners/conda-dockerfile @@ -0,0 +1,50 @@ +FROM condaforge/mambaforge + +ADD ./r-environment.yml /data/r-environment.yml + +WORKDIR /data + +RUN mamba init + +# Since we are using the user from the client computer to run the scripts, +# we need to create and open the permissions of a few files/directories. +RUN chmod a+w /data + +COPY .condarc /.condarc +RUN chmod 777 /.condarc + +# Conda cache and environments folder will be replaced by a virtual volume, but we want them to be writable by the runtime user. +# Permissions cannot be defined at mount time, hence we create empty folder with the appropriate permissions. +RUN mkdir /.cache && mkdir /.cache/conda && chmod a+w /.cache/conda +RUN mkdir /.conda && chmod a+w /.conda +RUN mkdir /r-libs-user && chmod a+w /r-libs-user +RUN mkdir /conda-env-yml && chmod a+w /conda-env-yml + +# Initialize mamba when logging in with bash +RUN echo 'eval "$(conda shell.bash hook)"; source /opt/conda/etc/profile.d/mamba.sh' > /.bashrc && chmod a+x /.bashrc + +# Allow to read bashrc to execute mamba init when using docker exec +# See https://stackoverflow.com/a/74017557/3519951 +RUN sed -e '/[ -z "$PS1" ] && return/s/^/#/g' -i /root/.bashrc + +RUN mamba env create -f /data/r-environment.yml + +# Hide "error libmamba Could not open lockfile '/opt/conda/pkgs/cache/cache.lock'" when installing manually with non-root user +# That error would not prevent the correct installation, but it looked like it to the user. +RUN chmod -R 777 /opt/conda/pkgs/cache + + +# These packages are not in conda-forge +# ADD CRAN PACKAGES HERE +RUN bash --login -c "mamba activate rbase; R -e 'install.packages(c(\"CoordinateCleaner\", \ + \"geodata\", \ + \"OpenStreetMap\"\ + ), repos=\"https://cloud.r-project.org/\")'" + + + +# ADD GITHUB PACKAGES HERE +RUN bash --login -c "mamba activate rbase; R -e 'devtools::install_github(\"ReseauBiodiversiteQuebec/stac-catalogue\")'" +RUN bash --login -c "mamba activate rbase; R -e 'devtools::install_github(\"connectscape/Makurhini\")'" + +RUN date +"%Y-%m-%d %R" > /version.txt diff --git a/runners/r-environment.yml b/runners/r-environment.yml new file mode 100644 index 000000000..7bb7072c3 --- /dev/null +++ b/runners/r-environment.yml @@ -0,0 +1,34 @@ +name: rbase +channels: + - conda-forge + - r +dependencies: + - conda-build + - libgdal + - r-abind + - r-base + - r-curl + - r-devtools + - r-dismo + - r-downloader + - r-enmeval + - r-essentials + - r-gdalcubes + - r-gdalutilities + - r-gdalutils + - r-ggsci + - r-rjava + - r-jpeg + - r-landscapemetrics + - r-png + - r-rcurl + - r-rgbif + - r-rjson + - r-rredlist + - r-rstac + - r-sf + - r-stars + - r-terra + - r-tidyselect + - r-unmarked + - r-magrittr diff --git a/scripts/CamTrap_format2/CamTrap_format2.R b/scripts/CamTrap_format2/CamTrap_format2.R index e712cd722..ca473e69b 100644 --- a/scripts/CamTrap_format2/CamTrap_format2.R +++ b/scripts/CamTrap_format2/CamTrap_format2.R @@ -2,7 +2,7 @@ # Install necessary libraries - packages packagesPrev<- installed.packages()[,"Package"] # Check and get a list of installed packages in this machine and R version -packagesNeed<- c("magrittr", "data.table", "terra", "raster", "sf", "pbapply", "this.path", "rjson", "tools", "unmarked", "reshape2", "Rcpp" , "RcppEigen", "RcppParallel", "RcppNumerical", "secr", "camtrapR") # Define the list of required packages to run the script +packagesNeed<- c("magrittr", "data.table", "terra", "raster", "sf", "pbapply", "this.path", "rjson", "tools", "unmarked", "reshape2", "Rcpp" , "RcppEigen", "RcppParallel", "RcppNumerical", "secr", "camtrapR", "mvtnorm") # Define the list of required packages to run the script new.packages <- packagesNeed[!(packagesNeed %in% packagesPrev)]; if(length(new.packages)) {install.packages(new.packages, binary=T, force=T, dependencies = F, repos= "https://packagemanager.posit.co/cran/__linux__/jammy/latest")} # Check and install required packages that are not previously installed # Load libraries diff --git a/scripts/SHI/scpSHI_Jetz_complete.R b/scripts/SHI/scpSHI_Jetz_complete.R index 80c8383fb..c278d540f 100644 --- a/scripts/SHI/scpSHI_Jetz_complete.R +++ b/scripts/SHI/scpSHI_Jetz_complete.R @@ -67,7 +67,10 @@ v_time_steps <- seq(t_0,t_n,time_step) #credentials token <- Sys.getenv("IUCN_TOKEN") +<<<<<<< Updated upstream print(token) +======= +>>>>>>> Stashed changes #Filter source for land cover, global or colombia # LC_source <- input$lc_source @@ -205,7 +208,11 @@ print("========== Map of suitable area generated ==========") #3.1 GFW data------------------------------------------------------------------- #forest base map cube_GFW_TC <- +<<<<<<< Updated upstream load_cube(stac_path = "https://io.biodiversite-quebec.ca/stac/", +======= + load_cube(stac_path = "https://stac.geobon.org/", +>>>>>>> Stashed changes limit = 1000, collections = c("gfw-treecover2000"), bbox = sf_ext_srs, @@ -232,7 +239,11 @@ print("========== Base forest layer downloaded ==========") # Download forest loss maps and create different layers for each year to remove from forest cube_GFW_loss <- +<<<<<<< Updated upstream load_cube(stac_path = "https://io.biodiversite-quebec.ca/stac/", +======= + load_cube(stac_path = "https://stac.geobon.org/", +>>>>>>> Stashed changes limit = 1000, collections = c("gfw-lossyear"), bbox = sf_ext_srs, @@ -262,7 +273,11 @@ if(t_0!=2000){ r_year_loss_mask_plot <- terra::classify(s_year_loss_mask[[length(l_r_year_loss)]],rcl=cbind(0,NA)) # turn 0 to NA cube_GFW_gain <- +<<<<<<< Updated upstream load_cube(stac_path = "https://io.biodiversite-quebec.ca/stac", +======= + load_cube(stac_path = "https://stac.geobon.org/", +>>>>>>> Stashed changes limit = 1000, collections = c("gfw-gain"), bbox = sf_ext_srs, diff --git a/scripts/data/loadFromStac.yml b/scripts/data/loadFromStac.yml index 45a0f2bd0..35dc9ceb7 100644 --- a/scripts/data/loadFromStac.yml +++ b/scripts/data/loadFromStac.yml @@ -53,3 +53,18 @@ outputs: label: Weight matrix with layers description: Weight matrix used for Bon optimization. Vector of layer linkes followed by weights. type: text +<<<<<<< Updated upstream +======= +conda: + channels: + - r + - conda-forge + dependencies: + - libgdal + - proj + - r-proj + - r-gdalcubes + - r-rstac + - r-dplyr + - r-rcurl +>>>>>>> Stashed changes