Commit bab1fd59 authored by Thomas Shatwell's avatar Thomas Shatwell
Browse files

Tidied line lengths and rephrased subset() instances cause build was complaining

parent ab486dc0
#' @title Calculates ice phenology
#'
#' @description Calculates seasonal ice phenology including annual mean,
#' @description Calculates seasonal ice phenology
#' including annual mean,
#' max and total duration of ice cover.
#'
#' @param H_ice A vector indicating the presence of ice cover.
#' Can be numerical or logical where `TRUE` or any number > `0` (e.g. ice thickness) indicates ice, and
#' Can be numerical or logical where `TRUE` or any number > `0`
#' (e.g. ice thickness) indicates ice, and
#' `FALSE` or `0` indicates no ice cover.
#' @param dates The dates corresponding to the ice observations in POSIX style and same length as `H_ice`.
#' @param dates The dates corresponding to the ice observations
#' in POSIX style and same length as `H_ice`.
#' @param NH Is the lake in the northern hemisphere? (logical)
#'
#' @details
#' To be added later.
#'
#' @return A `data.frame` containing ice stratification phenology
#' @return A `data.frame` containing ice stratification
#' phenology
#'
#' @author Tom Shatwell
#'
......@@ -26,26 +30,41 @@
# ice statistics -----------------------------------------------
# this function returns ice phenology statstics: annual mean, max and total
# this is a subset of the function above analyse_strat, but just for ice.
# NOTE: summer strat periods are allocated to the year in which the period
# starts. Winter stratification and ice periods are allocated to the year in
# which they end.
# H_ice: ice thickness time series, set to NULL if analysis not required
# dates: POSIX style date vector corresponding to rows of Ts and Tb.
# not used: dT: temperature difference between top and bottom indicating stratification.
# drho: density difference between top and bottom indicating stratificaiton [kg m^-3]
# this function returns ice phenology statstics:
# annual mean, max and total
# this is a subset of the function above analyse_strat,
# but just for ice.
# NOTE: summer strat periods are allocated to the year in which
# the period starts. Winter stratification and ice periods are
# allocated to the year in which they end.
# H_ice: ice thickness time series, set to NULL if analysis
# not required
# dates: POSIX style date vector corresponding to
# rows of Ts and Tb.
# not used: dT: temperature difference between top and bottom
# indicating stratification.
# drho: density difference between top and bottom indicating
# stratificaiton [kg m^-3]
# NH: northern hemisphere? TRUE or FALSE
ice_phenology <- function(H_ice, dates, NH=TRUE) {
the_years <- as.POSIXlt(dates)$year+1900
yrs <- unique(the_years)
doys <- as.POSIXlt(dates)$yday # day of the year [0..364]
alt_doys <- doys # alternative counting from [-182 .. 182] (July 2/3) for ice in northern hemisphere or strat in southern hemisphere
alt_doys[doys>182] <- doys[doys>182] - (365 + leap(the_years[doys>182])) # Jan 1 is day 0, correct for leap years
# alternative counting from [-182 .. 182] (July 2/3) for ice
# in northern hemisphere or strat in southern hemisphere
alt_doys <- doys
# Jan 1 is day 0, correct for leap years
alt_doys[doys>182] <- doys[doys>182] -
(365 + leap(the_years[doys>182]))
alt_years <- the_years
alt_years[alt_doys<0] <- the_years[alt_doys<0] +1 # alternative counting of years (shifted forward by half a year)
# alternative counting of years
# (shifted forward by half a year)
alt_years[alt_doys<0] <- the_years[alt_doys<0] +1
if(NH) { # NH ice and SH stratification use alternative doy and year counts to adjust for ice and stratification events that span more than one calendar year
# NH ice and SH stratification use alternative doy and year
# counts to adjust for ice and stratification events that
# span more than one calendar year
if(NH) {
ice_yrs <- alt_years
ice_doys <- alt_doys
} else {
......@@ -54,35 +73,51 @@ ice_phenology <- function(H_ice, dates, NH=TRUE) {
}
ice <- H_ice > 0
i_i_st <- diff(c(ice[1],ice))==1 # indices of ice cover onset
i_i_en <- diff(c(ice[1],ice))==-1 # # indices of ice cover end
if(ice[1]) i_i_st <- c(NA, i_i_st) # if initially frozen, set first start date to NA
if(ice[length(ice)]) i_i_en <- c(i_i_en, NA) # if frozen at end, set last thaw date to NA
ice_st <- dates[i_i_st] # ice start dates
ice_en <- dates[i_i_en] # ice end dates
# if(sum(ice)==0) # if there is no ice at all, set start and end to time=0
# indices of ice cover onset
i_i_st <- diff(c(ice[1],ice))==1
# indices of ice cover end
i_i_en <- diff(c(ice[1],ice))==-1
# if initially frozen, set first start date to NA
if(ice[1]) i_i_st <- c(NA, i_i_st)
# if frozen at end, set last thaw date to NA
if(ice[length(ice)]) i_i_en <- c(i_i_en, NA)
# ice start dates
ice_st <- dates[i_i_st]
# ice end dates
ice_en <- dates[i_i_en]
# if there is no ice at all, set start and end to time=0
# if(sum(ice)==0)
# maximum ice thickness
IceMax <- NULL
for(ii in unique(the_years)) {
Hice_maxi <- which.max(H_ice[ice_yrs == ii])
IceMaxOut <- data.frame(year=ii,
HiceMax = H_ice[ice_yrs == ii][Hice_maxi],
HiceMaxDay = ice_doys[ice_yrs==ii][Hice_maxi],
HiceMaxDate = dates[ice_yrs == ii][Hice_maxi])
if(sum(H_ice[ice_yrs == ii])==0) IceMaxOut[1,c("HiceMaxDay","HiceMaxDate")] <- NA
IceMaxOut <- data.frame(
year=ii,
HiceMax = H_ice[ice_yrs == ii][Hice_maxi],
HiceMaxDay = ice_doys[ice_yrs==ii][Hice_maxi],
HiceMaxDate = dates[ice_yrs == ii][Hice_maxi])
if(sum(H_ice[ice_yrs == ii])==0) {
IceMaxOut[1,c("HiceMaxDay","HiceMaxDate")] <- NA
}
IceMax <- rbind(IceMax, IceMaxOut)
}
ice_start_doys <- ice_doys[i_i_st] # day of year of start of ice cover events
ice_end_doys <- ice_doys[i_i_en] # day of year of end of ice cover events
ice_event_yrs <- ice_yrs[i_i_st] # the years assigned to each ice event
# day of year of start of ice cover events
ice_start_doys <- ice_doys[i_i_st]
# day of year of end of ice cover events
ice_end_doys <- ice_doys[i_i_en]
# the years assigned to each ice event
ice_event_yrs <- ice_yrs[i_i_st]
# if there is no ice, set values to NA ...
if(sum(ice)==0) {
ice_start_doys <- ice_end_doys <- ice_event_yrs <- ice_st <- ice_en <- NA
ice_start_doys <- ice_end_doys <- ice_event_yrs <-
ice_st <- ice_en <- NA
}
ice_dur <- as.double(difftime(ice_en, ice_st, units="days")) # duration of ice periods
# duration of ice periods
ice_dur <- as.double(difftime(ice_en, ice_st, units="days"))
# summary of ice cover events
......@@ -95,7 +130,8 @@ ice_phenology <- function(H_ice, dates, NH=TRUE) {
ice_out <- NULL
for(mm in unique(ice.summary$year[!is.na(ice.summary$year)])) {
ice2 <- subset(ice.summary, year==mm)
# ice2 <- subset(ice.summary, year==mm)
ice2 <- ice.summary[ice.summary$year==mm,]
ice2_on <- ice2[which.max(ice2$dur),"startday"]
ice2_off <- ice2[which.max(ice2$dur),"endday"]
if(anyNA(ice2$dur)) ice2_on <- ice2_off <- NA
......@@ -111,20 +147,33 @@ ice_phenology <- function(H_ice, dates, NH=TRUE) {
lastthaw=max(ice2$endday)))
}
ice_out <- ice_out[ice_out$year %in% yrs,] # trim years outside the simulation range (eg ice that forms at the end of the last year, which should be assigned to the following year outside the simulation period)
# trim years outside the simulation range
# (eg ice that forms at the end of
# the last year, which should be assigned to the following
# year outside the simulation period)
ice_out <- ice_out[ice_out$year %in% yrs,]
ice_out1 <- data.frame(year=yrs, MeanIceDur=NA, MaxIceDur=NA,
TotIceDur=NA, IceOn=NA, IceOff=NA, FirstFreeze=NA,
LastThaw=NA, HiceMax=NA, HiceMaxDay=NA)
ice_out1 <- data.frame(year=yrs,
MeanIceDur=NA,
MaxIceDur=NA,
TotIceDur=NA,
IceOn=NA,
IceOff=NA,
FirstFreeze=NA,
LastThaw=NA,
HiceMax=NA,
HiceMaxDay=NA)
ice_out1[match(ice_out$year, yrs),
c("MeanIceDur","MaxIceDur","TotIceDur",
"IceOn","IceOff","FirstFreeze","LastThaw")] <- ice_out[,-1]
"IceOn","IceOff","FirstFreeze",
"LastThaw")] <- ice_out[,-1]
ice_out1[,c("HiceMax","HiceMaxDay")] <- IceMax[,c("HiceMax","HiceMaxDay")]
i8 <- ice_out1$IceOff < ice_out1$IceOn
i8[is.na(i8)]<-FALSE # this gets rid of any NAs
if(sum(i8, na.rm=TRUE)>0) {
ice_out1[i8, "IceOff"] <- ice_out1[i8,"IceOn"] + ice_out1[i8,"MaxIceDur"]
ice_out1[i8, "IceOff"] <- ice_out1[i8,"IceOn"] +
ice_out1[i8,"MaxIceDur"]
}
i9 <- ice_out1$LastThaw < ice_out1$IceOn & ice_out1$TotIceDur < 366
i9[is.na(i9)]<-FALSE # this gets rid of any NAs
......
#' @title Calculates stratification phenology
#'
#' @description Calculates seasonal stratification phenology including annual mean,
#' @description Calculates seasonal stratification phenology
#' including annual mean,
#' max and total duration of summer stratification and ice cover.
#'
#' @param Ts Surface temperature (numeric vector).
#' @param Tb Bottom temperature (numeric vector with same length as `Ts`.
#' @param H_ice Ice thickness as numeric vector of the same length as `Ts`. `NULL` if ice statistics should not be calculated.
#' @param dates The dates corresponding to the temperature measurements in POSIX style and same length as `Ts`.
#' @param thresh The density or temperature threshold used to define the presence of stratification, ie whether the difference between Ts and Tb exceeds this threshold. If `bydensity` is `TRUE`, then `thresh` must be in (kg m^-3), and `Ts` and `Tb` must be in Celsius.
#' @param H_ice Ice thickness as numeric vector of the same length as `Ts`.
#' `NULL` if ice statistics should not be calculated.
#' @param dates The dates corresponding to the temperature measurements
#' in POSIX style and same length as `Ts`.
#' @param thresh The density or temperature threshold used to define the
#' presence of stratification, ie whether the difference between Ts and Tb
#' exceeds this threshold. If `bydensity` is `TRUE`, then `thresh` must
#' be in (kg m^-3), and `Ts` and `Tb` must be in Celsius.
#' @param NH Is the lake in the northern hemisphere? (logical)
#' @param bydensity Should `thresh` be defined as a density threshold (logical)? If `FALSE`, a temperature threshold is assumed. If `TRUE`, then `Ts` and `Tb` must be in degrees Celsius
#' @param bydensity Should `thresh` be defined as a density
#' threshold (logical)?
#' If `FALSE`, a temperature threshold is assumed.
#' If `TRUE`, then `Ts` and `Tb` must be in degrees Celsius
#'
#' @details
#' To be added later.
......@@ -32,28 +41,40 @@
# stratification statistics -----------------------------------------------
# this function returns stratification statstics: annual mean, max and total
# this function returns stratification statstics: annual mean,
# max and total
# length of summer, winter stratification and ice duration.
# NOTE: summer strat periods are allocated to the year in which the period
# starts. Winter stratification and ice periods are allocated to the year in
# which they end.
# res: (not used - data.frame containing simulation results (req Ts, Tb, H_ice))
# starts. Winter stratification and ice periods are allocated to the year
# in which they end.
# res: (not used - data.frame containing simulation results
# (req Ts, Tb, H_ice))
# Ts, Tb: time series of surface and bottom temperatures
# H_ice: ice thickness time series, set to NULL if analysis not required
# dates: POSIX style date vector corresponding to rows of Ts and Tb.
# not used: dT: temperature difference between top and bottom indicating stratification.
# drho: density difference between top and bottom indicating stratificaiton [kg m^-3]
# not used: dT: temperature difference between top and bottom indicating
# stratification.
# drho: density difference between top and bottom indicating
# stratificaiton [kg m^-3]
# NH: northern hemisphere? TRUE or FALSE
strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1, NH=TRUE, bydensity = TRUE) {
strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1,
NH=TRUE, bydensity = TRUE) {
the_years <- as.POSIXlt(dates)$year+1900
yrs <- unique(the_years)
doys <- as.POSIXlt(dates)$yday # day of the year [0..364]
alt_doys <- doys # alternative counting from [-182 .. 182] for ice in northern hemisphere or strat in southern hemisphere
alt_doys[doys>182] <- doys[doys>182] - (365 + leap(the_years[doys>182])) # Jan 1 is day 0, correct for leap years
# alternative counting from [-182 .. 182] for ice in northern hemisphere
# or stratification in southern hemisphere
alt_doys <- doys
# Jan 1 is day 0, correct for leap years
alt_doys[doys>182] <- doys[doys>182] - (365 + leap(the_years[doys>182]))
alt_years <- the_years
alt_years[alt_doys<0] <- the_years[alt_doys<0] +1 # alternative counting of years (shifted forward by half a year)
# alternative counting of years (shifted forward by half a year)
alt_years[alt_doys<0] <- the_years[alt_doys<0] +1
if(NH) { # NH ice and SH stratification use alternative doy and year counts to adjust for ice and stratification events that span more than one calendar year
# NH ice and SH stratification use alternative doy and year counts
# to adjust for ice and stratification events that span more than
# one calendar year
if(NH) {
ice_yrs <- alt_years
ice_doys <- alt_doys
strat_yrs <- the_years
......@@ -66,32 +87,45 @@ strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1, NH=TRUE, byde
}
if(bydensity) {
s_strat <- (rho_water(t=Tb) - rho_water(t=Ts)) >= thresh & Ts > Tb # logical whether stratified at each time step
# logical whether stratified at each time step
s_strat <- (rho_water(t=Tb) - rho_water(t=Ts)) >= thresh & Ts > Tb
} else {
s_strat <- Ts - Tb > thresh # logical whether stratified at each time step
# logical whether stratified at each time step
s_strat <- Ts - Tb > thresh
}
i_s_st <- diff(c(s_strat[1],s_strat))==1 # indices of stratification onset
i_s_en <- diff(c(s_strat[1],s_strat))==-1 # indices of stratification end
if(s_strat[1]) i_s_st <- c(NA, i_s_st) # if stratified at beginning of simulation, make first date NA
if(s_strat[length(s_strat)]) i_s_en <- c(i_s_en, NA) # if stratified at end of sim, set last strat date to NA
# indices of stratification onset
i_s_st <- diff(c(s_strat[1],s_strat))==1
# indices of stratification end
i_s_en <- diff(c(s_strat[1],s_strat))==-1
# if stratified at beginning of simulation, make first date NA
if(s_strat[1]) i_s_st <- c(NA, i_s_st)
# if stratified at end of sim, set last strat date to NA
if(s_strat[length(s_strat)]) i_s_en <- c(i_s_en, NA)
s_start <- dates[i_s_st] # summer strat start dates
s_end <- dates[i_s_en] # summer strat end dates
# if(sum(s_strat)==0) s_start <- s_end <- dates[1] # if never stratifies, set to time=0
s_dur <- as.double(difftime(s_end, s_start, units="days")) # duration of summer strat periods
# if never stratifies, set to time=0
# if(sum(s_strat)==0) s_start <- s_end <- dates[1]
# duration of summer stratification periods
s_dur <- as.double(difftime(s_end, s_start, units="days"))
a1 <- data.frame(year=strat_yrs[i_s_st],
start=s_start, end=s_end, dur=s_dur,
startday = strat_doys[i_s_st],
endday = strat_doys[i_s_en])
a1 <- subset(a1, year %in% yrs)
# a1 <- subset(a1, a1$year %in% yrs)
a1 <- a1[a1$year %in% yrs,]
s.max <- s.mean <- s.tot <- s.on <- s.off <-
s.first <- s.last <- yr <- NULL
for(mm in unique(a1$year[!is.na(a1$year)])) { # remove NAs which are generated when the lake is stratified at the satrt or end of the simulation
a2 <- subset(a1, year==mm)
for(mm in unique(a1$year[!is.na(a1$year)])) {
# remove NAs which are generated when the lake is
# stratified at the satrt or end of the time series
# a2 <- subset(a1, a1$year==mm)
a2 <- a1[a1$year==mm,]
ind <- which.max(a2$dur)
if(nrow(a2)==1) if(is.na(a2$dur)) ind <- NA # fixes issue if stratified at end of data period
# fixes issue if stratified at end of data period
if(nrow(a2)==1) if(is.na(a2$dur)) ind <- NA
yr <- c(yr,mm)
s.max <- c(s.max,max(a2$dur))
s.mean <- c(s.mean,mean(a2$dur))
......@@ -108,15 +142,16 @@ strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1, NH=TRUE, byde
for(ii in unique(the_years)) {
Ts_maxi <- which.max(Ts[strat_yrs == ii])
TsMaxOut <- data.frame(year=ii,
TsMax = Ts[strat_yrs == ii][Ts_maxi],
TsMaxDay = strat_doys[strat_yrs==ii][Ts_maxi],
TsMaxDate = dates[strat_yrs == ii][Ts_maxi]
TsMax = Ts[strat_yrs == ii][Ts_maxi],
TsMaxDay = strat_doys[strat_yrs==ii][Ts_maxi],
TsMaxDate= dates[strat_yrs == ii][Ts_maxi]
)
TsMax <- rbind(TsMax, TsMaxOut)
}
# create empty data frame to fill with data (not all years may have strat or ice)
# create empty data frame to fill with data
# (not all years may have strat or ice)
out <- data.frame(year=yrs, TsMax=NA, TsMaxDay=NA,
MaxStratDur=NA, MeanStratDur=NA, TotStratDur=NA,
StratStart=NA, StratEnd=NA,
......@@ -132,35 +167,50 @@ strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1, NH=TRUE, byde
# ice cover
if(!is.null(H_ice)) { # only do this if ice data provided
ice <- H_ice > 0
i_i_st <- diff(c(ice[1],ice))==1 # indices of ice cover onset
i_i_en <- diff(c(ice[1],ice))==-1 # # indices of ice cover end
if(ice[1]) i_i_st <- c(NA, i_i_st) # if initially frozen, set first start date to NA
if(ice[length(ice)]) i_i_en <- c(i_i_en, NA) # if frozen at end, set last thaw date to NA
ice_st <- dates[i_i_st] # ice start dates
ice_en <- dates[i_i_en] # ice end dates
# if(sum(ice)==0) # if there is no ice at all, set start and end to time=0
# indices of ice cover onset
i_i_st <- diff(c(ice[1],ice))==1
# indices of ice cover end
i_i_en <- diff(c(ice[1],ice))==-1
# if initially frozen, set first start date to NA
if(ice[1]) i_i_st <- c(NA, i_i_st)
# if frozen at end, set last thaw date to NA
if(ice[length(ice)]) i_i_en <- c(i_i_en, NA)
# ice start dates
ice_st <- dates[i_i_st]
# ice end dates
ice_en <- dates[i_i_en]
# if there is no ice at all, set start and end to time=0
# if(sum(ice)==0)
# maximum ice thickness
IceMax <- NULL
for(ii in unique(the_years)) {
Hice_maxi <- which.max(H_ice[ice_yrs == ii])
IceMaxOut <- data.frame(year=ii,
HiceMax = H_ice[ice_yrs == ii][Hice_maxi],
HiceMaxDay = ice_doys[ice_yrs==ii][Hice_maxi],
HiceMaxDate = dates[ice_yrs == ii][Hice_maxi])
if(sum(H_ice[ice_yrs == ii])==0) IceMaxOut[1,c("HiceMaxDay","HiceMaxDate")] <- NA
HiceMax =H_ice[ice_yrs == ii][Hice_maxi],
HiceMaxDay =ice_doys[ice_yrs==ii][Hice_maxi],
HiceMaxDate=dates[ice_yrs == ii][Hice_maxi])
if(sum(H_ice[ice_yrs == ii])==0) {
IceMaxOut[1,c("HiceMaxDay","HiceMaxDate")] <- NA
}
IceMax <- rbind(IceMax, IceMaxOut)
}
ice_start_doys <- ice_doys[i_i_st] # day of year of start of ice cover events
ice_end_doys <- ice_doys[i_i_en] # day of year of end of ice cover events
ice_event_yrs <- ice_yrs[i_i_st] # the years assigned to each ice event
# day of year of start of ice cover events
ice_start_doys <- ice_doys[i_i_st]
# day of year of end of ice cover events
ice_end_doys <- ice_doys[i_i_en]
# the years assigned to each ice event
ice_event_yrs <- ice_yrs[i_i_st]
# if there is no ice, set values to NA ...
if(sum(ice)==0) {
ice_start_doys <- ice_end_doys <- ice_event_yrs <- ice_st <- ice_en <- NA
ice_start_doys <- ice_end_doys <- ice_event_yrs <-
ice_st <- ice_en <- NA
}
ice_dur <- as.double(difftime(ice_en, ice_st, units="days")) # duration of ice periods
# duration of ice periods
ice_dur <- as.double(difftime(ice_en, ice_st, units="days"))
# summary of ice cover events
......@@ -173,7 +223,8 @@ strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1, NH=TRUE, byde
ice_out <- NULL
for(mm in unique(ice.summary$year[!is.na(ice.summary$year)])) {
ice2 <- subset(ice.summary, year==mm)
# ice2 <- subset(ice.summary, ice.summary$year==mm)
ice2 <- ice.summary[ice.summary$year==mm,]
ice2_on <- ice2[which.max(ice2$dur),"startday"]
ice2_off <- ice2[which.max(ice2$dur),"endday"]
if(anyNA(ice2$dur)) ice2_on <- ice2_off <- NA
......@@ -189,30 +240,45 @@ strat_phenology <- function(Ts, Tb, H_ice=NULL, dates, thresh=0.1, NH=TRUE, byde
lastthaw=max(ice2$endday)))
}
ice_out <- ice_out[ice_out$year %in% yrs,] # trim years outside the simulation range (eg ice that forms at the end of the last year, which should be assigned to the following year outside the simulation period)
# trim years outside the simulation range
# (eg ice that forms at the end of the last year,
# which should be assigned to the following year
# outside the simulation period)
ice_out <- ice_out[ice_out$year %in% yrs,]
ice_out1 <- data.frame(year=yrs, MeanIceDur=NA, MaxIceDur=NA,
TotIceDur=NA, IceOn=NA, IceOff=NA, FirstFreeze=NA,
LastThaw=NA, HiceMax=NA, HiceMaxDay=NA)
ice_out1 <- data.frame(year=yrs,
MeanIceDur=NA,
MaxIceDur=NA,
TotIceDur=NA,
IceOn=NA,
IceOff=NA,
FirstFreeze=NA,
LastThaw=NA,
HiceMax=NA,
HiceMaxDay=NA)
ice_out1[match(ice_out$year, yrs),
c("MeanIceDur","MaxIceDur","TotIceDur",
"IceOn","IceOff","FirstFreeze","LastThaw")] <- ice_out[,-1]
"IceOn","IceOff","FirstFreeze",
"LastThaw")] <- ice_out[,-1]
ice_out1[,c("HiceMax","HiceMaxDay")] <- IceMax[,c("HiceMax","HiceMaxDay")]
out <- data.frame(out, ice_out1[,-1])
}
# adjust some exceptions where stratification or ice extend longer than the cutoff period
# adjust some exceptions where stratification or
# ice extend longer than the cutoff period
i6 <- out$StratEnd < out$StratStart
i6[is.na(i6)]<-FALSE # this gets rid of any NAs
if(sum(i6, na.rm=TRUE)>0) out[i6, "StratEnd"] <- out[i6,"StratStart"] + out[i6,"MaxStratDur"]
if(sum(i6, na.rm=TRUE)>0) out[i6, "StratEnd"] <- out[i6,"StratStart"] +
out[i6,"MaxStratDur"]
i7 <- out$StratLast < out$StratStart & out$TotStratDur < 365
i7[is.na(i7)]<-FALSE # this gets rid of any NAs
if(sum(i7, na.rm=TRUE)>0) out[i7, "StratLast"] <- out[i7,"StratLast"] + 364
i8 <- out$IceOff < out$IceOn
i8[is.na(i8)]<-FALSE # this gets rid of any NAs
if(sum(i8, na.rm=TRUE)>0) out[i8, "IceOff"] <- out[i8,"IceOn"] + out[i8,"MaxIceDur"]
if(sum(i8, na.rm=TRUE)>0) out[i8, "IceOff"] <- out[i8,"IceOn"] +
out[i8,"MaxIceDur"]
i9 <- out$LastThaw < out$IceOn & out$TotIceDur < 366
i9[is.na(i9)]<-FALSE # this gets rid of any NAs
if(sum(i9, na.rm=TRUE)>0) {
......
......@@ -8,18 +8,22 @@ ice_phenology(H_ice, dates, NH = TRUE)
}
\arguments{
\item{H_ice}{A vector indicating the presence of ice cover.
Can be numerical or logical where \code{TRUE} or any number > \code{0} (e.g. ice thickness) indicates ice, and
Can be numerical or logical where \code{TRUE} or any number > \code{0}
(e.g. ice thickness) indicates ice, and
\code{FALSE} or \code{0} indicates no ice cover.}
\item{dates}{The dates corresponding to the ice observations in POSIX style and same length as \code{H_ice}.}
\item{dates}{The dates corresponding to the ice observations
in POSIX style and same length as \code{H_ice}.}
\item{NH}{Is the lake in the northern hemisphere? (logical)}
}
\value{
A \code{data.frame} containing ice stratification phenology
A \code{data.frame} containing ice stratification
phenology
}
\description{
Calculates seasonal ice phenology including annual mean,
Calculates seasonal ice phenology
including annual mean,
max and total duration of ice cover.
}
\details{
......
......@@ -19,21 +19,30 @@ strat_phenology(
\item{Tb}{Bottom temperature (numeric vector with same length as \code{Ts}.}
\item{H_ice}{Ice thickness as numeric vector of the same length as \code{Ts}. \code{NULL} if ice statistics should not be calculated.}
\item{H_ice}{Ice thickness as numeric vector of the same length as \code{Ts}.
\code{NULL} if ice statistics should not be calculated.}
\item{dates}{The dates corresponding to the temperature measurements in POSIX style and same length as \code{Ts}.}
\item{dates}{The dates corresponding to the temperature measurements
in POSIX style and same length as \code{Ts}.}
\item{thresh}{The density or temperature threshold used to define the presence of stratification, ie whether the difference between Ts and Tb exceeds this threshold. If \code{bydensity} is \code{TRUE}, then \code{thresh} must be in (kg m^-3), and \code{Ts} and \code{Tb} must be in Celsius.}
\item{thresh}{The density or temperature threshold used to define the
presence of stratification, ie whether the difference between Ts and Tb
exceeds this threshold. If \code{bydensity} is \code{TRUE}, then \code{thresh} must
be in (kg m^-3), and \code{Ts} and \code{Tb} must be in Celsius.}
\item{NH}{Is the lake in the northern hemisphere? (logical)}
\item{bydensity}{Should \code{thresh} be defined as a density threshold (logical)? If \code{FALSE}, a temperature threshold is assumed. If \code{TRUE}, then \code{Ts} and \code{Tb} must be in degrees Celsius}
\item{bydensity}{Should \code{thresh} be defined as a density
threshold (logical)?
If \code{FALSE}, a temperature threshold is assumed.
If \code{TRUE}, then \code{Ts} and \code{Tb} must be in degrees Celsius}
}
\value{
A \code{data.frame} containing the stratification phenology
}
\description{
Calculates seasonal stratification phenology including annual mean,
Calculates seasonal stratification phenology
including annual mean,
max and total duration of summer stratification and ice cover.
}
\details{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment