Hi Andreas,
Here’s how you do this to your original NetCDF file. If you don’t already have them on your computer, get the NetCDF operators from here: https://nco.sourceforge.net/
It’s highly likely your operating system’s packages or ports come with these, so installation should be easy enough.
I’m going to demonstrate on a file called ecmwf_202506021200.nc
- your file will look different, but it should be easy enough to translate what is done here to your needs.
First examine the structure of your file with ncdump
:
/Users/tim/ecmwf> ncdump -c ecmwf_202506021200.nc
netcdf ecmwf_202506021200 {
dimensions:
longitude = 1440 ;
latitude = 721 ;
time = 41 ;
variables:
float longitude(longitude) ;
longitude:units = "degrees_east" ;
longitude:long_name = "longitude" ;
float latitude(latitude) ;
latitude:units = "degrees_north" ;
latitude:long_name = "latitude" ;
int time(time) ;
time:units = "hours since 1900-01-01 00:00:00.0" ;
time:long_name = "time" ;
time:calendar = "gregorian" ;
float tp(time, latitude, longitude) ;
.
.
.
longitude = -180, -179.75, -179.5, -179.25, -179, -178.75, -178.5, -178.25,
-178, -177.75, -177.5, -177.25, -177, -176.75, -176.5, -176.25, -176,
-175.75, -175.5, -175.25, -175, -174.75, -174.5, -174.25, -174, -173.75,
-173.5, -173.25, -173, -172.75, -172.5, -172.25, -172, -171.75, -171.5
.
.
.
latitude = 90, 89.75, 89.5, 89.25, 89, 88.75, 88.5, 88.25, 88, 87.75, 87.5,
87.25, 87, 86.75, 86.5, 86.25, 86, 85.75, 85.5, 85.25, 85, 84.75, 84.5,
84.25, 84, 83.75, 83.5, 83.25, 83, 82.75, 82.5, 82.25, 82, 81.75, 81.5,
.
.
.
The dimensions I want to scale down by 1000 are longitude
and latitude
which currently range from -180.0 to 179.75 and 90.0 to -90.0 respectively.
This is done easily with ncap2
from the NetCDF operators:
ncap2 -O -s "longitude=longitude/1000; latitude=latitude/1000" ecmwf_202506021200.nc scaled.nc
Now if you run the previous ncdump
command you’ll see this:
/Users/tim/ecmwf> ncdump -c scaled.nc
netcdf scaled {
dimensions:
longitude = 1440 ;
latitude = 721 ;
time = 41 ;
variables:
float longitude(longitude) ;
longitude:long_name = "longitude" ;
longitude:units = "degrees_east" ;
float latitude(latitude) ;
latitude:long_name = "latitude" ;
latitude:units = "degrees_north" ;
.
.
.
longitude = -0.18, -0.17975, -0.1795, -0.17925, -0.179, -0.17875, -0.1785,
-0.17825, -0.178, -0.17775, -0.1775, -0.17725, -0.177, -0.17675, -0.1765,
-0.17625, -0.176, -0.17575, -0.1755, -0.17525, -0.175, -0.17475, -0.1745,
.
.
.
latitude = 0.09, 0.08975, 0.0895, 0.08925, 0.089, 0.08875, 0.0885, 0.08825,
0.088, 0.08775, 0.0875, 0.08725, 0.087, 0.08675, 0.0865, 0.08625, 0.086,
0.08575, 0.0855, 0.08525, 0.085, 0.08475, 0.0845, 0.08425, 0.084,
.
.
.
Which is probably all you need to do. But if you’re being picky, you’ll notice the units for the longitude
and latitude
dimensions are now incorrect (they’re still in units of degrees_east
and degrees_north
rather than in units of kdegrees_east
and kdegrees_north
). Another NetCDF operator, ncatted
can solve this:
ncatted -O -a units,longitude,o,c,kdegrees_east \
-a units,latitude,o,c,kdegrees_north scaled.nc scaled.nc
You can rerun ncdump
to confirm the units
attribute has indeed been changed.