how to change variable name?
Added by muhammad Shoaib over 3 years ago
hello!
hope you all are well. i had an issue in changing the variable name of a gridded population file.
which is changing variable name from (Population Density, v4.11 (2000, 2005, 2010, 2015, 2020): 1 degree) to (population).
i applied this CDO command but it give me an error:
cdo -chname,Population Density, v4.11 (2000, 2005, 2010, 2015, 2020): 1 degree,population pop1_2000.nc pop2_2000.nc
Badly placed ()'s.
i have attached the the file pop1_2000.nc
kindly help me
Thankyou
pop1_2000.nc (259 KB) pop1_2000.nc |
Replies (3)
RE: how to change variable name? - Added by Uwe Schulzweida over 3 years ago
Unfortunately, it is not possible to change names with CDO if they contain a comma.
It is also not possible with the NCO tool ncrename.
Cheers,
Uwe
RE: how to change variable name? - Added by Karin Meier-Fleischer over 3 years ago
Hi Shoaib,
usually there is a solution with NCL when CDO can't do something, so here too.
The following NCL script changes the variable name in the output file:
;-- open file f = addfile("pop1_2000.nc", "r") ;-- retrieve the variable names varnames = getfilevarnames(f) print("---------------------------------------------------------") print("Variable names: "+varnames) print("---------------------------------------------------------") ;-- in this case the desired variable is varnames(3) printVarSummary(f->$varnames(3)$) print("---------------------------------------------------------") ;-- if already existing, delete new output file system("rm -rf pop1_2000_new.nc") ;-- open output file fout = addfile("pop1_2000_new.nc", "c") ;-- write data to output file; new variable name 'population' fout->population = f->$varnames(3)$ printVarSummary(fout->population) print("---------------------------------------------------------")
Run the script in a terminal:
ncl chname.ncl
Output of 'ncdump -h pop1_2000_new.nc':
netcdf pop1_2000_new { dimensions: time = 1 ; latitude = 180 ; longitude = 360 ; variables: float population(time, latitude, longitude) ; population:long_name = "Population Density, v4.11 (2000, 2005, 2010, 2015, 2020): 1 degree" ; population:units = "Persons per square kilometer" ; population:_FillValue = -3.4e+38f ; population:missing_value = -3.4e+38f ; population:min = 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 4., 0., 0., 0., -9999., -9999., 0., 0., 0., 0. ; population:max = 11538.9345703125, 11883.712890625, 12329.0302734375, 12901.76953125, 13639.572265625, 207., 767642., 3., 12391.3994140625, 12322.5126953125, 32767., 6., 2015., 6., 6., 6., 2011., 2015., 4., 2016. ; double time(time) ; time:standard_name = "time" ; time:units = "day as %Y%m%d.%f" ; time:calendar = "proleptic_gregorian" ; time:axis = "T" ; double latitude(latitude) ; latitude:standard_name = "latitude" ; latitude:long_name = "latitude" ; latitude:units = "degrees_north" ; latitude:axis = "Y" ; double longitude(longitude) ; longitude:standard_name = "longitude" ; longitude:long_name = "longitude" ; longitude:units = "degrees_east" ; longitude:axis = "X" ; }
-Karin