Introduction

This document describes how to obtain information from EGRET results that describe the seasonal distribution of fluxes. For example, we might want to know the fraction of the load that takes place in the winter season (say that is December, January, and February). We can look at it for a single year, we can look at averages of it over several years, or we can look at it in terms of flow normalized fluxes.

Getting started

First, you need to have loaded the EGRET package and you need to have run the modelEstimation function and as a result of that, have an eList object.

Next, you will need to read in two new function called setupSeasons and setupYearsPlus designed for this purpose. You can copy them from here and paste them into your workspace (all as a single copy and paste) or you can create an .R file from them that you will source each time you want to use them.

setupSeasons <- function(localDaily, paLong, paStart) {
    SeasonResults <- setupYearsPlus(localDaily, paLong = paLong, 
        paStart = paStart)
    AnnualResults <- setupYearsPlus(localDaily, paLong = 12, 
        paStart = paStart)
    numYears <- length(AnnualResults$DecYear)
    divide <- 1e+06
    DecYear <- AnnualResults$DecYear
    Year <- trunc(DecYear)
    FluxYear <- AnnualResults$Flux * AnnualResults$Counts/divide
    FNFluxYear <- AnnualResults$FNFlux * AnnualResults$Counts/divide
    FluxSeason <- SeasonResults$Flux[1:numYears] * SeasonResults$Counts[1:numYears]/divide
    FNFluxSeason <- SeasonResults$FNFlux[1:numYears] * SeasonResults$Counts[1:numYears]/divide
    pctFlux <- ifelse(is.na(FluxYear) | is.na(FluxSeason), NA, 
        100 * FluxSeason/FluxYear)
    pctFNFlux <- ifelse(is.na(FNFluxYear) | is.na(FNFluxSeason), 
        NA, 100 * FNFluxSeason/FNFluxYear)
    seasonPctResults <- data.frame(DecYear, Year, FluxYear, FNFluxYear, 
        FluxSeason, FNFluxSeason, pctFlux, pctFNFlux)
    seasonLong <- rep(paLong, numYears)
    seasonStart <- rep(paStart, numYears)
    seasonPctResults <- data.frame(seasonPctResults, seasonLong, 
        seasonStart)
    return(seasonPctResults)
}

setupYearsPlus <- function(localDaily, paLong = 12, paStart = 10) {
    
    # This is an augmented version of setupYears that also
    # returns the number of good days in each year or season
    
    numDays <- length(localDaily$MonthSeq)
    firstMonthSeq <- localDaily$MonthSeq[1]
    lastMonthSeq <- localDaily$MonthSeq[numDays]
    Starts <- seq(paStart, lastMonthSeq, 12)
    Ends <- Starts + paLong - 1
    StartEndSeq <- data.frame(Starts, Ends)
    StartEndSeq <- StartEndSeq[(StartEndSeq$Starts >= firstMonthSeq) & 
        (StartEndSeq$Ends <= lastMonthSeq), ]
    firstMonth <- StartEndSeq[1, 1]
    numYears <- length(StartEndSeq$Starts)
    DecYear <- rep(NA, numYears)
    Q <- rep(NA, numYears)
    Conc <- rep(NA, numYears)
    Flux <- rep(NA, numYears)
    FNConc <- rep(NA, numYears)
    FNFlux <- rep(NA, numYears)
    Counts <- rep(NA, numYears)
    for (i in 1:numYears) {
        startMonth <- (i - 1) * 12 + firstMonth
        stopMonth <- startMonth + paLong - 1
        DailyYear <- localDaily[which(localDaily$MonthSeq %in% 
            startMonth:stopMonth), ]
        counter <- ifelse(is.na(DailyYear$ConcDay), 0, 1)
        if (length(counter) > 0) {
            good <- (sum(counter) > 25)
        } else {
            good <- FALSE
        }
        DecYear[i] <- mean(DailyYear$DecYear)
        Q[i] <- mean(DailyYear$Q)
        if (good) {
            Conc[i] <- mean(DailyYear$ConcDay, na.rm = TRUE)
            Flux[i] <- mean(DailyYear$FluxDay, na.rm = TRUE)
            FNConc[i] <- mean(DailyYear$FNConc, na.rm = TRUE)
            FNFlux[i] <- mean(DailyYear$FNFlux, na.rm = TRUE)
            Counts[i] <- sum(counter)
        }
    }
    PeriodStart <- rep(paStart, numYears)
    PeriodLong <- rep(paLong, numYears)
    AnnualResults <- data.frame(DecYear, Q, Conc, Flux, FNConc, 
        FNFlux, PeriodLong, PeriodStart, Counts)
    return(AnnualResults)
}

