How to change longitude range in a NetCDF

可紊 提交于 2019-12-22 17:48:34

问题


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"


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/20117749/how-to-change-longitude-range-in-a-netcdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!