Skip to content

Commit

Permalink
wip - rename Bowling 2003 methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfiorella committed Dec 28, 2024
1 parent c98d7a8 commit 581d0e3
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 46 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ URL: https://github.com/lanl/NEONiso,
https://lanl.github.io/NEONiso/
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
dplyr,
zoo,
Expand Down
1 change: 1 addition & 0 deletions NEONiso.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 66dd6b57-a079-4675-8584-64aae38613ba

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
11 changes: 10 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# NEONiso 0.7.0.9000
# NEONiso 0.7.1

* Substantial upgrades to package documentation.
* The name "Bowling_2003" in methods and functions has been deprecated in
favor of "gainoffset." This change was made primarily to improve clarity of
what the methods actually do. Code that uses the old "Bowling_2003" nomenclature
will continue to work until at least version 0.8.0, but will issue a deprecation
warning.

# NEONiso 0.7.0

* calibrate_carbon_bymonth and calibrate_water_bymonth have been removed. Use
calibrate_carbon and calibrate_water instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
calibrate_ambient_carbon_Bowling2003 <- function(...) {
lifecycle::deprecate_soft("0.7.1","calibrate_ambient_carbon_Bowling2003()",
"calibrate_ambient_carbon_gainoffset()")
calibrate_ambient_carbon_gainoffset(...)
}

