Question

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"

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top