-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
I am trying to run a Bayesian metabolism model using a 15-minute time series collected over 600 days from May 2023 to January 2025. When I attempt to run the model with the complete time series, I encounter the following error after a while (I'm not quite sure how to interpret it):
Error in conquerList(results, naming = data.frame(year = data2[!duplicated(ids), : length(u1) == s1 * s2 is not TRUE
However, if I run the model excluding December 31, 2024, it runs successfully. Why can't the model handle the inclusion of December 31, 2024?
2024 was a leap year...
library(tidyverse)
library(dataRetrieval)
library(LakeMetabolizer)
library(streamMetabolizer) # to get irr estimates
library(forecastML) # for making time series evenly spaced
# 1. Download time series ----
wq_data <- readNWISuv(
siteNumbers = "01670144", # Red House
parameterCd = c("00010", "00300"), # 00010 = Wtemp (C), 00300 = DO (mgL)
tz = "America/New_York"
) |>
renameNWISColumns() |>
mutate(
k.gas = 0.55,
z.mix = 1.8,
do.sat = LakeMetabolizer::o2.at.sat.base(Wtemp_Inst, 960),
solar.time = streamMetabolizer::calc_solar_time(dateTime, -77.9),
irr = streamMetabolizer::calc_light(solar.time, 38.1, -77.9)
) |>
rename(
datetime = dateTime,
wtr = Wtemp_Inst,
do.obs = DO_Inst
) |>
select(datetime, do.obs, do.sat, k.gas, z.mix, irr, wtr)
# 2. Make time series evenly spaced ----
wq_data <- forecastML::fill_gaps(
data = wq_data,
date_col = 1,
frequency = "15 min"
)
# 3. Remove incomplete days at beginning and end of time series ----
wq_data <- wq_data |>
mutate(date = date(datetime)) |>
filter(date >= as.Date("2023-05-19") & date <= as.Date("2025-01-13")) |>
select(!date)
# 4. Interpolate missing data ----
wq_data <- wq_data |>
arrange(datetime) |>
mutate(do.obs = zoo::na.approx(do.obs, na.rm = FALSE),
do.sat = zoo::na.approx(do.sat, na.rm = FALSE),
k.gas = zoo::na.approx(k.gas, na.rm = FALSE),
z.mix = zoo::na.approx(z.mix, na.rm = FALSE),
irr = zoo::na.approx(irr, na.rm = FALSE),
wtr = zoo::na.approx(wtr, na.rm = FALSE))
# 5. Run bayesian metabolism model (full time series; results in error) ----
metab <- LakeMetabolizer::metab(wq_data, "bayesian", lake.lat = 38.1)
# Error in conquerList(results, naming = data.frame(year = data2[!duplicated(ids), :
# length(u1) == s1 * s2 is not TRUE
# 6. Run subset bayesian metabolism model (excludes 2024-12-31; runs without error) ----
subset_dat <- wq_data |>
mutate(date = date(datetime)) |>
filter(!date == as.Date("2024-12-31")) |>
select(!date)
subset_metab <- LakeMetabolizer::metab(subset_dat, "bayesian", lake.lat = 38.1)
Metadata
Metadata
Assignees
Labels
No labels