change unit of code
Added by Ronny Berndt over 12 years ago
Hi,
i have a netcdf file with Kelvin as unit and i want to change it to Celsius.
i used this command to convert:
cdo addc,-273.15 ifile ofile
okay, now i want to change to unit in the parameter table from K to C!
How can i do this? Is there a "chunit" command?
Regards,
Ronny
Replies (10)
RE: change unit of code - Added by Ralf Mueller over 12 years ago
I'm already working on an operator like this. It will be in the next release. As soon it finished it, I will create a new cdo-current release.
ralf
RE: change unit of code - Added by Jaison-Thomas Ambadan over 12 years ago
Hi,
for the time being, you can:
1) ncdump ifile.nc > ofile.dat 2) open the ofile.dat and replace the units to K (manually using a text editor), and save it. 3) ncgen -o new_ifile.nc ofile.dat
Cheers,
J.
RE: change unit of code - Added by Ralf Mueller over 12 years ago
I added a new cdo-current (https://code.zmaw.de/projects/cdo/files) release with setunit
and chnuit
operators. Please let me know, if they work properly!
regards
ralf
RE: change unit of code - Added by Ronny Berndt over 12 years ago
RE: change unit of code - Added by Christ Reflin over 3 years ago
Could you describe to me how to use aforementioned link?
I am new to this, I really appreciate for your help.
MfG,
Christ
RE: change unit of code - Added by Christ Reflin over 3 years ago
Christian Simanjuntak wrote in RE: change unit of code:
Could you describe to me how to use the aforementioned link?
I am new to this, I really appreciate for your help.
MfG,
Christ
RE: change unit of code - Added by Karin Meier-Fleischer over 3 years ago
Hi Christian,
this is a really old thread. To change the units of a variable use the setattribute operator.
For example change the units attribute of variable tas to degC :
cdo -setattribute,tas@units=degC infile.nc outfile.nc
-Karin
RE: change unit of code - Added by Christ Reflin over 3 years ago
Hallo Karin,
thank you for the response,
I obtain this warning
$ cdo -setattribute,tas@units=degC ifile.nc ofile.nc
cdo setattribute (Warning): Variable >tas< not found!
I am using ERA5 netcdf
$cdo partab ifile.nc
¶meter
name=Temperature_Air_2m_Mean_24h
long_name="2 meter air temperature (00-00LT)"
units="K"
datatype=F32
chunktype=lines
/
Could you direct me on this?
Thank you
Christ
RE: change unit of code - Added by Karin Meier-Fleischer over 3 years ago
This was an example for a variable named tas which is not in your ifile.nc (I don't know the content of your file). You have to change tas to the name of your variable (Temperature_Air_2m_Mean_24h ?). Do you want to set the units attribute to degC then it should be ok.
RE: change unit of code - Added by Christ Reflin over 3 years ago
Thank you I found the solution by replacing "the variable"
tas@units to Temperature_Air_2m_Mean_24h@units
Thank you
Christ