The next step is to establish what season you are interested in looking at. We do this by specifying paStart and paLong.

paStart is the number of the calendar month that is the start of the season.
paLong is the length of the season in months (it can be any number from 1 to 12).

For example lets say we want to consider the winter, defined here as December through February. This code we would use is. This is written with the example data set Choptank_eList, which comes out of the EGRET package. In running this script you would delete the line eList <- Choptank_eList and enter the values of paLong and paStart that you wish to use.

library(EGRET)
eList <- Choptank_eList
Daily <- eList$Daily
seasonPctResults <- setupSeasons(Daily, paLong = 3, paStart = 12)

Looking at your results

What you now have is a data frame called seasonPctResults. The columns it contains are the following:

variable Definition
DecYear Decimal Year of the mid-date of the season
Year Calendary Year of mid-date of the year
FluxYear Estimated flux for the year in millions of kg
FNFluxYear Flow Normalized flux for the year in millions of kg
FluxSeason Estimated flux for the season in millions of kg
FNFluxSeason Flow Normalized flux for the season in millions of kg
pctFlux Season flux as a percentage of Annual Flux
pctFNFlux FlowNormalized Seasonal Flux as a percent of Flow Normalized Annual Flux
seasonLong Length of the Season in Months
seasonStart Starting Month of the Season, 1=January

You can just print it out as a simple table:

seasonPctResults
##     DecYear Year   FluxYear FNFluxYear  FluxSeason
## 1  1980.415 1980 0.10823892  0.1066209 0.034945302
## 2  1981.416 1981 0.06289557  0.1083925 0.018116770
## 3  1982.416 1982 0.09681574  0.1099415 0.043460706
## 4  1983.416 1983 0.14078735  0.1117906 0.032289589
## 5  1984.415 1984 0.15194260  0.1145872 0.065385956
## 6  1985.416 1985 0.05669798  0.1165968 0.021771184
## 7  1986.416 1986 0.08217257  0.1195744 0.046869855
## 8  1987.416 1987 0.11299964  0.1225782 0.066702246
## 9  1988.415 1988 0.07141852  0.1257860 0.025894197
## 10 1989.416 1989 0.17884713  0.1274530 0.034505116
## 11 1990.416 1990 0.11676674  0.1292722 0.047507820
## 12 1991.416 1991 0.09793489  0.1306512 0.038402503
## 13 1992.415 1992 0.08640815  0.1321453 0.025287651
## 14 1993.416 1993 0.12383458  0.1322646 0.046262024
## 15 1994.416 1994 0.17074467  0.1328902 0.051046006
## 16 1995.416 1995 0.09727155  0.1336715 0.038019829
## 17 1996.415 1996 0.20572056  0.1351565 0.065220059
## 18 1997.416 1997 0.17735225  0.1355571 0.091607915
## 19 1998.416 1998 0.15078276  0.1365388 0.073410291
## 20 1999.416 1999 0.10578501  0.1377206 0.026892308
## 21 2000.415 2000 0.16013576  0.1396663 0.049706606
## 22 2001.416 2001 0.15539656  0.1403066 0.054060450
## 23 2002.416 2002 0.07553423  0.1414285 0.008278931
## 24 2003.416 2003 0.27128201  0.1426778 0.078498646
## 25 2004.415 2004 0.15746288  0.1446897 0.077891472
## 26 2005.416 2005 0.14874934  0.1457777 0.048747375
## 27 2006.416 2006 0.15703623  0.1474115 0.065908616
## 28 2007.416 2007 0.13160741  0.1486543 0.059610657
## 29 2008.415 2008 0.10150458  0.1498439 0.030332049
## 30 2009.416 2009 0.16987136  0.1492678 0.034404361
## 31 2010.416 2010 0.20117911  0.1491084 0.102522209
##    FNFluxSeason  pctFlux pctFNFlux seasonLong seasonStart
## 1    0.03874783 32.28534  36.34167          3          12
## 2    0.03969898 28.80452  36.62521          3          12
## 3    0.04069085 44.89012  37.01137          3          12
## 4    0.04159151 22.93501  37.20483          3          12
## 5    0.04309533 43.03333  37.60920          3          12
## 6    0.04364139 38.39851  37.42931          3          12
## 7    0.04483105 57.03832  37.49219          3          12
## 8    0.04600957 59.02872  37.53485          3          12
## 9    0.04752384 36.25698  37.78149          3          12
## 10   0.04767902 19.29308  37.40910          3          12
## 11   0.04812533 40.68609  37.22790          3          12
## 12   0.04826679 39.21228  36.94325          3          12
## 13   0.04870412 29.26535  36.85649          3          12
## 14   0.04786261 37.35792  36.18702          3          12
## 15   0.04756227 29.89610  35.79065          3          12
## 16   0.04741173 39.08628  35.46884          3          12
## 17   0.04798160 31.70323  35.50076          3          12
## 18   0.04757783 51.65309  35.09799          3          12
## 19   0.04784744 48.68613  35.04312          3          12
## 20   0.04827359 25.42166  35.05184          3          12
## 21   0.04937788 31.04029  35.35417          3          12
## 22   0.04931125 34.78870  35.14534          3          12
## 23   0.04981371 10.96050  35.22185          3          12
## 24   0.05038436 28.93618  35.31338          3          12
## 25   0.05166663 49.46656  35.70857          3          12
## 26   0.05188844 32.77149  35.59424          3          12
## 27   0.05268306 41.97032  35.73877          3          12
## 28   0.05326500 45.29430  35.83146          3          12
## 29   0.05405277 29.88244  36.07273          3          12
## 30   0.05328845 20.25318  35.69989          3          12
## 31   0.05304871 50.96066  35.57727          3          12

