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

TerraClimate data before 1980 for African AOIs #39

Closed urskalbitzer closed 3 years ago

urskalbitzer commented 3 years ago

According to the TerraClimate webpage, this datasets goes back to 1958: http://www.climatologylab.org/terraclimate.html

However, if getTerraClim is called with a date before 1980 (at least for AOIs in Africa) I get an error.

Is this an issue with climateR, or are some areas just not covered for the time before 1970?

Thanks, Urs

library(AOI)
library(climateR)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
sf_use_s2(F) # Otherwise issue with getTerraClim function and aoi
#> Spherical geometry (s2) switched off

kenya = aoi_get(country = "Kenya")

# Works with 1985
tc = getTerraClim(kenya, param = "prcp", startDate = "1985-01-01")
rasterVis::levelplot(tc$terraclim_prcp)


# But not with 1975
tc = getTerraClim(kenya, param = "prcp", startDate = "1975-01-01")
#> Error in seq.int(0, to0 - from, by): wrong sign in 'by' argument

sf_use_s2(T)
#> Spherical geometry (s2) switched on

Created on 2021-07-04 by the reprex package (v2.0.0.9000)

mikejohnson51 commented 3 years ago

I am not getting the same error here, for reference is the following, uses the new s2 correction:

library(climateR)
library(AOI)

tc = aoi_get(country = "Kenya") %>% 
  getTerraClim(param = "prcp", 
               startDate = "1975-01-01",
               endDate = "1975-12-31")
#> Spherical geometry (s2) switched off
#> Spherical geometry (s2) switched on

raster::plot(tc$terraclim_prcp)

Created on 2021-07-04 by the reprex package (v2.0.0)

urskalbitzer commented 3 years ago

