If longitude of a NetCDF file is in a form of 0~360 and one want to convert it to -180~180. There are two ways to make it.

Way1 - CDO:

cdo sellonlatbox,-180,180,-90,90 input.nc output.nc 

sellonlatbox is also used for selecting regions in with specified lon and lat.

Way2 - pycdo:

from cdo import Cdo 
cdo = Cdo() 

data = cdo.sellonlatbox(
    '-180,180,-90,90', 
    input = 'input.nc', 
    output = 'output.nc'
)     

#or
# data = cdo.sellonlatbox(
#    '-180,180,-90,90', 
#    input = 'input.nc',  

Last update: 01/07/2021