-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfixlon.py
27 lines (22 loc) · 852 Bytes
/
fixlon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
import netCDF4
import sys
ncfile = sys.argv[1]
nc = netCDF4.Dataset(ncfile, 'a', format='NETCDF3_64BIT')
lon_rho = nc.variables['lon_rho'][:]
lon_psi = nc.variables['lon_psi'][:]
lon_u = nc.variables['lon_u'][:]
lon_v = nc.variables['lon_v'][:]
#lon_rho = np.where(lon_rho>=-180, lon_rho, lon_rho+360.0)
#lon_psi = np.where(lon_psi>=-180, lon_psi, lon_psi+360.0)
#lon_u = np.where(lon_u>=-180, lon_u, lon_u+360.0)
#lon_v = np.where(lon_v>=-180, lon_v, lon_v+360.0)
lon_rho = np.where(lon_rho>=180, lon_rho-360.0, lon_rho)
lon_psi = np.where(lon_psi>=180, lon_psi-360.0, lon_psi)
lon_u = np.where(lon_u>=180, lon_u-360.0, lon_u)
lon_v = np.where(lon_v>=180, lon_v-360.0, lon_v)
nc.variables['lon_rho'][:] = lon_rho
nc.variables['lon_psi'][:] = lon_psi
nc.variables['lon_u'][:] = lon_u
nc.variables['lon_v'][:] = lon_v
nc.close()