PecanProject / pecan

The Predictive Ecosystem Analyzer (PEcAn) is an integrated ecological bioinformatics toolbox.
www.pecanproject.org
Other
202 stars 233 forks source link

`load.cfmet` end date is too strict? #2274

Open ashiklom opened 5 years ago

ashiklom commented 5 years ago

Bug Description

Based on this conversation on PR #2273.

Basically, data.atmosphere::load.cfmet throws an error like the following when given CRUNCEP input (this case is thrown from met2model.BIOCRO).

test.met2model.R:15: error: Met conversion runs without error
run end date 2000-12-31 23:59:59 after met data ends 2000-12-31 21:00:00
1: met2model.BIOCRO(in.path, in.prefix, outfolder, lat = 45.25, lon = -84.75, start_date = start_date, 
       end_date = end_date) at /Users/shik544/Box Sync/Projects/pecan_project/pecan/models/biocro/tests/testthat/test.met2model.R:15
2: PEcAn.data.atmosphere::load.cfmet(met.nc, lat = lat, lon = lon, start.date = yrstart, 
       end.date = yrend) at /Users/shik544/Box Sync/Projects/pecan_project/pecan/models/biocro/R/met2model.BIOCRO.R:71
3: PEcAn.logger::logger.severe("run end date", end.date, "after met data ends", max(all.dates$date))
4: stop(paste(msg, ...))

The issue is that this code block (load.cfmet) expects the end of the year to be 23:59 on December 31, but the last data point for 3-hourly met like CRUNCEP is at 21:00.

To Reproduce

Remove the skip statement from test.met2model.R for BIOCRO (once #2273 is merged); then, run devtools::test("models/biocro").

ashiklom commented 5 years ago

Possibly related to #1343, which was closed by @dlebauer without comment.

infotroph commented 5 years ago

@ashiklom I mean, @dlebauer closed it by merging my PR that claimed it was fixed, so I don't think this is too heavily on him.

infotroph commented 5 years ago

Proposed resolution:

delta <- stats::median(diff(all.dates$date), na.rm = TRUE)
...
if (end.date > (max(all.dates$date) + delta)) { ...

...our met files are all regularly spaced modulo missing data, yeah?

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 365 days with no activity.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 365 days with no activity.