Could use help reording dimensions on netCDF files
Added by Chris Bartolomei over 6 years ago
Hello,
I am running CDO version 1.9.5 on CentOS 7.5 ... I have some ECMWF runoff ensemble GRIB files which I an converting to netcdf and the order of the dimensions is not what I need but I can't figure out how to reorder them. The current order of the dimensions is time,lon,lat and I need them to be lon,lat,time. I tried using the NCO tool ncpdq but the reported order is still time,lon,lat. Here is the ncdump of the original file:
$ ncdump -h 99.runoff.nc netcdf \99.runoff { dimensions: time = UNLIMITED ; // (40 currently) lon = 1800 ; lat = 901 ; variables: double time(time) ; time:standard_name = "time" ; time:units = "hours since 2018-5-21 00:00:00" ; time:calendar = "proleptic_gregorian" ; time:axis = "T" ; double lon(lon) ; lon:standard_name = "longitude" ; lon:long_name = "longitude" ; lon:units = "degrees_east" ; lon:axis = "X" ; double lat(lat) ; lat:standard_name = "latitude" ; lat:long_name = "latitude" ; lat:units = "degrees_north" ; lat:axis = "Y" ; float RO(time, lat, lon) ; RO:long_name = "Runoff" ; RO:units = "m" ; RO:code = 205 ; RO:table = 128 ; // global attributes: :CDI = "Climate Data Interface version 1.9.5 (http://mpimet.mpg.de/cdi)" ; :Conventions = "CF-1.6" ; :history = "Fri Nov 09 13:35:21 2018: cdo -s -R -f nc4 -t ecmwf -copy 99.runoff.grb 99.runoff.nc" ; :institution = "European Centre for Medium-Range Weather Forecasts" ; :CDO = "Climate Data Operators version 1.9.5 (http://mpimet.mpg.de/cdo)" ; }
Here is the ncdump after I run "ncpdq --rdr=lon,lat,time 99.runoff.nc reorder.nc":
$ ncdump -h reorder.nc netcdf reorder { dimensions: time = 40 ; lon = UNLIMITED ; // (1800 currently) lat = 901 ; variables: double time(time) ; time:standard_name = "time" ; time:units = "hours since 2018-5-21 00:00:00" ; time:calendar = "proleptic_gregorian" ; time:axis = "T" ; double lon(lon) ; lon:standard_name = "longitude" ; lon:long_name = "longitude" ; lon:units = "degrees_east" ; lon:axis = "X" ; double lat(lat) ; lat:standard_name = "latitude" ; lat:long_name = "latitude" ; lat:units = "degrees_north" ; lat:axis = "Y" ; float RO(lon, lat, time) ; RO:long_name = "Runoff" ; RO:units = "m" ; RO:code = 205 ; RO:table = 128 ; // global attributes: :CDI = "Climate Data Interface version 1.9.5 (http://mpimet.mpg.de/cdi)" ; :Conventions = "CF-1.6" ; :history = "Mon Nov 19 10:01:41 2018: ncpdq --rdr=lon,lat,time 99.runoff.nc reorder.nc\nFri Nov 09 13:35:21 2018: cdo -s -R -f nc4 -t ecmwf -copy 99.runoff.grb 99.runoff.nc" ; :institution = "European Centre for Medium-Range Weather Forecasts" ; :CDO = "Climate Data Operators version 1.9.5 (http://mpimet.mpg.de/cdo)" ; :NCO = "netCDF Operators version 4.7.5 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)" ; :nco_openmp_thread_number = 1 ; }
and this is what I need:
$ ncdump -h 1.runoff.nc netcdf \1.runoff { dimensions: lon = 1800 ; lat = 901 ; time = UNLIMITED ; // (40 currently) variables: float lon(lon) ; lon:standard_name = "longitude" ; lon:long_name = "longitude" ; lon:units = "degrees_east" ; lon:axis = "X" ; float lat(lat) ; lat:standard_name = "latitude" ; lat:long_name = "latitude" ; lat:units = "degrees_north" ; lat:axis = "Y" ; double time(time) ; time:standard_name = "time" ; time:units = "hours since 2018-7-19 00:00:00" ; time:calendar = "proleptic_gregorian" ; time:axis = "T" ; float RO(time, lat, lon) ; RO:long_name = "Runoff" ; RO:units = "m" ; RO:code = 205 ; RO:table = 128 ; // global attributes: :CDI = "Climate Data Interface version 1.8.2 (http://mpimet.mpg.de/cdi)" ; :Conventions = "CF-1.6" ; :history = "Thu Jul 19 11:01:21 2018: cdo -s -R -f nc4 -t ecmwf -copy 1.runoff 1.runoff.nc" ; :institution = "European Centre for Medium-Range Weather Forecasts" ; :CDO = "Climate Data Operators version 1.8.2 (http://mpimet.mpg.de/cdo)" ; }
Would anyone know how to rearrange the order of the dimensions? Is this a result of something in the original GRIB file (attached)? :
$ cdo sinfon 99.runoff.grb File format : GRIB -1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name 1 : ECMWF unknown v instant 1 1 1621800 1 P12 : var205 Grid coordinates : 1 : lonlat : points=1621800 (1800x901) lon : -180 to 179.8 by 0.2 degrees_east circular lat : 90 to -90 by -0.2 degrees_north Vertical coordinates : 1 : surface : levels=1 Time coordinate : unlimited steps RefTime = 2018-05-21 00:00:00 Units = hours Calendar = proleptic_gregorian YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss 2018-05-21 00:00:00 2018-05-21 03:00:00 2018-05-21 06:00:00 2018-05-21 09:00:00 2018-05-21 12:00:00 2018-05-21 15:00:00 2018-05-21 18:00:00 2018-05-21 21:00:00 2018-05-22 00:00:00 2018-05-22 03:00:00 2018-05-22 06:00:00 2018-05-22 09:00:00 2018-05-22 12:00:00 2018-05-22 15:00:00 2018-05-22 18:00:00 2018-05-22 21:00:00 2018-05-23 00:00:00 2018-05-23 03:00:00 2018-05-23 06:00:00 2018-05-23 09:00:00 2018-05-23 12:00:00 2018-05-23 15:00:00 2018-05-23 18:00:00 2018-05-23 21:00:00 2018-05-24 00:00:00 2018-05-24 03:00:00 2018-05-24 06:00:00 2018-05-24 09:00:00 2018-05-24 12:00:00 2018-05-24 15:00:00 2018-05-24 18:00:00 2018-05-24 21:00:00 2018-05-25 00:00:00 2018-05-25 03:00:00 2018-05-25 06:00:00 2018-05-25 09:00:00 2018-05-25 12:00:00 2018-05-25 15:00:00 2018-05-25 18:00:00 2018-05-25 21:00:00 cdo sinfon: Processed 1 variable over 40 timesteps [0.06s 13MB]
Thank you for any help!
:)
Chris
99.runoff.grb.gz (8.53 MB) 99.runoff.grb.gz | original GRIB file |
Replies (3)
RE: Could use help reording dimensions on netCDF files - Added by Chris Bartolomei over 6 years ago
Interesting that the dimensions of RO got cut off with the cut and paste of my original message above ... the lines for float RO; should read:
for "ncdump -h 99.runoff.nc": float RO
for "ncdump -h reorder.nc": float RO
for "ncdump -h 1.runoff.nc": float RO
I'm not sure how or why that got removed but hopefully they show up on this message!
Chris
RE: Could use help reording dimensions on netCDF files - Added by Chris Bartolomei over 6 years ago
wow ... cut off again! weird ... let's try this:
for "ncdump -h 99.runoff.nc": float RO time,lat,lon in parenthesis
for "ncdump -h reorder.nc": float RO lon,lat,time in parenthesis
for "ncdump -h 1.runoff.nc": float RO time,lat,lon in parenthesis
ugh. sorry about this!
Chris
RE: Could use help reording dimensions on netCDF files - Added by Karin Meier-Fleischer over 3 years ago
Hi Chris,
late, but due to the search for an answer to a similar question I found a solution for your problem, too. See https://code.mpimet.mpg.de/boards/2/topics/11747.
ncks -A -v lon 99.runoff.nc reorder.nc ncks -A -v lat 99.runoff.nc reorder.nc ncks -A -v time 99.runoff.nc reorder.nc ncks -A -v RO 99.runoff.nc reorder.nc
-Karin