Skip to content

Commit

Permalink
initial commit, copy from VLIZ gitlab
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-v authored and Bart Vanhoorne committed Jun 26, 2024
0 parents commit c1e6c01
Show file tree
Hide file tree
Showing 19 changed files with 1,648 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/

#data
data/

# Environmental files
.nc
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Habitat suitability model

## About the model/project
Write a summary of the project and what the model does.

## How to use
Technical manual how to install & run the project.

## License
Mention developers, reusability, contact information.
Empty file added demo/app/getData.R
Empty file.
90 changes: 90 additions & 0 deletions demo/app/shinyApp.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "Tidymodels ensemble approach"
author: "Jo-Hannes Nowé"
output:
html_document:
toc=TRUE
---

# Loading the required packages

```{r}
library(shiny)
library(leaflet)
library(raster)
# Define UI
ui <- fluidPage(
tags$head(
tags$style(HTML("
body {
background-color: #333333; /* dark grey */
color: white; /* text color */
}
.text-box {
background-color: black;
color: white;
padding: 10px;
border-radius: 5px;
white-space: pre-line; /* Preserve line breaks */
}
"))
),
titlePanel("Species Habitat Suitability Maps"),
fluidRow(
column(
width = 5,
mainPanel(
h3("Introduction"),
p("This application displays habitat suitability maps for selected species from 2020 to 2100."),
p("A red to orange to yellow to green to blue to dark blue colour scale is used to indicate habitat suitability:"),
tags$ul(
tags$li("red = low suitability"),
tags$li("dark blue = high suitability"),
tags$li("all suitability is between 0 and 1")
),
p("A species, variable, and year can be selected using the options below."),
selectInput("species", "Select Species:", choices = c("Harbour porpoise")),
sliderInput("month", "Select Month:", min = 1, max = 12, value = 1, step = 1)
)
),
column(
width = 7,
leafletOutput("map", width = "100%", height = "800px"),
verbatimTextOutput("additional_text")
)
)
)
# Define server logic
server <- function(input, output) {
output$map <- renderLeaflet({
# Load TIFF file based on selected species, variable, and year
species <- input$species
month <- input$month
file_path <- paste0("PredictionRasters/Month", month, ".tif")
suitability_raster <- raster(file_path)
# Calculate the extent of the study area
raster_ext <- extent(suitability_raster)
leaflet() %>%
setView(lng = mean(c(raster_ext@xmin, raster_ext@xmax)),
lat = mean(c(raster_ext@ymin, raster_ext@ymax)), zoom = 5.1) %>%
addProviderTiles("Esri.WorldImagery") %>%
addRasterImage(suitability_raster, opacity = 0.8) %>%
addLegend("bottomright", title = "Habitat Suitability",
colors = c("red", "orange", "yellow", "green", "blue", "darkblue"),
labels = c("Low", "", "", "", "", "High"),
opacity = 0.8)
})
output$additional_text <- renderText({
"We employed a mechanistic niche modelling approach that mathematically describes each species' specific ecological niche based on their responses to temperature and salinity. This approach, utilizing fuzzy logic principles, provided a more nuanced understanding than traditional methods. Climate prediction data from Bio-ORACLE (www.bio-oracle.org) was incorporated, focusing on sea surface temperature and salinity. Baseline data from 2010 established the foundation for the current scenario, while future projections spanned from 2020 to 2090, covering each decade under six Shared Socioeconomic Pathways (SSPs) – including the most extreme scenario, SSP585.
Team
Our team comprises scientists and data managers from Flanders Marine Institute and Gent University: Rutendo Musimwa, Ward Standaert, Martha Stevens, Salvador Jesus Fernandez Bejarano, Carlota Muñiz, Elisabeth Debusschere, Steven Pint and Gert Everaert"
})
}
# Run the application
shinyApp(ui = ui, server = server)
```

21 changes: 21 additions & 0 deletions demo/config.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# script that reads yaml configuration and builds on the information provided.
# source this script and use settings to get config parameters.

library(yaml)

get_config = function(config){
#' function that gets the configuration settings from a yaml file
#' default config.yml is the one located in main dir.
#'
if (missing(config)){
config = "config.yml"
}
## ---------------------------------------------------------------------------
# READ CONFIG FILE
settings= yaml.load_file("config.yml")
return(settings)
}

settings = get_config()


5 changes: 5 additions & 0 deletions demo/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
edito:
url: something
data:
start_date: 2000
end_date: 2020
25 changes: 25 additions & 0 deletions demo/install_dependencies.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# use this script to install a number of dependencies.

packages = x <- scan("requirements.txt", what="", sep="\n")

packagecheck <- match( packages, utils::installed.packages()[,1] )
packagestoinstall <- packages[ is.na( packagecheck ) ]

if( length( packagestoinstall ) > 0L ) {
utils::install.packages( packagestoinstall,
repos = "http://cran.csiro.au"
)
} else {
print( "All requested packages already installed" )
}

for( package in packages ) {
suppressPackageStartupMessages(
library( package, character.only = TRUE, quietly = TRUE )
)
}

# install.packages(setdiff(packages, rownames(installed.packages())))
# lapply(packages, require, character.only = TRUE)

rm(list = ls.str())
Empty file added demo/requiremets.txt
Empty file.
42 changes: 42 additions & 0 deletions model_training/0_1Preparation.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "Folder structure preparation"
author: "Jo-Hannes Nowé"
date: "05-04-2024"
output:
pdf_document:default
---

A script to prepare the folder structure and download all the used packages.

```{r folder-structure, EVAL=FALSE}
############# Define different folders
downloaddir <- "data/raw_data"
datadir <- "data/derived_data"
mapsdir <- "product/maps"
rasterdir <- "product/species_rasters"
plotsdir <- "product/species_plots"
envdir <-"data/raw_data/environmental_layers"
occdir <-"data/raw_data/occurrences"
spatdir <- "data/raw_data/spatial_layers"
folderstruc <- c(downloaddir,
datadir,
mapsdir,
rasterdir,
plotsdir,
envdir,
occdir,
spatdir)
############# Check for their existence, create if missing
for(i in 1:length(folderstruc)){
if(!dir.exists(folderstruc[i])){
# If not, create the folder
dir.create(folderstruc[i],recursive = TRUE)
cat("Folder created:", folderstruc[i], "\n")
} else {
cat("Folder already exists:", folderstruc[i], "\n")
}
}
```


Loading

0 comments on commit c1e6c01

Please sign in to comment.