rspatial / geodata

download geographic data
GNU General Public License v3.0
147 stars 15 forks source link

How to use the new CMIP6 data with geodata #27

Closed maurobio closed 1 year ago

maurobio commented 1 year ago

Hi

I am trying to adapt the example from here (https://rstudio-pubs-static.s3.amazonaws.com/224303_df34f170cd9144cda6477ae8232887f7.html), which uses the CMIP5 data (now obsolete), to the latest WorldClim models (http://www.worldclim.org/) using the new CMIP6 data,

For retrieving the data, I am using the geodata package.

Here is the script as far as I could run it:

[edited to just show the relevant part]

library(geodata)
# Get climate data
currentEnv <- worldclim_global(var="bio", res=2.5, path=getwd())
currentEnv <- dropLayer(currentEnv, c("bio2", "bio3", "bio4", "bio10", "bio11", "bio13", "bio14", "bio15"))
#Error in (function (classes, fdef, mtable)  : 
#  unable to find an inherited method for function ‘dropLayer’ for signature ‘"SpatRaster"’

Could a working example of using the latest CMIP6 data with geodata be provided?

Rapsodia86 commented 1 year ago

The error says that there is not function 'dropLayer' in the terra package. Here are examples how to drop a layer: https://github.com/rspatial/terra/issues/664#issuecomment-1150794478

rhijmans commented 1 year ago

This is not really the place for Q&A (see e.g. stackoverflow for that),

Anyway, currentEnv is a SpatRaster (a class defined by "terra") but you are treating it like a RasterStack or RasterBrick (from the "raster" package). This means that you may have to either change more things in your script, or use

library(raster)
currentEnv <- as(currentEnv, "Raster")
maurobio commented 1 year ago

Thanks, Mr; Hijmans, that's the kind of little trick which makes a world of difference! No, It solved my problem and right now I have been able to use geodata successfully.

Em qua., 21 de set. de 2022 às 23:49, Robert Hijmans < @.***> escreveu:

This is not really the place for Q&A (see e.g. stackoverflow for that),

Anyway, currentEnv is a SpatRaster (a class defined by "terra") but you are treating it like a RasterStack or RasterBrick (from the "raster" package). This means that you may have to either change more things in your script, or use

library(raster) currentEnv <- as(currentEnv, "Raster")

— Reply to this email directly, view it on GitHub https://github.com/rspatial/geodata/issues/27#issuecomment-1254449526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPMACIKJKPL7RL6333U52TV7PCNHANCNFSM6AAAAAAQL2B32A . You are receiving this because you authored the thread.Message ID: @.***>

-- Dr. Mauro J. Cavalcanti E-mail: @.*** Web: https://github.com/maurobio "Life is complex. It consists of real and imaginary parts."