#' Calibrate ambient carbon isotope data using gain-and-offset method
#'
#' @author Rich Fiorella \email{rfiorella@@lanl.gov}
Expand All @@ -14,8 +20,7 @@
#' 12C and 13C isotopologues.
#' @param site Four-letter NEON code corresponding to site being processed.
#' @param filter_data Apply median absolute deviation filter from Brock 86 to
#' remove impulse spikes? Inherited from
#' `calibrate_ambient_carbon_Bowling2003()`
#' remove impulse spikes?
#' @param force_to_end In given month, calibrate ambient data later than last
#' calibration, using the last calibration? (default true)
#' @param force_to_beginning In given month, calibrate ambient data before than
Expand All @@ -38,7 +43,7 @@
#' @importFrom magrittr %>%
#' @importFrom lubridate %within%
#'
calibrate_ambient_carbon_Bowling2003 <- function(amb_data_list,
calibrate_ambient_carbon_gainoffset <- function(amb_data_list,
caldf,
site,
filter_data = TRUE,
Expand Down
21 changes: 13 additions & 8 deletions R/calibrate_carbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ calibrate_carbon <- function(inname,
inname <- inname[!grepl("2019-07", inname)]
}
}

if (method == "Bowling_2003") {
lifecycle::deprecate_warn("0.7.1","calibrate_carbon(method = 'Bowling_2003')",
"calibrate_carbon(method = 'gainoffset')")
}

#-----------------------------------------------------------
# Extract reference data from input HDF5 file.
Expand Down Expand Up @@ -194,18 +199,18 @@ calibrate_carbon <- function(inname,

ciso_subset <- c(ciso$ambient, ciso$reference)

if (method == "Bowling_2003") {
if (method == "gainoffset" | method == "Bowling_2003") {

ciso_subset_cal <-
lapply(names(ciso_subset),
function(x) {
calibrate_ambient_carbon_Bowling2003(amb_data_list = ciso_subset[[x]],
caldf = cal_df,
site = site,
filter_data = filter_ambient,
force_to_end = force_cal_to_end,
force_to_beginning = force_cal_to_beginning,
r2_thres = r2_thres)
calibrate_ambient_carbon_gainoffset(amb_data_list = ciso_subset[[x]],
caldf = cal_df,
site = site,
filter_data = filter_ambient,
force_to_end = force_cal_to_end,
force_to_beginning = force_cal_to_beginning,
r2_thres = r2_thres)
})

} else if (method == "linreg") {
Expand Down
4 changes: 2 additions & 2 deletions R/reference_data_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ estimate_calibration_error <- function(formula, data) {
#' to define a peak.
#'
#' @return Returns a data.frame of calibration parameters. If
#' `method == "Bowling_2003"`, then data.frame includes
#' `method == "gainoffset"`, then data.frame includes
#' gain and offset parameters for 12CO2 and 13CO2, and r^2
#' values for each regression. If `method == "linreg"`,
#' then data.frame includes slope, intercept, and r^2 values
Expand Down Expand Up @@ -87,7 +87,7 @@ fit_carbon_regression <- function(ref_data, method, calibration_half_width,
analyte = "co2",
min_nobs = min_nobs)

if (method == "Bowling_2003") {
if (method == "gainoffset" | method == "Bowling_2003") {

# calculate mole fraction (12CO2 / 13CO2) for ref gases and observed values
ref_data$conc12CCO2_ref <- calculate_12CO2(ref_data$rtioMoleDryCo2Refe.mean,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/fit_carbon_regression.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/testthat/test-data_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ test_that("carbon calibration data frames correct even when no input data", {
# work through ambient calibrations

# test carbon - bowling ambient calibration
temp <- calibrate_ambient_carbon_Bowling2003(co2test$ambient$`000_010_09m`,
caldf_b03,
site = "ONAQ")
temp_gf <- calibrate_ambient_carbon_Bowling2003(co2test$ambient$`000_010_09m`,
caldf_b03,
site = "ONAQ",
gap_fill_parameters = TRUE)
temp <- calibrate_ambient_carbon_gainoffset(co2test$ambient$`000_010_09m`,
caldf_b03,
site = "ONAQ")
temp_gf <- calibrate_ambient_carbon_gainoffset(co2test$ambient$`000_010_09m`,
caldf_b03,
site = "ONAQ",
gap_fill_parameters = TRUE)

test_that("calibrate_ambient_carbon_Bowling2003 returns a list",{
skip_on_cran()
Expand Down
31 changes: 21 additions & 10 deletions tests/testthat/test-high_level_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,27 @@ test_that("calibrate_carbon returns no error", {

skip_on_cran()
# these tests could probably be made more useful!!
expect_warning(calibrate_carbon(fin, fout1, "ONAQ",
method = "Bowling_2003",
calibration_half_width = 0.5,
force_cal_to_beginning = TRUE,
force_cal_to_end = TRUE,
gap_fill_parameters = FALSE,
filter_ambient = TRUE,
r2_thres = 0.95,
correct_ref_data = TRUE,
write_to_file = TRUE))

expect_no_error(calibrate_carbon(fin, fout1, "ONAQ",
method = "Bowling_2003",
calibration_half_width = 0.5,
force_cal_to_beginning = TRUE,
force_cal_to_end = TRUE,
gap_fill_parameters = FALSE,
filter_ambient = TRUE,
r2_thres = 0.95,
correct_ref_data = TRUE,
write_to_file = TRUE))
method = "gainoffset",
calibration_half_width = 0.5,
force_cal_to_beginning = TRUE,
force_cal_to_end = TRUE,
gap_fill_parameters = FALSE,
filter_ambient = TRUE,
r2_thres = 0.95,
correct_ref_data = TRUE,
write_to_file = TRUE))

expect_no_error(calibrate_carbon(fin, fout2, "ONAQ",
method = "linreg",
Expand All @@ -44,7 +55,7 @@ test_that("calibrate_carbon returns no error", {

# these tests could probably be made more useful!!
expect_no_error(calibrate_carbon(fin, "/dev/null", "ONAQ",
method = "Bowling_2003",
method = "gainoffset",
calibration_half_width = 0.5,
force_cal_to_beginning = TRUE,
force_cal_to_end = TRUE,
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-output_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ ciso_subset <- co2test$ambient

ciso_subset_cal <- lapply(names(ciso_subset),
function(x) {
calibrate_ambient_carbon_Bowling2003(amb_data_list = ciso_subset[[x]],
caldf = caldf_b03,
site = "YELL",
filter_data = TRUE,
force_to_end = TRUE,
force_to_beginning = TRUE,
r2_thres = 0.9)
calibrate_ambient_carbon_gainoffset(amb_data_list = ciso_subset[[x]],
caldf = caldf_b03,
site = "YELL",
filter_data = TRUE,
force_to_end = TRUE,
force_to_beginning = TRUE,
r2_thres = 0.9)
})

names(ciso_subset_cal) <- names(ciso_subset)
Expand Down

0 comments on commit 581d0e3

Please sign in to comment.