Mercurial > repos > climate > shift_longitudes
comparison shift_lon.py @ 0:5708a3a46f2e draft default tip
planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/shift-longitudes commit c1362af034361b6fb869411f1ea928388f230d72
author | climate |
---|---|
date | Thu, 25 Apr 2019 18:12:13 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5708a3a46f2e |
---|---|
1 #!/usr/bin/env python3 | |
2 # | |
3 import argparse | |
4 import warnings | |
5 | |
6 import xarray as xr | |
7 | |
8 if __name__ == '__main__': | |
9 warnings.filterwarnings("ignore") | |
10 parser = argparse.ArgumentParser() | |
11 parser.add_argument( | |
12 'input', | |
13 help='input filename with geographical coordinates (netCDF format)' | |
14 ) | |
15 | |
16 parser.add_argument( | |
17 'lon', | |
18 help='name of the variable for longitudes' | |
19 ) | |
20 | |
21 parser.add_argument( | |
22 'output', | |
23 help='output filename to store resulting image (png format)' | |
24 ) | |
25 parser.add_argument("-v", "--verbose", help="switch on verbose mode", | |
26 action="store_true") | |
27 args = parser.parse_args() | |
28 | |
29 dset = xr.open_dataset(args.input, decode_cf=False) | |
30 | |
31 if dset[args.lon].max() > 180.: | |
32 for i in range(dset[args.lon].size): | |
33 if dset[args.lon].values[i] > 180.: | |
34 dset[args.lon].values[i] = dset[args.lon].values[i] - 360. | |
35 | |
36 dset.sortby(args.lon).to_netcdf(args.output) | |
37 if args.verbose: | |
38 print("Longitudes shifted to -180. and 180.") |