DOI-USGS / streamMetabolizer

streamMetabolizer uses inverse modeling to estimate aquatic metabolism (photosynthesis and respiration) from time series data on dissolved oxygen, water temperature, depth, and light.
http://usgs-r.github.io/streamMetabolizer/
Other
37 stars 22 forks source link

calc_light_merged throws deprecated error #434

Open spencer-tassone opened 1 day ago

spencer-tassone commented 1 day ago

Brief problem description

I am trying to use the calc_light_merged function to model PAR based on observed PAR and the smoothed PAR produced with calc_light. However, the calc_light_merged function produces an error caused by a function that is deprecated in dplyr (rename_vars). Is there a work around for this issue?

# 1. Load libraries ----
library(tidyverse)
library(nasapower)
library(streamMetabolizer)

# 2. Download shortwave radiation from NASA POWER ----
nasa_par <- get_power(
  community = 'ag',
  pars = c('ALLSKY_SFC_PAR_TOT'), # All Sky Surface PAR Total (W/m^2) 
  temporal_api = 'hourly',
  lonlat = c(-78.6, 38.7),
  dates = '2010-09-19')

# 3. Some data wrangling to create the 2-column data frame needed for calc_light_merged ----
nasa_par_df <- nasa_par %>%
  mutate(dateTime = make_datetime(year = YEAR,
                                  month = MO,
                                  day = DY,
                                  hour = HR),
         solar.time = calc_solar_time(dateTime, -78.6), # throws a warning but still works
         light = convert_SW_to_PAR(ALLSKY_SFC_PAR_TOT)) %>% 
  select(solar.time, light) %>% 
  data.frame()
#> Warning: There was 1 warning in `mutate()`.
#> ℹ In argument: `solar.time = calc_solar_time(dateTime, -78.6)`.
#> Caused by warning in `lookup_timezone()`:
#> ! Google timezone lookup now requires an API key; see http://g.co/dev/maps-no-account or provide the timezone

max_PAR_value <- max(nasa_par_df$light, na.rm = TRUE)

# 4. Apply calc_light_merged ----
light_mod <- nasa_par_df %>%
  mutate(light = calc_light_merged(PAR.obs = nasa_par_df,
                                   solar.time = solar.time,
                                   latitude = 38.7,
                                   longitude = -78.6,
                                   max.PAR = max_PAR_value))
#> Error in `mutate()`:
#> ℹ In argument: `light = calc_light_merged(...)`.
#> Caused by error:
#> ! error in evaluating the argument 'object' in selecting a method for function 'deunitted': `rename_vars()` was deprecated in dplyr 0.8.4 and is now defunct.
#> ℹ Please use `tidyselect::vars_rename()` instead.

Created on 2024-10-22 with reprex v2.1.1

devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14 ucrt)
#>  os       Windows 11 x64 (build 22631)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       America/New_York
#>  date     2024-10-22
#>  pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cachem        1.1.0   2024-05-16 [1] CRAN (R 4.4.1)
#>  cli           3.6.3   2024-06-21 [1] CRAN (R 4.4.1)
#>  devtools      2.4.5   2022-10-11 [1] CRAN (R 4.4.1)
#>  digest        0.6.36  2024-06-23 [1] CRAN (R 4.4.1)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.4.1)
#>  evaluate      0.24.0  2024-06-10 [1] CRAN (R 4.4.1)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.1)
#>  fs            1.6.4   2024-04-25 [1] CRAN (R 4.4.1)
#>  glue          1.7.0   2024-01-09 [1] CRAN (R 4.4.1)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1)
#>  htmlwidgets   1.6.4   2023-12-06 [1] CRAN (R 4.4.1)
#>  httpuv        1.6.15  2024-03-26 [1] CRAN (R 4.4.1)
#>  knitr         1.48    2024-07-07 [1] CRAN (R 4.4.1)
#>  later         1.3.2   2023-12-06 [1] CRAN (R 4.4.1)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.1)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.4.1)
#>  memoise       2.0.1   2021-11-26 [1] CRAN (R 4.4.1)
#>  mime          0.12    2021-09-28 [1] CRAN (R 4.4.0)
#>  miniUI        0.1.1.1 2018-05-18 [1] CRAN (R 4.4.1)
#>  pkgbuild      1.4.4   2024-03-17 [1] CRAN (R 4.4.1)
#>  pkgload       1.4.0   2024-06-28 [1] CRAN (R 4.4.1)
#>  profvis       0.3.8   2023-05-02 [1] CRAN (R 4.4.1)
#>  promises      1.3.0   2024-04-05 [1] CRAN (R 4.4.1)
#>  purrr         1.0.2   2023-08-10 [1] CRAN (R 4.4.1)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.4.1)
#>  Rcpp          1.0.12  2024-01-09 [1] CRAN (R 4.4.1)
#>  remotes       2.5.0   2024-03-17 [1] CRAN (R 4.4.1)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.4.1)
#>  rlang         1.1.4   2024-06-04 [1] CRAN (R 4.4.1)
#>  rmarkdown     2.27    2024-05-17 [1] CRAN (R 4.4.1)
#>  rstudioapi    0.16.0  2024-03-24 [1] CRAN (R 4.4.1)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.4.1)
#>  shiny         1.8.1.1 2024-04-02 [1] CRAN (R 4.4.1)
#>  stringi       1.8.4   2024-05-06 [1] CRAN (R 4.4.0)
#>  stringr       1.5.1   2023-11-14 [1] CRAN (R 4.4.1)
#>  urlchecker    1.0.1   2021-11-30 [1] CRAN (R 4.4.1)
#>  usethis       2.2.3   2024-02-19 [1] CRAN (R 4.4.1)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.4.1)
#>  withr         3.0.0   2024-01-16 [1] CRAN (R 4.4.1)
#>  xfun          0.45    2024-06-16 [1] CRAN (R 4.4.1)
#>  xtable        1.8-4   2019-04-21 [1] CRAN (R 4.4.1)
#>  yaml          2.3.9   2024-07-05 [1] CRAN (R 4.4.1)
#> 
#>  [1] C:/Users/stassone/AppData/Local/Programs/R/R-4.4.1/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Created on 2024-10-22 with reprex v2.1.1

