0% found this document useful (0 votes)
181 views4 pages

Converting Longitude in Netcdf From 0:360 To - 180:180 Using Nco

The document discusses converting the longitude coordinate in NetCDF files from a 0-360 degree range to a -180 to 180 degree range using the NCO (NetCDF Operator) tool. It provides code examples to perform this conversion using NCO commands like ncks and ncap2. Specifically, it suggests using ncks to shift the longitude data and ncap2 to recalibrate the coordinate values.

Uploaded by

JLAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views4 pages

Converting Longitude in Netcdf From 0:360 To - 180:180 Using Nco

The document discusses converting the longitude coordinate in NetCDF files from a 0-360 degree range to a -180 to 180 degree range using the NCO (NetCDF Operator) tool. It provides code examples to perform this conversion using NCO commands like ncks and ncap2. Specifically, it suggests using ncks to shift the longitude data and ncap2 to recalibrate the coordinate values.

Uploaded by

JLAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

bash - Converting longitude in NetCDF from 0:360 to -180:180 using nco - Sta... https://stackoverflow.com/questions/57682977/converting-longitude-in-netcdf-...

Converting longitude in NetCDF from 0:360 to -180:180 using nco


Asked 1 year, 3 months ago Active 6 months ago Viewed 1k times

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

1 of 4 12/8/20, 2:11 PM
bash - Converting longitude in NetCDF from 0:360 to -180:180 using nco - Sta... https://stackoverflow.com/questions/57682977/converting-longitude-in-netcdf-...

I have two NetCDF files, each for a different period of years, that I want to concatenate. They appear to have identical structures, with time as the
unlimited dimension, except that for one, longitude is on the scale of 0:360 and for the other on the scale of -180:180.
2
This question addresses how to deal with this issue using the raster package in R, but I want to use nco.

I have found the instructions (provided below) for converting -180:180-->0:360, but am not familiar enough with the syntax to allow me to reverse the
instructions in the other direction.

Details about my NetCDF file:

netcdf soda3.3.1_1980_2015_sst {
dimensions:
depth = 1 ;
latitude = 330 ;
longitude = 720 ;
time = UNLIMITED ; // (432 currently)
variables:
float depth(depth) ;
depth:long_name = "depth" ;
depth:units = "m" ;
depth:axis = "Z" ;
float latitude(latitude) ;
latitude:long_name = "latitude" ;
latitude:units = "degrees_north" ;
latitude:axis = "Y" ;
float longitude(longitude) ;
longitude:long_name = "longitude" ;
longitude:units = "degrees_east" ;
longitude:modulo = 360.f ;
longitude:axis = "X" ;
float temp(time, depth, latitude, longitude) ;
temp:long_name = "Potential temperature" ;
temp:units = "degrees C" ;
temp:valid_range = -10.f, 500.f ;
temp:missing_value = -1.e+20f ;
temp:cell_methods = "time: mean" ;
temp:standard_name = "sea_water_potential_temperature" ;
float time(time) ;
time:long_nime = "time" ;
time:units = "month" ;

data:
longitude = 0.25, 0.75, 1.25, 1.75, 2.25, 2.75, 3.25, 3.75, 4.25, 4.75,
5.25, 5.75, 6.25, 6.75, 7.25, 7.75, 8.25, 8.75, 9.25, 9.75, 10.25, 10.75, 11.25,
11.75, 12.25, 12.75, 13.25, 13.75, 14.25, 14.75, 15.25, 15.75, 16.25, 16.75,
17.25, 17.75, 18.25, 18.75, 19.25, 19.75, 20.25, 20.75, 21.25, 21.75, 22.25,
22.75, 23.25, 23.75, 24.25, 24.75, 25.25, 25.75, 26.25, 26.75, 27.25, 27.75,
28.25, 28.75, 29.25, 29.75, 30.25, 30.75, 31.25, 31.75, 32.25, 32.75, 33.25,
33.75, 34.25, 34.75, 35.25, 35.75, 36.25, 36.75, 37.25, 37.75, 38.25, 38.75,
39.25, 39.75, 40.2
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
50.25, 50.75, 51.2

2 of 4 12/8/20, 2:11 PM
bash - Converting longitude in NetCDF from 0:360 to -180:180 using nco - Sta... https://stackoverflow.com/questions/57682977/converting-longitude-in-netcdf-...

Does this answer your question? How to change longitude range in a NetCDF – Adrian Tompkins Jun 3 at 10:39

3 Answers Active Oldest Votes

Good question. Try

3 ncks -O --msa -d lon,181.,360. -d lon,0.,180.0 in.nc out.nc


ncap2 -O -s 'where(lon > 180) lon=lon-360' out.nc out.nc

The first command shifts the data, the second command recalibrates the coordinate to the newly shifted data. One comment on applying this algorithm:
Be careful to specify hemispheres that do not overlap, e.g., by inadvertently specifying coordinate ranges in the first command that both include the date
line. Some users will find using index-based rather than coordinate-based hyperslabs makes this clearer. Examine a plot of the field to make sure your
rotation was correct.

answered Aug 28 '19 at 17:52


Charlie Zender
4,236 10 18

If the fields are global you can convert from 0-360 to -180,180 with

5 cdo sellonlatbox,-180,180,-90,90 in.nc out.nc

and to convert the other way:

cdo sellonlatbox,0,360,-90,90 in.nc out.nc

No interpolation is involved, it should simply change the lon coordinate.

answered Aug 28 '19 at 6:58


Adrian Tompkins
3,751 1 17 51

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

3 of 4 12/8/20, 2:11 PM
bash - Converting longitude in NetCDF from 0:360 to -180:180 using nco - Sta... https://stackoverflow.com/questions/57682977/converting-longitude-in-netcdf-...

this behaviour seems to me very counter-intuitive...so CDO automatically converts from 0-360 to -180,180? I would expect that a function for selection (as sellonlatbox)
would "just" select and not change any coordinate...do you know the rationale behind this? – Matteo De Felice Aug 28 '19 at 14:02

CDO doesn't automatically convert to -180,180, only if you specify this in the command line, if the input file was defined 0,360 and you type sellonlatbox,0,360,-90,90 then
the output file will be identical. – Adrian Tompkins Sep 7 '19 at 18:13

I solved a similar problem in CDO by setting the grid of one data to the other. For instance, if you want both files to have the same -180:180 notation,
then try this:
1
cdo setgrid,file_with_-180:180_grid.nc file_with_0-360_grid.nc new_file.nc

edited May 19 at 13:20 answered May 19 at 13:13


Jacob Zora-Oni
11 2

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

4 of 4 12/8/20, 2:11 PM

You might also like