OSGeo / grass-addons

GRASS GIS Addons Repository
https://grass.osgeo.org/grass-stable/manuals/addons/
GNU General Public License v2.0
103 stars 154 forks source link

[Bug] r.bioclim: bio18 and bio19 not working #753

Closed Giordano8 closed 2 years ago

Giordano8 commented 2 years ago

I used r.bioclim to calculate the 19 bioclimatic variables from the global rasters of precipitation, min temperature and max temperature of CHELSA database. This function takes as input a list of monthly data on precipitation, min temperature and max temperature and automatically calculates the bioclimatic variables. 17 out of 19 biclimatic variables were calculated correctly, but the 18th and the 19th resulted in a raster of 0s. This is quite strange because these variables are calculated from other rasters that the function calculated well.

I'm using GRASS GIS 7.8.6 on Ubuntu 20.04 .4 LTS

neteler commented 2 years ago

Please edit above and add which GRASS GIS version and which operating system you use.

metzm commented 2 years ago

Can you please provide information about

With this information it would be possible to reproduce the problem.

Giordano8 commented 2 years ago

I use the climate data of Karger et al. 2020. The data are available for 4 GCMs and 2 RCP, here the path to download the monthly data for precipitation, min temperature and max temperature for the period 2006-2029 (to use as an example):

https://os.zhdk.cloud.switch.ch/envicloud/chelsa/chelsa_V1/chelsa_cmip5_ts/CHELSAcmip5ts_pr_ACCESS1-3_rcp45_2006-2029_V1.1.nc https://os.zhdk.cloud.switch.ch/envicloud/chelsa/chelsa_V1/chelsa_cmip5_ts/CHELSAcmip5ts_tasmax_ACCESS1-3_rcp45_2006-2029_V1.1.nc https://os.zhdk.cloud.switch.ch/envicloud/chelsa/chelsa_V1/chelsa_cmip5_ts/CHELSAcmip5ts_tasmin_ACCESS1-3_rcp45_2006-2029_V1.1.nc

These files are quite big, so it would be better if you can download just the first 12 layers of each netCDF.

Additional info:

Here the code I used in GRASS:

# first: I used one of the nc file to create a new location using its georeferenced information. The projection info is the sam for the entire CHELSA database

# IMPORT TASMAX RCP45 RASTER
# import the first 12 layers (eg 1 year) of max temp, min temp and precipitation
r.in.gdal -ol input=/path/tasmax_rcp45_2030-2049.nc output=tasmax_rcp45 band=1,2,3,4,5,6,7,8,9,10,11,12 offset=1 num_digits=4 --o

# IMPORT TASMIN RCP45 RASTER
r.in.gdal -ol input=/path/tasmin_rcp45_2030-2049.nc output=tasmin_rcp45 band=1,2,3,4,5,6,7,8,9,10,11,12 offset=1 num_digits=4 --o 

# IMPORT PR RCP45 RASTER
r.in.gdal -ol input=/path/pr_rcp45_2030-2049.nc output=pr_rcp45 band=1,2,3,4,5,6,7,8,9,10,11,12 offset=1 num_digits=4 --o 

# computation region
# I used one of the imported raster to set the region

g.region raster=pr_rcp45.0001 --o

# calculatio nof the bioclimatic variables

r.bioclim prec=`g.list type=rast pat="pr*"map=. sep=,` \ # using g.list function to select all the raster that bagin with the string "pr"
tmax=`g.list type=rast pat="tasmax*" map=. sep=,` \
tmin=`g.list type=rast pat="tasmin*" map=. sep=,` \
out=bioclim_rcp45_ --o 

After applying r.bioclim I have 19 raster, one for each 19 bioclimatic variables, but bio18 and bio19 are rasters of 0s.

metzm commented 2 years ago

I tested with historical CHELSA climatologies for the years 1981-2010, results seem reasonable, not all zeros.

I will have a look at the CMIP5 model data.

metzm commented 2 years ago

Got it: the unit of CHELSAcmip5ts_pr_ACCESS1-3_rcp45_2006-2029_V1.1.nc is kg m-2 s-1, i.e. precipitation per second and not per month. The GDAL datatype is Float32, values are all well below 1, close to zero. r.bioclim expects precipitation per month as integer and for the variables 18 and 19 rounds the result to the nearest integer. Because all values are close to zero, the result is zero.

The solution is to first convert precipitation per second to precipitation per month and store it as integer, this also saves a lot of disk space.

Giordano8 commented 2 years ago

Following the suggestion from @metzm I was able to properly calculate all the bioclimatic variables. I would suggest to add a couple of sentences on the r.bioclim manual specifying that bio 18 and 19 round the result to the nearest integer. It couldd be helpful for people that are not used to work with climatic rasters. But thanks a lot for the help!

neteler commented 2 years ago

I would suggest to add a couple of sentences on the r.bioclim manual specifying that bio 18 and 19 round the result to the nearest integer. It couldd be helpful for people that are not used to work with climatic rasters. But thanks a lot for the help!

Please be so kind to suggest some text - you can edit the manual page and propose it as a pull request, see

https://github.com/OSGeo/grass-addons/blob/grass8/src/raster/r.bioclim/r.bioclim.html