Plotting the time series

We can make a graph showing the percentage flux (estimated annual and flow normalized)

nYears <- length(seasonPctResults$DecYear)
xlim <- c(seasonPctResults$DecYear[1] - 1, seasonPctResults$DecYear[nYears] + 
    1)
xTicks <- pretty(xlim)
ylim <- c(0, 100)
yTicks <- seq(0, 100, 10)
plotTitle = paste("Seasonal Flux as a Percent of Annual Flux\n", 
    eList$INFO$shortName, eList$INFO$paramShortName, "\nSolid line is percentage of flow normalized flux")
genericEGRETDotPlot(seasonPctResults$DecYear, seasonPctResults$pctFlux, 
    xlim = xlim, ylim = ylim, xTicks = xTicks, yTicks = yTicks, 
    xaxs = "i", yaxs = "i", xlab = "Year", ylab = "Percentage of Annual Flux", 
    plotTitle = plotTitle, xDate = TRUE, cex = 1.5)
par(new = TRUE)
genericEGRETDotPlot(seasonPctResults$DecYear, seasonPctResults$pctFNFlux, 
    xlim = xlim, ylim = ylim, xTicks = xTicks, yTicks = yTicks, 
    xaxs = "i", yaxs = "i", xlab = "", ylab = "", plotTitle = plotTitle, 
    xDate = TRUE, cex = 1.5, type = "l", col = "green", lwd = 2)

We can interpret this example graph as follows. The winter flux of nitrate fluctuates a good deal from year to year. From a low of around 10% to a high of around 60% but the mean percentage hasn’t changed much over the years. It is around 35% of the annual total flux.

Computing averages over a period of years

Let’s say we wanted to answer the question, what percentage of the annual total flux moved in the winter season during the years 2000 through 2010. We can answer that question with a simple set of calculations.

sumYears <- sum(seasonPctResults$FluxYear[21:31])
# This is the total flux for all years 
# in the period of interest in millions of kg
sumYears
## [1] 1.729759
sumSeasons <- sum(seasonPctResults$FluxSeason[21:31])
# This is the total seasonal flux for all years 
# of the period of interest in millions of kg 
sumSeasons 
## [1] 0.6099614
avePct <- 100 * sumSeasons / sumYears
# This is the percentage of the total flux for the
# period of interest that was transported during the season of interest
avePct
## [1] 35.26279

This is the percentage of the total flux for the years 2000 through 2010 that was transported in the winter months.

This can be determined for any set of years simply by changing the two numbers inside the brackets to the index numbers of the first and last years of interest.

Disclaimer

Software created by USGS employees along with contractors and grantees (unless specific stipulations are made in a contract or grant award) are to be released as Public Domain and free of copyright or license. Contributions of software components such as specific algorithms to existing software licensed through a third party are encouraged, but those contributions should be annotated as freely available in the Public Domain wherever possible. If USGS software uses existing licensed components, those licenses must be adhered to and redistributed.

Although this software has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to accuracy and functionality, nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith.