Regridding problem

  • Maria Catala

    Maria Catala - 2013-12-09

    Hi everyone,

    I posted a question about regridding few days ago and thanks a lot to Henry for his answer.

    The use of ncap2 works perfectly for almost all my variables (Temperature, Geopotential height, relative humidity and vertical wind speed). Before regridding these variables I had to treat them: reverse latitude (which was N-> S), modify longitude (which was from 0 to 360 and not from -180 to 180) and delete the level dimension (my variables had 4 dimensions: time, longitude, latitude and level (which is the pressure level, size 1)).

    My problem comes from my variable called TCW (Total Column Water). For this variable the entire atmosphere is considered as a single layer so there is no level dimension. I just had to invert latitude and modify longitude.

    The regridding doesn't work, it gives a grid with random values from -20 000 to +20 000.
    This is what I obtain with the comparison (up: TCW before regridding, down: TCW after regridding, at the same timestep).

    alternate text

    Can someone help me?

    My code:


    // Bilinear interpolation

    defdim("latitude",13); // Define new dimension: latitude
    defdim("longitude",19); // Define new dimension: longitude
    latitude[$latitude] = {30, 32.5, 35, 37.5, 40, 42.5, 45, 47.5, 50, 52.5, 55, 57.5, 60};
    longitude[$longitude] = {-17.5, -15, -12.5, -10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20 ,22.5, 25, 27.5};

    out[$latitude,$longitude]=0.0; // Output structure

    // Bi-linear interpolation

    for( idx=0 ; idx<$time.size ; idx++){


    and after that:

    # include Regrid.nco

    for fichier in /home/caillouet/Documents/Data/20Cr/TCW/*.nc

    sfx=$( echo $fichier )
    out_name=$( basename $fichier .${fichier##*.} )

    #Invert latitude
    cdo invertlat $sfx

    Modify longitude
    ncap2 -O -s 'where(lon>180) lon=lon-360'

    ncap2 -v -S Regrid.nco

    Then in the console I call the last file (./


    Last edit: Maria Catala 2013-12-09
  • henry Butowsky

    henry Butowsky - 2013-12-09

    Hi Maria,
    I think the problem is with the "Modify longitude" step in -
    the command " ncap2 -O -s 'where(lon>180) lon=lon-360'" only changes the values in lon and NOT the order
    All the variables which use the dimension "lon" (including var lon) need to be re-ordered. This can be achieved with a single ncks command. So we now have:

    // Modify longitude
    ncks -O --msa_usr_rdr -d lon,180.0,359.999 -d lon,0.0,179.999
    ncap2 -O -s 'where(lon>180) lon=lon-360'

    ... Henry


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks