DOI-USGS / dataRetrieval

This R package is designed to obtain USGS or EPA water quality sample data, streamflow data, and metadata directly from web services.
https://doi-usgs.github.io/dataRetrieval/
Other
259 stars 84 forks source link

tz issue with 2.7.7 readNWISgwl #566

Closed jmusgs closed 3 years ago

jmusgs commented 3 years ago

This version does not convert lev_dateTime to the time zone specified.

> gwl <-readNWISgwl("413535072253701",
   startDate = "2021-01-01",
   endDate = Sys.Date(),
   parameterCd = "72019",
   convertType = TRUE,
   tz = "America/New_York" )
> head(gwl)
  agency_cd         site_no site_tp_cd     lev_dt lev_tm lev_tz_cd lev_va sl_lev_va sl_datum_cd lev_status_cd lev_agency_cd lev_dt_acy_cd lev_acy_cd lev_src_cd lev_meth_cd lev_age_cd parameter_cd        lev_dateTime
1      USGS 413535072253701         GW 2021-01-25  18:56       UTC   2.49        NA        <NA>             1          USGS             m       <NA>          S           V          P        72019 2021-01-25 18:56:00
2      USGS 413535072253701         GW 2021-02-23  19:57       UTC   2.74        NA        <NA>             1          USGS             m       <NA>          S           V          P        72019 2021-02-23 19:57:00
3      USGS 413535072253701         GW 2021-03-09  14:51       UTC   2.67        NA        <NA>             1          USGS             m       <NA>          S           V          P        72019 2021-03-09 14:51:00
4      USGS 413535072253701         GW 2021-03-22  13:06       UTC   2.68        NA        <NA>             1          USGS             m       <NA>          S           V          P        72019 2021-03-22 13:06:00
ldecicco-USGS commented 3 years ago

Try this update:

remotes::install_github("USGS-R/dataRetrieval")
gwl <-readNWISgwl("413535072253701",
                  startDate = "2021-01-01",
                  endDate = Sys.Date(),
                  parameterCd = "72019",
                  convertType = TRUE,
                  tz = "America/New_York" )
gwl$lev_dateTime[1]
[1] "2021-01-25 13:56:00 EST"
gwl
  agency_cd         site_no site_tp_cd     lev_dt lev_tm lev_tz_cd_reported
1      USGS 413535072253701         GW 2021-01-25  18:56                UTC
2      USGS 413535072253701         GW 2021-02-23  19:57                UTC
3      USGS 413535072253701         GW 2021-03-09  14:51                UTC
4      USGS 413535072253701         GW 2021-03-22  13:06                UTC
  lev_va sl_lev_va sl_datum_cd lev_status_cd lev_agency_cd lev_dt_acy_cd
1   2.49        NA        <NA>             1          USGS             m
2   2.74        NA        <NA>             1          USGS             m
3   2.67        NA        <NA>             1          USGS             m
4   2.68        NA        <NA>             1          USGS             m
  lev_acy_cd lev_src_cd lev_meth_cd lev_age_cd parameter_cd        lev_dateTime
1       <NA>          S           V          P        72019 2021-01-25 13:56:00
2       <NA>          S           V          P        72019 2021-02-23 14:57:00
3       <NA>          S           V          P        72019 2021-03-09 09:51:00
4       <NA>          S           V          P        72019 2021-03-22 09:06:00
         lev_tz_cd
1 America/New_York
2 America/New_York
3 America/New_York
4 America/New_York

One thing that I know is confusing is the column "lev_tz_cd_reported"...that is what came back from the services (thus.."reported"). The "lev_tz_cd" is the time zone attribute associated with lev_dateTime. There's a ton of other date/time columns that get merged together. We wanted to retain the information that came back (so you can check how the date/time/tz looks compared to the merged dateTime column....but sometimes people get confused by the "tz_cd_reported" and the "tz_cd" columns.

jmusgs commented 3 years ago

ok, I think this works ok now. It does bother me that the system converts all things to UTC for reporting on the web. I guess I can still go back to AQuarius to get the original time code entered when the measurement was collected. It is clear that you always need to be checking times to make sure you are getting what you want. Thanks for following up on this.