robohall commented 13 hours ago

Spencer,

If it were me I would simply use the calc_light function. We are working on a paper that shows that using such idealized light is not much of a problem. Then when you go to predict that day’s GPP, use the —real-- light from NASA. This way you also main independence of not using light to predict something estimated from the same light.

As for the error. 1. Try outside of a big tidyverse function to make sure you get the error outside of mutate. Then if brave you can make the recommended fix in the calc_light_merged function, see if now works, and get a pull request.

But I would use calc_light.

Bob

On Oct 22, 2024, at 1:38 PM, Spencer Tassone, Ph.D. @.***> wrote:

Brief problem description

I am trying to use the calc_light_merged function to model PAR based on observed PAR and the smoothed PAR produced with calc_light. However, the calc_light_merged function produces an error caused by a function that is deprecated in dplyr (rename_vars). Is there a work around for this issue?

1. Load libraries ----

library(tidyverse) library(nasapower) library(streamMetabolizer)

2. Download shortwave radiation from NASA POWER ----

nasa_par <- get_power( community = 'ag', pars = c('ALLSKY_SFC_PAR_TOT'), # All Sky Surface PAR Total (W/m^2) temporal_api = 'hourly', lonlat = c(-78.6, 38.7), dates = '2010-09-19')

3. Some data wrangling to create the 2-column data frame needed for calc_light_merged ----

nasa_par_df <- nasa_par %>% mutate(dateTime = make_datetime(year = YEAR, month = MO, day = DY, hour = HR), solar.time = calc_solar_time(dateTime, -78.6), # throws a warning but still works light = convert_SW_to_PAR(ALLSKY_SFC_PAR_TOT)) %>% select(solar.time, light) %>% data.frame()

> Warning: There was 1 warning in mutate().

> ℹ In argument: solar.time = calc_solar_time(dateTime, -78.6).

> Caused by warning in lookup_timezone():

> ! Google timezone lookup now requires an API key; see http://g.co/dev/maps-no-account or provide the timezone

max_PAR_value <- max(nasa_par_df$light, na.rm = TRUE)

4. Apply calc_light_merged ----

light_mod <- nasa_par_df %>% mutate(light = calc_light_merged(PAR.obs = nasa_par_df, solar.time = solar.time, latitude = 38.7, longitude = -78.6, max.PAR = max_PAR_value))

> Error in mutate():

> ℹ In argument: light = calc_light_merged(...).

> Caused by error:

> ! error in evaluating the argument 'object' in selecting a method for function 'deunitted': rename_vars() was deprecated in dplyr 0.8.4 and is now defunct.

> ℹ Please use tidyselect::vars_rename() instead.

Created on 2024-10-22 with reprex v2.1.1 https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Freprex.tidyverse.org%2F&data=05%7C02%7Cbob.hall%40flbs.umt.edu%7Cca0d90c1329a4e105ce708dcf2d12915%7C68407ce503da49ffaf0a724be0d37c9d%7C0%7C0%7C638652227355026839%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=H5Jihx58yr01SSKzpJjBwV%2B84YPjBcbAoiVlDQoNXFw%3D&reserved=0 devtools::session_info()

> ─ Session info ───────────────────────────────────────────────────────────────

> setting value

> version R version 4.4.1 (2024-06-14 ucrt)

> os Windows 11 x64 (build 22631)

> system x86_64, mingw32

> ui RTerm

> language (EN)

> collate English_United States.utf8

> ctype English_United States.utf8

> tz America/New_York

> date 2024-10-22

> pandoc 3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

>

> ─ Packages ───────────────────────────────────────────────────────────────────

> package * version date (UTC) lib source

> cachem 1.1.0 2024-05-16 [1] CRAN (R 4.4.1)

> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.1)

> devtools 2.4.5 2022-10-11 [1] CRAN (R 4.4.1)

> digest 0.6.36 2024-06-23 [1] CRAN (R 4.4.1)

> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.4.1)

> evaluate 0.24.0 2024-06-10 [1] CRAN (R 4.4.1)

> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.1)

> fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.1)

> glue 1.7.0 2024-01-09 [1] CRAN (R 4.4.1)

> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1)

> htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.4.1)

> httpuv 1.6.15 2024-03-26 [1] CRAN (R 4.4.1)

> knitr 1.48 2024-07-07 [1] CRAN (R 4.4.1)

> later 1.3.2 2023-12-06 [1] CRAN (R 4.4.1)

> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.1)

> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.1)

> memoise 2.0.1 2021-11-26 [1] CRAN (R 4.4.1)

> mime 0.12 2021-09-28 [1] CRAN (R 4.4.0)

> miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.4.1)

> pkgbuild 1.4.4 2024-03-17 [1] CRAN (R 4.4.1)

> pkgload 1.4.0 2024-06-28 [1] CRAN (R 4.4.1)

> profvis 0.3.8 2023-05-02 [1] CRAN (R 4.4.1)

> promises 1.3.0 2024-04-05 [1] CRAN (R 4.4.1)

> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.4.1)

> R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.1)

> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.4.1)

> remotes 2.5.0 2024-03-17 [1] CRAN (R 4.4.1)

> reprex 2.1.1 2024-07-06 [1] CRAN (R 4.4.1)

> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.1)

> rmarkdown 2.27 2024-05-17 [1] CRAN (R 4.4.1)

> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.4.1)

> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.1)

> shiny 1.8.1.1 2024-04-02 [1] CRAN (R 4.4.1)

> stringi 1.8.4 2024-05-06 [1] CRAN (R 4.4.0)

> stringr 1.5.1 2023-11-14 [1] CRAN (R 4.4.1)

> urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.4.1)

> usethis 2.2.3 2024-02-19 [1] CRAN (R 4.4.1)

> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.1)

> withr 3.0.0 2024-01-16 [1] CRAN (R 4.4.1)

> xfun 0.45 2024-06-16 [1] CRAN (R 4.4.1)

> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.4.1)

> yaml 2.3.9 2024-07-05 [1] CRAN (R 4.4.1)

>

> [1] C:/Users/stassone/AppData/Local/Programs/R/R-4.4.1/library

>

> ──────────────────────────────────────────────────────────────────────────────

Created on 2024-10-22 with reprex v2.1.1 https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Freprex.tidyverse.org%2F&data=05%7C02%7Cbob.hall%40flbs.umt.edu%7Cca0d90c1329a4e105ce708dcf2d12915%7C68407ce503da49ffaf0a724be0d37c9d%7C0%7C0%7C638652227355047958%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=stjile04PdssIz0zXqQgmp%2FR90VXi6MbqR3%2Fgy7GOCg%3D&reserved=0 — Reply to this email directly, view it on GitHub https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FDOI-USGS%2FstreamMetabolizer%2Fissues%2F434&data=05%7C02%7Cbob.hall%40flbs.umt.edu%7Cca0d90c1329a4e105ce708dcf2d12915%7C68407ce503da49ffaf0a724be0d37c9d%7C0%7C0%7C638652227355058500%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=xy%2B%2Bkxb%2ByVOTeLRYclUiOdE%2BCY4Xw3ZSlXTyigJtWgo%3D&reserved=0, or unsubscribe https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAC4CU5QXFK2N7LKK3SQIILLZ42SUXAVCNFSM6AAAAABQNHPLZWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGYYDMMZRG43DQNI&data=05%7C02%7Cbob.hall%40flbs.umt.edu%7Cca0d90c1329a4e105ce708dcf2d12915%7C68407ce503da49ffaf0a724be0d37c9d%7C0%7C0%7C638652227355068586%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=mlyn%2F4yZXQTT%2Bfm7DDKyuPaEniGKHUhV0dM00OuqcDc%3D&reserved=0. You are receiving this because you are subscribed to this thread.