0

I am a beginner with Spatio-temporal data in R. I have daily precipitation data in .tif format and I created netCDF file to use as input to Climpact. But I get an error when I use this data as input to Climpact.

Fehler in create.file.metadata(f, variable.name.map) : 
  !is.null(projection) ist nicht TRUE
Ruft auf: create.indices.from.files -> create.file.metadata -> stopifnot
Ausführung angehalten

I assume that the issue is with the CRS system. How can I write the data in netCDF format in R which will be compatible with Climpact?

My code to write necDCF file was

library(raster)

raster_paths <- "/Users/dipesh/Desktop/demo/data"
raster_paths <- list.files(raster_paths, full.names = TRUE) # only one year sample

ptot_data<- lapply(raster_paths, brick)
ptot_data<- stack(ptot_data)

ptot_data <- projectRaster(from=ptot_data, crs="EPSG:4326")

dates_obs<- hydroTSM::dip("2020-01-01", "2020-12-31")
ptot_data<- setZ(ptot_data, dates_obs, name='time')


if(require(ncdf4)){
  writeRaster(ptot_data, "DC/daily_ppt_npl_2020.nc", overwrite=TRUE, format="CDF", varname="ppt", varunit="kg m-2 d-1",
              longname="Total Daily Precipitation", xname="Longitude",   yname="Latitude", zname="time", zunit = "day")
  
}

I want to organize my data similar to this sample https://github.com/ARCCSS-extremes/climpact/blob/master/www/sample_data/climpact.sampledata.gridded.1991-2010.nc

Looking for your support.

Revision:

I guess I lost the CRS information while writing the netCDF in R so I added it back using gdal_translate. I also edited variable attributes using NCO ncatted and the data is now CF-Compliance compatible. My initial error is now gone but I got another error.

'''Creating cluster of 3 nodes of type SOCK 
proj_create: Error 1027 (Invalid value for an argument): pj_init_ctx: Must specify ellipsoid or sphere''''

Is this error familiar to you?

  • I cannot see any specific requirements for Climpact data. But it should be able to handle any CF-compliant data. Upload your file here and see what is going wrong https://pumatest.nerc.ac.uk/cgi-bin/cf-checker.pl – Robert Wilson Jun 05 '22 at 14:57
  • Thanks Robert for your prompt reply. I checked and it says: 'AttributeError: NetCDF: Attribute not found'. "No grid_mapping_name attribute set: %s" % var.grid_mapping_name. How do I add such an attribute while writing netCDF? Could you please suggest revision on my writeRaster code above. – Dipesh Chapagain Jun 05 '22 at 16:02
  • It is better to try solving problem personally before asking others to do so. SO is not, to put it clearly, a code writing service. – Robert Wilson Jun 05 '22 at 16:34
  • Totally agree. And I am trying to solve this issue myself for several days. Sometimes, a simple trick from the expert can be a huge relief to the struggling beginners. So, I was just asking for some suggestions. – Dipesh Chapagain Jun 05 '22 at 16:55
  • It is better practise to modify the question in light of comments – Robert Wilson Jun 05 '22 at 18:36
  • perhaps try terra::writeCDF instead – Robert Hijmans Jun 05 '22 at 23:46
  • Robert, I have the same issue with terra::writeCDF. I updated my question with the progress and the new error I got. – Dipesh Chapagain Jun 13 '22 at 08:44

0 Answers0