Skip to content
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

coops_search() time_zone weirdness? #184

Closed
drf5n opened this issue Dec 16, 2016 · 9 comments
Closed

coops_search() time_zone weirdness? #184

drf5n opened this issue Dec 16, 2016 · 9 comments
Assignees
Labels
Milestone

Comments

@drf5n
Copy link

drf5n commented Dec 16, 2016

> ss= coops_search(begin_date=20161210, end_date=20161210,station_name=8638610,product='water_level',datum='NAVD',time_zone='lst')
> ss$data$t[2]
[1] "2016-12-10 00:06:00 EST"
> ss$data$v[2]
[1] -0.453
> ss= coops_search(begin_date=20161210, end_date=20161210,station_name=8638610,product='water_level',datum='NAVD',time_zone='gmt')
> ss$data$t[2]
[1] "2016-12-10 00:06:00 EST"
> ss$data$v[2]
[1] 0.019
> 

These are consistent with what you see at https://tidesandcurrents.noaa.gov/waterlevels.html?id=8638610&units=metric&bdate=20161210&edate=20161210&timezone=GMT&datum=NAVD&interval=6&action=data

I would expect the resultant values to be the same if the times are the same, but the vaues differ while the time remains the same.

If I unclass the resultant time, I see that the timezone attribute exists but is not set:

> unclass(ss$data$t[2])
[1] 1481346360
attr(,"tzone")
[1] ""

Here, I'd expect the attribute to be set appropriately, as GMT, and EST or EST/EDT for the Sewells Point Virginia station.

How should one use the resultant data to get consistent times?

@sckott
Copy link
Contributor

sckott commented Dec 16, 2016

thanks for the issue @drf5n

I'll have a look

@drf5n
Copy link
Author

drf5n commented Dec 17, 2016

My workaround right now is to set the timezone to GMT, do the request, then assign GMT to the returned data:

Sys.setenv('TZ'='GMT')  # make sure the system time attribute is set.
Sys.timezone()
ss= coops_search(begin_date=20161210, end_date=20161210,station_name=8638610,product='water_level',datum='NAVD',time_zone='gmt')
attr(ss$data$t,'tzone')<-'GMT'  # fix up the time attribute

ss$data$t[2]
# [1] "2016-12-10 00:06:00 GMT"
Sys.setenv('TZ'='EST')  # change TZ to see if it affects the data... nope:
ss$data$t[2]
# [1] "2016-12-10 00:06:00 GMT"

@sckott sckott self-assigned this Jan 13, 2017
@sckott sckott added the bug label Jan 13, 2017
@sckott sckott added this to the v0.7 milestone Jan 13, 2017
@sckott
Copy link
Contributor

sckott commented Jan 13, 2017

one problem is that if we need to use LST, that's the local time zone of the station, but they don't give us the time zone of the station in the response. so we have to get it somehow,

then i can correct the date values given back

@sckott
Copy link
Contributor

sckott commented Jan 13, 2017

@drf5n do you ever use lst_ldt?

@sckott
Copy link
Contributor

sckott commented Jan 13, 2017

try again after reinstalling

devtools::install_github("ropensci/rnoaa")
library(rnoaa)
ss <- coops_search(begin_date=20161210, end_date=20161210,station_name=8638610,product='water_level',datum='NAVD',time_zone='lst')
ss$data$t[2]
#> [1] "2016-12-10 00:06:00 EST"
rr <- coops_search(begin_date=20161210, end_date=20161210,station_name=8638610,product='water_level',datum='NAVD',time_zone='gmt')
rr$data$t[2]
#> [1] "2016-12-10 00:06:00 GMT"
head(ss$data, n = 3)
#>                     t      v     s       f q
#> 1 2016-12-10 00:00:00 -0.458 0.005 0,0,0,0 v
#> 2 2016-12-10 00:06:00 -0.453 0.005 0,0,0,0 v
#> 3 2016-12-10 00:12:00 -0.444 0.004 0,0,0,0 v
rr$data[51:53,]
#>                      t      v     s       f q
#> 51 2016-12-10 05:00:00 -0.458 0.005 0,0,0,0 v
#> 52 2016-12-10 05:06:00 -0.453 0.005 0,0,0,0 v
#> 53 2016-12-10 05:12:00 -0.444 0.004 0,0,0,0 v
# convert
ss$data$t <- as.POSIXlt(ss$data$t, tz = "GMT")
head(ss$data, n = 3)
#>                     t      v     s       f q
#> 1 2016-12-10 05:00:00 -0.458 0.005 0,0,0,0 v
#> 2 2016-12-10 05:06:00 -0.453 0.005 0,0,0,0 v
#> 3 2016-12-10 05:12:00 -0.444 0.004 0,0,0,0 v
rr$data[51:53,]
#>                      t      v     s       f q
#> 51 2016-12-10 05:00:00 -0.458 0.005 0,0,0,0 v
#> 52 2016-12-10 05:06:00 -0.453 0.005 0,0,0,0 v
#> 53 2016-12-10 05:12:00 -0.444 0.004 0,0,0,0 v

@sckott
Copy link
Contributor

sckott commented Jan 13, 2017

changes in ddad05b

@drf5n
Copy link
Author

drf5n commented Jan 14, 2017

Re. LST_LDT, no, I try to always use UTC.

This fix works for me. Thanks.

@sckott
Copy link
Contributor

sckott commented Jan 14, 2017

Glad it works

@sckott sckott modified the milestones: v0.6.8, v0.7 Jan 18, 2017
@sckott
Copy link
Contributor

sckott commented Feb 16, 2017

done

@sckott sckott closed this as completed Feb 16, 2017
@sckott sckott modified the milestones: v0.6.8, v0.7 Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants