1
votes

I have a netcdf file containing maximum daily air temperature, time, lat and lon. I successfully got maximum temperature from a netcdf of 6 hourly temperatures using the nco command:

ncra -y max --mro -d time,,,4,4 6hourly.nc max.nc"

The only problem is, my time steps are still split into quarter days:

variables:

double lon(lon) ;
    lon:units = "degrees_east" ;
    lon:long_name = "lon" ;
    lon:standard_name = "longitude" ;
double lat(lat) ;
    lat:units = "degrees_north" ;
    lat:long_name = "lat" ;
    lat:standard_name = "latitude" ;
double time(time) ;
    time:units = "days since 0850-01-01 00:00:00" ;
    time:long_name = "time" ;
    time:calendar = "proleptic_gregorian" ;
double tair(time, lat, lon) ;
    tair:units = "K" ;
    tair:_FillValue = 1.e+30 ;
    tair:long_name = "2 meter air temperature" ;
    tair:days\ since\ 850 = 0., 0.25, 0.5, 0.75, 1., 1.25, 1.5, 1.75, 2., 2.25, 2.5, 2.75, 3., 3.25, 3.5, 3.75, 4., 4.25, 4.5, 4.75, 5., 5.25, 5.5, 5.75, 6., 6.25, 6.5, 6.75, 7., 7.25, 7.5, 7.75, 8., 8.25, 8.5, 8.75, 9., 9.25, 9.5, 9.75, 10., 10.25, 10.5, 10.75, 11., 11.25, 11.5...

My question is, how do I change the time step for the 'days\ since\ 850' attribute in the variable tair, to whole numbers?

Thanks!

Charlotte

2

2 Answers

1
votes

ncap2 can work with attributes. However, you have a particularly thorny issue because your attribute name contains whitespace, and the attribute value is an array. I think in this case you need to first rename the attribute, then manipulate it. (Then you can rename it back if desired.):

ncrename -O -a "tair@days since 850",tair@days_since_850 in.nc foo.nc
ncap2 -O -s 'tair@days_since_850=int(tair@days_since_850)' foo.nc out.nc

Edit 20210209 in answer to comment below: To copy an attribute from one variable to another, try

ncap2 -s 'var1@att1=var2@att2' in.nc out.nc
0
votes

In case anyone has a similar problem, this ended up working for me:

ncap2 -s 'time=array(0,1,$time)' outmax.nc outmax2.nc
ncap2 -s 'time=array(0,1,$time)' outmin.nc outmin2.nc