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

Best way to get prism data for a single point #82

Closed BaxW closed 9 months ago

BaxW commented 9 months ago

Hi, thanks for all your work on this package. I've used it with great success in the past, but now I'm trying to run old code with the newer version and running into issues.

for example:

with climateR_0.1.0 running on R version 3.5.1 I would do something like:

pt  <- st_point(c(-72.4, 41.5)) %>% 
  st_sfc(crs = 4326) %>% 
  st_sf()

pt_prism <- getPRISM(pt, param = c('tmax', 'tmin'), startDate = "2022-1-1", endDate = "2022-6-1") 

but with climateR_0.3.1.4 running on R version 4.1.2

pt  <- st_point(c(-72.4, 41.5)) %>% 
  st_sfc(crs = 4326) %>% 
  st_sf()

pt_prism <- getPRISM(pt, varname = c('tmax', 'tmin'), startDate = "2022-1-1", endDate = "2022-6-1") 

returns an empty dataframe. (note that I changed 'param' to 'varname' in the getPRISM() call)

Can you help me figure out the best way to download prism data for a given point with the new version? Thanks!!

mikejohnson51 commented 9 months ago

Thanks @BaxW! It looks like we had a small bug in the catalog generation. It should be resolved now.

library(sf);library(climateR)
#> Linking to GEOS 3.12.0, GDAL 3.7.1, PROJ 9.3.0; sf_use_s2() is TRUE

pt  <- st_point(c(-72.4, 41.5)) %>% 
  st_sfc(crs = 4326) %>% 
  st_sf()

(pt_prism <- getPRISM(AOI = pt, 
                      varname = c('tmax', 'tmin'), 
                      startDate = "2022-01-01", 
                      endDate = "2022-01-05") )
#>         date    tmax    tmin
#> 1 2022-01-01  8.6426  5.3327
#> 2 2022-01-02 11.5295  7.8424
#> 3 2022-01-03 11.1797 -1.8261
#> 4 2022-01-04 -1.9251 -9.4544
#> 5 2022-01-05  1.2640 -9.5007

Created on 2023-10-05 by the reprex package (v2.0.1)

I think there are some ways to speed up multi-variable daily PRISM requests too and I will look into that!

Mike

BaxW commented 9 months ago

Yes! Working now. Thanks so much