Project

General

Profile

Coordinates lat/lon flipped in each variable

Added by Alonso Arriagada almost 3 years ago

Hi CDO community!
I have a problem with a NC file that have variables with dimentions in this order (time, lon, lat), and I need to have the variables in this order (time, lat, lon).
Could anyone help me to change the order of the dimentions in each variable?

I attach the NC file.
In case of, these is the information of the file (using "ncdump -h"):

Historico_subset_invertlat.nc
netcdf Historico_subset_invertlat {
dimensions:
        time = UNLIMITED ; // (444 currently)
        lon = 50 ;
        lat = 70 ;
variables:
        int time(time) ;
                time:standard_name = "time" ;
                time:long_name = "Time" ;
                time:units = "months since 1978-12-15" ;
                time:calendar = "standard" ;
                time:axis = "T" ;
        double lon(lon) ;
                lon:standard_name = "longitude" ;
                lon:long_name = "Longitude" ;
                lon:units = "degree east" ;
                lon:axis = "X" ;
        double lat(lat) ;
                lat:standard_name = "latitude" ;
                lat:long_name = "Latitude" ;
                lat:units = "degree north" ;
                lat:axis = "Y" ;
        float ET(time, lon, lat) ;
                ET:units = "mm" ;
                ET:_FillValue = NaNf ;
                ET:missing_value = NaNf ;
        float runoff(time, lon, lat) ;
                runoff:units = "mm" ;
                runoff:_FillValue = NaNf ;
                runoff:missing_value = NaNf ;
        float fsca(time, lon, lat) ;
                fsca:units = " " ;
                fsca:_FillValue = NaNf ;
                fsca:missing_value = NaNf ;
        float riego(time, lon, lat) ;
                riego:units = "mm" ;
                riego:_FillValue = NaNf ;
                riego:missing_value = NaNf ;
        float SWE(time, lon, lat) ;
                SWE:units = "mm" ;
                SWE:_FillValue = NaNf ;
                SWE:missing_value = NaNf ;
        float SM(time, lon, lat) ;
                SM:units = "mm" ;
                SM:_FillValue = NaNf ;
                SM:missing_value = NaNf ;
        float recarga(time, lon, lat) ;
                recarga:units = "mm" ;
                recarga:_FillValue = NaNf ;
                recarga:missing_value = NaNf ;

// global attributes:
                :CDI = "Climate Data Interface version 1.9.9rc1 (https://mpimet.mpg.de/cdi)" ;
                :Conventions = "CF-1.6" ;
                :history = "Tue Jun 29 16:38:58 2021: cdo invertlat Historico_subset.nc Historico_subset_invertlat.nc\n",
                        "Tue Jun 29 13:33:24 2021: cdo sellonlatbox,-72,-69.5,-32.3,-28.8 Historico.nc Historico_subset.nc" ;
                :CDO = "Climate Data Operators version 1.9.9rc1 (https://mpimet.mpg.de/cdo)" ;
}

Thanks to all!!
Regards.

Alonso A M


Replies (2)

RE: Coordinates lat/lon flipped in each variable - Added by Karin Meier-Fleischer almost 3 years ago

Hi Alonso,

to change the order of the dimensions of a variable you can use NCO's ncpdq .

To change the order of all variables as shown below

float ET(time, lat, lon) ;

float runoff(time, lat, lon) ;

float fsca(time, lat, lon) ;

float riego(time, lat, lon) ;

float SWE(time, lat, lon) ;

float SM(time, lat, lon) ;

float recarga(time, lat, lon) ;

Do the following in the command line:

ncpdq --rdr=time,lat,lon Historico_subset_invertlat.nc outfile.nc

To reorder the order of the dimensions itself, because your programs needs to have it in another order, instead of

dimensions:
    time = UNLIMITED ; // (444 currently)
    lon = 50 ;
    lat = 70 ;

you need something like

dimensions:
    lon = 50 ;
    lat = 70 ;
    time = UNLIMITED ; // (444 currently)

this is a little bit tricky and more work you have to do.
When the variables have the right dimension order (if not do the step from above) you have to append each dimension step by step to a new file, and at the end append all variables, too.

ncks -A -v lon Historico_subset_invertlat.nc outfile.nc

ncks -A -v lat Historico_subset_invertlat.nc outfile.nc

ncks -A -v time Historico_subset_invertlat.nc outfile.nc

ncks -A -v ET,runoff,fsca,riego,SWE,SM,recarga Historico_subset_invertlat.nc outfile.nc

-Karin

RE: Coordinates lat/lon flipped in each variable - Added by Alonso Arriagada almost 3 years ago

Hi Karin!

Thank you very much!

NCO's ncpdq did the job!
Thanks for the rest of the recommendations, they will surely be useful in the future.

Best regards!
Alonso A M

    (1-2/2)