3

My NetCDF file has 4 dimensions (longitude, latitude, time, level pressure) and several variables.

I want to replace the longitude data which is [340 342 344 ... 360 0 2 4 ... 18 20] by [-20 -18 -16 ... -2 0 2 4 ... 18 20]. In fact the longitude is counted from 0° to 360° but I need to have it from -180° to 180°.

I have found some ideas on Internet but I don't know how to apply them.

Here an explanation:

"Some netcdf files contain strictly positive values [0,360] which are not compatible with the way gdal/QGis treat longitude values - they do not wrap around the dateline. This also causes errors with gdalwarp and when combined with other datasets (with [-180,180] values), they are not aligned properly due to a 180 degree longitude shift.

Simple fix is to test for longitude variables and convert any values in the [180,360] interval to [-180,180] by subtracting 180 - in IReadBlock and also in SRS detection."

I also read about "gdal-translate" but I don't know how to use it.

Edit: I also had a problem with the latitude which was N -> S (I wanted it S -> N) and I reversed it thanks to "cdo invertlat"

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Douie
  • 201
  • 4
  • 11
  • 1
    Please show us what you did: why did ncclamp not install, what commands did you try in `cdo`, what does `did not work` mean, what where the errors you got? Right now your question is too vague. – Paul Hiemstra Nov 21 '13 at 10:10
  • Please also provide a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) together with the code you have tried. Thanks! – Henrik Nov 21 '13 at 10:47
  • Sorry, I didn't see your answers! I edit my main post. I only have one problem but I really don't know how to fix it. – Douie Nov 25 '13 at 15:27

2 Answers2

5

This is what I found:

ncap2 -O -s 'where(lon>180) lon=lon-360' ifile ofile

I am not sure yet it doesn't change anything else but it seems work.

Douie
  • 201
  • 4
  • 11
5

I realise this is an old thread, but as I had a very similar problem recently I thought I'd add my solution as I didn't manage to find it elsewhere...

I used the cdo package (https://code.zmaw.de/projects/cdo) command sellonlatbox to translate my input data from [0, 360) longitude range to be [-180, 180), and also reorder latitudes to be [-90, 90] (i.e. S -> N):

cdo sellonlatbox,-180,180,-90,90 infile.nc outfile.nc
trafter
  • 51
  • 1
  • 3