-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for date formats, with conversion for POSIXlt #186
base: master
Are you sure you want to change the base?
Conversation
/document |
@WillemVervoort and @buzacott - does this look ok to you? I was unable to create a reproducible example that causes errors with POSIXct, so do let me know if you have one. Note that the checks are only run when a |
I can't fit anything with a POSIXct index. Does it also need to be coerced to library(hydromad)
data("Corin")
# Date
Corin = Corin[1:365,]
mod <- hydromad(DATA = Corin,
sma = 'gr4j',
routing = 'gr4jrouting')
fit <- fitByOptim(mod)
# Works
# POSIXlt
index(Corin) = as.POSIXlt(strftime(index(Corin)), tz='Australia/Queensland')
mod <- hydromad(DATA = Corin,
sma = 'gr4j',
routing = 'gr4jrouting')
fit <- fitByOptim(mod)
# Works
# POSIXct
index(Corin) = as.POSIXct(strftime(index(Corin)), tz='Australia/Queensland')
mod <- hydromad(DATA = Corin,
sma = 'gr4j',
routing = 'gr4jrouting')
fit <- fitByOptim(mod)
# Doesn't work, just hangs
# Try with hourly data
data(Wye)
class(index(Wye))
# [1] "POSIXct" "POSIXt"
Wye$E = 1 # add ET
mod <- hydromad(DATA = Wye,
sma = 'gr4j',
routing = 'gr4jrouting')
fit <- fitByOptim(mod)
# Doesn't work |
Thanks for the examples! index(Corin) = as.POSIXct(strftime(index(Corin)), tz='Australia/Queensland')
as.ts(head(Corin,n=2))
If instead, a zoo object is constructed without a frequency, it works: Corin=zoo(coredata(Corin),order.by=as.POSIXct(strftime(index(Corin)), tz='Australia/Queensland')) If I want to keep a zooreg object, I can also set the frequency correctly: index(Corin) = as.POSIXct(strftime(index(Corin)), tz='Australia/Queensland')
frequency(Corin)<-1/86400
as.ts(head(Corin,n=2)) If I convert to chron, a unit of 1 is a day, so the frequency of 1 is correct index(Corin)<-chron::as.chron(index(Corin))
as.numeric(head(index(Corin))) If I somehow got the frequency wrong with chron, I would again get the NA-filling behaviour: frequency(Corin)<-2
as.ts(head(Corin,n=2)) So what we have is a usability issue rather than a pure incompatibility with POSIXct. Corin <- as.zoo(Corin)
Corin = Corin[1:365,]
index(Corin) = as.POSIXct(strftime(index(Corin)), tz='Australia/Queensland')
as.ts(head(Corin,n=2)) Edit: the datasets in hydromad that are zooreg with incorrect frequencies obviously need to be changed regardless! |
Maybe a simple solution is to give a warning if (end-start)*frequency is more than e.g. 10% greater/smaller than the number of rows in the dataset. |
Also revisit error in nseStat, as described in merged PR: #187 (comment) |
It turns out chron conversion is only necessary for POSIXlt according to these tests, and conversion is therefore added to the hydromad constructor.
All Submissions:
Closes #31
Types of changes
Changes to Core Features: