Project

General

Profile

flatten/expand levels to time dimension

Added by Stuart Brown 12 months ago

Hi,
I have a large netcdf file of a paleoclimate simulation which should contain 24000 layers/timesteps. Unfortunately the variable of interest (monthly mean temp) is stored as {time, mon, lat, lon} where mon is set-up as a level. This means I only have 2000 timesteps with 12 levels for each timestep.

netcdf test_file {
dimensions:
        depth = 1 ;
        lat = 181 ;
        lon = 720 ;
        time = 2000 ;
        month = 12 ;
variables:
        float depth(depth) ;
                depth:positive = "up" ;
                depth:units = "m" ;
        float lat(lat) ;
                lat:units = "degrees_north" ;
                lat:standard_name = "latitude" ;
                lat:long_name = "latitude" ;
        float lon(lon) ;
                lon:units = "degrees_east" ;
                lon:standard_name = "longitude" ;
                lon:long_name = "longitude" ;
        float mask(time, depth, lat, lon) ;
                mask:_FillValue = -999.f ;
                mask:long_name = "Raw land sea mask (Possibly modified)" ;
                mask:units = "0-1" ;
                mask:lonFlip = "longitude coordinate variable has been reordered via lonFlip" ;
        float temp_mm_1_5m(time, month, lat, lon) ;
                temp_mm_1_5m:name = "temp_mm_1_5m" ;
                temp_mm_1_5m:title = "TEMPERATURE AT 1.5M" ;
                temp_mm_1_5m:long_name = "TEMPERATURE AT 1.5M" ;
                temp_mm_1_5m:standard_name = "air_temperature" ;
                temp_mm_1_5m:pcmdi_name = "tas" ;
                temp_mm_1_5m:stash_code = 3236s ;
                temp_mm_1_5m:submodel = 1s ;
                temp_mm_1_5m:processing = "monthly_mean_1.5m_above_surface" ;
                temp_mm_1_5m:units = "degC" ;
                temp_mm_1_5m:valid_min = 219.8786f ;
                temp_mm_1_5m:valid_max = 306.9277f ;
                temp_mm_1_5m:lonFlip = "longitude coordinate variable has been reordered via lonFlip" ;
                temp_mm_1_5m:missing_value = 2.e+20f ;
                temp_mm_1_5m:_FillValue = 2.e+20f ;
                temp_mm_1_5m:depth = -1.f ;
        int time(time) ;
                time:calendar = "1yr linear" ;
                time:standard_name = "time" ;
                time:short_name = "time" ;
                time:long_name = "time" ;

// global attributes:
                :creation_date = "Thu May  4 13:03:24 BST 2023" ;
                :Conventions = "CF-1.4" ;
                :Title = "HadCM3B Quaternary Climate Output" ;
}

Is there anyway to flatten or expand the month levels along the time index? Essentially, I want to convert each timestep (with 12 levels) into 12 timesteps with no levels. The expanded timesteps could have any arbitary value as I know the actual start/end dates of the simulation. I have attached a small example file with only 10 timesteps which I have subset from the actual file.

netcdf foo {
dimensions:
    lat = 31 ;
    lon = 31 ;
    time = 10 ;
    month = 12 ;
variables:
    float lat(lat) ;
        lat:units = "degrees_north" ;
        lat:standard_name = "latitude" ;
        lat:long_name = "latitude" ;
        lat:missing_value = -32767.f ;
        lat:_FillValue = -32767.f ;
    float lon(lon) ;
        lon:units = "degrees_east" ;
        lon:standard_name = "longitude" ;
        lon:long_name = "longitude" ;
        lon:missing_value = -32767.f ;
        lon:_FillValue = -32767.f ;
    float temp_mm_1_5m(time, month, lat, lon) ;
        temp_mm_1_5m:name = "temp_mm_1_5m" ;
        temp_mm_1_5m:title = "TEMPERATURE AT 1.5M" ;
        temp_mm_1_5m:long_name = "TEMPERATURE AT 1.5M" ;
        temp_mm_1_5m:standard_name = "air_temperature" ;
        temp_mm_1_5m:pcmdi_name = "tas" ;
        temp_mm_1_5m:stash_code = 3236s ;
        temp_mm_1_5m:units = "degC" ;
        temp_mm_1_5m:lonFlip = "longitude coordinate variable has been reordered via lonFlip" ;
        temp_mm_1_5m:missing_value = -32767.f ;
        temp_mm_1_5m:depth = -1.f ;
        temp_mm_1_5m:_FillValue = -32767.f ;
    int time(time) ;
        time:calendar = "1yr linear" ;
        time:standard_name = "time" ;
        time:short_name = "time" ;
        time:long_name = "time" ;
        time:missing_value = -32767.f ;
        time:_FillValue = -32767.f ;

// global attributes:
        :creation_date = "Thu May  4 13:03:24 BST 2023" ;
        :Creator_email = "edward.armstrong@.ad.helsinki.fi/edward.armstrong@bristol.ac.uk" ;
        :Creator_name = "Edward Armstrong" ;
        :Conventions = "CF-1.4" ;
        :Title = "HadCM3B Quaternary Climate Output" ;
        :NCO = "netCDF Operators version 5.0.6 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)" ;
        :history = "Fri May 12 11:30:14 2023: ncatted -O -a _FillValue,,o,f,-32767 foo.nc\n",
            "Fri May 12 11:30:05 2023: ncatted -O -a missing_value,,o,f,-32767 foo.nc\n",
            "Fri May 12 11:29:38 2023: ncatted -O -a valid_min,,d,, foo.nc\n",
            "Fri May 12 11:29:35 2023: ncatted -O -a valid_max,,d,, foo.nc\n",
            "Fri May 12 11:29:32 2023: ncks -v temp_mm_1_5m -d time,1,10 -d lon,15.0,30.0 -d lat,45.0,60.0 test_file.nc foo.nc\n";
}

Any help/guidance would be greatly appreciated.

foo.nc (304 KB) foo.nc

Replies (1)

RE: flatten/expand levels to time dimension - Added by Estanislao Gavilan 12 months ago

Hi,

I think you cannot do this with cdo because it does not follow the cf-convention.

Kind regards,

Estanislao

    (1-1/1)