mikejohnson51 / climateR

An R 📦 for getting point and gridded climate data by AOI
https://mikejohnson51.github.io/climateR/
MIT License
165 stars 40 forks source link

Daymet return data date range is off by 1 #77

Closed anguswg-ucsb closed 11 months ago

anguswg-ucsb commented 11 months ago

It looks like getDaymet() returns data that is off by one for any given date range. If this is the expected behavior, this issue can be closed. Here is an example of what I am describing:

library(AOI)
library(terra)
library(climateR)

aoi <- AOI::aoi_get(state = "CA", county = "San Luis Obispo")

# get Daymet precipitation data for "2018-01-01" - "2018-01-02"
daymet <- climateR::getDaymet(
                    AOI       = aoi,
                    varname   = "prcp",
                    startDate = "2018-01-01",
                    endDate   = "2018-01-02",
                    verbose   = TRUE
                    )

# returns Daymet precipitation data for "2017-12-31" and "2018-01-01"

# I would expect the function to return 2 SpatRaster layers for "2018-01-01" and "2018-01-02" 
# (given these are the startDate/endDate given to the function) 
mikejohnson51 commented 11 months ago

with new code:

library(climateR)

daymet <- climateR::getDaymet(
  AOI       = AOI::aoi_get(state = "CA", county = "San Luis Obispo"),
  varname   = "tmax",
  startDate = "2018-01-01",
  endDate   = "2018-01-02",
  verbose   = TRUE
)
#> source:   https://thredds.daac.ornl.gov/thredds/dodsC/daymet-v4-agg/na... 
#> varname(s):
#>    > tmax [degrees C] (daily maximum temperature)
#> ==================================================
#> diminsions:  149, 135, 2 (names: x,y,time)
#> resolution:  1000, 1000, 1 days
#> extent:      -1843750, -1694750, -608500, -473500 (xmin, xmax, ymin, ymax)
#> crs:         +proj=lcc +lat_1=25 +lat_2=60 +x_0=0 +y_0=0 +units...
#> time:        2018-01-01 12:00:00 to 2018-01-02 12:00:00
#> ==================================================
#> values: 40,230 (vars*X*Y*T)

terra::plot(daymet[[1]])

Created on 2023-08-21 by the reprex package (v2.0.1)

mikejohnson51 commented 11 months ago

@anguswg-ucsb please see these last changes and if they need to be addressed in climatePy. Thanks!