mikejohnson51 / climateR

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

getBCCA and getLOCA date errors #8

Closed mbjoseph closed 5 years ago

mbjoseph commented 5 years ago

Hey @mikejohnson51 -- awesome package! I am running into some issues extracting BCCA and LOCA data. It looks like the date column from the dates object does not exist -- maybe because dates is a vector of dates, and not a data.frame?

library(climateR)
#> Loading required package: AOI
#> Loading required package: leaflet

getBCCA(getAOI(state = 'CO'),
        param = 'tmax',
        model = 'inmcm4',
        scenario = 'rcp45',
        startDate = '2030-10-29',
        endDate = '2030-12-29')
#> Error in dates$date: $ operator is invalid for atomic vectors

getLOCA(getAOI(state = 'CO'),
        param = 'tmax',
        model = 'ACCESS1-0',
        scenario = 'rcp45',
        startDate = '2030-10-29',
        endDate = '2030-12-29')
#> Error in dates$date: $ operator is invalid for atomic vectors

Created on 2019-08-12 by the reprex package (v0.3.0)

Possibly related, I'm noticing that the function calls to define.versions differ for MACA vs. BCCA and LOCA. MACA passes a data frame (https://github.com/mikejohnson51/climateR/blob/master/R/getMACA.R#L23), but BCCA and LOCA both pass vectors of dates (https://github.com/mikejohnson51/climateR/blob/master/R/getBCCA.R#L24 https://github.com/mikejohnson51/climateR/blob/master/R/getLOCA.R#L23).

Any help would be much appreciated!

mikejohnson51 commented 5 years ago

Hi Max,

Thanks for this - these were a casualty of not having any tests written to catch changes in URL creation :).

As you suspected, it was the related dates being passed!

It should be fixed in 89cecf3.

library(raster)
#> Loading required package: sp
library(climateR)
#> Loading required package: AOI
#> Loading required package: leaflet

bcca = getBCCA(AOI = getAOI(state = 'CO'),
        param = 'tmax',
        model = 'inmcm4',
        scenario = 'rcp45',
        startDate = '2030-10-29',
        endDate = '2030-12-29')

names(bcca)
#> [1] "inmcm4_r1i1p1_tasmax"
message(paste("This stack has", nlayers(bcca[[1]]), "layers with XY dims:", nrow(bcca[[1]]), ncol(bcca[[1]])))
#> This stack has 62 layers with XY dims: 36 59

loca = getLOCA(getAOI(state = 'CO'),
        param = 'tmax',
        model = 'ACCESS1-0',
        scenario = 'rcp45',
        startDate = '2030-10-29',
        endDate = '2030-12-29')

names(loca)
#> [1] "ACCESS1-0_tmax"
message(paste("This stack has", nlayers(loca[[1]]), "layers with XY dims:", nrow(loca[[1]]), ncol(loca[[1]])))
#> This stack has 62 layers with XY dims: 68 115

Created on 2019-08-12 by the reprex package (v0.3.0)

Please let me know if it works for you. FYI, you may need to update AOI due to a new error catch that checks if requested domains are within the model domains.

Thanks again,

Mike

mbjoseph commented 5 years ago

Great - thank you @mikejohnson51! I'm getting the expected results now. :+1: