Skip to content

Commit

Permalink
added fix to plot_summary to plot same years on anomaly graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Mar 20, 2015
1 parent d5c0f94 commit 85119d5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 13 deletions.
21 changes: 16 additions & 5 deletions R/swmpr_analyze.R
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ hist.swmpr <- function(x, subset = NULL, select, operator = NULL, ...) {
#' dat <- qaqc(apacpnut)
#'
#' ## plot
#' plot_summary(dat, param = 'chla_n')
#' plot_summary(dat, param = 'chla_n', years = c(2007, 2013))
#'
plot_summary <- function(swmpr_in, ...) UseMethod('plot_summary')

Expand Down Expand Up @@ -849,6 +849,8 @@ plot_summary.swmpr <- function(swmpr_in, param, years = NULL, ...){
# universal plot setting
my_theme <- theme(axis.text = element_text(size = 8))

# browser()

# plot 1 - means and obs
cols <- colorRampPalette(c('lightblue', 'lightgreen'))(nrow(mo_agg))
cols <- cols[rank(mo_agg[, param])]
Expand Down Expand Up @@ -890,13 +892,18 @@ plot_summary.swmpr <- function(swmpr_in, param, years = NULL, ...){
# monthly means by year
to_plo <- dat_plo[, names(dat_plo) %in% c('month', 'year', param)]
form_in <- as.formula(paste(param, '~ .'))
to_plo <- aggregate(form_in, to_plo, function(x) mean(x, na.rm = T))
to_plo <- aggregate(form_in, to_plo, function(x) mean(x, na.rm = T),
na.action = na.pass)

to_plo$month <- factor(to_plo$month, labels = mo_labs, levels = mo_levs)
names(to_plo)[names(to_plo) %in% param] <- 'V1'
midpt <- mean(to_plo$V1, na.rm = T)
p4 <- ggplot(to_plo, aes(x = year, y = month, fill = V1)) +
p4 <- ggplot(subset(to_plo, !is.na(V1)),
aes(x = year, y = month, fill = V1)) +
geom_tile() +
geom_tile(data = subset(to_plo, is.na(V1)),
aes(x = year, y = month), fill = NA
) +
scale_fill_gradient2(name = ylab,
low = 'lightblue', mid = 'lightgreen', high = 'tomato', midpoint = midpt) +
theme_classic() +
Expand All @@ -912,8 +919,12 @@ plot_summary.swmpr <- function(swmpr_in, param, years = NULL, ...){
names(to_plo)[names(to_plo) %in% param] <- 'trend'
to_plo$anom <- with(to_plo, V1 - trend)
rngs <- max(abs(range(to_plo$anom, na.rm = T)))
p5 <- ggplot(to_plo, aes(x = year, y = month, fill = anom)) +
p5 <- ggplot(subset(to_plo, !is.na(anom)),
aes(x = year, y = month, fill = anom)) +
geom_tile() +
geom_tile(data = subset(to_plo, is.na(anom)),
aes(x = year, y = month), fill = NA
) +
scale_fill_gradient2(name = ylab,
low = 'lightblue', mid = 'lightgreen', high = 'tomato', midpoint = 0,
limits = c(-1 * rngs, rngs)) +
Expand Down Expand Up @@ -982,7 +993,7 @@ plot_summary.swmpr <- function(swmpr_in, param, years = NULL, ...){
#'
#' The open-water method is a common approach to quantify net ecosystem metabolism using a mass balance equation that describes the change in dissolved oxygen over time from the balance between photosynthetic and respiration processes, corrected using an empirically constrained air-sea gas diffusion model (see Ro and Hunt 2006, Thebault et al. 2008). The diffusion-corrected DO flux estimates are averaged separately over each day and night of the time series. The nighttime average DO flux is used to estimate respiration rates, while the daytime DO flux is used to estimate net primary production. To generate daily integrated rates, respiration rates are assumed constant such that hourly night time DO flux rates are multiplied by 24. Similarly, the daytime DO flux rates are multiplied by the number of daylight hours, which varies with location and time of year, to yield net daytime primary production. Respiration rates are subtracted from daily net production estimates to yield gross production rates. The metabolic day is considered the 24 hour period between sunsets on two adjacent calendar days.
#'
#' Aereal rates for gross production and total respiration are based on volumetric rates normalized to the depth of the water column at the sampling location, which is assumed to be well-mixed, such that the DO sensor is reflecting the integrated processes in the entire water column (including the benthos). Water column depth is calculated as the mean value of the depth variable across the time series in the \code{\link{swmpr}} object. Depth values are floored at one meter for very shallow stations and 0.5 meters is also added to reflect the practice of placing sensors slightly off of the bottom. Additionally, the air-sea gas exchange model is calibrated with wind data either collected at, or adjusted to, wind speed at 10 m above the surface. The metadata should be consulted for exact height. The value can be changed manually using a \code{height} argument, which is passed to \code{\link{calckl}}.
#' Areal rates for gross production and total respiration are based on volumetric rates normalized to the depth of the water column at the sampling location, which is assumed to be well-mixed, such that the DO sensor is reflecting the integrated processes in the entire water column (including the benthos). Water column depth is calculated as the mean value of the depth variable across the time series in the \code{\link{swmpr}} object. Depth values are floored at one meter for very shallow stations and 0.5 meters is also added to reflect the practice of placing sensors slightly off of the bottom. Additionally, the air-sea gas exchange model is calibrated with wind data either collected at, or adjusted to, wind speed at 10 m above the surface. The metadata should be consulted for exact height. The value can be changed manually using a \code{height} argument, which is passed to \code{\link{calckl}}.
#'
#' A minimum of three records are required for both day and night periods to calculate daily metabolism estimates. Occasional missing values for air temperature, barometric pressure, and wind speed are replaced with the climatological means (hourly means by month) for the period of record using adjacent data within the same month as the missing data.
#'
Expand Down
5 changes: 2 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,12 @@ data(apacpnut)
dat <- qaqc(apacpnut)
## plot
plot_summary(dat, param = 'chla_n')
plot_summary(dat, param = 'chla_n', years = c(2007, 2013))
```

Estimates of ecosystem metabolism provide a useful measure of overall system productivity. These estimates are commonly used to evaluate whether an ecosystem is a net source or sink of organic material. The open-water method is a common approach to quantify net ecosystem metabolism using a mass balance equation that describes the change in dissolved oxygen over time from the balance between photosynthetic and respiration rates, corrected for air-sea gas diffusion at the surface. The diffusion-corrected DO flux estimates are averaged during day and night for each 24 hour period in the time series, where flux is an hourly rate of DO change. DO flux is averaged during night hours for respiration and averaged during day hours for net production. Respiration rates are assumed constant during day and night such that total daily rates are calculated as hourly respiration multiplied by 24. The metabolic day is considered the 24 hour period between sunsets on two adjacent calendar days. Respiration is subtracted from daily net production estimates to yield gross production.

The `ecometab` function is used to implement an adaptation of the open-water method.
Several assumptions must be met for a valid interpretation of the results. In general, the dissolved oxygen time series is assumed to represent the same water mass over time. Tidal advection may have a significant influence on the time series, which can contribute to a significant amount of noise in metabolic estimates. The extent to which tidal advection influences the dissolved oxygen signal depends on various site-level characteristics and an intimate knowledge of the site may be required. Volumetric rates for gross production and total respiration are also based on total depth of the water column, which is assumed to be mixed. Water column depth is based on mean value for the depth variable across the time series and is floored at 1 meter for very shallow stations. Additionally, the volumetric reaeration coefficient requires an estimate of the anemometer height of the weather station, which is set as 10 meters by default. The metadata should be consulted for exact height. Other assumptions may apply and the user should consult the relevant literature (see the references in the help file). All estimates are in mmol of oxygen but can be converted to grams by changing the default arguments (i.e., 1mmol O2 = 32 mg O2, 1000 mg = 1g, multiply all estimates by 32/1000).
The `ecometab` function is used to implement an adaptation of the open-water method. Several assumptions must be met for a valid interpretation of the results. In general, the dissolved oxygen time series is assumed to represent the same water mass over time. Tidal advection may have a significant influence on the time series, which can contribute to a significant amount of noise in metabolic estimates. The extent to which tidal advection influences the dissolved oxygen signal depends on various site-level characteristics and an intimate knowledge of the site may be required. Volumetric rates for gross production and total respiration are also based on total depth of the water column, which is assumed to be mixed. Water column depth is based on mean value for the depth variable across the time series and is floored at 1 meter for very shallow stations. Additionally, the volumetric reaeration coefficient requires an estimate of the anemometer height of the weather station, which is set as 10 meters by default. The metadata should be consulted for exact height. Other assumptions may apply and the user should consult the relevant literature (see the references in the help file). All estimates are in mmol of oxygen but can be converted to grams by changing the default arguments (i.e., 1mmol O2 = 32 mg O2, 1000 mg = 1g, multiply all estimates by 32/1000).

The following is an example that shows how to use the function from a combined water quality and weather data set. The results can be plotted using `plot_metab`.

Expand Down
4 changes: 2 additions & 2 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ <h1>An overview of methods for swmpr objects</h1>
dat &lt;- qaqc(apacpnut)

## plot
plot_summary(dat, param = &#39;chla_n&#39;)</code></pre>
plot_summary(dat, param = &#39;chla_n&#39;, years = c(2007, 2013))</code></pre>
<p><img src="README_files/figure-html/unnamed-chunk-21.png" alt="plot of chunk unnamed-chunk-21" /></p>
<p>Estimates of ecosystem metabolism provide a useful measure of overall system productivity. These estimates are commonly used to evaluate whether an ecosystem is a net source or sink of organic material. The open-water method is a common approach to quantify net ecosystem metabolism using a mass balance equation that describes the change in dissolved oxygen over time from the balance between photosynthetic and respiration rates, corrected for air-sea gas diffusion at the surface. The diffusion-corrected DO flux estimates are averaged during day and night for each 24 hour period in the time series, where flux is an hourly rate of DO change. DO flux is averaged during night hours for respiration and averaged during day hours for net production. Respiration rates are assumed constant during day and night such that total daily rates are calculated as hourly respiration multiplied by 24. The metabolic day is considered the 24 hour period between sunsets on two adjacent calendar days. Respiration is subtracted from daily net production estimates to yield gross production.</p>
<p>The <code>ecometab</code> function is used to implement an adaptation of the open-water method.<br />Several assumptions must be met for a valid interpretation of the results. In general, the dissolved oxygen time series is assumed to represent the same water mass over time. Tidal advection may have a significant influence on the time series, which can contribute to a significant amount of noise in metabolic estimates. The extent to which tidal advection influences the dissolved oxygen signal depends on various site-level characteristics and an intimate knowledge of the site may be required. Volumetric rates for gross production and total respiration are also based on total depth of the water column, which is assumed to be mixed. Water column depth is based on mean value for the depth variable across the time series and is floored at 1 meter for very shallow stations. Additionally, the volumetric reaeration coefficient requires an estimate of the anemometer height of the weather station, which is set as 10 meters by default. The metadata should be consulted for exact height. Other assumptions may apply and the user should consult the relevant literature (see the references in the help file). All estimates are in mmol of oxygen but can be converted to grams by changing the default arguments (i.e., 1mmol O2 = 32 mg O2, 1000 mg = 1g, multiply all estimates by 32/1000).</p>
<p>The <code>ecometab</code> function is used to implement an adaptation of the open-water method. Several assumptions must be met for a valid interpretation of the results. In general, the dissolved oxygen time series is assumed to represent the same water mass over time. Tidal advection may have a significant influence on the time series, which can contribute to a significant amount of noise in metabolic estimates. The extent to which tidal advection influences the dissolved oxygen signal depends on various site-level characteristics and an intimate knowledge of the site may be required. Volumetric rates for gross production and total respiration are also based on total depth of the water column, which is assumed to be mixed. Water column depth is based on mean value for the depth variable across the time series and is floored at 1 meter for very shallow stations. Additionally, the volumetric reaeration coefficient requires an estimate of the anemometer height of the weather station, which is set as 10 meters by default. The metadata should be consulted for exact height. Other assumptions may apply and the user should consult the relevant literature (see the references in the help file). All estimates are in mmol of oxygen but can be converted to grams by changing the default arguments (i.e., 1mmol O2 = 32 mg O2, 1000 mg = 1g, multiply all estimates by 32/1000).</p>
<p>The following is an example that shows how to use the function from a combined water quality and weather data set. The results can be plotted using <code>plot_metab</code>.</p>
<pre class="r"><code>## import water quality and weather data
data(apadbwq)
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,14 @@ data(apacpnut)
dat <- qaqc(apacpnut)

## plot
plot_summary(dat, param = 'chla_n')
plot_summary(dat, param = 'chla_n', years = c(2007, 2013))
```

![plot of chunk unnamed-chunk-21](README_files/figure-html/unnamed-chunk-21.png)

Estimates of ecosystem metabolism provide a useful measure of overall system productivity. These estimates are commonly used to evaluate whether an ecosystem is a net source or sink of organic material. The open-water method is a common approach to quantify net ecosystem metabolism using a mass balance equation that describes the change in dissolved oxygen over time from the balance between photosynthetic and respiration rates, corrected for air-sea gas diffusion at the surface. The diffusion-corrected DO flux estimates are averaged during day and night for each 24 hour period in the time series, where flux is an hourly rate of DO change. DO flux is averaged during night hours for respiration and averaged during day hours for net production. Respiration rates are assumed constant during day and night such that total daily rates are calculated as hourly respiration multiplied by 24. The metabolic day is considered the 24 hour period between sunsets on two adjacent calendar days. Respiration is subtracted from daily net production estimates to yield gross production.

The `ecometab` function is used to implement an adaptation of the open-water method.
Several assumptions must be met for a valid interpretation of the results. In general, the dissolved oxygen time series is assumed to represent the same water mass over time. Tidal advection may have a significant influence on the time series, which can contribute to a significant amount of noise in metabolic estimates. The extent to which tidal advection influences the dissolved oxygen signal depends on various site-level characteristics and an intimate knowledge of the site may be required. Volumetric rates for gross production and total respiration are also based on total depth of the water column, which is assumed to be mixed. Water column depth is based on mean value for the depth variable across the time series and is floored at 1 meter for very shallow stations. Additionally, the volumetric reaeration coefficient requires an estimate of the anemometer height of the weather station, which is set as 10 meters by default. The metadata should be consulted for exact height. Other assumptions may apply and the user should consult the relevant literature (see the references in the help file). All estimates are in mmol of oxygen but can be converted to grams by changing the default arguments (i.e., 1mmol O2 = 32 mg O2, 1000 mg = 1g, multiply all estimates by 32/1000).
The `ecometab` function is used to implement an adaptation of the open-water method. Several assumptions must be met for a valid interpretation of the results. In general, the dissolved oxygen time series is assumed to represent the same water mass over time. Tidal advection may have a significant influence on the time series, which can contribute to a significant amount of noise in metabolic estimates. The extent to which tidal advection influences the dissolved oxygen signal depends on various site-level characteristics and an intimate knowledge of the site may be required. Volumetric rates for gross production and total respiration are also based on total depth of the water column, which is assumed to be mixed. Water column depth is based on mean value for the depth variable across the time series and is floored at 1 meter for very shallow stations. Additionally, the volumetric reaeration coefficient requires an estimate of the anemometer height of the weather station, which is set as 10 meters by default. The metadata should be consulted for exact height. Other assumptions may apply and the user should consult the relevant literature (see the references in the help file). All estimates are in mmol of oxygen but can be converted to grams by changing the default arguments (i.e., 1mmol O2 = 32 mg O2, 1000 mg = 1g, multiply all estimates by 32/1000).

The following is an example that shows how to use the function from a combined water quality and weather data set. The results can be plotted using `plot_metab`.

Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified README_files/figure-html/unnamed-chunk-21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 85119d5

Please sign in to comment.