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

+init=epsg:XXXX syntax deprecation #25

Closed mbjoseph closed 3 years ago

mbjoseph commented 3 years ago

Currently some of the function calls in climateR will raise a warning about +init=epsg syntax deprecation, e.g.,

library(AOI)
library(climateR)

climateR::getMACA(
  AOI::aoi_get(state = "FL"), 
  model = "CCSM4", 
  param = 'prcp', 
  scenario = c('rcp45', 'rcp85'), 
  startDate = "2080-06-29", endDate = "2080-06-30")
#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
#> deprecated. It might return a CRS with a non-EPSG compliant axis order.
#> $ccsm4_prcp_rcp45_mm
#> class      : RasterStack 
#> dimensions : 144, 183, 26352, 2  (nrow, ncol, ncell, nlayers)
#> resolution : 0.04142886, 0.04137668  (x, y)
#> extent     : -87.61456, -80.03308, 25.06308, 31.02132  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> names      : X2080.06.29, X2080.06.30 
#> min values :           0,           0 
#> max values :    66.55993,    17.49149 
#> 
#> 
#> $ccsm4_prcp_rcp85_mm
#> class      : RasterStack 
#> dimensions : 144, 183, 26352, 2  (nrow, ncol, ncell, nlayers)
#> resolution : 0.04142886, 0.04137668  (x, y)
#> extent     : -87.61456, -80.03308, 25.06308, 31.02132  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> names      : X2080.06.29, X2080.06.30 
#> min values :           0,           0 
#> max values :    33.06903,    23.11818

Created on 2021-01-15 by the reprex package (v0.3.0)

For MACA, this appears to happen because of this line: https://github.com/mikejohnson51/climateR/blob/9afa270f7ed93d5e87fb171ce94c2a201b29332d/data-raw/grid_meta2.R#L5

Suggested solution

Changing this to the integer value of the EPSG code solves the issue for MACA:

if(is.null(proj)){proj = 4326}

This integer would then get used here: https://github.com/mikejohnson51/climateR/blob/master/R/utility_define_grid.R#L29

The deprecated syntax also shows up for EDDI: https://github.com/mikejohnson51/climateR/blob/9afa270f7ed93d5e87fb171ce94c2a201b29332d/data-raw/grid_meta2.R#L54-L55

I think a fix there might be to use the proj4string like this:

raster::crs(t) = "+proj=longlat +datum=WGS84 +no_defs"
mikejohnson51 commented 3 years ago

should be good to go! Thanks again @mbjoseph

library(AOI)
library(climateR)

climateR::getMACA(
  AOI = AOI::aoi_get(state = "FL"), 
  model = "CCSM4", 
  param = 'prcp', 
  scenario = c('rcp45', 'rcp85'), 
  startDate = "2080-06-29", endDate = "2080-06-30")
#> $ccsm4_prcp_rcp45_mm
#> class      : RasterStack 
#> dimensions : 144, 183, 26352, 2  (nrow, ncol, ncell, nlayers)
#> resolution : 0.04165649, 0.04166603  (x, y)
#> extent     : -87.63539, -80.01225, 25.04224, 31.04215  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> names      : X2080.06.29, X2080.06.30 
#> min values :           0,           0 
#> max values :    17.49149,    29.23121 
#> 
#> 
#> $ccsm4_prcp_rcp85_mm
#> class      : RasterStack 
#> dimensions : 144, 183, 26352, 2  (nrow, ncol, ncell, nlayers)
#> resolution : 0.04165649, 0.04166603  (x, y)
#> extent     : -87.63539, -80.01225, 25.04224, 31.04215  (xmin, xmax, ymin, ymax)
#> crs        : +proj=longlat +datum=WGS84 +no_defs 
#> names      : X2080.06.29, X2080.06.30 
#> min values :           0,           0 
#> max values :    23.11818,    30.21123

Created on 2021-01-19 by the reprex package (v0.3.0)