From 1d8facc6eb1bb3c2145911bfa9673105eb0e1967 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Wed, 27 Jul 2022 14:23:26 +0000 Subject: [PATCH 01/37] replaced ud.convert() with ud_convert() in PEcAn.utils and PEcAn.DB package --- base/db/DESCRIPTION | 2 +- base/db/R/insert.format.vars.R | 4 ++-- base/db/R/query.dplyr.R | 4 ++-- base/db/R/query.format.vars.R | 2 +- base/db/inst/import-try/96.load.data.R | 3 +-- base/utils/DESCRIPTION | 2 +- base/utils/NAMESPACE | 1 + base/utils/R/cf2date.R | 4 ++-- base/utils/R/read.output.R | 4 ++-- base/utils/R/seconds_in_year.R | 2 +- base/utils/R/ud_convert.R | 17 +++++++++++++++ base/utils/R/units_are_equivalent.R | 2 +- base/utils/R/utils.R | 18 ++++++++-------- base/utils/man/ud_convert.Rd | 29 ++++++++++++++++++++++++++ 14 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 base/utils/R/ud_convert.R create mode 100644 base/utils/man/ud_convert.Rd diff --git a/base/db/DESCRIPTION b/base/db/DESCRIPTION index c93e5afea2e..b9dcbd6c8e4 100644 --- a/base/db/DESCRIPTION +++ b/base/db/DESCRIPTION @@ -58,7 +58,7 @@ Imports: rlang, tibble, tidyr, - udunits2, + units Suggests: bit64, data.table, diff --git a/base/db/R/insert.format.vars.R b/base/db/R/insert.format.vars.R index f58349eb6e4..eeb5115560e 100644 --- a/base/db/R/insert.format.vars.R +++ b/base/db/R/insert.format.vars.R @@ -126,13 +126,13 @@ insert.format.vars <- function(con, format_name, mimetype_id, notes = NULL, head u1 <- formats_variables[1,"unit"] u2 <- dplyr::tbl(con, "variables") %>% dplyr::select(.data$id, units) %>% dplyr::filter(.data$id %in% !!formats_variables[[1, "variable_id"]]) %>% dplyr::pull(.data$units) - if(!udunits2::ud.is.parseable(u1)){ + if(!units::install_unit(u1)){ PEcAn.logger::logger.error( "Units not parseable. Please enter a unit that is parseable by the udunits library." ) } # Grab the bety units and - if(!udunits2::ud.are.convertible(u1, u2)){ + if(!units::ud_are_convertible(u1, u2)){ PEcAn.logger::logger.error( "Units are not convertable." ) diff --git a/base/db/R/query.dplyr.R b/base/db/R/query.dplyr.R index 631ed507aa0..4db6696334f 100644 --- a/base/db/R/query.dplyr.R +++ b/base/db/R/query.dplyr.R @@ -62,8 +62,8 @@ dplyr.count <- function(df) { #' @export ncdays2date <- function(time, unit) { date <- lubridate::parse_date_time(unit, c("ymd_hms", "ymd_h", "ymd")) - days <- udunits2::ud.convert(time, unit, paste("days since ", date)) - seconds <- udunits2::ud.convert(days, "days", "seconds") + days <- PEcAn.utils::ud_convert(time, unit, paste("days since ", date)) + seconds <- PEcAn.utils::ud_convert(days, "days", "seconds") return(as.POSIXct.numeric(seconds, origin = date, tz = "UTC")) } # ncdays2date diff --git a/base/db/R/query.format.vars.R b/base/db/R/query.format.vars.R index cb93825599c..6f426c134bd 100644 --- a/base/db/R/query.format.vars.R +++ b/base/db/R/query.format.vars.R @@ -133,7 +133,7 @@ query.format.vars <- function(bety, input.id=NA, format.id=NA, var.ids=NA) { # This would be a good place to put a test for valid sotrage types. Currently not implemented. - } else if (udunits2::ud.are.convertible(format$vars$input_units[i], format$vars$pecan_units[i]) == FALSE) { + } else if (units::ud_are_convertible(format$vars$input_units[i], format$vars$pecan_units[i]) == FALSE) { if (PEcAn.utils::misc.are.convertible(format$vars$input_units[i], format$vars$pecan_units[i]) == FALSE) { PEcAn.logger::logger.warn("Units not convertible for",format$vars$input_name[i], "with units of",format$vars$input_units[i], ". Please make sure the varible has units that can be converted to", format$vars$pecan_units[i]) diff --git a/base/db/inst/import-try/96.load.data.R b/base/db/inst/import-try/96.load.data.R index 037bbe936fc..4570282a4a0 100644 --- a/base/db/inst/import-try/96.load.data.R +++ b/base/db/inst/import-try/96.load.data.R @@ -1,7 +1,6 @@ # 6. Add TRY data to BETY source("common.R") load("try.5.RData") -library(udunits2) library(stringr) setkey(try.dat, ObservationID) @@ -57,7 +56,7 @@ for(i in 1:nrow(try.entities)){ site_id = try.sub[j, bety.site.id], specie_id = try.sub[j, bety.species.id], citation_id = try.sub[j, bety.citation.id], - mean = try.sub[j, udunits2::ud.convert(StdValue, UnitName, units)], + mean = try.sub[j, PEcAn.utils::ud_convert(StdValue, UnitName, units)], n = try.sub[j, Replicates], user_id = user_id, entity_id = entity, diff --git a/base/utils/DESCRIPTION b/base/utils/DESCRIPTION index b398950316a..16935ae1b54 100644 --- a/base/utils/DESCRIPTION +++ b/base/utils/DESCRIPTION @@ -41,7 +41,7 @@ Imports: RCurl, rlang, stringi, - udunits2 (>= 0.11), + units, XML Suggests: coda (>= 0.18), diff --git a/base/utils/NAMESPACE b/base/utils/NAMESPACE index 83ee767abda..900b3e64ab4 100644 --- a/base/utils/NAMESPACE +++ b/base/utils/NAMESPACE @@ -54,6 +54,7 @@ export(to_ncvar) export(trait.lookup) export(transformstats) export(tryl) +export(ud_convert) export(units_are_equivalent) export(vecpaste) export(zero.truncate) diff --git a/base/utils/R/cf2date.R b/base/utils/R/cf2date.R index 012bdc4c872..bef5fb9d795 100644 --- a/base/utils/R/cf2date.R +++ b/base/utils/R/cf2date.R @@ -18,7 +18,7 @@ #' cf2datetime(365, "days since 2000-01-01 12:00:00 -05:00") cf2datetime <- function(value, unit, tz = "UTC") { origin <- "1970-01-01 00:00:00 UTC" - ctint <- udunits2::ud.convert(value, unit, paste("seconds since", origin)) + ctint <- ud_convert(value, unit, paste("seconds since", origin)) result <- as.POSIXct(ctint, origin = origin) attr(result, "tzone") <- tz result @@ -43,7 +43,7 @@ datetime2cf <- function(datetime, unit, ...) { } origin <- "1970-01-01 00:00:00 UTC" raw_ct <- as.numeric(datetime, origin = origin) - udunits2::ud.convert(raw_ct, paste("seconds since", origin), unit) + ud_convert(raw_ct, paste("seconds since", origin), unit) } #' Extract Julian day from CF or POSIXct date-times diff --git a/base/utils/R/read.output.R b/base/utils/R/read.output.R index 1fa2aa4a689..2929c3cb76b 100644 --- a/base/utils/R/read.output.R +++ b/base/utils/R/read.output.R @@ -218,7 +218,7 @@ read.output <- function(runid, outdir, } if (dataframe) { - seconds <- udunits2::ud.convert( + seconds <- ud_convert( nc$dim$time$vals, nc$dim$time$units, paste("seconds since", run_origin) @@ -264,7 +264,7 @@ read.output <- function(runid, outdir, # Dropping attempt to provide more sensible units because of graph unit errors, # issue #792 # if (v %in% c(cflux, wflux)) { - # newresult <- udunits2::ud.convert(newresult, 'kg m-2 s-1', 'kg ha-1 yr-1') + # newresult <- ud_convert(newresult, 'kg m-2 s-1', 'kg ha-1 yr-1') # } result[[v]] <- abind::abind(result[[v]], newresult) } diff --git a/base/utils/R/seconds_in_year.R b/base/utils/R/seconds_in_year.R index d45ab750bd8..03746670dc9 100644 --- a/base/utils/R/seconds_in_year.R +++ b/base/utils/R/seconds_in_year.R @@ -11,6 +11,6 @@ #' @export seconds_in_year <- function(year, leap_year = TRUE, ...) { diy <- days_in_year(year, leap_year) - siy <- udunits2::ud.convert(diy, 'days', 'seconds') + siy <- ud_convert(diy, 'days', 'seconds') return(siy) } diff --git a/base/utils/R/ud_convert.R b/base/utils/R/ud_convert.R new file mode 100644 index 00000000000..ef826fc767a --- /dev/null +++ b/base/utils/R/ud_convert.R @@ -0,0 +1,17 @@ +##' @title Convert units +##' +##' This function takes the numeric argument `x`, quantified in units `u1` and converts it to be of units `u2`. +##' @author Chris Black +##' +##' @param x numeric vector with units `u1` to be converted to units `u2` +##' @param u1 string which is parseable into a `units` compatible unit. +##' @param u2 string which is parseable into a `units` compatible unit, +##' and for which there exists a defined transformation from the units represented by `u1`. +##' +##' @return numeric vector stripped of units +##' @export +ud_convert <- function(x, u1, u2) { + stopifnot(units::ud_are_convertible(u1, u2)) + a <- units::set_units(x, value = u1, mode = "standard") + units::drop_units(units::set_units(a, value = u2, mode = "standard")) +} # ud_convert \ No newline at end of file diff --git a/base/utils/R/units_are_equivalent.R b/base/utils/R/units_are_equivalent.R index 8e38dac9c93..5671ec0ba5e 100644 --- a/base/utils/R/units_are_equivalent.R +++ b/base/utils/R/units_are_equivalent.R @@ -8,6 +8,6 @@ #' @author Alexey Shiklomanov #' @export units_are_equivalent <- function(x, y) { - x2y <- udunits2::ud.convert(1, x, y) + x2y <- ud_convert(1, x, y) 1 == x2y } diff --git a/base/utils/R/utils.R b/base/utils/R/utils.R index bf0bc04b763..427427612cc 100644 --- a/base/utils/R/utils.R +++ b/base/utils/R/utils.R @@ -389,8 +389,8 @@ tabnum <- function(x, n = 3) { ##' @export ##' @author unknown arrhenius.scaling <- function(observed.value, old.temp, new.temp = 25) { - new.temp.K <- udunits2::ud.convert(new.temp, "degC", "K") - old.temp.K <- udunits2::ud.convert(old.temp, "degC", "K") + new.temp.K <- ud_convert(new.temp, "degC", "K") + old.temp.K <- ud_convert(old.temp, "degC", "K") return(observed.value / exp(3000 * (1 / (new.temp.K) - 1 / (old.temp.K)))) } # arrhenius.scaling #--------------------------------------------------------------------------------------------------# @@ -558,21 +558,21 @@ misc.convert <- function(x, u1, u2) { mmH2O <- 18.01528 # molar mass of H2O, g/mol if (u1 == "umol C m-2 s-1" & u2 == "kg C m-2 s-1") { - val <- udunits2::ud.convert(x, "ug", "kg") * amC + val <- ud_convert(x, "ug", "kg") * amC } else if (u1 == "kg C m-2 s-1" & u2 == "umol C m-2 s-1") { - val <- udunits2::ud.convert(x, "kg", "ug") / amC + val <- ud_convert(x, "kg", "ug") / amC } else if (u1 == "mol H2O m-2 s-1" & u2 == "kg H2O m-2 s-1") { - val <- udunits2::ud.convert(x, "g", "kg") * mmH2O + val <- ud_convert(x, "g", "kg") * mmH2O } else if (u1 == "kg H2O m-2 s-1" & u2 == "mol H2O m-2 s-1") { - val <- udunits2::ud.convert(x, "kg", "g") / mmH2O + val <- ud_convert(x, "kg", "g") / mmH2O } else if (u1 == "Mg ha-1" & u2 == "kg C m-2") { - val <- x * udunits2::ud.convert(1, "Mg", "kg") * udunits2::ud.convert(1, "ha-1", "m-2") + val <- x * ud_convert(1, "Mg", "kg") * ud_convert(1, "ha-1", "m-2") } else if (u1 == "kg C m-2" & u2 == "Mg ha-1") { - val <- x * udunits2::ud.convert(1, "kg", "Mg") * udunits2::ud.convert(1, "m-2", "ha-1") + val <- x * ud_convert(1, "kg", "Mg") * ud_convert(1, "m-2", "ha-1") } else { u1 <- gsub("gC","g*12",u1) u2 <- gsub("gC","g*12",u2) - val <- udunits2::ud.convert(x,u1,u2) + val <- ud_convert(x,u1,u2) # PEcAn.logger::logger.severe(paste("Unknown units", u1, u2)) diff --git a/base/utils/man/ud_convert.Rd b/base/utils/man/ud_convert.Rd new file mode 100644 index 00000000000..265cca8f3a8 --- /dev/null +++ b/base/utils/man/ud_convert.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ud_convert.R +\name{ud_convert} +\alias{ud_convert} +\title{Convert units + +This function takes the numeric argument \code{x}, quantified in units \code{u1} and converts it to be of units \code{u2}.} +\usage{ +ud_convert(x, u1, u2) +} +\arguments{ +\item{x}{numeric vector with units \code{u1} to be converted to units \code{u2}} + +\item{u1}{string which is parseable into a \code{units} compatible unit.} + +\item{u2}{string which is parseable into a \code{units} compatible unit, +and for which there exists a defined transformation from the units represented by \code{u1}.} +} +\value{ +numeric vector stripped of units +} +\description{ +Convert units + +This function takes the numeric argument \code{x}, quantified in units \code{u1} and converts it to be of units \code{u2}. +} +\author{ +Chris Black +} From a357f3b539286733a6d5dfe4309adf0456b04820 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Wed, 27 Jul 2022 14:34:29 +0000 Subject: [PATCH 02/37] updated docker/depends/pecan.depends.R --- docker/depends/pecan.depends.R | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index 0544b052de8..d3990aec169 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -133,6 +133,7 @@ wanted <- c( 'TruncatedNormal', 'truncnorm', 'udunits2', +'units', 'urltools', 'utils', 'vdiffr', From 7d8cd4b09dde4681f2373b556b556cb731454847 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Wed, 27 Jul 2022 20:23:44 +0000 Subject: [PATCH 03/37] replaced ud.convert() with ud_convert() --- models/basgra/DESCRIPTION | 1 - models/basgra/R/run_BASGRA.R | 36 ++++++++--------- models/basgra/R/write.config.BASGRA.R | 40 +++++++++---------- models/biocro/DESCRIPTION | 1 - models/biocro/R/met2model.BIOCRO.R | 14 +++---- models/biocro/R/model2netcdf.BIOCRO.R | 8 ++-- models/biocro/R/write.configs.BIOCRO.R | 4 +- models/clm45/DESCRIPTION | 1 - models/clm45/R/met2model.CLM45.R | 2 +- models/dalec/DESCRIPTION | 1 - models/dalec/R/met2model.DALEC.R | 8 ++-- models/dalec/R/write.configs.dalec.R | 16 ++++---- models/dvmdostem/R/write.config.dvmdostem.R | 4 +- models/ed/DESCRIPTION | 1 - models/ed/R/met2model.ED2.R | 4 +- models/ed/R/model2netcdf.ED2.R | 6 +-- models/ed/R/read_restart.ED2.R | 12 +++--- models/ed/R/write_restart.ED2.R | 2 +- models/fates/R/write.configs.FATES.R | 14 +++---- models/jules/R/write.config.JULES.R | 4 +- models/linkages/DESCRIPTION | 1 - models/linkages/R/met2model.LINKAGES.R | 2 +- models/linkages/R/read_restart.LINKAGES.R | 2 +- models/lpjguess/R/write.config.LPJGUESS.R | 2 +- models/maat/DESCRIPTION | 1 - models/maat/R/met2model.MAAT.R | 12 +++--- models/maat/R/model2netcdf.MAAT.R | 2 +- models/maat/R/write.config.MAAT.R | 12 +++--- .../inst/generate_maat_met_drivers_ngee.R | 4 +- .../generate_maat_met_drivers_ngee_pa-bar.R | 2 +- models/maespa/DESCRIPTION | 1 - models/maespa/R/met2model.MAESPA.R | 6 +-- models/preles/DESCRIPTION | 1 - models/preles/R/runPRELES.jobsh.R | 12 +++--- models/sipnet/DESCRIPTION | 1 - models/sipnet/R/met2model.SIPNET.R | 12 +++--- models/sipnet/R/read_restart.SIPNET.R | 6 +-- models/sipnet/R/sample.IC.SIPNET.R | 2 +- models/sipnet/R/write.configs.SIPNET.R | 10 ++--- models/sipnet/R/write_restart.SIPNET.R | 8 ++-- models/stics/DESCRIPTION | 1 - models/stics/R/met2model.STICS.R | 4 +- models/stics/R/write.config.STICS.R | 2 +- modules/assim.batch/DESCRIPTION | 1 - .../assim.batch/R/pda.generate.externals.R | 2 +- modules/assim.batch/R/pda.get.model.output.R | 2 +- .../inst/NEFI/graph_SDA_fluxtowers.R | 4 +- .../inst/NEFI/graph_fluxtowers.R | 4 +- modules/benchmark/DESCRIPTION | 2 +- modules/benchmark/R/load_data.R | 4 +- modules/benchmark/R/load_netcdf.R | 2 +- modules/data.atmosphere/DESCRIPTION | 2 +- .../R/download.CRUNCEP_Global.R | 2 +- modules/data.atmosphere/R/download.GFDL.R | 2 +- .../data.atmosphere/R/download.MsTMIP_NARR.R | 2 +- .../data.atmosphere/R/download.NARR_site.R | 6 +-- modules/data.atmosphere/R/download.NEONmet.R | 4 +- modules/data.atmosphere/R/download.US_WCr.R | 10 ++--- modules/data.atmosphere/R/download.US_Wlef.R | 10 ++--- modules/data.atmosphere/R/load.cfmet.R | 4 +- .../data.atmosphere/R/merge.met.variable.R | 8 ++-- modules/data.atmosphere/R/met2CF.ALMA.R | 14 +++---- modules/data.atmosphere/R/met2CF.Ameriflux.R | 14 +++---- modules/data.atmosphere/R/met2CF.FACE.R | 4 +- modules/data.atmosphere/R/met2CF.Geostreams.R | 2 +- modules/data.atmosphere/R/met2CF.csv.R | 12 +++--- modules/data.atmosphere/R/met2cf.ERA5.R | 6 +-- modules/data.atmosphere/R/metgapfill.R | 24 +++++------ modules/data.atmosphere/R/metutils.R | 6 +-- modules/data.atmosphere/R/split_wind.R | 2 +- .../data.atmosphere/R/temporal.downscaling.R | 14 +++---- modules/data.atmosphere/R/upscale_met.R | 8 ++-- .../inst/scripts/ncep/met2csv.R | 5 +-- .../tests/testthat/test.upscale_met.R | 4 +- modules/data.land/DESCRIPTION | 1 - modules/data.land/R/IC_BADM_Utilities.R | 8 ++-- modules/data.land/R/extract_soil_nc.R | 2 +- modules/data.land/R/get.soil.R | 2 +- modules/data.land/R/soil_utils.R | 2 +- modules/data.land/inst/BCI_AGB.R | 4 +- .../inst/build_soil_texture_variables.R | 2 +- modules/uncertainty/DESCRIPTION | 3 +- .../uncertainty/R/run.sensitivity.analysis.R | 2 +- 83 files changed, 241 insertions(+), 256 deletions(-) diff --git a/models/basgra/DESCRIPTION b/models/basgra/DESCRIPTION index 659d5cfb7c7..d06b2c970c7 100644 --- a/models/basgra/DESCRIPTION +++ b/models/basgra/DESCRIPTION @@ -13,7 +13,6 @@ Imports: PEcAn.utils (>= 1.4.8), lubridate, ncdf4, - udunits2 Suggests: testthat (>= 1.0.2) OS_type: unix diff --git a/models/basgra/R/run_BASGRA.R b/models/basgra/R/run_BASGRA.R index 418ac028c9c..13ee6614d21 100644 --- a/models/basgra/R/run_BASGRA.R +++ b/models/basgra/R/run_BASGRA.R @@ -93,7 +93,7 @@ run_BASGRA <- function(run_met, run_params, site_harvest, site_fertilize, start_ ## convert time to seconds sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- diff(sec)[1] tstep <- round(86400 / dt) @@ -121,7 +121,7 @@ run_BASGRA <- function(run_met, run_params, site_harvest, site_fertilize, start_ Tair <- ncdf4::ncvar_get(nc, "air_temperature") ## in Kelvin Tair <- Tair[ydays %in% simdays] - Tair_C <- udunits2::ud.convert(Tair, "K", "degC") + Tair_C <- PEcAn.utils::ud_convert(Tair, "K", "degC") #in BASGRA tmin and tmax is only used to calculate the average daily temperature, see environment.f90 @@ -360,36 +360,36 @@ run_BASGRA <- function(run_met, run_params, site_harvest, site_fertilize, start_ outlist[[length(outlist)+1]] <- output[thisyear, which(outputNames == "LAI")] # LAI in (m2 m-2) CropYield <- output[thisyear, which(outputNames == "YIELD_POT")] # (g DM m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(CropYield, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(CropYield, "g m-2", "kg m-2") clitt <- output[thisyear, which(outputNames == "CLITT")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(clitt, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(clitt, "g m-2", "kg m-2") cstub <- output[thisyear, which(outputNames == "CSTUB")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(cstub, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(cstub, "g m-2", "kg m-2") cst <- output[thisyear, which(outputNames == "CST")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(cst, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(cst, "g m-2", "kg m-2") crt <- output[thisyear, which(outputNames == "CRT")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(crt, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(crt, "g m-2", "kg m-2") cres <- output[thisyear, which(outputNames == "CRES")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(cres, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(cres, "g m-2", "kg m-2") clv <- output[thisyear, which(outputNames == "CLV")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(clv, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(clv, "g m-2", "kg m-2") clvd <- output[thisyear, which(outputNames == "CLVD")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(clvd, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(clvd, "g m-2", "kg m-2") csomf <- output[thisyear, which(outputNames == "CSOMF")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(csomf, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(csomf, "g m-2", "kg m-2") csoms <- output[thisyear, which(outputNames == "CSOMS")] # (g C m-2) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(csoms, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(csoms, "g m-2", "kg m-2") - outlist[[length(outlist)+1]] <- udunits2::ud.convert(csomf + csoms, "g m-2", "kg m-2") + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(csomf + csoms, "g m-2", "kg m-2") outlist[[length(outlist)+1]] <- output[thisyear, which(outputNames == "TILG1")] outlist[[length(outlist)+1]] <- output[thisyear, which(outputNames == "TILG2")] @@ -401,11 +401,11 @@ run_BASGRA <- function(run_met, run_params, site_harvest, site_fertilize, start_ # Soil Respiration in kgC/m2/s rsoil <- output[thisyear, which(outputNames == "Rsoil")] # (g C m-2 d-1) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(rsoil, "g m-2", "kg m-2") / sec_in_day + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(rsoil, "g m-2", "kg m-2") / sec_in_day # Autotrophic Respiration in kgC/m2/s rplantaer <- output[thisyear, which(outputNames == "RplantAer")] # (g C m-2 d-1) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(rplantaer, "g m-2", "kg m-2") / sec_in_day + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(rplantaer, "g m-2", "kg m-2") / sec_in_day # NEE in kgC/m2/s # NOTE: According to BASGRA_N documentation: LUEMXQ (used in PHOT calculation) accounts for carbon lost to maintenance respiration, @@ -413,10 +413,10 @@ run_BASGRA <- function(run_met, run_params, site_harvest, site_fertilize, start_ # So this is not really GPP, but it wasn't obvious to add what to get GPP, but I just want NEE for now, so it's OK phot <- output[thisyear, which(outputNames == "PHOT")] # (g C m-2 d-1) nee <- -1.0 * (phot - (rsoil + rplantaer)) - outlist[[length(outlist)+1]] <- udunits2::ud.convert(nee, "g m-2", "kg m-2") / sec_in_day + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(nee, "g m-2", "kg m-2") / sec_in_day # again this is not technically GPP - outlist[[length(outlist)+1]] <- udunits2::ud.convert(phot, "g m-2", "kg m-2") / sec_in_day + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(phot, "g m-2", "kg m-2") / sec_in_day # Qle W/m2 outlist[[length(outlist)+1]] <- ( output[thisyear, which(outputNames == "EVAP")] + output[thisyear, which(outputNames == "TRAN")] * @@ -425,7 +425,7 @@ run_BASGRA <- function(run_met, run_params, site_harvest, site_fertilize, start_ # SoilMoist (!!! only liquid water !!!) kg m-2 # during the groowing season its depth will mainly be equal to the rooting depth, but during winter its depth will be ROOTD-Fdepth soilm <- output[thisyear, which(outputNames == "WAL")] # mm - outlist[[length(outlist)+1]] <- udunits2::ud.convert(soilm, "mm", "m") * 1000 # (kg m-3) density of water in soil + outlist[[length(outlist)+1]] <- PEcAn.utils::ud_convert(soilm, "mm", "m") * 1000 # (kg m-3) density of water in soil # ******************** Declare netCDF dimensions and variables ********************# t <- ncdf4::ncdim_def(name = "time", diff --git a/models/basgra/R/write.config.BASGRA.R b/models/basgra/R/write.config.BASGRA.R index e2c7a87902b..0f9217d0f47 100644 --- a/models/basgra/R/write.config.BASGRA.R +++ b/models/basgra/R/write.config.BASGRA.R @@ -49,7 +49,7 @@ write.config.BASGRA <- function(defaults, trait.values, settings, run.id, IC = N # Maximum SLA of new leaves if ("SLAMAX" %in% pft.names) { - run_params[which(names(run_params) == "SLAMAX")] <- udunits2::ud.convert(pft.traits[which(pft.names == "SLAMAX")], "kg-1","g-1") + run_params[which(names(run_params) == "SLAMAX")] <- PEcAn.utils::ud_convert(pft.traits[which(pft.names == "SLAMAX")], "kg-1","g-1") } # Number of elongating leaves per non-elongating tiller @@ -88,12 +88,12 @@ write.config.BASGRA <- function(defaults, trait.values, settings, run.id, IC = N if ("leaf_width" %in% pft.names) { # Leaf width on non-elongating tillers (m) - run_params[which(names(run_params) == "LFWIDV")] <- udunits2::ud.convert(pft.traits[which(pft.names == "leaf_width")], "mm", "m") + run_params[which(names(run_params) == "LFWIDV")] <- PEcAn.utils::ud_convert(pft.traits[which(pft.names == "leaf_width")], "mm", "m") } if ("generative_leaf_width" %in% pft.names) { # Leaf width on elongating tillers (m) - run_params[which(names(run_params) == "LFWIDG")] <- udunits2::ud.convert(pft.traits[which(pft.names == "generative_leaf_width")], "mm", "m") + run_params[which(names(run_params) == "LFWIDG")] <- PEcAn.utils::ud_convert(pft.traits[which(pft.names == "generative_leaf_width")], "mm", "m") } # Maximum root depth growth rate (m day-1) @@ -263,44 +263,44 @@ write.config.BASGRA <- function(defaults, trait.values, settings, run.id, IC = N } if ("fast_soil_pool_carbon_content" %in% ic.names) { - run_params[names(run_params) == "CSOMF0"] <- udunits2::ud.convert(IC$fast_soil_pool_carbon_content, "kg", "g") + run_params[names(run_params) == "CSOMF0"] <- PEcAn.utils::ud_convert(IC$fast_soil_pool_carbon_content, "kg", "g") } if ("slow_soil_pool_carbon_content" %in% ic.names) { - run_params[names(run_params) == "CSOMS0"] <- udunits2::ud.convert(IC$slow_soil_pool_carbon_content, "kg", "g") + run_params[names(run_params) == "CSOMS0"] <- PEcAn.utils::ud_convert(IC$slow_soil_pool_carbon_content, "kg", "g") } if ("CropYield" %in% ic.names) { - run_params[names(run_params) == "YIELDI"] <- udunits2::ud.convert(IC$CropYield, "kg", "g") + run_params[names(run_params) == "YIELDI"] <- PEcAn.utils::ud_convert(IC$CropYield, "kg", "g") } if ("litter_carbon_content" %in% ic.names) { - run_params[names(run_params) == "CLITT0"] <- udunits2::ud.convert(IC$litter_carbon_content, "kg", "g") + run_params[names(run_params) == "CLITT0"] <- PEcAn.utils::ud_convert(IC$litter_carbon_content, "kg", "g") } # not as important as others but you can throw this into the SDA too, then comment out last value overwriting below # if ("stubble_carbon_content" %in% ic.names) { - # run_params[names(run_params) == "CSTUBI"] <- udunits2::ud.convert(IC$stubble_carbon_content, "kg", "g") + # run_params[names(run_params) == "CSTUBI"] <- PEcAn.utils::ud_convert(IC$stubble_carbon_content, "kg", "g") # } if ("stem_carbon_content" %in% ic.names) { - run_params[names(run_params) == "CSTI"] <- udunits2::ud.convert(IC$stem_carbon_content, "kg", "g") + run_params[names(run_params) == "CSTI"] <- PEcAn.utils::ud_convert(IC$stem_carbon_content, "kg", "g") } if ("root_carbon_content" %in% ic.names) { - run_params[names(run_params) == "LOG10CRTI"] <- udunits2::ud.convert(IC$root_carbon_content, "kg", "g") + run_params[names(run_params) == "LOG10CRTI"] <- PEcAn.utils::ud_convert(IC$root_carbon_content, "kg", "g") } if ("reserve_carbon_content" %in% ic.names) { - run_params[names(run_params) == "LOG10CRESI"] <- udunits2::ud.convert(IC$reserve_carbon_content, "kg", "g") + run_params[names(run_params) == "LOG10CRESI"] <- PEcAn.utils::ud_convert(IC$reserve_carbon_content, "kg", "g") } if ("leaf_carbon_content" %in% ic.names) { - run_params[names(run_params) == "LOG10CLVI"] <- udunits2::ud.convert(IC$leaf_carbon_content, "kg", "g") + run_params[names(run_params) == "LOG10CLVI"] <- PEcAn.utils::ud_convert(IC$leaf_carbon_content, "kg", "g") } if ("dead_leaf_carbon_content" %in% ic.names) { - run_params[names(run_params) == "CLVDI"] <- udunits2::ud.convert(IC$dead_leaf_carbon_content, "kg", "g") + run_params[names(run_params) == "CLVDI"] <- PEcAn.utils::ud_convert(IC$dead_leaf_carbon_content, "kg", "g") } if ("nonelongating_generative_tiller" %in% ic.names) { @@ -341,40 +341,40 @@ write.config.BASGRA <- function(defaults, trait.values, settings, run.id, IC = N # Initial value of litter C (g C m-2) clitt0 <- try(ncdf4::ncvar_get(IC.nc, "litter_carbon_content"), silent = TRUE) if (!is.na(clitt0) && is.numeric(clitt0)) { - run_params[which(names(run_params) == "CLITT0")] <- udunits2::ud.convert(clitt0, "kg", "g") + run_params[which(names(run_params) == "CLITT0")] <- PEcAn.utils::ud_convert(clitt0, "kg", "g") } # Initial value of slow SOM (g C m-2) csoms0 <- try(ncdf4::ncvar_get(IC.nc, "slow_soil_pool_carbon_content"), silent = TRUE) if (!is.na(csoms0) && is.numeric(csoms0)) { - run_params[which(names(run_params) == "CSOMS0")] <- udunits2::ud.convert(csoms0, "kg", "g") + run_params[which(names(run_params) == "CSOMS0")] <- PEcAn.utils::ud_convert(csoms0, "kg", "g") } # Initial value of fast SOM (g C m-2) csomf0 <- try(ncdf4::ncvar_get(IC.nc, "fast_soil_pool_carbon_content"), silent = TRUE) if (!is.na(csomf0) && is.numeric(csomf0)) { - run_params[which(names(run_params) == "CSOMF0")] <- udunits2::ud.convert(csomf0, "kg", "g") + run_params[which(names(run_params) == "CSOMF0")] <- PEcAn.utils::ud_convert(csomf0, "kg", "g") } # Initial value of root C (g C m-2) crti <- try(ncdf4::ncvar_get(IC.nc, "root_carbon_content"), silent = TRUE) if (!is.na(crti) && is.numeric(crti)) { # not log10 anymore, don't mind the name - run_params[which(names(run_params) == "LOG10CRTI")] <- udunits2::ud.convert(crti, "kg", "g") + run_params[which(names(run_params) == "LOG10CRTI")] <- PEcAn.utils::ud_convert(crti, "kg", "g") } # Initial value of leaf C (g C m-2) clvi <- try(ncdf4::ncvar_get(IC.nc, "leaf_carbon_content"), silent = TRUE) if (!is.na(clvi) && is.numeric(clvi)) { # not log10 anymore, don't mind the name - run_params[which(names(run_params) == "LOG10CLVI")] <- udunits2::ud.convert(clvi, "kg", "g") + run_params[which(names(run_params) == "LOG10CLVI")] <- PEcAn.utils::ud_convert(clvi, "kg", "g") } # Initial mineral N nmin0 <- try(ncdf4::ncvar_get(IC.nc, "soil_nitrogen_content"), silent = TRUE) if (!is.na(nmin0) && is.numeric(nmin0)) { - run_params[which(names(run_params) == "NMIN0")] <- udunits2::ud.convert(nmin0, "kg", "g") + run_params[which(names(run_params) == "NMIN0")] <- PEcAn.utils::ud_convert(nmin0, "kg", "g") } # Rooting depth (m) @@ -405,7 +405,7 @@ write.config.BASGRA <- function(defaults, trait.values, settings, run.id, IC = N cresi <- try(ncdf4::ncvar_get(IC.nc, "reserve_carbon_content"), silent = TRUE) if (!is.na(cresi) && is.numeric(cresi)) { # not log10 anymore, don't mind the name - run_params[which(names(run_params) == "LOG10CRESI")] <- udunits2::ud.convert(cresi, "kg", "g") + run_params[which(names(run_params) == "LOG10CRESI")] <- PEcAn.utils::ud_convert(cresi, "kg", "g") } # N-C ratio of roots diff --git a/models/biocro/DESCRIPTION b/models/biocro/DESCRIPTION index 60dff6ceac4..fed0cb91f87 100644 --- a/models/biocro/DESCRIPTION +++ b/models/biocro/DESCRIPTION @@ -20,7 +20,6 @@ Imports: PEcAn.settings, PEcAn.data.atmosphere, PEcAn.data.land, - udunits2 (>= 0.11), ncdf4 (>= 1.15), lubridate (>= 1.7.0), data.table, diff --git a/models/biocro/R/met2model.BIOCRO.R b/models/biocro/R/met2model.BIOCRO.R index c0f25ee6a0b..638a1c7110b 100644 --- a/models/biocro/R/met2model.BIOCRO.R +++ b/models/biocro/R/met2model.BIOCRO.R @@ -51,7 +51,7 @@ met2model.BIOCRO <- function(in.path, in.prefix, outfolder, overwrite = FALSE, on.exit(close_nc_if_open(met.nc), add = FALSE) # add = FALSE because any previous file was closed at end of prev. loop - dt <- mean(diff(udunits2::ud.convert( + dt <- mean(diff(PEcAn.utils::ud_convert( met.nc$dim$time$vals, met.nc$dim$time$units, "hours since 1700-01-01 00:00:00"))) @@ -143,15 +143,15 @@ met2model.BIOCRO <- function(in.path, in.prefix, outfolder, overwrite = FALSE, cf2biocro <- function(met, longitude = NULL, zulu2solarnoon = FALSE) { if ((!is.null(longitude)) & zulu2solarnoon) { - solarnoon_offset <- udunits2::ud.convert(longitude/360, "day", "minute") + solarnoon_offset <- PEcAn.utils::ud_convert(longitude/360, "day", "minute") met[, `:=`(solardate = met$date + lubridate::minutes(solarnoon_offset))] } if (!"relative_humidity" %in% colnames(met)) { if (all(c("air_temperature", "air_pressure", "specific_humidity") %in% colnames(met))) { rh <- PEcAn.data.atmosphere::qair2rh( qair = met$specific_humidity, - temp = udunits2::ud.convert(met$air_temperature, "Kelvin", "Celsius"), - press = udunits2::ud.convert(met$air_pressure, "Pa", "hPa")) + temp = PEcAn.utils::ud_convert(met$air_temperature, "Kelvin", "Celsius"), + press = PEcAn.utils::ud_convert(met$air_pressure, "Pa", "hPa")) met[, `:=`(relative_humidity = rh)] } else { PEcAn.logger::logger.error("neither relative_humidity nor [air_temperature, air_pressure, and specific_humidity]", @@ -160,7 +160,7 @@ cf2biocro <- function(met, longitude = NULL, zulu2solarnoon = FALSE) { } if (!"ppfd" %in% colnames(met)) { if ("surface_downwelling_photosynthetic_photon_flux_in_air" %in% colnames(met)) { - ppfd <- udunits2::ud.convert(met$surface_downwelling_photosynthetic_photon_flux_in_air, "mol", "umol") + ppfd <- PEcAn.utils::ud_convert(met$surface_downwelling_photosynthetic_photon_flux_in_air, "mol", "umol") } else if ("surface_downwelling_shortwave_flux_in_air" %in% colnames(met)) { par <- PEcAn.data.atmosphere::sw2par(met$surface_downwelling_shortwave_flux_in_air) ppfd <- PEcAn.data.atmosphere::par2ppfd(par) @@ -184,10 +184,10 @@ cf2biocro <- function(met, longitude = NULL, zulu2solarnoon = FALSE) { doy = lubridate::yday(met$date), hour = round(lubridate::hour(met$date) + lubridate::minute(met$date) / 60, 0), solar = ppfd, - Temp = udunits2::ud.convert(met$air_temperature, "Kelvin", "Celsius"), + Temp = PEcAn.utils::ud_convert(met$air_temperature, "Kelvin", "Celsius"), RH = met$relative_humidity, windspeed = wind_speed, - precip = udunits2::ud.convert(met$precipitation_flux, "s-1", "h-1"))] + precip = PEcAn.utils::ud_convert(met$precipitation_flux, "s-1", "h-1"))] newmet <- newmet[newmet$hour <= 23,] return(as.data.frame(newmet)) } # cf2biocro diff --git a/models/biocro/R/model2netcdf.BIOCRO.R b/models/biocro/R/model2netcdf.BIOCRO.R index 65b52b15e2f..3d8269266cc 100644 --- a/models/biocro/R/model2netcdf.BIOCRO.R +++ b/models/biocro/R/model2netcdf.BIOCRO.R @@ -70,20 +70,20 @@ model2netcdf.BIOCRO <- function(result, genus = NULL, outdir, lat = -9999, lon = LAI = PEcAn.utils::to_ncvar("LAI", dims)) biomass2c <- 0.4 - k <- udunits2::ud.convert(1, "Mg/ha", "kg/m2") * biomass2c + k <- PEcAn.utils::ud_convert(1, "Mg/ha", "kg/m2") * biomass2c result_yeari_std <- with(result_yeari, list( TotLivBiom = k * (Leaf + Root + Stem + Rhizome + Grain), root_carbon_content = k * Root, AbvGrndWood = k * Stem, AGB = k * (Leaf + Stem + Grain), - Evap = udunits2::ud.convert(SoilEvaporation + CanopyTrans, "Mg/ha/h", "kg/m2/s"), - TVeg = udunits2::ud.convert(CanopyTrans, "Mg/ha/h", "kg/m2/s"), + Evap = PEcAn.utils::ud_convert(SoilEvaporation + CanopyTrans, "Mg/ha/h", "kg/m2/s"), + TVeg = PEcAn.utils::ud_convert(CanopyTrans, "Mg/ha/h", "kg/m2/s"), LAI = LAI)) total_biomass <- with(result_yeari, # this is for calculating NPP and includes litter k * (Leaf + Root + Stem + Rhizome + Grain + AboveLitter + BelowLitter)) - delta_biomass <- udunits2::ud.convert(c(0, diff(total_biomass)), "kg/m2/h", "kg/m2/s") + delta_biomass <- PEcAn.utils::ud_convert(c(0, diff(total_biomass)), "kg/m2/h", "kg/m2/s") delta_biomass[delta_biomass < 0] <- 0 result_yeari_std$NPP <- delta_biomass ncfile <- file.path(outdir, paste0(yeari, ".nc")) diff --git a/models/biocro/R/write.configs.BIOCRO.R b/models/biocro/R/write.configs.BIOCRO.R index d4c5d999976..6bbca20db36 100644 --- a/models/biocro/R/write.configs.BIOCRO.R +++ b/models/biocro/R/write.configs.BIOCRO.R @@ -28,10 +28,10 @@ convert.samples.BIOCRO <- function(trait.samples, biocro_version=1.0) { ## transform values with different units cuticular conductance - BETY default is ## umol; BioCro uses mol if ("cuticular_cond" %in% trait.names) { - trait.samples$cuticular_cond = udunits2::ud.convert(trait.samples$cuticular_cond, "umol", "mol") + trait.samples$cuticular_cond = PEcAn.utils::ud_convert(trait.samples$cuticular_cond, "umol", "mol") } if ("SLA" %in% trait.names) { - trait.samples$SLA = udunits2::ud.convert(trait.samples$SLA, "kg/m2", "g/cm2") + trait.samples$SLA = PEcAn.utils::ud_convert(trait.samples$SLA, "kg/m2", "g/cm2") } ## rename bety variables to match active version of biocro diff --git a/models/clm45/DESCRIPTION b/models/clm45/DESCRIPTION index 2df097ae3c9..f24051b2290 100644 --- a/models/clm45/DESCRIPTION +++ b/models/clm45/DESCRIPTION @@ -18,7 +18,6 @@ Depends: PEcAn.logger, PEcAn.utils Imports: - udunits2 (>= 0.11), ncdf4 (>= 1.15) Suggests: testthat (>= 1.0.2) diff --git a/models/clm45/R/met2model.CLM45.R b/models/clm45/R/met2model.CLM45.R index 27ebb38c2ce..60dda63ca0f 100644 --- a/models/clm45/R/met2model.CLM45.R +++ b/models/clm45/R/met2model.CLM45.R @@ -55,7 +55,7 @@ met2model.CLM45 <- function(in.path,in.prefix,outfolder,start_date, end_date, ls # # ## convert time to seconds # sec <- nc$dim$time$vals -# sec = udunits2::ud.convert(sec,unlist(strsplit(nc$dim$time$units," "))[1],"seconds") +# sec = PEcAn.utils::ud_convert(sec,unlist(strsplit(nc$dim$time$units," "))[1],"seconds") # # # diff --git a/models/dalec/DESCRIPTION b/models/dalec/DESCRIPTION index 6b09e7e2f97..db27f2ec787 100644 --- a/models/dalec/DESCRIPTION +++ b/models/dalec/DESCRIPTION @@ -15,7 +15,6 @@ Imports: PEcAn.remote, lubridate (>= 1.6.0), ncdf4 (>= 1.15), - udunits2 (>= 0.11), PEcAn.utils Suggests: testthat (>= 1.0.2) diff --git a/models/dalec/R/met2model.DALEC.R b/models/dalec/R/met2model.DALEC.R index 831aa103d67..71d95195a81 100644 --- a/models/dalec/R/met2model.DALEC.R +++ b/models/dalec/R/met2model.DALEC.R @@ -103,7 +103,7 @@ met2model.DALEC <- function(in.path, in.prefix, outfolder, start_date, end_date, ## convert time to seconds sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") timestep.s <- 86400 # seconds in a day dt <- PEcAn.utils::seconds_in_year(year) / length(sec) tstep <- round(timestep.s / dt) @@ -147,9 +147,9 @@ met2model.DALEC <- function(in.path, in.prefix, outfolder, start_date, end_date, doy <- rep(seq_len(diy), each = timestep.s / dt)[seq_along(sec)] ## Aggregate variables up to daily - Tmean <- udunits2::ud.convert(tapply(Tair, doy, mean, na.rm = TRUE), "Kelvin", "Celsius") - Tmin <- udunits2::ud.convert(tapply(Tair, doy, min, na.rm = TRUE), "Kelvin", "Celsius") - Tmax <- udunits2::ud.convert(tapply(Tair, doy, max, na.rm = TRUE), "Kelvin", "Celsius") + Tmean <- PEcAn.utils::ud_convert(tapply(Tair, doy, mean, na.rm = TRUE), "Kelvin", "Celsius") + Tmin <- PEcAn.utils::ud_convert(tapply(Tair, doy, min, na.rm = TRUE), "Kelvin", "Celsius") + Tmax <- PEcAn.utils::ud_convert(tapply(Tair, doy, max, na.rm = TRUE), "Kelvin", "Celsius") Rin <- tapply(SW, doy, sum) * dt * 1e-06 # J/m2/s * s * MJ/J LeafWaterPot <- tapply(LeafWaterPot, doy, mean) CO2 <- tapply(CO2, doy, mean) diff --git a/models/dalec/R/write.configs.dalec.R b/models/dalec/R/write.configs.dalec.R index 141442c76a7..c0b926cde40 100644 --- a/models/dalec/R/write.configs.dalec.R +++ b/models/dalec/R/write.configs.dalec.R @@ -116,10 +116,10 @@ write.config.DALEC <- function(defaults, trait.values, settings, run.id) { #grab SLA from parameters and convert to PECAN standard sla <- NULL if("SLA" %in% names(params)){ - sla <- udunits2::ud.convert(params[1,"SLA"], 'm2 g-1', 'm2 kg-1') #convert SLA to m2/kgC from m2/gC (revert convert.samples conversion to dalec default; need standard for prepare.pools) + sla <- PEcAn.utils::ud_convert(params[1,"SLA"], 'm2 g-1', 'm2 kg-1') #convert SLA to m2/kgC from m2/gC (revert convert.samples conversion to dalec default; need standard for prepare.pools) } else{ default.param <- read.table(system.file("default_param.dalec", package = "PEcAn.DALEC"), header = TRUE) - sla <- udunits2::ud.convert(default.param[which(default.param$cmdFlag == "SLA"),"val"], 'm2 g-1', 'm2 kg-1') #convert SLA to m2/kgC from m2/gC (dalec default) + sla <- PEcAn.utils::ud_convert(default.param[which(default.param$cmdFlag == "SLA"),"val"], 'm2 g-1', 'm2 kg-1') #convert SLA to m2/kgC from m2/gC (dalec default) } IC.pools <- PEcAn.data.land::prepare_pools(IC.path, constants = list(sla = sla)) @@ -129,31 +129,31 @@ write.config.DALEC <- function(defaults, trait.values, settings, run.id) { # cf0 initial canopy foliar carbon (g/m2) if ("leaf" %in% names(IC.pools)) { - IC.params[["cf0"]] <- udunits2::ud.convert(IC.pools$leaf, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 + IC.params[["cf0"]] <- PEcAn.utils::ud_convert(IC.pools$leaf, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 } # cw0 initial pool of woody carbon (g/m2) if ("wood" %in% names(IC.pools)) { - IC.params[["cw0"]] <- udunits2::ud.convert(IC.pools$wood, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 + IC.params[["cw0"]] <- PEcAn.utils::ud_convert(IC.pools$wood, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 } # cr0 initial pool of fine root carbon (g/m2) if ("fine.roots" %in% names(IC.pools)) { - IC.params[["cr0"]] <- udunits2::ud.convert(IC.pools$fine.roots, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 + IC.params[["cr0"]] <- PEcAn.utils::ud_convert(IC.pools$fine.roots, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 } ###non-living variables # cl0 initial pool of litter carbon (g/m2) if ("litter" %in% names(IC.pools)) { - IC.params[["cl0"]] <- udunits2::ud.convert(IC.pools$litter, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 + IC.params[["cl0"]] <- PEcAn.utils::ud_convert(IC.pools$litter, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 } # cs0 initial pool of soil organic matter and woody debris carbon (g/m2) if("soil" %in% names(IC.pools)){ if("wood.debris" %in% names(IC.pools)){ - IC.params[["cs0"]] <- udunits2::ud.convert(IC.pools$soil + sum(IC.pools$wood.debris), 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 + IC.params[["cs0"]] <- PEcAn.utils::ud_convert(IC.pools$soil + sum(IC.pools$wood.debris), 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 } else { - IC.params[["cs0"]] <- udunits2::ud.convert(IC.pools$soil, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 + IC.params[["cs0"]] <- PEcAn.utils::ud_convert(IC.pools$soil, 'kg m-2', 'g m-2') #from PEcAn standard kg C m-2 PEcAn.logger::logger.warn("write.configs.DALEC IC: Loading soil carbon pool without woody debris.") } } diff --git a/models/dvmdostem/R/write.config.dvmdostem.R b/models/dvmdostem/R/write.config.dvmdostem.R index 77bb6da58ce..5293990bdab 100644 --- a/models/dvmdostem/R/write.config.dvmdostem.R +++ b/models/dvmdostem/R/write.config.dvmdostem.R @@ -229,12 +229,12 @@ convert.samples.dvmdostem <- function(trait_values) { if("vpd_open" %in% names(trait_values)) { # Convert from kPa to Pa - trait_values[["vpd_open"]] <- udunits2::ud.convert(trait_values[["vpd_open"]],"kPa","Pa") + trait_values[["vpd_open"]] <- PEcAn.utils::ud_convert(trait_values[["vpd_open"]],"kPa","Pa") } if("vpd_close" %in% names(trait_values)) { # Convert from kPa to Pa - trait_values[["vpd_close"]] <- udunits2::ud.convert(trait_values[["vpd_close"]],"kPa","Pa") + trait_values[["vpd_close"]] <- PEcAn.utils::ud_convert(trait_values[["vpd_close"]],"kPa","Pa") } # Return the modifed version diff --git a/models/ed/DESCRIPTION b/models/ed/DESCRIPTION index 8e7bce5a8c7..d1134bffe4c 100644 --- a/models/ed/DESCRIPTION +++ b/models/ed/DESCRIPTION @@ -46,7 +46,6 @@ Imports: stringr(>= 1.1.0), tidyr, tibble, - udunits2 (>= 0.11), utils, XML (>= 3.98-1.4) Suggests: diff --git a/models/ed/R/met2model.ED2.R b/models/ed/R/met2model.ED2.R index 7279cbe024a..b9d57c4f2b2 100644 --- a/models/ed/R/met2model.ED2.R +++ b/models/ed/R/met2model.ED2.R @@ -72,7 +72,7 @@ met2model.ED2 <- function(in.path, in.prefix, outfolder, start_date, end_date, l start_year <- lubridate::year(start_date) end_year <- lubridate::year(end_date) year_seq <- seq(start_year, end_year) - day_secs <- udunits2::ud.convert(1, "day", "seconds") + day_secs <- PEcAn.utils::ud_convert(1, "day", "seconds") # Check that we have all the input files we need need_input_files <- file.path(in.path, paste(in.prefix, year_seq, "nc", sep = ".")) @@ -179,7 +179,7 @@ met2model.ED2 <- function(in.path, in.prefix, outfolder, start_date, end_date, l useCO2 <- is.numeric(CO2) ## convert time to seconds - sec <- udunits2::ud.convert(tdays, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(tdays, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") ncdf4::nc_close(nc) diff --git a/models/ed/R/model2netcdf.ED2.R b/models/ed/R/model2netcdf.ED2.R index 13064d68dff..c24534f8d45 100644 --- a/models/ed/R/model2netcdf.ED2.R +++ b/models/ed/R/model2netcdf.ED2.R @@ -670,8 +670,8 @@ put_T_values <- function(yr, nc_var, out, lat, lon, begins, ends, ...){ ## Conversion factor for umol C -> kg C Mc <- 12.017 #molar mass of C, g/mol - umol2kg_C <- Mc * udunits2::ud.convert(1, "umol", "mol") * udunits2::ud.convert(1, "g", "kg") - yr2s <- udunits2::ud.convert(1, "s", "yr") + umol2kg_C <- Mc * PEcAn.utils::ud_convert(1, "umol", "mol") * PEcAn.utils::ud_convert(1, "g", "kg") + yr2s <- PEcAn.utils::ud_convert(1, "s", "yr") # TODO - remove this function and replace with ifelse statements inline below (SPS) conversion <- function(col, mult) { @@ -731,7 +731,7 @@ put_T_values <- function(yr, nc_var, out, lat, lon, begins, ends, ...){ # ----- fill list - out <- conversion(1, udunits2::ud.convert(1, "t ha-1", "kg m-2")) ## tC/ha -> kg/m2 + out <- conversion(1, PEcAn.utils::ud_convert(1, "t ha-1", "kg m-2")) ## tC/ha -> kg/m2 nc_var[[s + 1]] <- ncdf4::ncvar_def("AbvGrndWood", units = "kg C m-2", dim = list(lon, lat, t), missval = -999, longname = "Above ground woody biomass") out <- conversion(2, umol2kg_C) ## umol/m2 s-1 -> kg/m2 s-1 diff --git a/models/ed/R/read_restart.ED2.R b/models/ed/R/read_restart.ED2.R index 1c8e64f8af1..eb5f55c1900 100644 --- a/models/ed/R/read_restart.ED2.R +++ b/models/ed/R/read_restart.ED2.R @@ -50,7 +50,7 @@ read_restart.ED2 <- function(outdir, if (var_name == "AGB") { forecast_tmp <- switch(perpft+1, sum(histout$AGB, na.rm = TRUE), histout$AGB) # kgC/m2 - forecast[[length(forecast)+1]] <- udunits2::ud.convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha + forecast[[length(forecast)+1]] <- PEcAn.utils::ud_convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha names(forecast)[length(forecast)] <- switch(perpft+1, "AGB", paste0("AGB.", pft_names)) } @@ -59,14 +59,14 @@ read_restart.ED2 <- function(outdir, perpft <- TRUE forecast_tmp <- switch(perpft+1, sum(histout$AGB, na.rm = TRUE), histout$AGB) # kgC/m2 names(forecast_tmp) <- switch(perpft + 1, "AGB", paste0(pft_names)) - forecast[[length(forecast)+1]] <- udunits2::ud.convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha + forecast[[length(forecast)+1]] <- PEcAn.utils::ud_convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha names(forecast)[length(forecast)] <- "AGB.pft" } if (var_name == "TotLivBiom") { forecast_tmp <- switch(perpft+1, sum(histout$TotLivBiom, na.rm = TRUE), histout$TotLivBiom) # kgC/m2 - forecast[[length(forecast)+1]] <- udunits2::ud.convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha + forecast[[length(forecast)+1]] <- PEcAn.utils::ud_convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha names(forecast)[length(forecast)] <- switch(perpft+1, "TotLivBiom", paste0("TotLivBiom.", pft_names)) } @@ -74,7 +74,7 @@ read_restart.ED2 <- function(outdir, if (var_name == "AbvGrndWood") { forecast_tmp <- switch(perpft+1, sum(histout$AbvGrndWood, na.rm = TRUE), histout$AbvGrndWood) # kgC/m2 - forecast[[length(forecast)+1]] <- udunits2::ud.convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha + forecast[[length(forecast)+1]] <- PEcAn.utils::ud_convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha names(forecast)[length(forecast)] <- switch(perpft+1, "AbvGrndWood", paste0("AbvGrndWood.", pft_names)) } @@ -82,7 +82,7 @@ read_restart.ED2 <- function(outdir, if (var_name == "leaf_carbon_content") { forecast_tmp <- switch(perpft+1, sum(histout$leaf_carbon_content, na.rm = TRUE), histout$leaf_carbon_content) # kgC/m2 - forecast[[length(forecast)+1]] <- udunits2::ud.convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha + forecast[[length(forecast)+1]] <- PEcAn.utils::ud_convert(forecast_tmp, "kg/m^2", "Mg/ha") # conv to MgC/ha names(forecast)[length(forecast)] <- switch(perpft+1, "leaf_carbon_content", paste0("leaf_carbon_content.", pft_names)) } @@ -98,7 +98,7 @@ read_restart.ED2 <- function(outdir, if (var_name == "GWBI") { forecast_tmp <- switch(perpft+1, sum(histout$GWBI, na.rm = TRUE), histout$GWBI) # kgC/m2/yr - forecast[[length(forecast)+1]] <- udunits2::ud.convert(forecast_tmp, "kg/m^2/yr", "Mg/ha/yr") # conv to MgC/ha/yr + forecast[[length(forecast)+1]] <- PEcAn.utils::ud_convert(forecast_tmp, "kg/m^2/yr", "Mg/ha/yr") # conv to MgC/ha/yr names(forecast)[length(forecast)] <- switch(perpft+1, "GWBI", paste0("GWBI.", pft_names)) } diff --git a/models/ed/R/write_restart.ED2.R b/models/ed/R/write_restart.ED2.R index 011c5fc5899..ea6e4012499 100644 --- a/models/ed/R/write_restart.ED2.R +++ b/models/ed/R/write_restart.ED2.R @@ -79,7 +79,7 @@ write_restart.ED2 <- function(outdir, runid, start.time, stop.time, # none is provided in `new.state`. new_tmp <- new.state[grep(var_name, names(new.state))] - new_tmp <- udunits2::ud.convert(new_tmp, "Mg/ha/yr", "kg/m^2/yr") + new_tmp <- PEcAn.utils::ud_convert(new_tmp, "Mg/ha/yr", "kg/m^2/yr") agb_co <- restart$AGB_CO # reaggregate old state diff --git a/models/fates/R/write.configs.FATES.R b/models/fates/R/write.configs.FATES.R index 43dd776368a..67b1ddf87ce 100644 --- a/models/fates/R/write.configs.FATES.R +++ b/models/fates/R/write.configs.FATES.R @@ -379,7 +379,7 @@ write.config.FATES <- function(defaults, trait.values, settings, run.id){ } if(var == "SLA"){ ## default 0.012 ncdf4::ncvar_put(nc=fates.param.nc, varid='fates_slatop', start = ipft, count = 1, - vals=udunits2::ud.convert(pft[v],"m2 kg-1","m2 g-1")/leafC) + vals=PEcAn.utils::ud_convert(pft[v],"m2 kg-1","m2 g-1")/leafC) } if(var == "leaf_turnover_rate"){ ## fates_leaf_long:long_name = "Leaf longevity (ie turnover timescale)" ; ncdf4::ncvar_put(nc=fates.param.nc, varid='fates_leaf_long', start = ipft, count = 1, @@ -400,7 +400,7 @@ write.config.FATES <- function(defaults, trait.values, settings, run.id){ # if(var == "sapwood_ratio"){ # leaf to sapwood area ratio. IS THIS NOW fates_sapwood_ratio(fates_pft)?? # ncvar_put(nc=fates.param.nc, varid='latosa', start = ipft, count = 1, - # vals=udunits2::ud.convert(pft[v],"m2 m-2","m2 cm-2")) + # vals=PEcAn.utils::ud_convert(pft[v],"m2 m-2","m2 cm-2")) # } # leaf to sapwood area ratio. This is the INTERCEPT parameter in FATES @@ -415,12 +415,12 @@ write.config.FATES <- function(defaults, trait.values, settings, run.id){ # fates_allom_latosa_slp = 0, 0 ; if(var == "sapwood_ratio"){ ncdf4::ncvar_put(nc=fates.param.nc, varid='fates_allom_latosa_int', start = ipft, count = 1, - vals=udunits2::ud.convert(pft[v],"m2 m-2","m2 cm-2")) + vals=PEcAn.utils::ud_convert(pft[v],"m2 m-2","m2 cm-2")) } if(var == "leaf_width"){ # Characteristic leaf dimension use for aerodynamic resistance ncdf4::ncvar_put(nc=fates.param.nc, varid='fates_dleaf', start = ipft, count = 1, - vals=udunits2::ud.convert(pft[v],"mm","m")) - #PEcAn.logger::logger.debug(paste0("fates_dleaf: ",udunits2::ud.convert(pft[v],"mm","m"))) # temp debugging + vals=PEcAn.utils::ud_convert(pft[v],"mm","m")) + #PEcAn.logger::logger.debug(paste0("fates_dleaf: ",PEcAn.utils::ud_convert(pft[v],"mm","m"))) # temp debugging } ## Currently not in param.nc file despite being on NGEE-T parameter list # if(var == "nonlocal_dispersal"){ # Place-holder parameter for important seed dispersal parameters @@ -488,11 +488,11 @@ write.config.FATES <- function(defaults, trait.values, settings, run.id){ if(var == "psi_stomata_closure"){ # Soil water potential at full stomatal closure [mm] # fates_smpsc:long_name = "Soil water potential at full stomatal closure" ; ncdf4::ncvar_put(nc=fates.param.nc, varid='fates_smpsc', start = ipft, count = 1, - vals=udunits2::ud.convert(pft[v],"m","mm")) + vals=PEcAn.utils::ud_convert(pft[v],"m","mm")) } if(var == "psi_stomata_open"){ # Soil water potential at full stomatal opening pft [mm] ncdf4::ncvar_put(nc=fates.param.nc, varid='fates_smpso', start = ipft, count = 1, - vals=udunits2::ud.convert(pft[v],"m","mm")) + vals=PEcAn.utils::ud_convert(pft[v],"m","mm")) } ## --- update these to match new FATES hydro code when that code-base is added to FATES master -- ## diff --git a/models/jules/R/write.config.JULES.R b/models/jules/R/write.config.JULES.R index 4abf9908cef..890d0fd88f4 100644 --- a/models/jules/R/write.config.JULES.R +++ b/models/jules/R/write.config.JULES.R @@ -171,7 +171,7 @@ write.config.JULES <- function(defaults, trait.values, settings, run.id) { ## SPIN the CO2 file if(!is.null(settings$spin)){ - dt.co2 = udunits2::ud.convert(as.numeric(as.Date(settings$run$end.date)- + dt.co2 = PEcAn.utils::ud_convert(as.numeric(as.Date(settings$run$end.date)- as.Date(settings$run$start.date)),"days","years") co2.dat <- read.table(settings$run$inputs$co2$path,header=FALSE) co2.per.year <- round(nrow(co2.dat)/dt.co2) @@ -276,7 +276,7 @@ write.config.JULES <- function(defaults, trait.values, settings, run.id) { in.soil[['b']] <- ncdf4::ncvar_get(nc.soil,"soil_hydraulic_b") # sathh in.soil[['satcon']] <- ncdf4::ncvar_get(nc.soil,"soil_hydraulic_conductivity_at_saturation") - in.soil[['satcon']] <- udunits2::ud.convert(in.soil[['satcon']],"m s-1","mm s-1") + in.soil[['satcon']] <- PEcAn.utils::ud_convert(in.soil[['satcon']],"m s-1","mm s-1") in.soil[['sm_sat']] <- ncdf4::ncvar_get(nc.soil,"volume_fraction_of_water_in_soil_at_saturation") #sm_crit in.soil[['sm_wilt']] <- ncdf4::ncvar_get(nc.soil,"volume_fraction_of_condensed_water_in_soil_at_wilting_point") diff --git a/models/linkages/DESCRIPTION b/models/linkages/DESCRIPTION index 99052f1239d..c0d16074384 100644 --- a/models/linkages/DESCRIPTION +++ b/models/linkages/DESCRIPTION @@ -19,7 +19,6 @@ Imports: PEcAn.remote, lubridate (>= 1.6.0), ncdf4 (>= 1.15), - udunits2 (>= 0.11) Suggests: testthat (>= 1.0.2), linkages diff --git a/models/linkages/R/met2model.LINKAGES.R b/models/linkages/R/met2model.LINKAGES.R index d45f5d807a8..9d7c28136b7 100644 --- a/models/linkages/R/met2model.LINKAGES.R +++ b/models/linkages/R/met2model.LINKAGES.R @@ -85,7 +85,7 @@ met2model.LINKAGES <- function(in.path, in.prefix, outfolder, start_date, end_da ## convert time to seconds sec <- ncin$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(ncin$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(ncin$dim$time$units, " "))[1], "seconds") dt <- PEcAn.utils::seconds_in_year(as.numeric(year[i])) / length(sec) tstep <- 86400 / dt diff --git a/models/linkages/R/read_restart.LINKAGES.R b/models/linkages/R/read_restart.LINKAGES.R index 50b5c77d54d..c4173f888f1 100644 --- a/models/linkages/R/read_restart.LINKAGES.R +++ b/models/linkages/R/read_restart.LINKAGES.R @@ -52,7 +52,7 @@ read_restart.LINKAGES <- function(outdir, runid, stop.time, settings, var.names } if ("TotSoilCarb" %in% var.names) { - forecast[[length(forecast)+1]] <- ens$TotSoilCarb #udunits2::ud.convert(ens$TotSoilCarb, "kg/m^2", "Mg/ha") #* unit.conv + forecast[[length(forecast)+1]] <- ens$TotSoilCarb #PEcAn.utils::ud_convert(ens$TotSoilCarb, "kg/m^2", "Mg/ha") #* unit.conv names(forecast[[length(forecast)]]) <- c("TotSoilCarb") } diff --git a/models/lpjguess/R/write.config.LPJGUESS.R b/models/lpjguess/R/write.config.LPJGUESS.R index d89725b518b..8c5f900704f 100644 --- a/models/lpjguess/R/write.config.LPJGUESS.R +++ b/models/lpjguess/R/write.config.LPJGUESS.R @@ -302,7 +302,7 @@ pecan2lpjguess <- function(trait.values){ canconvert <- toconvert[toconvert %in% names(x)] if(length(canconvert) != 0){ for(c in seq_along(canconvert)){ - x[,names(x) == canconvert[c]] <- udunits2::ud.convert(x[,names(x) == canconvert[c]], + x[,names(x) == canconvert[c]] <- PEcAn.utils::ud_convert(x[,names(x) == canconvert[c]], vartable$pecanunits[vartable$lpjguessname == canconvert[c]], vartable$lpjguessunits[vartable$lpjguessname == canconvert[c]]) } diff --git a/models/maat/DESCRIPTION b/models/maat/DESCRIPTION index 2584fba8a0a..235a1fcbf58 100644 --- a/models/maat/DESCRIPTION +++ b/models/maat/DESCRIPTION @@ -17,7 +17,6 @@ Imports: PEcAn.utils, lubridate (>= 1.6.0), ncdf4 (>= 1.15), - udunits2 (>= 0.11), XML Suggests: testthat (>= 1.0.2) diff --git a/models/maat/R/met2model.MAAT.R b/models/maat/R/met2model.MAAT.R index ed8a1ecb0ba..8997e890704 100644 --- a/models/maat/R/met2model.MAAT.R +++ b/models/maat/R/met2model.MAAT.R @@ -74,7 +74,7 @@ met2model.MAAT <- function(in.path, in.prefix, outfolder, start_date, end_date, # get start/end year since inputs are specified on year basis start_year <- lubridate::year(start_date) end_year <- lubridate::year(end_date) - day_secs <- udunits2::ud.convert(1, "day", "seconds") + day_secs <- PEcAn.utils::ud_convert(1, "day", "seconds") ## loop over files ## TODO need to filter out the data that is not inside start_date, end_date @@ -90,7 +90,7 @@ met2model.MAAT <- function(in.path, in.prefix, outfolder, start_date, end_date, ## convert time to seconds sec <- nc$dim$time$vals frac.day <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- PEcAn.utils::seconds_in_year(year, leap_year) / length(sec) @@ -103,7 +103,7 @@ met2model.MAAT <- function(in.path, in.prefix, outfolder, start_date, end_date, # Air temperature Tair <- ncdf4::ncvar_get(nc, "air_temperature") ## in Kelvin - Tair_C <- udunits2::ud.convert(Tair, "K", "degC") ## in degC + Tair_C <- PEcAn.utils::ud_convert(Tair, "K", "degC") ## in degC # Precipitation Rain <- ncdf4::ncvar_get(nc, "precipitation_flux") ## 'kg/m^2/s' @@ -114,13 +114,13 @@ met2model.MAAT <- function(in.path, in.prefix, outfolder, start_date, end_date, # get humidity vars RH_perc <- try(ncdf4::ncvar_get(nc, "relative_humidity"), silent = TRUE) ## RH Percentage Qair <- try(ncdf4::ncvar_get(nc, "specific_humidity"), silent = TRUE) #humidity (kg/kg) - SVP <- udunits2::ud.convert(PEcAn.data.atmosphere::get.es(Tair_C), "millibar", "Pa") ## Saturation vapor pressure + SVP <- PEcAn.utils::ud_convert(PEcAn.data.atmosphere::get.es(Tair_C), "millibar", "Pa") ## Saturation vapor pressure VPD <- try(ncdf4::ncvar_get(nc, "water_vapor_saturation_deficit"), silent = TRUE) ## in Pa if (!is.numeric(VPD)) { VPD <- SVP * (1 - PEcAn.data.atmosphere::qair2rh(Qair, Tair_C)) PEcAn.logger::logger.info("water_vapor_saturation_deficit absent; VPD calculated from Qair, Tair, and SVP (saturation vapor pressure) ") } - VPD_kPa <- udunits2::ud.convert(VPD, "Pa", "kPa") + VPD_kPa <- PEcAn.utils::ud_convert(VPD, "Pa", "kPa") e_a <- SVP - VPD # AirVP if (!is.numeric(RH_perc)) { RH_perc <- PEcAn.data.atmosphere::qair2rh(Qair, Tair_C,Atm_press) @@ -165,7 +165,7 @@ met2model.MAAT <- function(in.path, in.prefix, outfolder, start_date, end_date, asec <- sec for (y in seq(year, year + nyr - 1)) { diy <- PEcAn.utils::days_in_year(y, leap_year) - ytmp <- rep(y, udunits2::ud.convert(diy / dt, "days", "seconds")) + ytmp <- rep(y, PEcAn.utils::ud_convert(diy / dt, "days", "seconds")) dtmp <- rep(seq_len(diy), each = day_secs / dt) if (is.null(yr)) { yr <- ytmp diff --git a/models/maat/R/model2netcdf.MAAT.R b/models/maat/R/model2netcdf.MAAT.R index a7e758be0a4..b254699e42d 100755 --- a/models/maat/R/model2netcdf.MAAT.R +++ b/models/maat/R/model2netcdf.MAAT.R @@ -26,7 +26,7 @@ model2netcdf.MAAT <- function(rundir, outdir, sitelat = -999, sitelon = -999, start_date = NULL, end_date = NULL) { # setup constants - day_secs <- udunits2::ud.convert(1, "day", "seconds") + day_secs <- PEcAn.utils::ud_convert(1, "day", "seconds") # setup helper function var_update <- function(data, out, oldname, newname, oldunits, newunits = NULL, missval = -999, longname, ncdims) { diff --git a/models/maat/R/write.config.MAAT.R b/models/maat/R/write.config.MAAT.R index b9e8d1b5189..27f13216b68 100644 --- a/models/maat/R/write.config.MAAT.R +++ b/models/maat/R/write.config.MAAT.R @@ -59,19 +59,19 @@ convert.samples.MAAT <- function(trait.samples, runid) { } if ("Ha.vcmax" %in% names(trait.samples)) { ## Convert from kJ mol-1 to J mol-1 - trait.samples <- transform(trait.samples, Ha.vcmax = udunits2::ud.convert(Ha.vcmax, "kJ", "J")) + trait.samples <- transform(trait.samples, Ha.vcmax = PEcAn.utils::ud_convert(Ha.vcmax, "kJ", "J")) } if ("Hd.vcmax" %in% names(trait.samples)) { ## Convert from kJ mol-1 to J mol-1 - trait.samples <- transform(trait.samples, Hd.vcmax = udunits2::ud.convert(Hd.vcmax, "kJ", "J")) + trait.samples <- transform(trait.samples, Hd.vcmax = PEcAn.utils::ud_convert(Hd.vcmax, "kJ", "J")) } if ("Ha.jmax" %in% names(trait.samples)) { ## Convert from kJ mol-1 to J mol-1 - trait.samples <- transform(trait.samples, Ha.jmax = udunits2::ud.convert(Ha.jmax, "kJ", "J")) + trait.samples <- transform(trait.samples, Ha.jmax = PEcAn.utils::ud_convert(Ha.jmax, "kJ", "J")) } if ("Hd.jmax" %in% names(trait.samples)) { ## Convert from kJ mol-1 to J mol-1 - trait.samples <- transform(trait.samples, Hd.jmax = udunits2::ud.convert(Hd.jmax, "kJ", "J")) + trait.samples <- transform(trait.samples, Hd.jmax = PEcAn.utils::ud_convert(Hd.jmax, "kJ", "J")) } if ("leaf_reflect_vis" %in% names(trait.samples) & "leaf_trans_vis" %in% names(trait.samples) ){ leaf_abs <- 1-(trait.samples[["leaf_reflect_vis"]]+trait.samples[["leaf_trans_vis"]]) @@ -81,11 +81,11 @@ convert.samples.MAAT <- function(trait.samples, runid) { } if ("leaf_width" %in% names(trait.samples)) { ## Convert from mm to m - trait.samples <- transform(trait.samples, leaf_width = udunits2::ud.convert(leaf_width, "mm", "m")) + trait.samples <- transform(trait.samples, leaf_width = PEcAn.utils::ud_convert(leaf_width, "mm", "m")) } if ("g0" %in% names(trait.samples)) { ## Convert from umol H2O m-2 s-1 to mol m-2s-1 - trait.samples <- transform(trait.samples, g0 = udunits2::ud.convert(g0, "umol H2O m-2 s-1", "mol H2O m-2 s-1")) + trait.samples <- transform(trait.samples, g0 = PEcAn.utils::ud_convert(g0, "umol H2O m-2 s-1", "mol H2O m-2 s-1")) } # for debugging conversions diff --git a/models/maat/inst/generate_maat_met_drivers_ngee.R b/models/maat/inst/generate_maat_met_drivers_ngee.R index e9732f01956..7d4fee47bf3 100644 --- a/models/maat/inst/generate_maat_met_drivers_ngee.R +++ b/models/maat/inst/generate_maat_met_drivers_ngee.R @@ -46,13 +46,13 @@ met_drivers$Prec_mm <- met_drivers$Rain..mm.min.*30 # converting to mm per 30 m # get additional variables if (pressure){ - met_drivers$Press_Pa <- udunits2::ud.convert(met_drivers$BP_hPa, "mmHg", "Pa") # need to match this with source, when availible + met_drivers$Press_Pa <- PEcAn.utils::ud_convert(met_drivers$BP_hPa, "mmHg", "Pa") # need to match this with source, when availible } else { met_drivers$Press_Pa <- rep(101325,length(met_drivers$Time)) } if (wind) { - met_drivers$Windspeed_m_s <- udunits2::ud.convert(met_drivers$WS..km.h., "km/h", "m/s") + met_drivers$Windspeed_m_s <- PEcAn.utils::ud_convert(met_drivers$WS..km.h., "km/h", "m/s") } # subset diff --git a/models/maat/inst/generate_maat_met_drivers_ngee_pa-bar.R b/models/maat/inst/generate_maat_met_drivers_ngee_pa-bar.R index 2078e44afb1..98954ea46f8 100644 --- a/models/maat/inst/generate_maat_met_drivers_ngee_pa-bar.R +++ b/models/maat/inst/generate_maat_met_drivers_ngee_pa-bar.R @@ -52,7 +52,7 @@ met_drivers$Prec_mm <- met_drivers$RA_mm_d/24 # converting to mm per 1 hour per # get additional variables if (pressure){ - met_drivers$Press_Pa <- udunits2::ud.convert(met_drivers$BP_hPa, "mmHg", "Pa") # need to match this with source, when availible + met_drivers$Press_Pa <- PEcAn.utils::ud_convert(met_drivers$BP_hPa, "mmHg", "Pa") # need to match this with source, when availible } else { met_drivers$Press_Pa <- rep(101325,length(met_drivers$Time)) # just use standard atmospheric pressure at sea level } diff --git a/models/maespa/DESCRIPTION b/models/maespa/DESCRIPTION index 7a7e0671159..6b25f455e9b 100644 --- a/models/maespa/DESCRIPTION +++ b/models/maespa/DESCRIPTION @@ -21,7 +21,6 @@ Imports: PEcAn.utils, lubridate (>= 1.6.0), ncdf4 (>= 1.15), - udunits2 (>= 0.11) Suggests: Maeswrap, coda, diff --git a/models/maespa/R/met2model.MAESPA.R b/models/maespa/R/met2model.MAESPA.R index 4b34a3c749e..cec8c29147d 100755 --- a/models/maespa/R/met2model.MAESPA.R +++ b/models/maespa/R/met2model.MAESPA.R @@ -79,7 +79,7 @@ met2model.MAESPA <- function(in.path, in.prefix, outfolder, start_date, end_date nc <- ncdf4::nc_open(old.file) ## convert time to seconds sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- PEcAn.utils::seconds_in_year(year) / length(sec) tstep <- round(86400 / dt) @@ -107,11 +107,11 @@ met2model.MAESPA <- function(in.path, in.prefix, outfolder, start_date, end_date PAR <- PEcAn.data.atmosphere::sw2par(RAD) } else { # convert - PAR <- udunits2::ud.convert(PAR, "mol", "umol") + PAR <- PEcAn.utils::ud_convert(PAR, "mol", "umol") } # Convert air temperature to Celsius - TAIR <- udunits2::ud.convert(TAIR, "kelvin", "celsius") + TAIR <- PEcAn.utils::ud_convert(TAIR, "kelvin", "celsius") #### ppm. atmospheric CO2 concentration. ### Constant from Environ namelist used instead if CA is nonexistent diff --git a/models/preles/DESCRIPTION b/models/preles/DESCRIPTION index 342cae0ceb5..cd703301f19 100644 --- a/models/preles/DESCRIPTION +++ b/models/preles/DESCRIPTION @@ -23,7 +23,6 @@ Imports: PEcAn.logger, lubridate (>= 1.6.0), ncdf4 (>= 1.15), - udunits2 (>= 0.11), PEcAn.data.atmosphere, PEcAn.utils Suggests: diff --git a/models/preles/R/runPRELES.jobsh.R b/models/preles/R/runPRELES.jobsh.R index 3fd1a785c95..deb925a4b3a 100644 --- a/models/preles/R/runPRELES.jobsh.R +++ b/models/preles/R/runPRELES.jobsh.R @@ -30,7 +30,7 @@ runPRELES.jobsh <- function(met.file, outdir, parameters, sitelat, sitelon, star start_year <- lubridate::year(start_date) end_year <- lubridate::year(end_date) - timestep.s <- udunits2::ud.convert(1, "day", "seconds") # Number of seconds in a day + timestep.s <- PEcAn.utils::ud_convert(1, "day", "seconds") # Number of seconds in a day ## Build met met <- NULL @@ -45,7 +45,7 @@ runPRELES.jobsh <- function(met.file, outdir, parameters, sitelat, sitelon, star ## convert time to seconds sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") ## build day and year @@ -80,12 +80,12 @@ runPRELES.jobsh <- function(met.file, outdir, parameters, sitelat, sitelon, star ## Get PPFD from SW PPFD <- PEcAn.data.atmosphere::sw2ppfd(SW) # PPFD in umol/m2/s - PPFD <- udunits2::ud.convert(PPFD, "umol m-2 s-1", "mol m-2 s-1") + PPFD <- PEcAn.utils::ud_convert(PPFD, "umol m-2 s-1", "mol m-2 s-1") ## Format/convert inputs ppfd <- tapply(PPFD, doy, mean, na.rm = TRUE) # Find the mean for the day - tair <- udunits2::ud.convert(tapply(Tair, doy, mean, na.rm = TRUE), "kelvin", "celsius") # Convert Kelvin to Celcius - vpd <- udunits2::ud.convert(tapply(VPD, doy, mean, na.rm = TRUE), "Pa", "kPa") # pascal to kila pascal + tair <- PEcAn.utils::ud_convert(tapply(Tair, doy, mean, na.rm = TRUE), "kelvin", "celsius") # Convert Kelvin to Celcius + vpd <- PEcAn.utils::ud_convert(tapply(VPD, doy, mean, na.rm = TRUE), "Pa", "kPa") # pascal to kila pascal precip <- tapply(Precip, doy, sum, na.rm = TRUE) # Sum to daily precipitation co2 <- tapply(CO2, doy, mean) # need daily average, so sum up day co2 <- co2 * 1e+06 # convert to ppm @@ -152,7 +152,7 @@ runPRELES.jobsh <- function(met.file, outdir, parameters, sitelat, sitelon, star sub.PRELES.output.dims <- dim(sub.PRELES.output) output <- list() - output[[1]] <- udunits2::ud.convert(sub.PRELES.output[, 1], 'g m-2 day-1', 'kg m-2 sec-1') #GPP - gC/m2day to kgC/m2s1 + output[[1]] <- PEcAn.utils::ud_convert(sub.PRELES.output[, 1], 'g m-2 day-1', 'kg m-2 sec-1') #GPP - gC/m2day to kgC/m2s1 output[[2]] <- (sub.PRELES.output[, 2])/timestep.s #Evapotranspiration - mm =kg/m2 output[[3]] <- (sub.PRELES.output[, 3])/timestep.s #Soilmoisture - mm = kg/m2 output[[6]] <- (sub.PRELES.output[, 6])/timestep.s #Evaporation - mm = kg/m2 diff --git a/models/sipnet/DESCRIPTION b/models/sipnet/DESCRIPTION index acafb741b1c..ffc7e81d875 100644 --- a/models/sipnet/DESCRIPTION +++ b/models/sipnet/DESCRIPTION @@ -21,7 +21,6 @@ Imports: PEcAn.utils, lubridate (>= 1.6.0), ncdf4 (>= 1.15), - udunits2 (>= 0.11) Suggests: coda, testthat (>= 1.0.2) diff --git a/models/sipnet/R/met2model.SIPNET.R b/models/sipnet/R/met2model.SIPNET.R index 6fae182085c..91a4673b967 100644 --- a/models/sipnet/R/met2model.SIPNET.R +++ b/models/sipnet/R/met2model.SIPNET.R @@ -118,7 +118,7 @@ met2model.SIPNET <- function(in.path, in.prefix, outfolder, start_date, end_date ## convert time to seconds sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") # Calculate the delta time. If using whole-year data, the appropriate length in seconds is # fetched; otherwise, it is assumed that the length of time provided in the time dimension of @@ -136,7 +136,7 @@ met2model.SIPNET <- function(in.path, in.prefix, outfolder, start_date, end_date lat <- ncdf4::ncvar_get(nc, "latitude") lon <- ncdf4::ncvar_get(nc, "longitude") Tair <-ncdf4::ncvar_get(nc, "air_temperature") ## in Kelvin - Tair_C <- udunits2::ud.convert(Tair, "K", "degC") + Tair_C <- PEcAn.utils::ud_convert(Tair, "K", "degC") Qair <-ncdf4::ncvar_get(nc, "specific_humidity") #humidity (kg/kg) ws <- try(ncdf4::ncvar_get(nc, "wind_speed")) if (!is.numeric(ws)) { @@ -163,20 +163,20 @@ met2model.SIPNET <- function(in.path, in.prefix, outfolder, start_date, end_date filt <- exp(-(1:length(Tair)) / tau) filt <- (filt / sum(filt)) soilT <- convolve(Tair, filt) - soilT <- udunits2::ud.convert(soilT, "K", "degC") + soilT <- PEcAn.utils::ud_convert(soilT, "K", "degC") PEcAn.logger::logger.info("soil_temperature absent; soilT approximated from Tair") } else { - soilT <- udunits2::ud.convert(soilT, "K", "degC") + soilT <- PEcAn.utils::ud_convert(soilT, "K", "degC") } - SVP <- udunits2::ud.convert(PEcAn.data.atmosphere::get.es(Tair_C), "millibar", "Pa") ## Saturation vapor pressure + SVP <- PEcAn.utils::ud_convert(PEcAn.data.atmosphere::get.es(Tair_C), "millibar", "Pa") ## Saturation vapor pressure VPD <- try(ncdf4::ncvar_get(nc, "water_vapor_saturation_deficit")) ## in Pa if (!is.numeric(VPD)) { VPD <- SVP * (1 - PEcAn.data.atmosphere::qair2rh(Qair, Tair_C, pres/100)) PEcAn.logger::logger.info("water_vapor_saturation_deficit absent; VPD calculated from Qair, Tair, and SVP (saturation vapor pressure) ") } e_a <- SVP - VPD - VPDsoil <- udunits2::ud.convert(PEcAn.data.atmosphere::get.es(soilT), "millibar", "Pa") * + VPDsoil <- PEcAn.utils::ud_convert(PEcAn.data.atmosphere::get.es(soilT), "millibar", "Pa") * (1 - PEcAn.data.atmosphere::qair2rh(Qair, soilT, pres/100)) ncdf4::nc_close(nc) diff --git a/models/sipnet/R/read_restart.SIPNET.R b/models/sipnet/R/read_restart.SIPNET.R index fb4393b01e6..503d43b6708 100755 --- a/models/sipnet/R/read_restart.SIPNET.R +++ b/models/sipnet/R/read_restart.SIPNET.R @@ -42,7 +42,7 @@ read_restart.SIPNET <- function(outdir, runid, stop.time, settings, var.names, p #### PEcAn Standard Outputs if ("AbvGrndWood" %in% var.names) { - forecast[[length(forecast) + 1]] <- udunits2::ud.convert(ens$AbvGrndWood[last], "kg/m^2", "Mg/ha") + forecast[[length(forecast) + 1]] <- PEcAn.utils::ud_convert(ens$AbvGrndWood[last], "kg/m^2", "Mg/ha") names(forecast[[length(forecast)]]) <- c("AbvGrndWood") # calculate fractions, store in params, will use in write_restart @@ -59,7 +59,7 @@ read_restart.SIPNET <- function(outdir, runid, stop.time, settings, var.names, p } if ("GWBI" %in% var.names) { - forecast[[length(forecast) + 1]] <- udunits2::ud.convert(mean(ens$GWBI), "kg/m^2/s", "Mg/ha/yr") + forecast[[length(forecast) + 1]] <- PEcAn.utils::ud_convert(mean(ens$GWBI), "kg/m^2/s", "Mg/ha/yr") names(forecast[[length(forecast)]]) <- c("GWBI") } @@ -104,7 +104,7 @@ read_restart.SIPNET <- function(outdir, runid, stop.time, settings, var.names, p } if ("TotLivBiom" %in% var.names) { - forecast[[length(forecast) + 1]] <- udunits2::ud.convert(ens$TotLivBiom[last], "kg/m^2", "Mg/ha") + forecast[[length(forecast) + 1]] <- PEcAn.utils::ud_convert(ens$TotLivBiom[last], "kg/m^2", "Mg/ha") names(forecast[[length(forecast)]]) <- c("TotLivBiom") } diff --git a/models/sipnet/R/sample.IC.SIPNET.R b/models/sipnet/R/sample.IC.SIPNET.R index afde3d29f38..d1578c4df33 100644 --- a/models/sipnet/R/sample.IC.SIPNET.R +++ b/models/sipnet/R/sample.IC.SIPNET.R @@ -32,7 +32,7 @@ sample.IC.SIPNET <- function(ne, state, year = 1) { # reminder : when working with kgC m-2 s-1 as NPP units singularity issues pop up in sda.enkf # using MgC ha-1 yr-1 for NPP in SDA and also brought back AbvGrndWood to MgC ha-1 for sanity reasons AbvGrndWood <- ifelse(rep("AbvGrndWood" %in% names(state), ne), - udunits2::ud.convert(state$AbvGrndWood[sample.int(length(state$AbvGrndWood), ne)], "Mg/ha", "g/m^2"), + PEcAn.utils::ud_convert(state$AbvGrndWood[sample.int(length(state$AbvGrndWood), ne)], "Mg/ha", "g/m^2"), runif(ne, 700, 15000)) ## prior # sipnet accepts a plantWoodC pool that is above-ground + roots diff --git a/models/sipnet/R/write.configs.SIPNET.R b/models/sipnet/R/write.configs.SIPNET.R index a6bd2becb4c..f051b1c2c4c 100755 --- a/models/sipnet/R/write.configs.SIPNET.R +++ b/models/sipnet/R/write.configs.SIPNET.R @@ -475,7 +475,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs IC.nc <- ncdf4::nc_open(IC.path) #for additional variables specific to SIPNET ## plantWoodInit gC/m2 if ("wood" %in% names(IC.pools)) { - param[which(param[, 1] == "plantWoodInit"), 2] <- udunits2::ud.convert(IC.pools$wood, "g m-2", "g m-2") + param[which(param[, 1] == "plantWoodInit"), 2] <- PEcAn.utils::ud_convert(IC.pools$wood, "g m-2", "g m-2") } ## laiInit m2/m2 lai <- try(ncdf4::ncvar_get(IC.nc,"LAI"),silent = TRUE) @@ -489,11 +489,11 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs } ## litterInit gC/m2 if ("litter" %in% names(IC.pools)) { - param[which(param[, 1] == "litterInit"), 2] <- udunits2::ud.convert(IC.pools$litter, 'g m-2', 'g m-2') # BETY: kgC m-2 + param[which(param[, 1] == "litterInit"), 2] <- PEcAn.utils::ud_convert(IC.pools$litter, 'g m-2', 'g m-2') # BETY: kgC m-2 } ## soilInit gC/m2 if ("soil" %in% names(IC.pools)) { - param[which(param[, 1] == "soilInit"), 2] <- udunits2::ud.convert(sum(IC.pools$soil), 'g m-2', 'g m-2') # BETY: kgC m-2 + param[which(param[, 1] == "soilInit"), 2] <- PEcAn.utils::ud_convert(sum(IC.pools$soil), 'g m-2', 'g m-2') # BETY: kgC m-2 } ## soilWFracInit fraction soilWFrac <- try(ncdf4::ncvar_get(IC.nc,"SoilMoistFrac"),silent = TRUE) @@ -506,7 +506,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs ## snowInit cm water equivalent (cm = g / cm2 because 1 g water = 1 cm3 water) snow = try(ncdf4::ncvar_get(IC.nc,"SWE"),silent = TRUE) if (!is.na(snow) && is.numeric(snow)) { - param[which(param[, 1] == "snowInit"), 2] <- udunits2::ud.convert(snow, "kg m-2", "g cm-2") # BETY: kg m-2 + param[which(param[, 1] == "snowInit"), 2] <- PEcAn.utils::ud_convert(snow, "kg m-2", "g cm-2") # BETY: kg m-2 } ## leafOnDay leafOnDay <- try(ncdf4::ncvar_get(IC.nc,"date_of_budburst"),silent = TRUE) @@ -520,7 +520,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs } microbe <- try(ncdf4::ncvar_get(IC.nc,"Microbial Biomass C"),silent = TRUE) if (!is.na(microbe) && is.numeric(microbe)) { - param[which(param[, 1] == "microbeInit"), 2] <- udunits2::ud.convert(microbe, "mg kg-1", "mg g-1") #BETY: mg microbial C kg-1 soil + param[which(param[, 1] == "microbeInit"), 2] <- PEcAn.utils::ud_convert(microbe, "mg kg-1", "mg g-1") #BETY: mg microbial C kg-1 soil } ncdf4::nc_close(IC.nc) diff --git a/models/sipnet/R/write_restart.SIPNET.R b/models/sipnet/R/write_restart.SIPNET.R index a933db9b4ad..1ed2f49dde5 100755 --- a/models/sipnet/R/write_restart.SIPNET.R +++ b/models/sipnet/R/write_restart.SIPNET.R @@ -55,7 +55,7 @@ write_restart.SIPNET <- function(outdir, runid, start.time, stop.time, settings, analysis.save <- list() if ("NPP" %in% variables) { - analysis.save[[length(analysis.save) + 1]] <- udunits2::ud.convert(new.state$NPP, "kg/m^2/s", "Mg/ha/yr") #*unit.conv -> Mg/ha/yr + analysis.save[[length(analysis.save) + 1]] <- PEcAn.utils::ud_convert(new.state$NPP, "kg/m^2/s", "Mg/ha/yr") #*unit.conv -> Mg/ha/yr names(analysis.save[[length(analysis.save)]]) <- c("NPP") } @@ -65,7 +65,7 @@ write_restart.SIPNET <- function(outdir, runid, start.time, stop.time, settings, } if ("AbvGrndWood" %in% variables) { - AbvGrndWood <- udunits2::ud.convert(new.state$AbvGrndWood, "Mg/ha", "g/m^2") + AbvGrndWood <- PEcAn.utils::ud_convert(new.state$AbvGrndWood, "Mg/ha", "g/m^2") analysis.save[[length(analysis.save) + 1]] <- AbvGrndWood names(analysis.save[[length(analysis.save)]]) <- c("AbvGrndWood") @@ -86,13 +86,13 @@ write_restart.SIPNET <- function(outdir, runid, start.time, stop.time, settings, } if ("Litter" %in% variables) { - analysis.save[[length(analysis.save) + 1]] <- udunits2::ud.convert(new.state$Litter, 'kg m-2', 'g m-2') # kgC/m2 -> gC/m2 + analysis.save[[length(analysis.save) + 1]] <- PEcAn.utils::ud_convert(new.state$Litter, 'kg m-2', 'g m-2') # kgC/m2 -> gC/m2 if (new.state$Litter < 0) analysis.save[[length(analysis.save)]] <- 0 names(analysis.save[[length(analysis.save)]]) <- c("litter") } if ("TotSoilCarb" %in% variables) { - analysis.save[[length(analysis.save) + 1]] <- udunits2::ud.convert(new.state$TotSoilCarb, 'kg m-2', 'g m-2') # kgC/m2 -> gC/m2 + analysis.save[[length(analysis.save) + 1]] <- PEcAn.utils::ud_convert(new.state$TotSoilCarb, 'kg m-2', 'g m-2') # kgC/m2 -> gC/m2 if (new.state$TotSoilCarb < 0) analysis.save[[length(analysis.save)]] <- 0 names(analysis.save[[length(analysis.save)]]) <- c("soil") } diff --git a/models/stics/DESCRIPTION b/models/stics/DESCRIPTION index f5466b025b7..46dad370680 100644 --- a/models/stics/DESCRIPTION +++ b/models/stics/DESCRIPTION @@ -18,7 +18,6 @@ Imports: ncdf4, purrr, XML, - udunits2, dplyr Suggests: testthat (>= 1.0.2) diff --git a/models/stics/R/met2model.STICS.R b/models/stics/R/met2model.STICS.R index eba287815bb..ed7e9e1feb6 100644 --- a/models/stics/R/met2model.STICS.R +++ b/models/stics/R/met2model.STICS.R @@ -110,7 +110,7 @@ met2model.STICS <- function(in.path, in.prefix, outfolder, start_date, end_date, ## convert time to seconds sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- PEcAn.utils::seconds_in_year(year) / length(sec) tstep <- round(86400 / dt) @@ -120,7 +120,7 @@ met2model.STICS <- function(in.path, in.prefix, outfolder, start_date, end_date, # column 6: minimum temperature (°C) Tair <- ncdf4::ncvar_get(nc, "air_temperature") ## in Kelvin - Tair_C <- udunits2::ud.convert(Tair, "K", "degC") + Tair_C <- PEcAn.utils::ud_convert(Tair, "K", "degC") t_dmin <- round(tapply(Tair_C, ind, min, na.rm = TRUE), digits = 2) # maybe round these numbers weather_df[ ,6] <- t_dmin diff --git a/models/stics/R/write.config.STICS.R b/models/stics/R/write.config.STICS.R index 83cc7b747cc..3b190b31b3f 100644 --- a/models/stics/R/write.config.STICS.R +++ b/models/stics/R/write.config.STICS.R @@ -91,7 +91,7 @@ write.config.STICS <- function(defaults, trait.values, settings, run.id) { # specific root length (cm g-1) # plt_list[[10]][[6]][[2]][[4]] position if ("SRL" %in% pft.names) { - srl_val <- udunits2::ud.convert(pft.traits[which(pft.names == "SRL")], "m", "cm") + srl_val <- PEcAn.utils::ud_convert(pft.traits[which(pft.names == "SRL")], "m", "cm") plt_list <- plt_list %>% purrr::modify_depth(-1, ~if(all(.x == "@longsperac@")) srl_val else .x) } diff --git a/modules/assim.batch/DESCRIPTION b/modules/assim.batch/DESCRIPTION index b48d4b1e5d7..5b48cbf320b 100644 --- a/modules/assim.batch/DESCRIPTION +++ b/modules/assim.batch/DESCRIPTION @@ -46,7 +46,6 @@ Imports: prodlim, MCMCpack, TruncatedNormal (>= 2.2), - udunits2 (>= 0.11), utils, XML, lqmm, diff --git a/modules/assim.batch/R/pda.generate.externals.R b/modules/assim.batch/R/pda.generate.externals.R index 5187d2cf2d4..a4c3bf49dbd 100644 --- a/modules/assim.batch/R/pda.generate.externals.R +++ b/modules/assim.batch/R/pda.generate.externals.R @@ -170,7 +170,7 @@ pda.generate.externals <- function(external.data = FALSE, obs = NULL, varn = model.raw <- as.data.frame(PEcAn.utils::read.output(basename(model.out), outdir = model.out, start_year, end_year, variables = vars)) - model.secs <- udunits2::ud.convert(model.raw$time, "days" ,"seconds") + model.secs <- PEcAn.utils::ud_convert(model.raw$time, "days" ,"seconds") model.raw$posix <- seq.POSIXt(from = as.POSIXlt(start_date, tz="GMT"), by = round(diff(model.secs)[1]), length.out = length(model.raw$time)) for(i in seq_along(varn)){ diff --git a/modules/assim.batch/R/pda.get.model.output.R b/modules/assim.batch/R/pda.get.model.output.R index fd361a196ae..3eac5f602fc 100644 --- a/modules/assim.batch/R/pda.get.model.output.R +++ b/modules/assim.batch/R/pda.get.model.output.R @@ -111,7 +111,7 @@ pda.get.model.output <- function(settings, run.id, bety, inputs, external.format ## Handle model time # the model output time is in days since the beginning of the year - model.secs <- udunits2::ud.convert(model$time, "days" ,"seconds") + model.secs <- PEcAn.utils::ud_convert(model$time, "days" ,"seconds") # seq.POSIXt returns class "POSIXct" # the model output is since the beginning of the year but 'settings$run$start.date' may not be the first day of the year, using lubridate::floor_date diff --git a/modules/assim.sequential/inst/NEFI/graph_SDA_fluxtowers.R b/modules/assim.sequential/inst/NEFI/graph_SDA_fluxtowers.R index a173ba6a733..a6a9754b4e9 100644 --- a/modules/assim.sequential/inst/NEFI/graph_SDA_fluxtowers.R +++ b/modules/assim.sequential/inst/NEFI/graph_SDA_fluxtowers.R @@ -244,14 +244,14 @@ sda.tower.graphs <- function(site.num, site.abv, outdir, db.num){ setwd(dir.index[i]) nc <- nc_open(nc.files[[i]][1]) sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- mean(diff(sec), na.rm=TRUE) tstep <- round(86400 / dt) dt <- 86400 / tstep Tair <-ncdf4::ncvar_get(nc, "air_temperature") ## in Kelvin - Tair_C <- udunits2::ud.convert(Tair, "K", "degC") + Tair_C <- PEcAn.utils::ud_convert(Tair, "K", "degC") Qair <-ncdf4::ncvar_get(nc, "specific_humidity") #humidity (kg/kg) ws <- try(ncdf4::ncvar_get(nc, "wind_speed")) if (!is.numeric(ws)) { diff --git a/modules/assim.sequential/inst/NEFI/graph_fluxtowers.R b/modules/assim.sequential/inst/NEFI/graph_fluxtowers.R index a531a8dd78d..5f8804589b2 100644 --- a/modules/assim.sequential/inst/NEFI/graph_fluxtowers.R +++ b/modules/assim.sequential/inst/NEFI/graph_fluxtowers.R @@ -272,14 +272,14 @@ for(i in 1:21){ setwd(dir.index[i]) nc <- nc_open(nc.files[[i]][1]) sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- mean(diff(sec), na.rm=TRUE) tstep <- round(86400 / dt) dt <- 86400 / tstep Tair <-ncdf4::ncvar_get(nc, "air_temperature") ## in Kelvin - Tair_C <- udunits2::ud.convert(Tair, "K", "degC") + Tair_C <- PEcAn.utils::ud_convert(Tair, "K", "degC") Qair <-ncdf4::ncvar_get(nc, "specific_humidity") #humidity (kg/kg) ws <- try(ncdf4::ncvar_get(nc, "wind_speed")) if (!is.numeric(ws)) { diff --git a/modules/benchmark/DESCRIPTION b/modules/benchmark/DESCRIPTION index fda0bf14b76..b871e8307e6 100644 --- a/modules/benchmark/DESCRIPTION +++ b/modules/benchmark/DESCRIPTION @@ -36,9 +36,9 @@ Imports: SimilarityMeasures, stringr, tidyselect, + units, utils, grDevices, - udunits2 (>= 0.11), XML (>= 3.98-1.4), zoo Suggests: diff --git a/modules/benchmark/R/load_data.R b/modules/benchmark/R/load_data.R index a534cd74950..10289ae9898 100644 --- a/modules/benchmark/R/load_data.R +++ b/modules/benchmark/R/load_data.R @@ -83,11 +83,11 @@ load_data <- function(data.path, format, start_year = NA, end_year = NA, site = x <- as.matrix(out[col]) u1 <- vars_used$input_units[i] u2 <- vars_used$pecan_units[i] - if (udunits2::ud.are.convertible(u1, u2)) { + if (units::ud_are_convertible(u1, u2)) { print(sprintf("convert %s %s to %s %s", vars_used$input_name[i], vars_used$input_units[i], vars_used$pecan_name[i], vars_used$pecan_units[i])) - out[col] <- udunits2::ud.convert(as.numeric(x), u1, u2) + out[col] <- PEcAn.utils::ud_convert(as.numeric(x), u1, u2) colnames(out)[col] <- vars_used$pecan_name[i] } else if (PEcAn.utils::misc.are.convertible(u1, u2)) { print(sprintf("convert %s %s to %s %s", diff --git a/modules/benchmark/R/load_netcdf.R b/modules/benchmark/R/load_netcdf.R index 6b77b5df077..629ee006f36 100644 --- a/modules/benchmark/R/load_netcdf.R +++ b/modules/benchmark/R/load_netcdf.R @@ -70,7 +70,7 @@ load_x_netcdf <- function(data.path, format, site, vars = NULL) { t.units) # need to change system TZ otherwise, lines below keeps writing in the current time zone Sys.setenv(TZ = 'UTC') - foo <- as.POSIXct(date.origin, tz = "UTC") + udunits2::ud.convert(time.col[[i]], t.units, "seconds") + foo <- as.POSIXct(date.origin, tz = "UTC") + PEcAn.utils::ud_convert(time.col[[i]], t.units, "seconds") time.col[[i]] <- foo } # needed to use 'round' to 'mins' here, otherwise I end up with values like '2006-12-31 23:29:59' diff --git a/modules/data.atmosphere/DESCRIPTION b/modules/data.atmosphere/DESCRIPTION index 64a4b9d8bf7..5df51db6584 100644 --- a/modules/data.atmosphere/DESCRIPTION +++ b/modules/data.atmosphere/DESCRIPTION @@ -57,7 +57,7 @@ Imports: tidyr, tidyselect, truncnorm, - udunits2 (>= 0.11), + units, XML (>= 3.98-1.4), xts, zoo diff --git a/modules/data.atmosphere/R/download.CRUNCEP_Global.R b/modules/data.atmosphere/R/download.CRUNCEP_Global.R index 54fb4cea4f7..4c61ab19a30 100644 --- a/modules/data.atmosphere/R/download.CRUNCEP_Global.R +++ b/modules/data.atmosphere/R/download.CRUNCEP_Global.R @@ -221,7 +221,7 @@ download.CRUNCEP <- function(outfolder, start_date, end_date, lat.in, lon.in, if (dap$dim$time$len != ntime) { PEcAn.logger::logger.severe("Expected", ntime, "observations, but", url, "contained", dap$dim$time$len) } - dap_time <- udunits2::ud.convert(dap$dim$time$vals, + dap_time <- PEcAn.utils::ud_convert(dap$dim$time$vals, dap$dim$time$units, time$units) if (!isTRUE(all.equal(dap_time, time$vals))){ diff --git a/modules/data.atmosphere/R/download.GFDL.R b/modules/data.atmosphere/R/download.GFDL.R index 23bd360698b..2f0c975e85d 100644 --- a/modules/data.atmosphere/R/download.GFDL.R +++ b/modules/data.atmosphere/R/download.GFDL.R @@ -152,7 +152,7 @@ download.GFDL <- function(outfolder, start_date, end_date, lat.in, lon.in, # timestamped in middle of interval, others at end. # But if these disagree by more than 3 hours, we have a problem. raw_time <- ncdf4::ncvar_get(dap, "time", start = time_offset, count = obs_per_year) - converted_time <- udunits2::ud.convert(raw_time, dap$dim$time$units, dim$time$units) + converted_time <- PEcAn.utils::ud_convert(raw_time, dap$dim$time$units, dim$time$units) if(!all(diff(converted_time) == 3 * 60 * 60)){ PEcAn.logger::logger.error( "Expected timestamps at 3-hour intervals, got", diff --git a/modules/data.atmosphere/R/download.MsTMIP_NARR.R b/modules/data.atmosphere/R/download.MsTMIP_NARR.R index 5a0c66e86f8..dfa59ec9742 100644 --- a/modules/data.atmosphere/R/download.MsTMIP_NARR.R +++ b/modules/data.atmosphere/R/download.MsTMIP_NARR.R @@ -53,7 +53,7 @@ download.MsTMIP_NARR <- function(outfolder, start_date, end_date, site_id, lat.i for (i in seq_len(rows)) { year <- ylist[i] - ntime <- udunits2::ud.convert(PEcAn.utils::days_in_year(year), "days", "hours") / 3 - 1 # Number of 3 hour timesteps in one year + ntime <- PEcAn.utils::ud_convert(PEcAn.utils::days_in_year(year), "days", "hours") / 3 - 1 # Number of 3 hour timesteps in one year loc.file <- file.path(outfolder, paste("MsTMIP_NARR", year, "nc", sep = ".")) diff --git a/modules/data.atmosphere/R/download.NARR_site.R b/modules/data.atmosphere/R/download.NARR_site.R index 61195cbdbea..a97f4a69cae 100644 --- a/modules/data.atmosphere/R/download.NARR_site.R +++ b/modules/data.atmosphere/R/download.NARR_site.R @@ -94,7 +94,7 @@ prepare_narr_year <- function(dat, file, lat_nc, lon_nc, verbose = FALSE) { starttime_f <- strftime(starttime, "%Y-%m-%dT%H:%M:%SZ", tz = "UTC") time <- difftime(dat$datetime, starttime) %>% as.numeric() %>% - udunits2::ud.convert("seconds", "hours") + PEcAn.utils::ud_convert("seconds", "hours") time_nc <- ncdf4::ncdim_def( name = "time", units = paste0("hours since ", starttime_f), @@ -414,9 +414,9 @@ read_narr_var <- function(nc, xy, variable, unit, flx, pb = NULL) { # So, divide by seconds in 3 hours and change unit accordingly if (variable == "Total_precipitation_surface_3_Hour_Accumulation") { nc_unit <- paste0(nc_unit, "/s") - out <- out / udunits2::ud.convert(3, "hours", "seconds") + out <- out / PEcAn.utils::ud_convert(3, "hours", "seconds") } - final <- udunits2::ud.convert(out, nc_unit, unit) + final <- PEcAn.utils::ud_convert(out, nc_unit, unit) if (!is.null(pb)) pb$tick() final } diff --git a/modules/data.atmosphere/R/download.NEONmet.R b/modules/data.atmosphere/R/download.NEONmet.R index 9e6d1b4c117..87cdb8faaaf 100644 --- a/modules/data.atmosphere/R/download.NEONmet.R +++ b/modules/data.atmosphere/R/download.NEONmet.R @@ -311,7 +311,7 @@ download.NEONmet <- function(sitename, outfolder, start_date, end_date, units=c("degrees", "degrees")) ncdf4::ncvar_put(nc, varid = WDir.var, vals = ncdata_dir) - wdir_rad <- udunits2::ud.convert(ncdata_dir,"degrees","radians") + wdir_rad <- PEcAn.utils::ud_convert(ncdata_dir,"degrees","radians") ncdata_e <- ncdata_spd * cos(wdir_rad) ncdata_n <- ncdata_spd * sin(wdir_rad) ncdf4::ncvar_put(nc, varid = Ewind.var, vals = ncdata_e) @@ -386,7 +386,7 @@ neonmet.getVals <- function(dates,product,site,datetime, csvVar[which(csvQF!=QF)] <- NA } if ((length(units)=2)&&(units[1]!=units[2])) { - csvVar <- udunits2::ud.convert(csvVar,units[1], units[2]) + csvVar <- PEcAn.utils::ud_convert(csvVar,units[1], units[2]) #need a correction for precip or rate conversion /1800 } ncdata[arrLoc] <- csvVar diff --git a/modules/data.atmosphere/R/download.US_WCr.R b/modules/data.atmosphere/R/download.US_WCr.R index f6a67b56227..3924311f526 100644 --- a/modules/data.atmosphere/R/download.US_WCr.R +++ b/modules/data.atmosphere/R/download.US_WCr.R @@ -43,7 +43,7 @@ download.US_WCr <- function(start_date, end_date, timestep = 1) { if (is.null(influx)) { #Error encountered in data fetching. PEcAn.logger::logger.warn(paste0("Data not avaliable for year ", year, ". All values for ", year, " will be NA.")) # Determine the number of days in the year - rows_in_year <- udunits2::ud.convert(lubridate::as.duration(lubridate::interval(as.POSIXct(paste0(year, "-01-01")), as.POSIXct(paste0(year + 1, "-01-01")))), "s", "day") + rows_in_year <- PEcAn.utils::ud_convert(lubridate::as.duration(lubridate::interval(as.POSIXct(paste0(year, "-01-01")), as.POSIXct(paste0(year + 1, "-01-01")))), "s", "day") rows_in_year = rows_in_year * 48 # 48 measurements per day, one every half hour. influx <- matrix(rep(-999, rows_in_year * 13), nrow=rows_in_year, ncol = 13) } @@ -62,8 +62,8 @@ download.US_WCr <- function(start_date, end_date, timestep = 1) { start_interval <- lubridate::interval(year_start, start_date) days <- lubridate::as.duration(start_interval) # Actually returns a number of seconds - days <- udunits2::ud.convert(as.integer(days), "s", "day") # Days, including fractional part, if any. - hours <- floor(udunits2::ud.convert(days - floor(days), "day", "hr")) # Extract the hour component, round to the previous hour. + days <- PEcAn.utils::ud_convert(as.integer(days), "s", "day") # Days, including fractional part, if any. + hours <- floor(PEcAn.utils::ud_convert(days - floor(days), "day", "hr")) # Extract the hour component, round to the previous hour. if (days - floor(days) >= 0.5) { # Flux data is at half-hour precision hours <- hours + 0.5 } @@ -73,8 +73,8 @@ download.US_WCr <- function(start_date, end_date, timestep = 1) { data_interval <- lubridate::interval(start_date, end_date) days <- lubridate::as.duration(data_interval) # a number of seconds - days <- udunits2::ud.convert(as.integer(days), "s", "day") - hours <- floor(udunits2::ud.convert(as.integer(days - floor(days)), "day", "hr")) # Round down to the nearest half hour + days <- PEcAn.utils::ud_convert(as.integer(days), "s", "day") + hours <- floor(PEcAn.utils::ud_convert(as.integer(days - floor(days)), "day", "hr")) # Round down to the nearest half hour if (days - floor(days) >= 0.5) { hours <- hours + 0.5 } diff --git a/modules/data.atmosphere/R/download.US_Wlef.R b/modules/data.atmosphere/R/download.US_Wlef.R index 1372ef6e12b..a92e7599e31 100644 --- a/modules/data.atmosphere/R/download.US_Wlef.R +++ b/modules/data.atmosphere/R/download.US_Wlef.R @@ -39,7 +39,7 @@ download.US_Wlef <- function(start_date, end_date, timestep = 1) { if (is.null(influx)) { #Error encountered in data fetching. PEcAn.logger::logger.warn(paste0("Data not avaliable for year ", year, ". All values for ", year, " will be NA.")) # Determine the number of days in the year - rows_in_year <- udunits2::ud.convert(lubridate::as.duration(lubridate::interval(as.POSIXct(paste0(year, "-01-01")), as.POSIXct(paste0(year + 1, "-01-01")))), "s", "day") + rows_in_year <- PEcAn.utils::ud_convert(lubridate::as.duration(lubridate::interval(as.POSIXct(paste0(year, "-01-01")), as.POSIXct(paste0(year + 1, "-01-01")))), "s", "day") rows_in_year = rows_in_year * 24 # 48 measurements per day, one every half hour. influx <- matrix(rep(-999, rows_in_year * 13), nrow=rows_in_year, ncol = 13) } @@ -58,16 +58,16 @@ download.US_Wlef <- function(start_date, end_date, timestep = 1) { start_interval <- lubridate::interval(year_start, start_date) days <- lubridate::as.duration(start_interval) # Actually returns a number of seconds - days <- udunits2::ud.convert(as.integer(days), "s", "day") # Days, including fractional part, if any. - hours <- floor(udunits2::ud.convert(days - floor(days), "day", "hr")) # Extract the hour component, round to the previous hour. + days <- PEcAn.utils::ud_convert(as.integer(days), "s", "day") # Days, including fractional part, if any. + hours <- floor(PEcAn.utils::ud_convert(days - floor(days), "day", "hr")) # Extract the hour component, round to the previous hour. days <- floor(days) # Extract the whole day component start_row <- as.integer(days * 24 + hours) data_interval <- lubridate::interval(start_date, end_date) days <- lubridate::as.duration(data_interval) # a number of seconds - days <- udunits2::ud.convert(as.integer(days), "s", "day") - hours <- floor(udunits2::ud.convert(as.integer(days - floor(days)), "day", "hr")) # Round down to the nearest half hour + days <- PEcAn.utils::ud_convert(as.integer(days), "s", "day") + hours <- floor(PEcAn.utils::ud_convert(as.integer(days - floor(days)), "day", "hr")) # Round down to the nearest half hour days <- floor(days) end_row <- start_row + as.integer(days * 24 + hours) diff --git a/modules/data.atmosphere/R/load.cfmet.R b/modules/data.atmosphere/R/load.cfmet.R index fb5de4938bd..b7b03532899 100644 --- a/modules/data.atmosphere/R/load.cfmet.R +++ b/modules/data.atmosphere/R/load.cfmet.R @@ -44,9 +44,9 @@ load.cfmet <- function(met.nc, lat, lon, start.date, end.date) { ## convert to days if (!base.units == "days") { - time.idx <- udunits2::ud.convert(time.idx, basetime.string, paste("days since ", base.date)) + time.idx <- PEcAn.utils::ud_convert(time.idx, basetime.string, paste("days since ", base.date)) } - time.idx <- udunits2::ud.convert(time.idx, "days", "seconds") + time.idx <- PEcAn.utils::ud_convert(time.idx, "days", "seconds") date <- as.POSIXct.numeric(time.idx, origin = base.date, tz = "UTC") ## data table warns not to use POSIXlt, which is induced by round() diff --git a/modules/data.atmosphere/R/merge.met.variable.R b/modules/data.atmosphere/R/merge.met.variable.R index 85cde6a2c59..93052d37b33 100644 --- a/modules/data.atmosphere/R/merge.met.variable.R +++ b/modules/data.atmosphere/R/merge.met.variable.R @@ -48,9 +48,9 @@ merge_met_variable <- function(in.path,in.prefix,start_date, end_date, merge.fil merge.time.attr <- ncdf4::ncatt_get(merge.nc,"time") merge.data <- ncdf4::ncvar_get(merge.nc,varid = merge.vars[1]) - udunits2::ud.is.parseable(merge.time.attr$units) + units::install_unit(merge.time.attr$units) origin <- "1970-01-01 00:00:00 UTC" - merge.time.std <- udunits2::ud.convert(merge.time, + merge.time.std <- PEcAn.utils::ud_convert(merge.time, merge.time.attr$units, paste0("seconds since ",origin)) @@ -82,7 +82,7 @@ merge_met_variable <- function(in.path,in.prefix,start_date, end_date, merge.fil ## name and variable conversions if(toupper(merge.vars[1]) == "CO2"){ merge.vars[1] <- "mole_fraction_of_carbon_dioxide_in_air" - merge.data <- udunits2::ud.convert(merge.data,merge.attr$units,"mol/mol") + merge.data <- PEcAn.utils::ud_convert(merge.data,merge.attr$units,"mol/mol") merge.attr$units = "mol/mol" } @@ -117,7 +117,7 @@ merge_met_variable <- function(in.path,in.prefix,start_date, end_date, merge.fil ##extract target time target.time <- ncdf4::ncvar_get(nc,"time") target.time.attr <- ncdf4::ncatt_get(nc,"time") - target.time.std <- udunits2::ud.convert(target.time, + target.time.std <- PEcAn.utils::ud_convert(target.time, target.time.attr$units, paste0("seconds since ",origin)) target.time.std <- as.POSIXct(target.time.std,tz = "UTC",origin=origin) diff --git a/modules/data.atmosphere/R/met2CF.ALMA.R b/modules/data.atmosphere/R/met2CF.ALMA.R index 4aa0ceeff8f..5b47429ece7 100644 --- a/modules/data.atmosphere/R/met2CF.ALMA.R +++ b/modules/data.atmosphere/R/met2CF.ALMA.R @@ -110,7 +110,7 @@ met2CF.PalEONregional <- function(in.path, in.prefix, outfolder, start_date, end # create new coordinate dimensions based on site location lat/lon nc1 <- ncdf4::nc_open(old.file) tdim <- nc1$dim[["time"]] - met[["time"]] <- udunits2::ud.convert(met[["time"]],"days","seconds") + met[["time"]] <- PEcAn.utils::ud_convert(met[["time"]],"days","seconds") tdim$units <- paste0("seconds since ",year,"-01-01 00:00:00") tdim$vals <- met[["time"]] tdim$len <- length(tdim$vals) @@ -511,7 +511,7 @@ met2CF.ALMA <- function(in.path, in.prefix, outfolder, start_date, end_date, ove nc2 = nc2, var2 = "air_temperature", units2 = "K", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "degC", "K") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "degC", "K") }, verbose = verbose) # convert PRESS to air_pressure @@ -520,7 +520,7 @@ met2CF.ALMA <- function(in.path, in.prefix, outfolder, start_date, end_date, ove nc2 = nc2, var2 = "air_pressure", units2 = "Pa", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, 'kPa', 'Pa') }, + conv = function(x) { PEcAn.utils::ud_convert(x, 'kPa', 'Pa') }, verbose = verbose) # convert CO2 to mole_fraction_of_carbon_dioxide_in_air @@ -528,7 +528,7 @@ met2CF.ALMA <- function(in.path, in.prefix, outfolder, start_date, end_date, ove var1 = "CO2", nc2 = nc2, var2 = "mole_fraction_of_carbon_dioxide_in_air", units2 = "mole/mole", - dim2 = dim, conv = function(x) { udunits2::ud.convert(x, "mol/mol", "ppm") }, + dim2 = dim, conv = function(x) { PEcAn.utils::ud_convert(x, "mol/mol", "ppm") }, verbose = verbose) # convert TS1 to soil_temperature @@ -537,7 +537,7 @@ met2CF.ALMA <- function(in.path, in.prefix, outfolder, start_date, end_date, ove nc2 = nc2, var2 = "soil_temperature", units2 = "K", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "degC", "K") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "degC", "K") }, verbose = verbose) # copy RH to relative_humidity @@ -553,7 +553,7 @@ met2CF.ALMA <- function(in.path, in.prefix, outfolder, start_date, end_date, ove rh <- rh/100 ta <- ncdf4::ncvar_get(nc = nc1, varid = "TA") ta[ta == -6999 | ta == -9999] <- NA - ta <- udunits2::ud.convert(ta, "degC", "K") + ta <- PEcAn.utils::ud_convert(ta, "degC", "K") sh <- rh2qair(rh = rh, T = ta) var <- ncdf4::ncvar_def(name = "specific_humidity", units = "kg/kg", dim = dim, missval = -6999, verbose = verbose) @@ -590,7 +590,7 @@ met2CF.ALMA <- function(in.path, in.prefix, outfolder, start_date, end_date, ove nc2 = nc2, var2 = "surface_downwelling_photosynthetic_photon_flux_in_air", units2 = "mol m-2 s-1", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "umol m-2 s-1", "mol m-2 s-1") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "umol m-2 s-1", "mol m-2 s-1") }, verbose = verbose) # copy WD to wind_direction (not official CF) diff --git a/modules/data.atmosphere/R/met2CF.Ameriflux.R b/modules/data.atmosphere/R/met2CF.Ameriflux.R index fcc4d3a6361..9686b6e7732 100644 --- a/modules/data.atmosphere/R/met2CF.Ameriflux.R +++ b/modules/data.atmosphere/R/met2CF.Ameriflux.R @@ -170,7 +170,7 @@ met2CF.Ameriflux <- function(in.path, in.prefix, outfolder, start_date, end_date rh <- rh/100 ta <- ncdf4::ncvar_get(nc = nc1, varid = "TA") ta[ta == -6999 | ta == -9999] <- NA - ta <- udunits2::ud.convert(ta, "degC", "K") + ta <- PEcAn.utils::ud_convert(ta, "degC", "K") sh <- rh2qair(rh = rh, T = ta) var <- ncdf4::ncvar_def(name = "specific_humidity", units = "kg/kg", dim = dim, missval = -6999, verbose = verbose) @@ -180,14 +180,14 @@ met2CF.Ameriflux <- function(in.path, in.prefix, outfolder, start_date, end_date # convert TA to air_temperature copyvals(nc1 = nc1, var1 = "TA", nc2 = nc2, var2 = "air_temperature", units2 = "K", - dim2 = dim, conv = function(x) { udunits2::ud.convert(x, "degC", "K") }, + dim2 = dim, conv = function(x) { PEcAn.utils::ud_convert(x, "degC", "K") }, verbose = verbose) # convert PRESS to air_pressure copyvals(nc1 = nc1, var1 = "PRESS", nc2 = nc2, var2 = "air_pressure", units2 = "Pa", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "kPa", "Pa") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "kPa", "Pa") }, verbose = verbose) # convert CO2 to mole_fraction_of_carbon_dioxide_in_air @@ -195,14 +195,14 @@ met2CF.Ameriflux <- function(in.path, in.prefix, outfolder, start_date, end_date var2 = "mole_fraction_of_carbon_dioxide_in_air", units2 = "mole/mole", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "ppm", "mol/mol") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "ppm", "mol/mol") }, verbose = verbose) # convert TS1 to soil_temperature copyvals(nc1 = nc1, var1 = "TS1", nc2 = nc2, var2 = "soil_temperature", units2 = "K", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "degC", "K") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "degC", "K") }, verbose = verbose) # copy RH to relative_humidity @@ -215,7 +215,7 @@ met2CF.Ameriflux <- function(in.path, in.prefix, outfolder, start_date, end_date copyvals(nc1 = nc1, var1 = "VPD", nc2 = nc2, var2 = "water_vapor_saturation_deficit", units2 = "Pa", dim2 = dim, - conv = function(x) { ifelse(x < 0, NA, udunits2::ud.convert(x, "kPa", "Pa")) }, + conv = function(x) { ifelse(x < 0, NA, PEcAn.utils::ud_convert(x, "kPa", "Pa")) }, verbose = verbose) # copy Rg to surface_downwelling_shortwave_flux_in_air @@ -234,7 +234,7 @@ met2CF.Ameriflux <- function(in.path, in.prefix, outfolder, start_date, end_date copyvals(nc1 = nc1, var1 = "PAR", nc2 = nc2, var2 = "surface_downwelling_photosynthetic_photon_flux_in_air", units2 = "mol m-2 s-1", dim2 = dim, - conv = function(x) { udunits2::ud.convert(x, "umol m-2 s-1", "mol m-2 s-1") }, + conv = function(x) { PEcAn.utils::ud_convert(x, "umol m-2 s-1", "mol m-2 s-1") }, verbose = verbose) # copy WD to wind_direction (not official CF) diff --git a/modules/data.atmosphere/R/met2CF.FACE.R b/modules/data.atmosphere/R/met2CF.FACE.R index 52000cf94ac..13bcc1eddd5 100644 --- a/modules/data.atmosphere/R/met2CF.FACE.R +++ b/modules/data.atmosphere/R/met2CF.FACE.R @@ -84,11 +84,11 @@ met2CF.FACE <- function(in.path,in.prefix,outfolder,start_date,end_date,input.id } else { u1 <- vars_used$input_units[i] u2 <- vars_used$pecan_units[i] - if (udunits2::ud.are.convertible(u1, u2)) { + if (units::ud_are_convertible(u1, u2)) { print(sprintf("convert %s %s to %s %s", vars_used$input_name[i], vars_used$input_units[i], vars_used$pecan_name[i], vars_used$pecan_units[i])) - vals <- udunits2::ud.convert(vals, u1, u2) + vals <- PEcAn.utils::ud_convert(vals, u1, u2) } else if (PEcAn.utils::misc.are.convertible(u1, u2)) { print(sprintf("convert %s %s to %s %s", vars_used$input_name[i], u1, diff --git a/modules/data.atmosphere/R/met2CF.Geostreams.R b/modules/data.atmosphere/R/met2CF.Geostreams.R index 07f7ce6fe8d..ef7d372d206 100644 --- a/modules/data.atmosphere/R/met2CF.Geostreams.R +++ b/modules/data.atmosphere/R/met2CF.Geostreams.R @@ -44,7 +44,7 @@ met2CF.Geostreams <- function(in.path, in.prefix, outfolder, dat$mid_time <- dat$start_time + (dat$end_time - dat$start_time)/2 dat <- dat[dat$start_time >= start_date & dat$end_time <= end_date,] secs_elapsed <- unclass(dat$mid_time) - unclass(start_date) - days_elapsed <- udunits2::ud.convert(secs_elapsed, "sec", "days") + days_elapsed <- PEcAn.utils::ud_convert(secs_elapsed, "sec", "days") ref_time_str <- strftime(start_date, format = "%FT%TZ") time <- ncdf4::ncdim_def(name = "time", units = paste("days since", ref_time_str), diff --git a/modules/data.atmosphere/R/met2CF.csv.R b/modules/data.atmosphere/R/met2CF.csv.R index ab9035d9f78..59487c602dc 100644 --- a/modules/data.atmosphere/R/met2CF.csv.R +++ b/modules/data.atmosphere/R/met2CF.csv.R @@ -243,7 +243,7 @@ met2CF.csv <- function(in.path, in.prefix, outfolder, start_date, end_date, form ### create time dimension days_since_1700 <- datetime - lubridate::ymd_hm("1700-01-01 00:00") t <- ncdf4::ncdim_def("time", "days since 1700-01-01", as.numeric(days_since_1700)) #define netCDF dimensions for variables - timestep <- as.numeric(mean(udunits2::ud.convert(diff(days_since_1700), "d", "s"))) + timestep <- as.numeric(mean(PEcAn.utils::ud_convert(diff(days_since_1700), "d", "s"))) ## create lat lon dimensions x <- ncdf4::ncdim_def("longitude", "degrees_east", lon) # define netCDF dimensions for variables @@ -507,10 +507,10 @@ met2CF.csv <- function(in.path, in.prefix, outfolder, start_date, end_date, form rain <- rain / timestep "Mg m-2 s-1" }, `in` = { - rain <- udunits2::ud.convert(rain / timestep, "in", "mm") + rain <- PEcAn.utils::ud_convert(rain / timestep, "in", "mm") "kg m-2 s-1" }, `mm h-1` = { - rain <- udunits2::ud.convert(rain / timestep, "h", "s") + rain <- PEcAn.utils::ud_convert(rain / timestep, "h", "s") "kg m-2 s-1" }, 'kg m-2 (30 minute)-1' = { @@ -656,9 +656,9 @@ met.conv <- function(x, orig, bety, CF) { if (nchar(orig) == 0) { orig <- bety ## if units not provided, default is that they were the same units as bety } - if (udunits2::ud.is.parseable(orig)) { - if (udunits2::ud.are.convertible(orig, bety)) { - return(udunits2::ud.convert(udunits2::ud.convert(x, orig, bety), bety, CF)) + if (units::install_unit(orig)) { + if (units::ud_are_convertible(orig, bety)) { + return(PEcAn.utils::ud_convert(PEcAn.utils::ud_convert(x, orig, bety), bety, CF)) } else { PEcAn.logger::logger.error(paste("met.conv could not convert", orig, bety, CF)) } diff --git a/modules/data.atmosphere/R/met2cf.ERA5.R b/modules/data.atmosphere/R/met2cf.ERA5.R index 2b5aff91232..1ec9b62dc69 100644 --- a/modules/data.atmosphere/R/met2cf.ERA5.R +++ b/modules/data.atmosphere/R/met2cf.ERA5.R @@ -50,13 +50,13 @@ met2CF.ERA5<- function(lat, ens[, "tp"] <- ens[, "tp"] * 1000 / 3 # divided by 3 because we have 3 hours data ens[, "tp"] <- - udunits2::ud.convert(ens[, "tp"], "kg m-2 hr-1", "kg m-2 6 s-1") #There are 21600 seconds in 6 hours + PEcAn.utils::ud_convert(ens[, "tp"], "kg m-2 hr-1", "kg m-2 6 s-1") #There are 21600 seconds in 6 hours #RH #Adopted from weathermetrics/R/moisture_conversions.R t <- - udunits2::ud.convert(ens[, "t2m"] %>% as.numeric(), "K", "degC") + PEcAn.utils::ud_convert(ens[, "t2m"] %>% as.numeric(), "K", "degC") dewpoint <- - udunits2::ud.convert(ens[, "d2m"] %>% as.numeric(), "K", "degC") + PEcAn.utils::ud_convert(ens[, "d2m"] %>% as.numeric(), "K", "degC") beta <- (112 - (0.1 * t) + dewpoint) / (112 + (0.9 * t)) relative.humidity <- beta ^ 8 #specific humidity diff --git a/modules/data.atmosphere/R/metgapfill.R b/modules/data.atmosphere/R/metgapfill.R index 5b4b61e73c1..6b46cb3fdd8 100644 --- a/modules/data.atmosphere/R/metgapfill.R +++ b/modules/data.atmosphere/R/metgapfill.R @@ -125,7 +125,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst if (!is.numeric(Tair)) { PEcAn.logger::logger.error("air_temperature not defined in met file for metgapfill") } - Tair_degC <- udunits2::ud.convert(Tair, "K", "degC") + Tair_degC <- PEcAn.utils::ud_convert(Tair, "K", "degC") precip <- try(ncdf4::ncvar_get(nc = nc, varid = "precipitation_flux"), silent = TRUE) if (!is.numeric(precip)) { PEcAn.logger::logger.error("precipitation_flux not defined in met file for metgapfill") @@ -174,7 +174,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst ## make night dark - based on met2model.ED2.R in models/ed/R First: calculate potential radiation sec <- nc$dim$time$vals - sec <- udunits2::ud.convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") + sec <- PEcAn.utils::ud_convert(sec, unlist(strsplit(nc$dim$time$units, " "))[1], "seconds") dt <- PEcAn.utils::seconds_in_year(year) / length(sec) doy <- rep(seq_len(diy), each = 86400 / dt) # diy computed above hr <- rep(seq(0, length = 86400 / dt, by = 24 * dt / 86400), diy) @@ -353,10 +353,10 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst ## make a data frame, convert -9999 to NA, convert to degrees C EddyData.F <- data.frame(Tair, Rg, rH, PAR, precip, sHum, Lw, Ts1, VPD, ws, co2, press, east_wind, north_wind) - EddyData.F[["Tair"]] <- udunits2::ud.convert(EddyData.F[["Tair"]], "K", "degC") + EddyData.F[["Tair"]] <- PEcAn.utils::ud_convert(EddyData.F[["Tair"]], "K", "degC") EddyData.F[["Tair"]] <- EddyData.F[["Tair"]] - EddyData.F[["Ts1"]] <- udunits2::ud.convert(EddyData.F[["Ts1"]], "K", "degC") - EddyData.F[["VPD"]] <- udunits2::ud.convert(EddyData.F[["VPD"]], "Pa", "kPa") + EddyData.F[["Ts1"]] <- PEcAn.utils::ud_convert(EddyData.F[["Ts1"]], "K", "degC") + EddyData.F[["VPD"]] <- PEcAn.utils::ud_convert(EddyData.F[["VPD"]], "Pa", "kPa") ## Optional need: ## Compute VPD EddyData.F <- cbind(EddyData.F,VPD=fCalcVPDfromRHandTair(EddyData.F$rH, EddyData.F$Tair)) @@ -383,7 +383,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst nelem <- length(time) tunit <- ncdf4::ncatt_get(nc = nc, varid = "time", attname = "units", verbose = verbose) origin <- "1900-01-01 00:00:00" - time <- round(as.POSIXlt(udunits2::ud.convert(time, tunit$value, paste("seconds since", origin)), + time <- round(as.POSIXlt(PEcAn.utils::ud_convert(time, tunit$value, paste("seconds since", origin)), origin = origin, tz = "UTC"), units = "mins") dtime <- diff(time) if (dtime[1] == 30) { @@ -496,7 +496,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst ## Write back to NC file, convert air T to Kelvin error <- c() if (("Tair_f" %in% colnames(Extracted))) { - Tair_f <- udunits2::ud.convert(Extracted[, "Tair_f"], "degC", "K") + Tair_f <- PEcAn.utils::ud_convert(Extracted[, "Tair_f"], "degC", "K") } if (length(which(is.na(Tair_f))) > 0) { error <- c(error, "air_temperature") @@ -542,7 +542,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst sHum_f[sHum_f < 0] <- 0 } sHum_f[is.na(sHum_f)] <- 0.622 * - (rH_f[is.na(sHum_f)] / 100) * (get.es(udunits2::ud.convert(Tair_f[is.na(sHum_f)], "K", "degC")) / 1000) + (rH_f[is.na(sHum_f)] / 100) * (get.es(PEcAn.utils::ud_convert(Tair_f[is.na(sHum_f)], "K", "degC")) / 1000) if (length(which(is.na(sHum_f))) > 0) { error <- c(error, "specific_humidity") } @@ -558,7 +558,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst ncdf4::ncvar_put(nc, varid = "surface_downwelling_longwave_flux_in_air", vals = Lw_f) if (("Ts1_f" %in% colnames(Extracted))) { - Ts1_f <- udunits2::ud.convert(Extracted[, "Ts1_f"], "degC", "K") + Ts1_f <- PEcAn.utils::ud_convert(Extracted[, "Ts1_f"], "degC", "K") } if (sum(is.na(Ts1_f)) > 0) { Tair_ff <- Tair_f @@ -575,10 +575,10 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst ncdf4::ncvar_put(nc, varid = "soil_temperature", vals = Ts1_f) if (("VPD_f" %in% colnames(Extracted))) { - VPD_f <- udunits2::ud.convert(Extracted[, "VPD_f"], "kPa", "Pa") + VPD_f <- PEcAn.utils::ud_convert(Extracted[, "VPD_f"], "kPa", "Pa") VPD_f[VPD_f < 0] <- 0 if (("Tair_f" %in% colnames(Extracted))) { - Tair_f_degC <- udunits2::ud.convert(Tair_f, "K", "degC") + Tair_f_degC <- PEcAn.utils::ud_convert(Tair_f, "K", "degC") es <- get.es(Tair_f_degC) * 100 badVPD_f <- which(VPD_f > es) @@ -599,7 +599,7 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst co2_f <- Extracted[, "co2_f"] } co2_f[is.na(co2_f)] <- mean(co2, na.rm = TRUE) - co2_f[is.na(co2_f)] <- udunits2::ud.convert(380, "ppm", "mol/mol") + co2_f[is.na(co2_f)] <- PEcAn.utils::ud_convert(380, "ppm", "mol/mol") if (length(which(is.na(co2_f))) > 0) { error <- c(error, "mole_fraction_of_carbon_dioxide_in_air") } diff --git a/modules/data.atmosphere/R/metutils.R b/modules/data.atmosphere/R/metutils.R index 66f985a788b..4ef16906842 100644 --- a/modules/data.atmosphere/R/metutils.R +++ b/modules/data.atmosphere/R/metutils.R @@ -44,7 +44,7 @@ qair2rh <- function(qair, temp, press = 1013.25) { ##' @aliases rh2rv rh2qair <- function(rh, T, press = 101325) { stopifnot(T[!is.na(T)] >= 0) - Tc <- udunits2::ud.convert(T, "K", "degC") + Tc <- PEcAn.utils::ud_convert(T, "K", "degC") es <- 6.112 * exp((17.67 * Tc) / (Tc + 243.5)) e <- rh * es p_mb <- press / 100 @@ -158,7 +158,7 @@ wide2long <- function(data.wide, lat, lon, var) { ##' @author David LeBauer par2ppfd <- function(watts) { ppfd <- watts/(2.35 * 10^5) - return(udunits2::ud.convert(ppfd, "mol ", "umol")) + return(PEcAn.utils::ud_convert(ppfd, "mol ", "umol")) } # par2ppfd @@ -244,6 +244,6 @@ AirDens <- function(pres, T, rv) { ##' @author Istem Fer ##' @return lV latent heat of vaporization (J kg-1) get.lv <- function(airtemp = 268.6465) { - airtemp_C <- udunits2::ud.convert(airtemp, "K", "degC") + airtemp_C <- PEcAn.utils::ud_convert(airtemp, "K", "degC") return((94.21 * (365 - airtemp_C) ^ 0.31249) * 4.183 * 1000) } # get.lv diff --git a/modules/data.atmosphere/R/split_wind.R b/modules/data.atmosphere/R/split_wind.R index 608198fa8d0..427d8a57aa4 100644 --- a/modules/data.atmosphere/R/split_wind.R +++ b/modules/data.atmosphere/R/split_wind.R @@ -69,7 +69,7 @@ split_wind <- function(in.path, in.prefix, start_date, end_date, wind_speed.attr <- ncdf4::ncatt_get(nc, "wind_speed") WD <- "wind_direction" %in% names(nc$var) if(WD){ - wind_dir <- pi/2 - udunits2::ud.convert(ncdf4::ncvar_get(nc, "wind_direction"), wind_dir$units, "radians") + wind_dir <- pi/2 - PEcAn.utils::ud_convert(ncdf4::ncvar_get(nc, "wind_direction"), wind_dir$units, "radians") wind_dir.attr <- ncdf4::ncatt_get(nc, "wind_direction") east <- wind_speed*cos(wind_dir) north <- wind_speed*sin(wind_dir) diff --git a/modules/data.atmosphere/R/temporal.downscaling.R b/modules/data.atmosphere/R/temporal.downscaling.R index 27bebddbeea..1e8eeba5aa3 100644 --- a/modules/data.atmosphere/R/temporal.downscaling.R +++ b/modules/data.atmosphere/R/temporal.downscaling.R @@ -19,8 +19,8 @@ cfmet.downscale.time <- cruncep_hourly <- function(cfmet, output.dt = 1, lat = l # if("specific_humidity" %in% colnames(cfmet) & (!"relative_humidity" %in% colnames(cfmet))){ # cfmet$relative_humidity <- cfmet[,list(qair2rh(qair = specific_humidity, -# temp = udunits2::ud.convert(air_temperature, "Kelvin", "Celsius"), -# press = udunits2::ud.convert(air_pressure, "Pa", "millibar"))] +# temp = PEcAn.utils::ud_convert(air_temperature, "Kelvin", "Celsius"), +# press = PEcAn.utils::ud_convert(air_pressure, "Pa", "millibar"))] # } if(dt_hr > output.dt & dt_hr <= 6) { @@ -75,9 +75,9 @@ cfmet.downscale.subdaily <- function(subdailymet, output.dt = 1) { } downscaled.result[["wind_speed"]] <- rep(subdailymet$wind_speed, each = tint) - solarMJ <- udunits2::ud.convert(subdailymet$surface_downwelling_shortwave_flux_in_air, paste0("W ", tint, "h"), "MJ" ) + solarMJ <- PEcAn.utils::ud_convert(subdailymet$surface_downwelling_shortwave_flux_in_air, paste0("W ", tint, "h"), "MJ" ) PAR <- 0.486 * solarMJ ## Cambell and Norman 1998 p 151, ch 10 - subdailymet$ppfd <- udunits2::ud.convert(PAR, "mol s", "micromol h") + subdailymet$ppfd <- PEcAn.utils::ud_convert(PAR, "mol s", "micromol h") downscaled.result[["ppfd"]] <- subdailymet$ppfd downscaled.result[["surface_downwelling_shortwave_flux_in_air"]] <- subdailymet$surface_downwelling_shortwave_flux_in_air @@ -149,7 +149,7 @@ cfmet.downscale.daily <- function(dailymet, output.dt = 1, lat) { qair <- dailymet[, list(year, doy, tmin, tmax, air_pressure, air_temperature, qmin = rh2qair(rh = relative_humidity/100, T = tmin), qmax = rh2qair(rh = relative_humidity/100, T = tmax))] - a <- qair[, list(year, doy, tmin, tmax, air_temperature, qmin, qmax, pressure = udunits2::ud.convert(air_pressure, + a <- qair[, list(year, doy, tmin, tmax, air_temperature, qmin, qmax, pressure = PEcAn.utils::ud_convert(air_pressure, "Pa", "millibar"))][, list(year, doy, rhmin = qair2rh(qmin, air_temperature, pressure), rhmax = qair2rh(qmax, air_temperature, pressure))] rhscale <- (cos(2 * pi * (tseq - 10)/tint) + 1)/2 @@ -176,7 +176,7 @@ cfmet.downscale.daily <- function(dailymet, output.dt = 1, lat) { ## Hour time <- dailymet[, list(hour = tseq), by = c("year", "doy")] - ans <- data.table::data.table(time, downwelling_photosynthetic_photon_flux = SolarR, air_temperature = udunits2::ud.convert(Temp, + ans <- data.table::data.table(time, downwelling_photosynthetic_photon_flux = SolarR, air_temperature = PEcAn.utils::ud_convert(Temp, "kelvin", "celsius"), relative_humidity = RH, wind = wind_speed, precipitation_flux = precip) return(ans) } # cfmet.downscale.daily @@ -222,7 +222,7 @@ get.ncvector <- function(var, lati = lati, loni = loni, run.dates = run.dates, m precip_units <- gsub("kg m-2", "mm", precip_units) precip_units <- gsub("kg/m2", "mm", precip_units) precip_units <- gsub("kg/m\\^2", "mm", precip_units) - ans <- udunits2::ud.convert(ans, precip_units, "mm s-1") + ans <- PEcAn.utils::ud_convert(ans, precip_units, "mm s-1") } return(ans) } # cfmet.downscale.time diff --git a/modules/data.atmosphere/R/upscale_met.R b/modules/data.atmosphere/R/upscale_met.R index 421a1db4fbc..6d7f3847c22 100644 --- a/modules/data.atmosphere/R/upscale_met.R +++ b/modules/data.atmosphere/R/upscale_met.R @@ -44,7 +44,7 @@ upscale_met <- function(outfolder, input_met, resolution = 1/24, overwrite = FAL time_unit <- sub(" since.*", "", tem$dim$time$units) time_base <- lubridate::parse_date_time(sub(".*since ", "", tem$dim$time$units), orders = c("ymdHMSz", "ymdHMS", "ymd")) - time_data <- udunits2::ud.convert(tem$dim$time$vals, time_unit, "days") + time_data <- PEcAn.utils::ud_convert(tem$dim$time$vals, time_unit, "days") lat_data <- as.numeric(ncdf4::ncvar_get(tem, "latitude")) lon_data <- as.numeric(ncdf4::ncvar_get(tem, "longitude")) @@ -78,7 +78,7 @@ upscale_met <- function(outfolder, input_met, resolution = 1/24, overwrite = FAL lon <- ncdf4::ncdim_def(name = "longitude", units = "degree_east", vals = lon_data, create_dimvar = TRUE) time <- ncdf4::ncdim_def(name = "time", units = paste(time_unit, "since", time_base), - vals = udunits2::ud.convert(upscaled_time, "days", time_unit), + vals = PEcAn.utils::ud_convert(upscaled_time, "days", time_unit), create_dimvar = TRUE, unlim = TRUE) dim <- list(lat, lon, time) @@ -103,8 +103,8 @@ upscale_met <- function(outfolder, input_met, resolution = 1/24, overwrite = FAL results$file <- loc.file results$host <- PEcAn.remote::fqdn() - results$startdate <- time_base + udunits2::ud.convert(upscaled_time[[1]], "days", "sec") - results$enddate <- time_base + udunits2::ud.convert(upscaled_time[[nrow(upscale_data)]], "days", "sec") + results$startdate <- time_base + PEcAn.utils::ud_convert(upscaled_time[[1]], "days", "sec") + results$enddate <- time_base + PEcAn.utils::ud_convert(upscaled_time[[nrow(upscale_data)]], "days", "sec") results$mimetype <- "application/x-netcdf" results$formatname <- "CF Meteorology" diff --git a/modules/data.atmosphere/inst/scripts/ncep/met2csv.R b/modules/data.atmosphere/inst/scripts/ncep/met2csv.R index 3b424c921bd..f2c822e8c88 100644 --- a/modules/data.atmosphere/inst/scripts/ncep/met2csv.R +++ b/modules/data.atmosphere/inst/scripts/ncep/met2csv.R @@ -49,7 +49,6 @@ for(loni in 1:192){ weather <- data.table(read.csv(file.path(weather.dir, "rawweather.csv"))) - library(udunits2) ## unit conversion Tmin <- min(weather$temp - 273.15, 0) @@ -79,11 +78,11 @@ for(loni in 1:192){ Tavg = qctemp(temp), Tmax = qctemp(tempmax), Tmin = qctemp(tempmin), - solarR = udunits2::ud.convert(qcsolar(solar), + solarR = PEcAn.utils::ud_convert(qcsolar(solar), "watt day", "megajoule"), WS = sqrt(qcwind(uwind)^2 + qcwind(vwind)^2), - precip = udunits2::ud.convert(qcprecip(precip), "mm s-1", "mm day-1")), + precip = PEcAn.utils::ud_convert(qcprecip(precip), "mm s-1", "mm day-1")), qcshum(shum), qcrh(rh)] diff --git a/modules/data.atmosphere/tests/testthat/test.upscale_met.R b/modules/data.atmosphere/tests/testthat/test.upscale_met.R index 892c22ca5d7..3b706893abc 100644 --- a/modules/data.atmosphere/tests/testthat/test.upscale_met.R +++ b/modules/data.atmosphere/tests/testthat/test.upscale_met.R @@ -20,7 +20,7 @@ ncdf4::nc_close(scaled) test_that("output is scaled correctly", { orig_dt <- mean(diff(otime$vals)) sc_dt <- mean(diff(stime$vals)) - sc_dt_hours <- udunits2::ud.convert( + sc_dt_hours <- PEcAn.utils::ud_convert( sc_dt, stime$units, sub("^.* since", "hours since", stime$units)) @@ -38,5 +38,5 @@ test_that("output is scaled correctly", { test_that("units are preserved", { # only checking if preserved well enough to parse -- # OK if not string identical - expect_equal(udunits2::ud.convert(1, stime$units, otime$units), 1) + expect_equal(PEcAn.utils::ud_convert(1, stime$units, otime$units), 1) }) diff --git a/modules/data.land/DESCRIPTION b/modules/data.land/DESCRIPTION index 34073b9bb82..788eecce336 100644 --- a/modules/data.land/DESCRIPTION +++ b/modules/data.land/DESCRIPTION @@ -54,7 +54,6 @@ Imports: sp, stringr, traits, - udunits2, XML (>= 3.98-1.4) Suggests: dataone, diff --git a/modules/data.land/R/IC_BADM_Utilities.R b/modules/data.land/R/IC_BADM_Utilities.R index a5a64627f9c..91b846c5ed5 100644 --- a/modules/data.land/R/IC_BADM_Utilities.R +++ b/modules/data.land/R/IC_BADM_Utilities.R @@ -129,7 +129,7 @@ Read.IC.info.BADM <-function(lat, long){ PlantWoodIni <- - udunits2::ud.convert(Gdf$DATAVALUE[1]%>% + PEcAn.utils::ud_convert(Gdf$DATAVALUE[1]%>% as.numeric()*cov.factor, unit.ready, "kg/m^2")#"AG_BIOMASS_CROP","AG_BIOMASS_SHRUB","AG_BIOMASS_TREE","AG_BIOMASS_OTHER" } else if (type == "*SOIL") { @@ -139,16 +139,16 @@ Read.IC.info.BADM <-function(lat, long){ as.numeric() if (length(val) > 0) - SoilIni <- udunits2::ud.convert(val*cov.factor, "g/m^2", "kg/m^2") + SoilIni <- PEcAn.utils::ud_convert(val*cov.factor, "g/m^2", "kg/m^2") } else if (type == "*_LIT_BIOMASS") { litterIni <- - udunits2::ud.convert(Gdf$DATAVALUE[1] %>% + PEcAn.utils::ud_convert(Gdf$DATAVALUE[1] %>% as.numeric()*cov.factor, unit.ready, "kg/m^2") } else if (type == "*_ROOT_BIOMASS") { Rootini <- - udunits2::ud.convert(Gdf$DATAVALUE[1]%>% + PEcAn.utils::ud_convert(Gdf$DATAVALUE[1]%>% as.numeric()*cov.factor, unit.ready, "kg/m^2") } diff --git a/modules/data.land/R/extract_soil_nc.R b/modules/data.land/R/extract_soil_nc.R index dff30b31335..688f69d67b2 100644 --- a/modules/data.land/R/extract_soil_nc.R +++ b/modules/data.land/R/extract_soil_nc.R @@ -326,7 +326,7 @@ extract_soil_nc <- function(in.file,outdir,lat,lon){ soil.data$clay <- soil.data$clay/100 soil.data$oc <- soil.data$oc/100 soil.data$gravel <- soil.data$gravel/100 - soil.data$ref_bulk <- udunits2::ud.convert(soil.data$ref_bulk,"g cm-3","kg m-3") + soil.data$ref_bulk <- PEcAn.utils::ud_convert(soil.data$ref_bulk,"g cm-3","kg m-3") names(soil.data)[which(names(soil.data) == "clay")] <- "fraction_of_clay_in_soil" names(soil.data)[which(names(soil.data) == "sand")] <- "fraction_of_sand_in_soil" names(soil.data)[which(names(soil.data) == "silt")] <- "fraction_of_silt_in_soil" diff --git a/modules/data.land/R/get.soil.R b/modules/data.land/R/get.soil.R index 12cf3c615aa..8ad20456393 100644 --- a/modules/data.land/R/get.soil.R +++ b/modules/data.land/R/get.soil.R @@ -18,7 +18,7 @@ get.soil <- function(lat, lon, soil.nc = soil.nc) { ## topsoil usda_class <- ncvar_get(soil.nc, "t_usda_tex", start = c(loni, lati), count = c(1, 1)) - ref_depth <- udunits2::ud.convert(ncvar_get(soil.nc, "ref_depth", start = c(loni, lati), count = c(1, 1)), + ref_depth <- PEcAn.utils::ud_convert(ncvar_get(soil.nc, "ref_depth", start = c(loni, lati), count = c(1, 1)), "cm", "m") return(list(usda_class = usda_class, ref_depth = ref_depth)) } # get.soil diff --git a/modules/data.land/R/soil_utils.R b/modules/data.land/R/soil_utils.R index e655f92136d..b89025c072f 100644 --- a/modules/data.land/R/soil_utils.R +++ b/modules/data.land/R/soil_utils.R @@ -118,7 +118,7 @@ soil_params <- function(soil_type=NULL, sand=NULL, silt=NULL, clay=NULL, bulk=NU mysoil$soil_water_potential_at_saturation[z] <- -0.01 * (10.^(2.17 - 0.63*mysoil$fraction_of_clay_in_soil[z] - 1.58*mysoil$fraction_of_sand_in_soil[z])) # Hydraulic conductivity at saturation [ m/s ] - mysoil$soil_hydraulic_conductivity_at_saturation[z] <- udunits2::ud.convert(10.^(-0.60 + 1.26*mysoil$fraction_of_sand_in_soil[z] - 0.64*mysoil$fraction_of_clay_in_soil[z]), + mysoil$soil_hydraulic_conductivity_at_saturation[z] <- PEcAn.utils::ud_convert(10.^(-0.60 + 1.26*mysoil$fraction_of_sand_in_soil[z] - 0.64*mysoil$fraction_of_clay_in_soil[z]), "inch/hour","meters/second") # Soil moisture at saturation [ m^3/m^3 ] diff --git a/modules/data.land/inst/BCI_AGB.R b/modules/data.land/inst/BCI_AGB.R index eb1d4de29ac..d2e120142a2 100644 --- a/modules/data.land/inst/BCI_AGB.R +++ b/modules/data.land/inst/BCI_AGB.R @@ -32,7 +32,7 @@ for(f in seq_along(files)){ bdead = 0.06896*(h^0.572)*(dbh^1.94)*wood_density^0.931 ## FATES allom, units = KgC?? ## conversion to plot-level mean - stats$AGB[i] <- udunits2::ud.convert(sum(bdead,na.rm=TRUE)/area,"kg ha-1","kg m-2") #AbvGrndWood kgC m-2 + stats$AGB[i] <- PEcAn.utils::ud_convert(sum(bdead,na.rm=TRUE)/area,"kg ha-1","kg m-2") #AbvGrndWood kgC m-2 ## extract dates date <- as.Date(dat$Date) @@ -45,7 +45,7 @@ for(f in seq_along(files)){ } ## sanity check -agb <- udunits2::ud.convert(stats$AGB,"kg m-2","Mg ha-1")/0.48 +agb <- PEcAn.utils::ud_convert(stats$AGB,"kg m-2","Mg ha-1")/0.48 plot(as.Date(stats$date,origin = "1970-01-01"),agb) stats$AGB[3] <- NA ## odd outlier, original value = 22.95379 diff --git a/modules/data.land/inst/build_soil_texture_variables.R b/modules/data.land/inst/build_soil_texture_variables.R index 02b68ddf00d..f52288c06c5 100644 --- a/modules/data.land/inst/build_soil_texture_variables.R +++ b/modules/data.land/inst/build_soil_texture_variables.R @@ -123,7 +123,7 @@ texture <- read.csv("~/pecan/modules/data.land/data/texture.csv",header=TRUE,str soil.key = c("Sa","LSa","SaL","SiL","L","SaCL","SiCL","CL","SaC","SiC","C","P","BR" ,"Si","CC","CSa","CSi") #----- Define some constants. ----------------------------------------------------------# -fieldcp.K = udunits2::ud.convert(0.1,"mm/day","meters/second") +fieldcp.K = PEcAn.utils::ud_convert(0.1,"mm/day","meters/second") # hydraulic conduct. at field capacity [ mm/day] soilcp.MPa = 3.1 # soil-water potential for air dry soil [ MPa] soilwp.MPa = 1.5 # soil-water potential at wilting point [ MPa] diff --git a/modules/uncertainty/DESCRIPTION b/modules/uncertainty/DESCRIPTION index 6743eda7c96..c55c45719e8 100644 --- a/modules/uncertainty/DESCRIPTION +++ b/modules/uncertainty/DESCRIPTION @@ -44,8 +44,7 @@ Imports: plyr (>= 1.8.4), purrr, randtoolbox, - rlang, - udunits2 + rlang Suggests: testthat (>= 1.0.2), License: BSD_3_clause + file LICENSE diff --git a/modules/uncertainty/R/run.sensitivity.analysis.R b/modules/uncertainty/R/run.sensitivity.analysis.R index ea57be97944..0f96313dd00 100644 --- a/modules/uncertainty/R/run.sensitivity.analysis.R +++ b/modules/uncertainty/R/run.sensitivity.analysis.R @@ -95,7 +95,7 @@ run.sensitivity.analysis <- function(settings,plot=TRUE, ensemble.id=NULL, varia C.units <- grepl('^Celsius$', trait.lookup(traits)$units, ignore.case = TRUE) if(any(C.units)){ for(x in which(C.units)) { - trait.samples[[pft$name]][[x]] <- udunits2::ud.convert(trait.samples[[pft$name]][[x]], "degC", "K") + trait.samples[[pft$name]][[x]] <- PEcAn.utils::ud_convert(trait.samples[[pft$name]][[x]], "degC", "K") } } From 1941da15dd35541faa7896c88563e097764c41ee Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Wed, 27 Jul 2022 20:30:10 +0000 Subject: [PATCH 04/37] updated docker/depends/pecan.depends.R --- docker/depends/pecan.depends.R | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index d3990aec169..280e2654785 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -132,7 +132,6 @@ wanted <- c( 'traits', 'TruncatedNormal', 'truncnorm', -'udunits2', 'units', 'urltools', 'utils', From 09b4c9548d539caabc6f138abc8a3a80e641d999 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Thu, 28 Jul 2022 13:38:28 +0530 Subject: [PATCH 05/37] Update base/utils/R/ud_convert.R Co-authored-by: Chris Black --- base/utils/R/ud_convert.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/utils/R/ud_convert.R b/base/utils/R/ud_convert.R index ef826fc767a..491117ee556 100644 --- a/base/utils/R/ud_convert.R +++ b/base/utils/R/ud_convert.R @@ -1,4 +1,4 @@ -##' @title Convert units +##' Convert units ##' ##' This function takes the numeric argument `x`, quantified in units `u1` and converts it to be of units `u2`. ##' @author Chris Black From 7e24653cdb7203186bc18065dbf75f628d28e630 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Thu, 28 Jul 2022 13:38:39 +0530 Subject: [PATCH 06/37] Update base/utils/R/ud_convert.R Co-authored-by: Chris Black --- base/utils/R/ud_convert.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/utils/R/ud_convert.R b/base/utils/R/ud_convert.R index 491117ee556..db7f863d972 100644 --- a/base/utils/R/ud_convert.R +++ b/base/utils/R/ud_convert.R @@ -1,6 +1,6 @@ ##' Convert units ##' -##' This function takes the numeric argument `x`, quantified in units `u1` and converts it to be of units `u2`. +##' Unit conversion to replace the now-unmaintained `udunits2::ud.convert` ##' @author Chris Black ##' ##' @param x numeric vector with units `u1` to be converted to units `u2` From 9ea3198281b71b296f922e06ae5992d4b15658ff Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Thu, 28 Jul 2022 13:38:46 +0530 Subject: [PATCH 07/37] Update base/utils/R/ud_convert.R Co-authored-by: Chris Black --- base/utils/R/ud_convert.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/base/utils/R/ud_convert.R b/base/utils/R/ud_convert.R index db7f863d972..139ee22006c 100644 --- a/base/utils/R/ud_convert.R +++ b/base/utils/R/ud_convert.R @@ -3,10 +3,9 @@ ##' Unit conversion to replace the now-unmaintained `udunits2::ud.convert` ##' @author Chris Black ##' -##' @param x numeric vector with units `u1` to be converted to units `u2` -##' @param u1 string which is parseable into a `units` compatible unit. -##' @param u2 string which is parseable into a `units` compatible unit, -##' and for which there exists a defined transformation from the units represented by `u1`. +##' @param x numeric vector +##' @param u1 string parseable as the units in which `x` is provided +##' @param u2 string parseable as the units to convert to ##' ##' @return numeric vector stripped of units ##' @export From 0be9b990523f470b3e45eabc01a104e19d7e03b3 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Thu, 28 Jul 2022 13:38:53 +0530 Subject: [PATCH 08/37] Update base/utils/R/ud_convert.R Co-authored-by: Chris Black --- base/utils/R/ud_convert.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/utils/R/ud_convert.R b/base/utils/R/ud_convert.R index 139ee22006c..1af8157642f 100644 --- a/base/utils/R/ud_convert.R +++ b/base/utils/R/ud_convert.R @@ -7,7 +7,7 @@ ##' @param u1 string parseable as the units in which `x` is provided ##' @param u2 string parseable as the units to convert to ##' -##' @return numeric vector stripped of units +##' @return numeric vector with values converted to units in `u2` ##' @export ud_convert <- function(x, u1, u2) { stopifnot(units::ud_are_convertible(u1, u2)) From d098c5ee86a3baa7f4f5a3ae199e9913baeeff73 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Thu, 28 Jul 2022 13:39:06 +0530 Subject: [PATCH 09/37] Update modules/data.atmosphere/R/merge.met.variable.R Co-authored-by: Chris Black --- modules/data.atmosphere/R/merge.met.variable.R | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/data.atmosphere/R/merge.met.variable.R b/modules/data.atmosphere/R/merge.met.variable.R index 93052d37b33..ad0a89f15b6 100644 --- a/modules/data.atmosphere/R/merge.met.variable.R +++ b/modules/data.atmosphere/R/merge.met.variable.R @@ -48,7 +48,6 @@ merge_met_variable <- function(in.path,in.prefix,start_date, end_date, merge.fil merge.time.attr <- ncdf4::ncatt_get(merge.nc,"time") merge.data <- ncdf4::ncvar_get(merge.nc,varid = merge.vars[1]) - units::install_unit(merge.time.attr$units) origin <- "1970-01-01 00:00:00 UTC" merge.time.std <- PEcAn.utils::ud_convert(merge.time, merge.time.attr$units, From 338e47af44d86c678f6710dd5c366358587ed84a Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Thu, 28 Jul 2022 13:39:13 +0530 Subject: [PATCH 10/37] Update base/utils/R/ud_convert.R Co-authored-by: Chris Black --- base/utils/R/ud_convert.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/base/utils/R/ud_convert.R b/base/utils/R/ud_convert.R index 1af8157642f..affc7bb4836 100644 --- a/base/utils/R/ud_convert.R +++ b/base/utils/R/ud_convert.R @@ -11,6 +11,8 @@ ##' @export ud_convert <- function(x, u1, u2) { stopifnot(units::ud_are_convertible(u1, u2)) - a <- units::set_units(x, value = u1, mode = "standard") - units::drop_units(units::set_units(a, value = u2, mode = "standard")) -} # ud_convert \ No newline at end of file + x1 <- units::set_units(x, value = u1, mode = "standard") + x2 <- units::set_units(x1, value = u2, mode = "standard") + + units::drop_units(x2) + } # ud_convert From 9d4dbf732f48c673f262935db205045368362178 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Thu, 28 Jul 2022 08:22:45 +0000 Subject: [PATCH 11/37] changes in ud_convert.Rd --- base/utils/man/ud_convert.Rd | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/base/utils/man/ud_convert.Rd b/base/utils/man/ud_convert.Rd index 265cca8f3a8..869b18ee389 100644 --- a/base/utils/man/ud_convert.Rd +++ b/base/utils/man/ud_convert.Rd @@ -2,27 +2,22 @@ % Please edit documentation in R/ud_convert.R \name{ud_convert} \alias{ud_convert} -\title{Convert units - -This function takes the numeric argument \code{x}, quantified in units \code{u1} and converts it to be of units \code{u2}.} +\title{Convert units} \usage{ ud_convert(x, u1, u2) } \arguments{ -\item{x}{numeric vector with units \code{u1} to be converted to units \code{u2}} +\item{x}{numeric vector} -\item{u1}{string which is parseable into a \code{units} compatible unit.} +\item{u1}{string parseable as the units in which \code{x} is provided} -\item{u2}{string which is parseable into a \code{units} compatible unit, -and for which there exists a defined transformation from the units represented by \code{u1}.} +\item{u2}{string parseable as the units to convert to} } \value{ -numeric vector stripped of units +numeric vector with values converted to units in \code{u2} } \description{ -Convert units - -This function takes the numeric argument \code{x}, quantified in units \code{u1} and converts it to be of units \code{u2}. +Unit conversion to replace the now-unmaintained \code{udunits2::ud.convert} } \author{ Chris Black From 9d83c1ec75839c0f9dd7ba25920de28a2b56b1d5 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Thu, 28 Jul 2022 08:43:45 +0000 Subject: [PATCH 12/37] changed base/db/R/insert.format.vars.R --- base/db/R/insert.format.vars.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/db/R/insert.format.vars.R b/base/db/R/insert.format.vars.R index eeb5115560e..4e507557834 100644 --- a/base/db/R/insert.format.vars.R +++ b/base/db/R/insert.format.vars.R @@ -126,7 +126,7 @@ insert.format.vars <- function(con, format_name, mimetype_id, notes = NULL, head u1 <- formats_variables[1,"unit"] u2 <- dplyr::tbl(con, "variables") %>% dplyr::select(.data$id, units) %>% dplyr::filter(.data$id %in% !!formats_variables[[1, "variable_id"]]) %>% dplyr::pull(.data$units) - if(!units::install_unit(u1)){ + if(!units::as_units(u1)){ PEcAn.logger::logger.error( "Units not parseable. Please enter a unit that is parseable by the udunits library." ) From 040d3e168f5e54cd864a95bf635f0fb2d2d8d360 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Fri, 29 Jul 2022 20:51:46 +0000 Subject: [PATCH 13/37] added test-ud_convert.R --- base/utils/tests/testthat/test-ud_convert.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 base/utils/tests/testthat/test-ud_convert.R diff --git a/base/utils/tests/testthat/test-ud_convert.R b/base/utils/tests/testthat/test-ud_convert.R new file mode 100644 index 00000000000..0304609846e --- /dev/null +++ b/base/utils/tests/testthat/test-ud_convert.R @@ -0,0 +1,18 @@ +test_that("successfully converted one unit to another", + { + expect_equal(ud_convert(4, "in", "cm"), 10.16) + expect_equal(ud_convert(23, "degC", "K"), 296.15) + expect_equal(ud_convert(6, "days", "seconds"), 518400) + expect_equal(ud_convert(32, "hour", "seconds"), 115200) + expect_equal(ud_convert(15, "days", "hour"), 360) + expect_equal(ud_convert(7, "ppm", "mol/mol"), 7e-06) + } +) + +test_that("trying to convert into different type", + { + expect_error(ud_convert(1, "miles", "grams")) + expect_error(ud_convert(1, "radians", "degC")) + expect_error(ud_convert(1, "in", "grams")) + } +) From b722c6d5da07a4f66008ec239d4de7be3dabc83d Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sat, 30 Jul 2022 11:57:23 +0530 Subject: [PATCH 14/37] Update base/utils/tests/testthat/test-ud_convert.R Co-authored-by: Chris Black --- base/utils/tests/testthat/test-ud_convert.R | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/base/utils/tests/testthat/test-ud_convert.R b/base/utils/tests/testthat/test-ud_convert.R index 0304609846e..415027a1ab5 100644 --- a/base/utils/tests/testthat/test-ud_convert.R +++ b/base/utils/tests/testthat/test-ud_convert.R @@ -1,13 +1,17 @@ -test_that("successfully converted one unit to another", - { - expect_equal(ud_convert(4, "in", "cm"), 10.16) - expect_equal(ud_convert(23, "degC", "K"), 296.15) - expect_equal(ud_convert(6, "days", "seconds"), 518400) - expect_equal(ud_convert(32, "hour", "seconds"), 115200) - expect_equal(ud_convert(15, "days", "hour"), 360) - expect_equal(ud_convert(7, "ppm", "mol/mol"), 7e-06) - } -) +test_that("unit conversions", { + expect_equal(ud_convert(4, "in", "cm"), 10.16) + expect_equal(ud_convert(23, "degC", "K"), 296.15) + expect_equal(ud_convert(6, "days", "seconds"), 518400) + expect_equal(ud_convert(32, "hour", "seconds"), 115200) + expect_equal(ud_convert(15, "days", "hour"), 360) + expect_equal(ud_convert(-7, "ppm", "mol/mol"), -7e-06) +}) + +test_that("unit conversion invariants", { + expect_equal(ud_convert(1, "g", "g"), 1) + expect_equal(ud_convert(0, "g", "kg"), 0) + expect_equal(ud_convert(Inf, "g", "kg") Inf) +}) test_that("trying to convert into different type", { From e964094b9775ce976691c7c8b2681af26f8a9515 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sat, 30 Jul 2022 11:57:32 +0530 Subject: [PATCH 15/37] Update base/utils/tests/testthat/test-ud_convert.R Co-authored-by: Chris Black --- base/utils/tests/testthat/test-ud_convert.R | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/base/utils/tests/testthat/test-ud_convert.R b/base/utils/tests/testthat/test-ud_convert.R index 415027a1ab5..52f5b009cea 100644 --- a/base/utils/tests/testthat/test-ud_convert.R +++ b/base/utils/tests/testthat/test-ud_convert.R @@ -13,10 +13,8 @@ test_that("unit conversion invariants", { expect_equal(ud_convert(Inf, "g", "kg") Inf) }) -test_that("trying to convert into different type", - { - expect_error(ud_convert(1, "miles", "grams")) - expect_error(ud_convert(1, "radians", "degC")) - expect_error(ud_convert(1, "in", "grams")) - } -) +test_that("incompatible units", { + expect_error(ud_convert(1, "miles", "grams")) + expect_error(ud_convert(1, "radians", "degC")) + expect_error(ud_convert(1, "in", "grams")) +}) From e0280345b0bc7f07d77dbebd0b206d9751fcaa90 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sat, 30 Jul 2022 06:37:48 +0000 Subject: [PATCH 16/37] added one more test --- base/utils/tests/testthat/test-ud_convert.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/utils/tests/testthat/test-ud_convert.R b/base/utils/tests/testthat/test-ud_convert.R index 0304609846e..a4b65c304e4 100644 --- a/base/utils/tests/testthat/test-ud_convert.R +++ b/base/utils/tests/testthat/test-ud_convert.R @@ -16,3 +16,11 @@ test_that("trying to convert into different type", expect_error(ud_convert(1, "in", "grams")) } ) + +test_that("output is type numeric and not class \"units\"", + { + x <- ud_convert(23, "degC", "K") + testthat::expect_failure(expect_s3_class(x, "units")) + testthat::expect_type(x, "double") + } +) From ebbd07b1dd14a4389868af26c872e79ec40d774c Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sat, 30 Jul 2022 16:35:43 +0000 Subject: [PATCH 17/37] updated the Rcheck_reference.log file for assim.batch --- modules/assim.batch/tests/Rcheck_reference.log | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/assim.batch/tests/Rcheck_reference.log b/modules/assim.batch/tests/Rcheck_reference.log index 725ed91b3af..f7860489eef 100644 --- a/modules/assim.batch/tests/Rcheck_reference.log +++ b/modules/assim.batch/tests/Rcheck_reference.log @@ -11,7 +11,7 @@ * checking package dependencies ... WARNING Requires orphaned package: ‘udunits2’ -Imports includes 28 non-default packages. +Imports includes 27 non-default packages. Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally. From 86db0a4272f4f0205fb7ae8e69c25581009cc26a Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sat, 30 Jul 2022 17:14:12 +0000 Subject: [PATCH 18/37] minor change in the Rcheck_reference.log file for assim.batch --- modules/assim.batch/tests/Rcheck_reference.log | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/assim.batch/tests/Rcheck_reference.log b/modules/assim.batch/tests/Rcheck_reference.log index f7860489eef..a563fde27dc 100644 --- a/modules/assim.batch/tests/Rcheck_reference.log +++ b/modules/assim.batch/tests/Rcheck_reference.log @@ -16,7 +16,7 @@ Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally. * checking package dependencies ... NOTE -Imports includes 28 non-default packages. +Imports includes 27 non-default packages. Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally. From 7482b9c8024843b9c0b729bcedb912cd084aa40d Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sun, 31 Jul 2022 02:52:12 +0530 Subject: [PATCH 19/37] Update base/db/R/insert.format.vars.R Co-authored-by: Chris Black --- base/db/R/insert.format.vars.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/db/R/insert.format.vars.R b/base/db/R/insert.format.vars.R index 4e507557834..1c838eeb64e 100644 --- a/base/db/R/insert.format.vars.R +++ b/base/db/R/insert.format.vars.R @@ -128,7 +128,8 @@ insert.format.vars <- function(con, format_name, mimetype_id, notes = NULL, head if(!units::as_units(u1)){ PEcAn.logger::logger.error( - "Units not parseable. Please enter a unit that is parseable by the udunits library." + "Units '", u1, "' not parseable.", + "Please provide a unit that is parseable by the udunits library." ) } # Grab the bety units and From 38feefb64e57dc3977596fb009354bd6189436d9 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sun, 31 Jul 2022 02:52:21 +0530 Subject: [PATCH 20/37] Update base/db/R/insert.format.vars.R Co-authored-by: Chris Black --- base/db/R/insert.format.vars.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base/db/R/insert.format.vars.R b/base/db/R/insert.format.vars.R index 1c838eeb64e..b47491fc3e7 100644 --- a/base/db/R/insert.format.vars.R +++ b/base/db/R/insert.format.vars.R @@ -126,7 +126,8 @@ insert.format.vars <- function(con, format_name, mimetype_id, notes = NULL, head u1 <- formats_variables[1,"unit"] u2 <- dplyr::tbl(con, "variables") %>% dplyr::select(.data$id, units) %>% dplyr::filter(.data$id %in% !!formats_variables[[1, "variable_id"]]) %>% dplyr::pull(.data$units) - if(!units::as_units(u1)){ + u1_recognized <- tryCatch(units::as_units(u1), error = function(e) FALSE) + if(!u1_recognized){ PEcAn.logger::logger.error( "Units '", u1, "' not parseable.", "Please provide a unit that is parseable by the udunits library." From 1cf137a964e18fd6222501679d11239b8bea7627 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sun, 31 Jul 2022 03:01:33 +0530 Subject: [PATCH 21/37] Update base/utils/tests/testthat/test-ud_convert.R Co-authored-by: Chris Black --- base/utils/tests/testthat/test-ud_convert.R | 1 + 1 file changed, 1 insertion(+) diff --git a/base/utils/tests/testthat/test-ud_convert.R b/base/utils/tests/testthat/test-ud_convert.R index 031f2a95f89..c84cf13d804 100644 --- a/base/utils/tests/testthat/test-ud_convert.R +++ b/base/utils/tests/testthat/test-ud_convert.R @@ -23,4 +23,5 @@ test_that("output is type numeric and not class \"units\"", { x <- ud_convert(23, "degC", "K") testthat::expect_failure(expect_s3_class(x, "units")) testthat::expect_type(x, "double") + }) \ No newline at end of file From 1a374af708b9af08feb63a8c8beded490bf01c46 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sun, 31 Jul 2022 03:01:48 +0530 Subject: [PATCH 22/37] Update modules/data.atmosphere/R/merge.met.variable.R Co-authored-by: Chris Black --- modules/data.atmosphere/R/merge.met.variable.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/data.atmosphere/R/merge.met.variable.R b/modules/data.atmosphere/R/merge.met.variable.R index ad0a89f15b6..13e8c404fb2 100644 --- a/modules/data.atmosphere/R/merge.met.variable.R +++ b/modules/data.atmosphere/R/merge.met.variable.R @@ -81,7 +81,7 @@ merge_met_variable <- function(in.path,in.prefix,start_date, end_date, merge.fil ## name and variable conversions if(toupper(merge.vars[1]) == "CO2"){ merge.vars[1] <- "mole_fraction_of_carbon_dioxide_in_air" - merge.data <- PEcAn.utils::ud_convert(merge.data,merge.attr$units,"mol/mol") + merge.data <- PEcAn.utils::ud_convert(merge.data, merge.attr$units, "mol/mol") merge.attr$units = "mol/mol" } From edfc16fd7fd58544da47680135dd5c857b2c1b0a Mon Sep 17 00:00:00 2001 From: Chris Black Date: Sat, 30 Jul 2022 21:56:58 +0000 Subject: [PATCH 23/37] Update base/utils/tests/testthat/test-ud_convert.R --- base/utils/tests/testthat/test-ud_convert.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/utils/tests/testthat/test-ud_convert.R b/base/utils/tests/testthat/test-ud_convert.R index c84cf13d804..2ef16d2a5ba 100644 --- a/base/utils/tests/testthat/test-ud_convert.R +++ b/base/utils/tests/testthat/test-ud_convert.R @@ -24,4 +24,4 @@ test_that("output is type numeric and not class \"units\"", { testthat::expect_failure(expect_s3_class(x, "units")) testthat::expect_type(x, "double") -}) \ No newline at end of file +}) From 45c238a2d3dd6e2e605ff7597a9741b6dc4c94ee Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Sun, 31 Jul 2022 12:40:41 +0530 Subject: [PATCH 24/37] Update modules/data.atmosphere/R/metgapfill.R Co-authored-by: Chris Black --- modules/data.atmosphere/R/metgapfill.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/data.atmosphere/R/metgapfill.R b/modules/data.atmosphere/R/metgapfill.R index 6b46cb3fdd8..2d3eba7f096 100644 --- a/modules/data.atmosphere/R/metgapfill.R +++ b/modules/data.atmosphere/R/metgapfill.R @@ -384,8 +384,8 @@ metgapfill <- function(in.path, in.prefix, outfolder, start_date, end_date, lst tunit <- ncdf4::ncatt_get(nc = nc, varid = "time", attname = "units", verbose = verbose) origin <- "1900-01-01 00:00:00" time <- round(as.POSIXlt(PEcAn.utils::ud_convert(time, tunit$value, paste("seconds since", origin)), - origin = origin, tz = "UTC"), units = "mins") - dtime <- diff(time) + origin = origin, tz = "UTC")) + dtime <- as.numeric(diff(time), units = "mins") if (dtime[1] == 30) { DTS.n <- 48 time <- 30 * 60 + time From 9f4ee29d62cacf585433443addf85cdc2e3e1cf6 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 07:32:18 +0000 Subject: [PATCH 25/37] change in Rcheck_reference.log of data.land --- modules/data.land/tests/Rcheck_reference.log | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/data.land/tests/Rcheck_reference.log b/modules/data.land/tests/Rcheck_reference.log index bdcae837bf7..669faf2f952 100644 --- a/modules/data.land/tests/Rcheck_reference.log +++ b/modules/data.land/tests/Rcheck_reference.log @@ -11,7 +11,7 @@ * checking package dependencies ... WARNING Requires orphaned package: ‘udunits2’ -Imports includes 33 non-default packages. +Imports includes 32 non-default packages. Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally. From 05e1dcfd2d4e0378ba5317be69cc8211a05bbafc Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 07:51:09 +0000 Subject: [PATCH 26/37] minor change in Rcheck_reference.log of data.land --- modules/data.land/tests/Rcheck_reference.log | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/data.land/tests/Rcheck_reference.log b/modules/data.land/tests/Rcheck_reference.log index 669faf2f952..e4cf8c984ea 100644 --- a/modules/data.land/tests/Rcheck_reference.log +++ b/modules/data.land/tests/Rcheck_reference.log @@ -12,9 +12,6 @@ Requires orphaned package: ‘udunits2’ Imports includes 32 non-default packages. -Importing from so many packages makes the package vulnerable to any of -them becoming unavailable. Move as many as possible to Suggests and -use conditionally. * checking package dependencies ... NOTE Imports includes 33 non-default packages. Importing from so many packages makes the package vulnerable to any of From f72a7b4741c0bee8727c2644a2053b27497e190b Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 07:53:21 +0000 Subject: [PATCH 27/37] changed Rcheck_reference.log of data.land --- modules/data.land/tests/Rcheck_reference.log | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/data.land/tests/Rcheck_reference.log b/modules/data.land/tests/Rcheck_reference.log index e4cf8c984ea..b731640ea8d 100644 --- a/modules/data.land/tests/Rcheck_reference.log +++ b/modules/data.land/tests/Rcheck_reference.log @@ -12,8 +12,11 @@ Requires orphaned package: ‘udunits2’ Imports includes 32 non-default packages. +Importing from so many packages makes the package vulnerable to any of +them becoming unavailable. Move as many as possible to Suggests and +use conditionally. * checking package dependencies ... NOTE -Imports includes 33 non-default packages. +Imports includes 32 non-default packages. Importing from so many packages makes the package vulnerable to any of them becoming unavailable. Move as many as possible to Suggests and use conditionally. From ad657cd6f1e7156c3975277fe021cd96a01a8e13 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 08:50:06 +0000 Subject: [PATCH 28/37] changed DESCRIPTION of PEcAn.dvmdostem --- models/dvmdostem/DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/dvmdostem/DESCRIPTION b/models/dvmdostem/DESCRIPTION index cd0bcc026b1..592e457c719 100644 --- a/models/dvmdostem/DESCRIPTION +++ b/models/dvmdostem/DESCRIPTION @@ -13,7 +13,9 @@ Maintainer: Tobey Carman , Shawn Serbin Description: This module provides functions to link the dvmdostem model to PEcAn. Imports: + lubridate, ncdf4, + PEcAn.logger, PEcAn.utils (>= 1.4.8), rjson Suggests: From 7aa393817757eadd36d999ea17b8bb0de98db0a0 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 08:54:12 +0000 Subject: [PATCH 29/37] updated Makefile.depends --- Makefile.depends | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.depends b/Makefile.depends index 826a80c5207..9212481f926 100644 --- a/Makefile.depends +++ b/Makefile.depends @@ -27,7 +27,7 @@ $(call depends,models/biocro): | .install/base/logger .install/base/remote .inst $(call depends,models/cable): | .install/base/logger .install/base/utils $(call depends,models/clm45): | .install/base/logger .install/base/utils $(call depends,models/dalec): | .install/base/logger .install/base/remote .install/base/utils -$(call depends,models/dvmdostem): | .install/base/utils +$(call depends,models/dvmdostem): | .install/base/logger .install/base/utils $(call depends,models/ed): | .install/modules/data.atmosphere .install/modules/data.land .install/base/logger .install/base/remote .install/base/settings .install/base/utils $(call depends,models/fates): | .install/base/utils .install/base/logger .install/base/remote $(call depends,models/gday): | .install/base/utils .install/base/logger .install/base/remote From a68c6b601e0a15d9740ef6628f42aaa055eff032 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 09:27:01 +0000 Subject: [PATCH 30/37] added stringr in the DESCRIPTION of fates --- models/fates/DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/models/fates/DESCRIPTION b/models/fates/DESCRIPTION index 50121d1a464..ff4aec9be9d 100644 --- a/models/fates/DESCRIPTION +++ b/models/fates/DESCRIPTION @@ -19,6 +19,7 @@ Description: The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific Depends: PEcAn.utils Imports: + stringr, PEcAn.logger, PEcAn.remote, lubridate (>= 1.6.0), From 00c33d000304ed82c04f834725dd4a68f14fc5d2 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 10:05:44 +0000 Subject: [PATCH 31/37] some changes in PEcAn.fates --- Makefile.depends | 2 +- models/fates/DESCRIPTION | 3 +-- models/fates/R/met2model.FATES.R | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile.depends b/Makefile.depends index 9212481f926..7828e0b819a 100644 --- a/Makefile.depends +++ b/Makefile.depends @@ -29,7 +29,7 @@ $(call depends,models/clm45): | .install/base/logger .install/base/utils $(call depends,models/dalec): | .install/base/logger .install/base/remote .install/base/utils $(call depends,models/dvmdostem): | .install/base/logger .install/base/utils $(call depends,models/ed): | .install/modules/data.atmosphere .install/modules/data.land .install/base/logger .install/base/remote .install/base/settings .install/base/utils -$(call depends,models/fates): | .install/base/utils .install/base/logger .install/base/remote +$(call depends,models/fates): | .install/base/logger .install/base/remote .install/base/utils $(call depends,models/gday): | .install/base/utils .install/base/logger .install/base/remote $(call depends,models/jules): | .install/base/utils .install/base/logger .install/base/remote $(call depends,models/linkages): | .install/base/utils .install/modules/data.atmosphere .install/base/logger .install/base/remote diff --git a/models/fates/DESCRIPTION b/models/fates/DESCRIPTION index ff4aec9be9d..8c346288a54 100644 --- a/models/fates/DESCRIPTION +++ b/models/fates/DESCRIPTION @@ -16,12 +16,11 @@ Description: The Predictive Ecosystem Carbon Analyzer (PEcAn) is a scientific streamline the interaction between data and models, and to improve the efficacy of scientific investigation. This package provides functions to link the FATES model to PEcAn. -Depends: - PEcAn.utils Imports: stringr, PEcAn.logger, PEcAn.remote, + PEcAn.utils, lubridate (>= 1.6.0), ncdf4 (>= 1.15) Suggests: diff --git a/models/fates/R/met2model.FATES.R b/models/fates/R/met2model.FATES.R index cc815974833..4f3b5937983 100644 --- a/models/fates/R/met2model.FATES.R +++ b/models/fates/R/met2model.FATES.R @@ -31,7 +31,7 @@ met2model.FATES <- function(in.path, in.prefix, outfolder, start_date, end_date, # close # defining temporal dimension needs to be figured out. If we configure FATES to use same tstep then we may not need to change dimensions - library(PEcAn.utils) + # library(PEcAn.utils) insert <- function(ncout, name, unit, data) { var <- ncdf4::ncvar_def(name = name, units = unit, dim = dim, missval = -6999, verbose = verbose) From 3a1e71e0e049532271cf95d2aeaf7b06cc8d759c Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 10:35:42 +0000 Subject: [PATCH 32/37] Some changes in the DESCRIPTION of jules package --- Makefile.depends | 2 +- models/jules/DESCRIPTION | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.depends b/Makefile.depends index 7828e0b819a..f9ce51a9dc7 100644 --- a/Makefile.depends +++ b/Makefile.depends @@ -31,7 +31,7 @@ $(call depends,models/dvmdostem): | .install/base/logger .install/base/utils $(call depends,models/ed): | .install/modules/data.atmosphere .install/modules/data.land .install/base/logger .install/base/remote .install/base/settings .install/base/utils $(call depends,models/fates): | .install/base/logger .install/base/remote .install/base/utils $(call depends,models/gday): | .install/base/utils .install/base/logger .install/base/remote -$(call depends,models/jules): | .install/base/utils .install/base/logger .install/base/remote +$(call depends,models/jules): | .install/modules/data.atmosphere .install/base/logger .install/base/remote .install/base/utils $(call depends,models/linkages): | .install/base/utils .install/modules/data.atmosphere .install/base/logger .install/base/remote $(call depends,models/lpjguess): | .install/base/utils .install/base/logger .install/base/remote $(call depends,models/maat): | .install/modules/data.atmosphere .install/base/logger .install/base/remote .install/base/settings .install/base/utils diff --git a/models/jules/DESCRIPTION b/models/jules/DESCRIPTION index 9b1aa5bdf55..cc780d30e56 100644 --- a/models/jules/DESCRIPTION +++ b/models/jules/DESCRIPTION @@ -9,13 +9,13 @@ Authors@R: c(person("Mike", "Dietze", role = c("aut", "cre"), Author: Mike Dietze Maintainer: Mike Dietze Description: This module provides functions to link the (JULES) to PEcAn. -Depends: - PEcAn.utils Imports: + PEcAn.data.atmosphere, PEcAn.logger, PEcAn.remote, + PEcAn.utils, lubridate (>= 1.6.0), - ncdf4 (>= 1.15), + ncdf4 (>= 1.15) Suggests: testthat (>= 1.0.2) SystemRequirements: JULES From 5612b9096265c500e78bc7983e894a41e99d0783 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Sun, 31 Jul 2022 11:10:21 +0000 Subject: [PATCH 33/37] updated DESCRIPTION of lpjguess --- Makefile.depends | 2 +- models/lpjguess/DESCRIPTION | 6 +++--- models/lpjguess/R/met2model.LPJGUESS.R | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.depends b/Makefile.depends index f9ce51a9dc7..bae1699cdef 100644 --- a/Makefile.depends +++ b/Makefile.depends @@ -33,7 +33,7 @@ $(call depends,models/fates): | .install/base/logger .install/base/remote .insta $(call depends,models/gday): | .install/base/utils .install/base/logger .install/base/remote $(call depends,models/jules): | .install/modules/data.atmosphere .install/base/logger .install/base/remote .install/base/utils $(call depends,models/linkages): | .install/base/utils .install/modules/data.atmosphere .install/base/logger .install/base/remote -$(call depends,models/lpjguess): | .install/base/utils .install/base/logger .install/base/remote +$(call depends,models/lpjguess): | .install/base/logger .install/base/remote .install/base/utils $(call depends,models/maat): | .install/modules/data.atmosphere .install/base/logger .install/base/remote .install/base/settings .install/base/utils $(call depends,models/maespa): | .install/modules/data.atmosphere .install/base/logger .install/base/remote .install/base/utils $(call depends,models/preles): | .install/base/utils .install/base/logger .install/modules/data.atmosphere .install/base/utils diff --git a/models/lpjguess/DESCRIPTION b/models/lpjguess/DESCRIPTION index 93870aa3852..c26970b8b8c 100644 --- a/models/lpjguess/DESCRIPTION +++ b/models/lpjguess/DESCRIPTION @@ -11,13 +11,13 @@ Authors@R: c(person("Istem", "Fer", role = c("aut", "cre"), Author: Istem Fer, Tony Gardella Maintainer: Istem Fer Description: This module provides functions to link LPJ-GUESS to PEcAn. -Depends: - PEcAn.utils Imports: PEcAn.logger, PEcAn.remote, + PEcAn.utils, lubridate (>= 1.6.0), - ncdf4 (>= 1.15) + ncdf4 (>= 1.15), + tibble Suggests: testthat (>= 1.0.2) SystemRequirements: LPJ-GUESS model diff --git a/models/lpjguess/R/met2model.LPJGUESS.R b/models/lpjguess/R/met2model.LPJGUESS.R index f4eb3383d8f..75cce48421e 100644 --- a/models/lpjguess/R/met2model.LPJGUESS.R +++ b/models/lpjguess/R/met2model.LPJGUESS.R @@ -29,7 +29,7 @@ met2model.LPJGUESS <- function(in.path, in.prefix, outfolder, start_date, end_date, overwrite = FALSE, verbose = FALSE, ...) { - library(PEcAn.utils) + # library(PEcAn.utils) print("START met2model.LPJGUESS") start_date <- as.POSIXlt(start_date, tz = "UTC") From 9f41042b988bbb735dd7ca027190421f4f63efbd Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Mon, 1 Aug 2022 10:51:51 +0530 Subject: [PATCH 34/37] Update models/fates/R/met2model.FATES.R Co-authored-by: Chris Black --- models/fates/R/met2model.FATES.R | 1 - 1 file changed, 1 deletion(-) diff --git a/models/fates/R/met2model.FATES.R b/models/fates/R/met2model.FATES.R index 4f3b5937983..df232462351 100644 --- a/models/fates/R/met2model.FATES.R +++ b/models/fates/R/met2model.FATES.R @@ -31,7 +31,6 @@ met2model.FATES <- function(in.path, in.prefix, outfolder, start_date, end_date, # close # defining temporal dimension needs to be figured out. If we configure FATES to use same tstep then we may not need to change dimensions - # library(PEcAn.utils) insert <- function(ncout, name, unit, data) { var <- ncdf4::ncvar_def(name = name, units = unit, dim = dim, missval = -6999, verbose = verbose) From ddf96d5faad356bb288113586f31aae75ecc530b Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Mon, 1 Aug 2022 10:52:03 +0530 Subject: [PATCH 35/37] Update models/lpjguess/R/met2model.LPJGUESS.R Co-authored-by: Chris Black --- models/lpjguess/R/met2model.LPJGUESS.R | 1 - 1 file changed, 1 deletion(-) diff --git a/models/lpjguess/R/met2model.LPJGUESS.R b/models/lpjguess/R/met2model.LPJGUESS.R index 75cce48421e..9b05a54db8f 100644 --- a/models/lpjguess/R/met2model.LPJGUESS.R +++ b/models/lpjguess/R/met2model.LPJGUESS.R @@ -29,7 +29,6 @@ met2model.LPJGUESS <- function(in.path, in.prefix, outfolder, start_date, end_date, overwrite = FALSE, verbose = FALSE, ...) { - # library(PEcAn.utils) print("START met2model.LPJGUESS") start_date <- as.POSIXlt(start_date, tz = "UTC") From 097e4b40ae22ce52d60a4427d9690e198d29eea4 Mon Sep 17 00:00:00 2001 From: Tanishq Jain Date: Mon, 1 Aug 2022 16:55:29 +0000 Subject: [PATCH 36/37] updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d279686163..7b3a4ba26e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ We are slowly change the license from NCSA opensource to BSD-3 to help with publ - when specifying diferent rstudio user, dev setup would mount pecan folder in wrong path. - Code cleanup in PEcAn.MA to protect against global namespace pollution (#2965, #2973; @nanu1605) - Fixed vignettes and cleaned up internal warnings in PEcAn.DB (#2966, #2971; @nanu1605). +- replaced udunits2 form all PEcAn as it was an orphaned package (#2989; @nanu1605) ### Changed From c1d07ce05ea068a4d96137656a3ffa733f99d9a4 Mon Sep 17 00:00:00 2001 From: Tanishq Jain <83662210+nanu1605@users.noreply.github.com> Date: Mon, 1 Aug 2022 23:55:24 +0530 Subject: [PATCH 37/37] Update CHANGELOG.md Co-authored-by: Chris Black --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3a4ba26e6..c70c3a64453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,11 @@ We are slowly change the license from NCSA opensource to BSD-3 to help with publ - when specifying diferent rstudio user, dev setup would mount pecan folder in wrong path. - Code cleanup in PEcAn.MA to protect against global namespace pollution (#2965, #2973; @nanu1605) - Fixed vignettes and cleaned up internal warnings in PEcAn.DB (#2966, #2971; @nanu1605). -- replaced udunits2 form all PEcAn as it was an orphaned package (#2989; @nanu1605) +- Updated unit conversions throughout PEcAn to use the `units` R package + instead of the unmaintained `udunits2`. + Note that both `units` and `udunits2` interface with the same underlying + compiled code, so the `udunits2` *system library* is still required. + (#2989; @nanu1605) ### Changed