Menu

Change dimensions of time-concatenated dataset

Developers
2019-10-16
2019-10-20
  • Richard Dixon

    Richard Dixon - 2019-10-16

    Hi there

    I have a dataset that is lat, lon, wind, time. The time axis is very large because each member of an ensemble has been concatenated along the time axis.

    So rather having a file of

    X=180, Y=90, T=51000

    Am looking to change the dimensions to

    X=180, Y=90, T=100, Z=51

    where Z is the ensemble member.

    I've been looking for worked examples but unable to find something similar.

    Thanks, Richard

     

    Last edit: Richard Dixon 2019-10-16
  • henry Butowsky

    henry Butowsky - 2019-10-16

    Hi Richard,
    Its abit fiddly with ncap2 but possible.
    Try the following script

    /*** new.nco ****/
    defdim("Tnw", 100);
    defdim("Z", 51);
    Tnw[Tnw]=T(::51)
    windnw[$T, $Z, $Y, $X]=0.0;
    windnw=wind;
    /
    *******
    /

    Then run the above script with the following command.

    ncap2 -C -v -S new .nco in.nc out.nc

    Then use ncrename to rename the variables "Tnw" and "windnw". and the dimension "Tnw". back to their original names

    ...Henry

     
  • Richard Dixon

    Richard Dixon - 2019-10-16

    Hi Henry - thanks for the quick reply, will give this a try, have not used any nco scripting on ncap2 before.

    Just to clarify - I presume the $X and $Y are for the names of the X and Y co-ordinates, respectively? (I've used X and Y above but they're actually Lon and Lat).

    Richard

     
  • henry Butowsky

    henry Butowsky - 2019-10-16

    Hi Richard,
    $X and $Y are the lon dimension and the lat dimension.
    So I guess you'll have to replace:
    $X with $Lon
    $Y with $Lat
    X with Lon
    Y with Lat

    ...Henry

     
  • Richard Dixon

    Richard Dixon - 2019-10-16

    Thanks, I will give it a try later. And sorry for using the wrong forum - please move to the Help one, if you can...!

     
  • Richard Dixon

    Richard Dixon - 2019-10-16

    Hi there - afraid I'm none the wiser on the above as it's all pretty new to me - maybe I need to provide more detail to help the script as it's crashing with a

    ew.nco line 1, column 20: unexpected character '

    A bit more detail on the data as I was a bit vague above: the contents of my netcdf file given by print (g.variables.keys()) is:

    odict_keys(['time', 'lon', 'lat', '10fg'])

    In terms of the shapes of the variables:

    10fg (wind data) is (10965, 181, 360) - so (Time, Latitude, Longitude)
    Lat is (181)
    Lon is (360)
    Time is (10965) - but time is just a repeating loop of 24 to 5160 in repeated 51 times over.

    I would there like the time array to be 215, and a new dimension being Ensemble (51) that just counts upwards from 1 to 51.

    i.e. 10fg would be (215, 51, 181, 360)

    Hope this is a bit clearer (but doesn't make it harder)...

    Thanks, Richard

     
  • henry Butowsky

    henry Butowsky - 2019-10-17

    HI Richard,
    An error on the first line ?
    Thi s is the revised script - the wind variable "10fg" has to be quoted in ncap2 so that it can be distinguished from a plain number. This assumes that the lattiude coordinate variable is 'Lat' and the longitude coordinate variable is 'Lon'

    defdim("time_nw", 215);
    time_nw[$time_nw]=time(0:214);
    
    defdim("Ensemble", 51);
    Ensemble=array(1.0,1.0, $Ensemble);
    
    wind_nw[$time_nw, $Ensemble, $Lat, $Lon]=0.0; 
    wind_nw='10fg';
    

    ....Henry

     
  • Richard Dixon

    Richard Dixon - 2019-10-17

    Hi Henry

    Many thanks for this - nearly there - one last thing is that I seem to lose the lat and lon variables in the process - the output file is:

    odict_keys(['time_nw', 'Ensemble', 'wind_nw'])

    Presumably I just need lines in there that are:

    lat_nw[$lat_nw]=lat(0:180) and the like (I thought I'd check first up!)

    Many thanks again
    Richard

     
  • henry Butowsky

    henry Butowsky - 2019-10-18

    Hi Richard,
    run the command line agin but omit the '-C' switch so all the used coordinate variables are pulled accross

    ncap2 -v -S new .nco in.nc out.nc

    Alternativly ammend the script as follows.

    defdim("time_nw", 215);
    time_nw[$time_nw]=time(0:214);
    
    defdim("Ensemble", 51);
    Ensemble=array(1.0,1.0, $Ensemble);
    
    wind_nw[$time_nw, $Ensemble, $Lat, $Lon]=0.0; 
    wind_nw='10fg';
    
    lat=lat;
    lon=lon;
    

    ...Henry

     

    Last edit: henry Butowsky 2019-10-18
  • Richard Dixon

    Richard Dixon - 2019-10-20

    Hi Henry - just wanted to thank you for all the help on this - all working!

     

Log in to post a comment.