I am using the Copernicus climate data, in particular de CERRA reanalysis data. I have downloaded the data for 2-meter temperature with the Grib format file, and everything looks correct. When I try to follow the same procedure for the Total precipitation I get negative values ranging from -160 to -260. Which does not make any sense. So if I try to download the data in the NetCDF format the values seem to be correct since it ranges from 0 to 110 but there is no coordinate system in the raster object and I get a warning saying:
"vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named y BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
I have tried to set multiple coordinate systems to the raster but nothing seems to work. Does anyone encounter this?
Here is the code that I am using for the grib file:
rm(list=ls())
library(ncdf4)
library(tidyverse)
library(sf)
library(raster)
library(terra)
library("mapSpain")
library(reticulate)
library(ncdf4)
conda_install("r-reticulate","cdsapi", pip=TRUE)#import python CDS-API
cdsapi <- import("cdsapi")
#for this step there must exist the file .cdsapirc
server = cdsapi$Client() #start the connection
year_n = "2020"
month_n = "03"
day_n = "01"
query <- r_to_py(list(
variable= "total_precipitation",
level_type= "surface_or_atmosphere",
data_type= "reanalysis",
product_type=" forecast",
year= year_n,
month= month_n,
day= day_n,
time="00:00",
format= "grib",
leadtime_hour = "24"
))
#query to get the ncdf
Path = paste0("1newera5_temp_",year_n,month_n, day_n,".grib")
server$retrieve("reanalysis-cerra-single-levels",
query,
Path)
nc_raster <- rast(Path)
plot(nc_raster,1)
This does not make any sense since the total precipitation has negative values. If instead of Grib I used NC format I get the following:
This seems correct but there is no coordinate system associated with the raster file so I can not understand the data and filter for Spain. Here is the data description of the raster for the .nc file where there is no coord. ref:
Does anyone know how to convert the values for the total precipitation to normal mm values where there are positive values for the Grib file? or set the coordinate system properly for the NC file where the values for the total precipitation are already correct?


I suspect the data is packed, i.e. stored as a 2 byte short and using add_offset and scale_factor. You can unpack it in cdo with
or