knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(NTLlakeloads)
library(tidyverse)
devtools::load_all(".")

Get LTER data

# Load NTL datasets
LTERtemp = loadLTERtemp() # Download NTL LTER data from EDI
LTERnutrients = loadLTERnutrients() # Download NTL LTER data from EDI
LTERions = loadLTERions() # Download NTL LTER data from EDI
LTERsecchi = loadLTERsecchi() # Download NTL LTER data from EDI

Additionally, these datasets can be viewed at

https://github.com/hdugan/NTLviewer

Variables available for plotting

# Available variables
availableVars()

# Available variables that are not depth-discrete. Used with weeklyInterpolate.1D.
availableVars.1D()

Interpolate weekly total phosphorus data for Lake Mendota

# printFigs = TRUE to output series of interpolated profiles (but slower)
# See help file for parameter descripts
df.ME = weeklyInterpolate(lakeAbr = 'ME', var = 'totpuf_sloh', dataset = LTERnutrients, maxdepth = 24, 
                          constrainMethod = 'zero', setThreshold = 0.1, printFigs = F)

Plotting entire timeseries

plotTimeseries(df.interpolated = df.ME$weeklyInterpolated, var = 'totpuf_sloh')

Plot specific year with observed data

# With observations
plotTimeseries.year(df.interpolated = df.ME$weeklyInterpolated, observations = df.ME$observations,  var = 'totpuf_sloh', chooseYear = 2008)

# Without observations, but adding legend title 
plotTimeseries.year(df.interpolated = df.ME$weeklyInterpolated, var = 'totpuf_sloh', chooseYear = 2008, legend.title = 'TP (µg/L)')

Calculate mass at annual or weekly timescales

df.mass.annual = calcMass(df.ME$weeklyInterpolated,lakeAbr = 'ME', time.res = 'annual', conversion = 1e6)

Example of plotting annual mass

library(ggplot2)

ggplot(df.mass.annual, aes(x = year, y = mass)) +
  geom_path() +
  geom_point() +
  ylab('TP (kg)') +
  labs(title = 'Lake Mendota annual TP mass', caption = 'Calculated from NTLlakeloads') +  
  theme_bw(base_size = 10) +
  theme(axis.title.x = element_blank())

Decompose weekly mass timeseries to analyse trends and seasonality

df.mass = calcMass(df.ME$weeklyInterpolated,lakeAbr = 'ME', time.res = 'weekly', conversion = 1e6)

decomposeTS(df.mass, lakeAbr = 'ME', var = 'totpuf_sloh')


hdugan/NTLlakeloads documentation built on June 16, 2024, 6:59 p.m.