mikejohnson51 / climateR

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

Not able to extract data using PRISM or Daymet #54

Closed alherca73 closed 1 year ago

alherca73 commented 2 years ago

Hello, I am a brand new user of climateR and while trying to extract time series for PRISM dataset (regardless of what parameter prcp, tmin, tmax):

Cal<-AOI::aoi_get(state = c("CA")) Ouput.PRISM<- getPRISM(AOI = Cal, param = c('tmax','tmin'), startDate = "2011-01-01", endDate = "2015-01-01")

I get the following error:

Spherical geometry (s2) switched off Spherical geometry (s2) switched on Error in dim(v) <- round(c(g$rows, g$cols, time)) : dims [product 82667328] do not match the length of object [56544]

An example trying to extract Daymet: Output.Dayment<- getDaymet(AOI = Cal, param = "prcp", startDate = "2011-01-01", endDate = "2015-01-01")

I get the error:

Spherical geometry (s2) switched off Spherical geometry (s2) switched on syntax error, unexpected $end, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: ^ syntax error, unexpected $end, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: ^ syntax error, unexpected $end, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: ^ syntax error, unexpected $end, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: ^ syntax error, unexpected $end, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR context: ^ Error in var[[i]] * scale_factor : non-numeric argument to binary operator

Any help will be much appreciated!

Thanks,

Alex

kaitlinperkins commented 2 years ago

Hi Alex,

I get the same error when attempting to import multi-day PRISM data with getPRISM using a shapefile for an AOI. I noticed that I can extract multi-day point data and single-day data over a region using a shapefile, but multiple days over a region produces the same error message you described above.

Did you ever reach resolution for this error?

Thanks,

Kate

mikejohnson51 commented 1 year ago

Hi @alherca73 and @kaitlinperkins,

Thanks for the issue and sorry for the delay! The package has been completely re-written to supply greater flexibility, more datasets, and easier use. In this example, both Dayment and PRISM work as expected. One note of caution with PRISM is that the server stores each day of data in a single file. So to extract it, the code will make a request for each per day.

When you make very large requests (e.g. many years) the odds of a server timeout is fairly large. In these cases I would make smaller requests and save the intermediary outputs. If you are able to do this I dont foresee any issues using these resources.

Example from above (with reduced dates for speed):

library(climateR)
#> Using GDAL version 3.6.0 which was retracted because it cannot write large GPKG files
library(AOI)
library(terra)
#> terra 1.7.9

Cal<-aoi_get(state = c("CA"))
Ouput.PRISM<- getPRISM(AOI = Cal, varname = c('tmax','tmin'),
                       startDate = "2011-01-01", endDate = "2011-02-01")

plot(Ouput.PRISM$tmax$`tmax_2011-01-01`)


plot(Ouput.PRISM$tmin$`tmin_2011-02-01`)


Output.Dayment<- getDaymet(AOI = Cal, varname = "prcp",
                          startDate = "2011-01-01", endDate = "2011-02-01")

plot(Output.Dayment$prcp_total[[6]])

Created on 2023-02-16 by the reprex package (v2.0.1)

I hope the package rewrite proves useful to you if you are still using it and pursuing simular research/data questions.

Mike