SkillAgentSearch skills...

LakeEnsemblR

An R package that facilitates multi-model ensembles for lake thermodynamics. Also includes tools for calibration, sensitivity analysis and data visualization.

Install / Use

/learn @aemon-j/LakeEnsemblR
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- README.md is generated from README.Rmd. Please edit that file -->

LakeEnsemblR <a href="https://aemon-j.github.io/LakeEnsemblR/"><img src="man/figures/logo.png" alt="LakeEnsemblR website" align="right" height="120"/></a>

<!-- badges: start -->

R-CMD-check codecov Project Status: Active – The project has reached a stable, usable
state and is being actively
developed. DOI Citation
Badge

<!-- badges: end -->

Tools for running an ensemble of lake models using standardised input data. Lake models currently incorporated are Freshwater Lake Model (FLake), General Lake Model (GLM), General Ocean Turbulence Model (GOTM) (lake-branch), Simstrat, and MyLake.

You can find example setups here: https://github.com/aemon-j/LER_examples.

Check out our published paper LakeEnsemblR: An R package that facilitates ensemble modelling of lakes.

In v1.1, some changes occurred in the configuration file. If you want to adapt your existing setup, see: https://github.com/aemon-j/LakeEnsemblR/wiki/From-v1.0-to-v1.1

Installation

Prior to installing the package, you will need to install the packages which run the models and the tools for manipulating model data from GitHub. It is recommended to do this each time before testing to ensure all packages are up-to-date as parallel development might be ongoing.

# install.packages("remotes")
remotes::install_github("GLEON/rLakeAnalyzer")
remotes::install_github("aemon-j/GLM3r", ref = "v3.1.1")
remotes::install_github("USGS-R/glmtools", ref = "ggplot_overhaul")
remotes::install_github("aemon-j/FLakeR", ref = "inflow")
remotes::install_github("aemon-j/GOTMr")
remotes::install_github("aemon-j/gotmtools")
remotes::install_github("aemon-j/SimstratR")
remotes::install_github("aemon-j/MyLakeR")

Following this you can install LakeEnsemblR from Github with:

remotes::install_github("aemon-j/LakeEnsemblR")

Should you run into unexpected installation issues, please have a look at this page: https://github.com/aemon-j/LakeEnsemblR/wiki/Installation-issues

Visualize

You can download PyNcView, a cross-platform NetCDF viewer, for viewing the NetCDF output.

Example model run


# Load LakeEnsemblR
library(LakeEnsemblR)
#> 
#> 
#>   _          _        _____                          _     _ ____  
#>  | |    __ _| | _____| ____|_ __  ___  ___ _ __ ___ | |__ | |  _ \ 
#>  | |   / _` | |/ / _ |  _| | '_ \/ __|/ _ | '_ ` _ \| '_ \| | |_) |
#>  | |__| (_| |   |  __| |___| | | \__ |  __| | | | | | |_) | |  _ < 
#>  |_____\__,_|_|\_\___|_____|_| |_|___/\___|_| |_| |_|_.__/|_|_| \_\
#>                                                                    
#> 
#>               https://github.com/aemon-j/LakeEnsemblR

# Copy template folder
template_folder <- system.file("extdata/feeagh", package= "LakeEnsemblR")
dir.create("example") # Create example folder
file.copy(from = template_folder, to = "example", recursive = TRUE)
#> [1] TRUE
setwd("example/feeagh") # Change working directory to example folder

# Set config file & models
config_file <- "LakeEnsemblR.yaml"
model <- c("FLake", "GLM", "GOTM", "Simstrat", "MyLake")

# Example run
# 1. Export settings - creates directories with all model setups and exports settings from the LER configuration file
export_config(config_file = config_file, model = model)
#>    depths wtemp
#> 1     0.9 4.977
#> 2     2.5 4.965
#> 3     5.0 4.953
#> 4     8.0 4.941
#> 5    11.0 4.883
#> 6    14.0 4.887
#> 7    16.0 4.877
#> 8    18.0 4.986
#> 9    20.0 4.960
#> 10   22.0 4.944
#> 11   27.0 4.980
#> 12   32.0 4.951
#> 13   42.0 4.905

# 2. Run ensemble lake models
run_ensemble(config_file = config_file, model = model)
#> [1] "Running MyLake from 01/01/10 to 01/01/11..."
#>    user  system elapsed 
#>    8.68    0.65    9.40

Post-processing


# Load libraries for post-processing
library(gotmtools)
library(ggplot2)

## Plot model output using gotmtools/ggplot2
# Extract names of all the variables in netCDF
ncdf <- "output/ensemble_output.nc"
vars <- gotmtools::list_vars(ncdf)
vars # Print variables
#> [1] "temp"       "ice_height" "w_level"

p1 <- plot_heatmap(ncdf)
#>            [,1]                    
#> short_name "temp"                  
#> units      "degC"                  
#> dimensions "lon lat z model member"
p1
<img src="man/figures/README-post-process-1.png" width="100%" />
# Change the theme and increase text size for saving
p1 <- p1 +
  theme_classic(base_size = 14) + 
  scale_colour_gradientn(limits = c(0, 21),
                         colours = rev(RColorBrewer::brewer.pal(11, "Spectral")))

p1
<img src="man/figures/README-post-process-2.png" width="100%" />

Plot Ensemble output

# Plot ensemble mean at 0.9m
model = c("FLake", "GLM", "GOTM", "Simstrat", "MyLake")
plot_ensemble(ncdf = ncdf, model = model, var = "temp", depth = 0.9)
<img src="man/figures/README-plot-ensemble-1.png" width="100%" />

# Load watertemp from netCDF file as a list
wtemp <- load_var(ncdf = ncdf, var = "temp", return = "list")
#>            [,1]                    
#> short_name "temp"                  
#> units      "degC"                  
#> dimensions "lon lat z model member"
names(wtemp)
#> [1] "FLake"    "GLM"      "GOTM"     "Simstrat" "MyLake"   "Obs"

# Plot residual diagnostic plots
plots <- plot_resid(var_list = wtemp) # Plot residuals - returns a list of plots
names(plots) #
#> [1] "obs_res"   "res_depth" "yday_res"  "res_dist"

# Plot residuals vs. depth ("res_depth")
plots[[2]]
<img src="man/figures/README-plot-ensemble-2.png" width="100%" />

# Analyse the netCDF output
out <- analyse_ncdf(ncdf, model = model, spin_up = 0)
#>   |                                                                              |                                                                      |   0%  |                                                                              |                                                                      |   1%  |                                                                              |=                                                                     |   1%  |                                                                              |=                                                                     |   2%  |                                                                              |==                                                                    |   2%  |                                                                              |==                                                                    |   3%  |                                                                              |==                                                                    |   4%  |                                                                              |===                                                                   |   4%  |                                                                              |===                                                                   |   5%  |                                                                              |====                                                                  |   5%  |                                                                              |====                                                                  |   6%  |                                                                              |=====                                                                 |   7%  |                                                                              |=====                                                                 |   8%  |                                                                              |======                                                                |   8%  |                                                                              |======                                                                |   9%  |                                                                              |=======                                                               |   9%  |                                                                              |=======                                                               |  10%  |                                                                              |=======                                                               |  11%  |                                                                              |========                                                              |  11%  |                                                                              |========                                                              |  12%  |                                                                              |=========                                                             |  12%  |                                                                              |
View on GitHub
GitHub Stars46
CategoryDevelopment
Updated13d ago
Forks21

Languages

R

Security Score

90/100

Audited on Mar 18, 2026

No findings