SxS
SxS

Reputation: 41

How do I downsample a netcdf data using box averaging method

I have a 500 hPa vertical velocity dataset with grid size 1440x721 and I need to downsample it to a grid size of 144x72 using the box averaging method. How do I do that in Python? I had been using cdo remapbil to change gridsizes but that's not recommended when downsampling data. I need to use the box-averaging method. I've attached the metadata below, if that helps.

    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" ;
    short w(time, latitude, longitude) ;
        w:scale_factor = 0.000102461538570508 ;
        w:add_offset = 0.689628391880861 ;
        w:_FillValue = -32767s ;
        w:missing_value = -32767s ;
        w:units = "Pa s**-1" ;
        w:long_name = "Vertical velocity" ;

Upvotes: 0

Views: 590

Answers (2)

ClimateUnboxed
ClimateUnboxed

Reputation: 8107

Robert's solution is the correct one when the grid sizes are exact integer ratios (as is the case here) - More generally if they are not, you are correct to say bilinear interpolation is inaccurate, but you can use some of the conservative remapping schemes available with this

First order remapping:

cdo remapcon,targetgrid.nc in.nc out.nc 

or second order conservative remapping:

cdo remapcon2,targetgrid.nc in.nc out.nc 

There are several ways to specify the target grid, if you want to see more details, I have a video on this topic posted on climate unboxed.

Upvotes: 0

Robert Wilson
Robert Wilson

Reputation: 3417

You should be able to do this with gridboxmean.

cdo gridboxmean,10,10 infile outfile

Upvotes: 1

Related Questions