Same as with the other issue (https://github.com/mikejohnson51/climateR/issues/38), the code works fine on my computer at work but not at home. I guess this is also an issue with package-updates and I will have a look at different version numbers later today.

Btw: if I use a longer period, e.g., from 1975 - 1990, the function only downloaded the data from 1980 - 1990 on my other computer (the one where the error occurred).

mikejohnson51 commented 3 years ago

Thanks for pointing these out! I am again not able to reproduce this one:

library(climateR)
library(AOI)

tc = AOI::aoi_get(country = "Kenya") %>% 
  getTerraClim(param = "prcp", 
               startDate = "1975-01-01",
               endDate = "1985-12-31")
#> Spherical geometry (s2) switched off
#> Spherical geometry (s2) switched on

names(tc$terraclim_prcp)
#>   [1] "X1975.01" "X1975.02" "X1975.03" "X1975.04" "X1975.05" "X1975.06"
#>   [7] "X1975.07" "X1975.08" "X1975.09" "X1975.10" "X1975.11" "X1975.12"
#>  [13] "X1976.01" "X1976.02" "X1976.03" "X1976.04" "X1976.05" "X1976.06"
#>  [19] "X1976.07" "X1976.08" "X1976.09" "X1976.10" "X1976.11" "X1976.12"
#>  [25] "X1977.01" "X1977.02" "X1977.03" "X1977.04" "X1977.05" "X1977.06"
#>  [31] "X1977.07" "X1977.08" "X1977.09" "X1977.10" "X1977.11" "X1977.12"
#>  [37] "X1978.01" "X1978.02" "X1978.03" "X1978.04" "X1978.05" "X1978.06"
#>  [43] "X1978.07" "X1978.08" "X1978.09" "X1978.10" "X1978.11" "X1978.12"
#>  [49] "X1979.01" "X1979.02" "X1979.03" "X1979.04" "X1979.05" "X1979.06"
#>  [55] "X1979.07" "X1979.08" "X1979.09" "X1979.10" "X1979.11" "X1979.12"
#>  [61] "X1980.01" "X1980.02" "X1980.03" "X1980.04" "X1980.05" "X1980.06"
#>  [67] "X1980.07" "X1980.08" "X1980.09" "X1980.10" "X1980.11" "X1980.12"
#>  [73] "X1981.01" "X1981.02" "X1981.03" "X1981.04" "X1981.05" "X1981.06"
#>  [79] "X1981.07" "X1981.08" "X1981.09" "X1981.10" "X1981.11" "X1981.12"
#>  [85] "X1982.01" "X1982.02" "X1982.03" "X1982.04" "X1982.05" "X1982.06"
#>  [91] "X1982.07" "X1982.08" "X1982.09" "X1982.10" "X1982.11" "X1982.12"
#>  [97] "X1983.01" "X1983.02" "X1983.03" "X1983.04" "X1983.05" "X1983.06"
#> [103] "X1983.07" "X1983.08" "X1983.09" "X1983.10" "X1983.11" "X1983.12"
#> [109] "X1984.01" "X1984.02" "X1984.03" "X1984.04" "X1984.05" "X1984.06"
#> [115] "X1984.07" "X1984.08" "X1984.09" "X1984.10" "X1984.11" "X1984.12"
#> [121] "X1985.01" "X1985.02" "X1985.03" "X1985.04" "X1985.05" "X1985.06"
#> [127] "X1985.07" "X1985.08" "X1985.09" "X1985.10" "X1985.11" "X1985.12"
#months
length(names(tc$terraclim_prcp))
#> [1] 132
#years
length(names(tc$terraclim_prcp)) / 12
#> [1] 11

utils::sessionInfo()
#> R version 4.0.5 (2021-03-31)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] AOI_0.2.0.9000 climateR_0.1.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.6           rnaturalearth_0.1.0  lattice_0.20-41     
#>  [4] class_7.3-18         assertthat_0.2.1     digest_0.6.27       
#>  [7] foreach_1.5.1        utf8_1.2.1           mime_0.10           
#> [10] R6_2.5.0             backports_1.2.1      USAboundaries_0.3.1 
#> [13] leaflet.extras_1.0.0 reprex_2.0.0         evaluate_0.14       
#> [16] e1071_1.7-7          httr_1.4.2           highr_0.8           
#> [19] pillar_1.6.1         rlang_0.4.11         raster_3.4-13       
#> [22] rmarkdown_2.7        styler_1.4.1         rgdal_1.5-23        
#> [25] stringr_1.4.0        htmlwidgets_1.5.3    shiny_1.6.0         
#> [28] proxy_0.4-26         httpuv_1.6.0         compiler_4.0.5      
#> [31] xfun_0.22            pkgconfig_2.0.3      rgeos_0.5-5         
#> [34] htmltools_0.5.1.1    tidyselect_1.1.1     tibble_3.1.2        
#> [37] codetools_0.2-18     fansi_0.5.0          later_1.2.0         
#> [40] crayon_1.4.1         dplyr_1.0.6          withr_2.4.2         
#> [43] sf_1.0-1             wk_0.4.1             grid_4.0.5          
#> [46] xtable_1.8-4         jsonlite_1.7.2       lifecycle_1.0.0     
#> [49] DBI_1.1.1            magrittr_2.0.1       units_0.7-2         
#> [52] KernSmooth_2.23-18   stringi_1.6.2        promises_1.2.0.1    
#> [55] fs_1.5.0             leaflet_2.0.4.1      doParallel_1.0.16   
#> [58] sp_1.4-5             xml2_1.3.2           ellipsis_0.3.2      
#> [61] generics_0.1.0       vctrs_0.3.8          s2_1.0.6            
#> [64] iterators_1.0.13     tools_4.0.5          glue_1.4.2          
#> [67] RNetCDF_2.4-2        purrr_0.3.4          crosstalk_1.1.1     
#> [70] fastmap_1.1.0        parallel_4.0.5       yaml_2.2.1          
#> [73] classInt_0.4-3       rvest_1.0.0          knitr_1.31

Created on 2021-07-07 by the reprex package (v2.0.0)

urskalbitzer commented 3 years ago

And another issue to close :) After updating all packages, including climateR, I am now getting TerraClimate data from years before 1980 and all seems fine.

Thanks for looking into this.