comparison psymap_simple.py @ 0:db8d76da4174 draft

planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/psy-maps commit c1362af034361b6fb869411f1ea928388f230d72
author climate
date Thu, 25 Apr 2019 18:11:49 -0400
parents
children 706666d912d5
comparison
equal deleted inserted replaced
-1:000000000000 0:db8d76da4174
1 #!/usr/bin/env python3
2 #
3 #
4 # usage: psymap_simple.py [-h] [--proj PROJ]
5 # [--cmap CMAP]
6 # [--output OUTPUT]
7 # [-v]
8 # input varname
9 #
10 # positional arguments:
11 # input input filename with geographical coordinates (netCDF
12 # format)
13 # varname Specify which variable to plot (case sensitive)
14 #
15 # optional arguments:
16 # -h, --help show this help message and exit
17 # --proj PROJ Specify the projection on which we draw
18 # --cmap CMAP Specify which colormap to use for plotting
19 # --output OUTPUT output filename to store resulting image (png format)
20 # -v, --verbose switch on verbose mode
21 #
22
23 import argparse
24 import warnings
25 from pathlib import Path
26
27 import matplotlib as mpl
28 mpl.use('Agg')
29 from matplotlib import pyplot # noqa: I202,E402
30
31 import psyplot.project as psy # noqa: I202,E402
32
33
34 class PsyPlot ():
35 def __init__(self, input, proj, varname, cmap, output,
36 verbose=False
37 ):
38 self.input = input
39 self.proj = proj
40 self.varname = varname
41 self.cmap = cmap
42 if output is None:
43 self.output = Path(input).stem + '.png'
44 else:
45 self.output = output
46 self.verbose = verbose
47 if verbose:
48 print("input: ", self.input)
49 print("proj: ", self.proj)
50 print("varname: ", self.varname)
51 print("cmap: ", self.cmap)
52 print("output: ", self.output)
53
54 def plot(self):
55 if self.cmap is None and self.proj is None:
56 print("op1")
57 psy.plot.mapplot(self.input, name=self.varname,
58 clabel='{desc}')
59 elif self.proj is None or self.proj == '':
60 print("op2")
61 psy.plot.mapplot(self.input, name=self.varname,
62 cmap=self.cmap, clabel='{desc}')
63 elif self.cmap is None or self.cmap == '':
64 print("op3")
65 psy.plot.mapplot(self.input, name=self.varname,
66 projection=self.proj,
67 clabel='{desc}')
68 else:
69 print("op4")
70 psy.plot.mapplot(self.input, name=self.varname,
71 cmap=self.cmap,
72 projection=self.proj,
73 clabel='{desc}')
74
75 pyplot.savefig(self.output)
76
77
78 def psymap_plot(input, proj, varname, cmap, output, verbose):
79 """Generate plot from input filename"""
80
81 p = PsyPlot(input, proj, varname, cmap, output, verbose)
82 p.plot()
83
84
85 if __name__ == '__main__':
86 warnings.filterwarnings("ignore")
87 parser = argparse.ArgumentParser()
88 parser.add_argument(
89 'input',
90 help='input filename with geographical coordinates (netCDF format)'
91 )
92
93 parser.add_argument(
94 '--proj',
95 help='Specify the projection on which we draw'
96 )
97 parser.add_argument(
98 'varname',
99 help='Specify which variable to plot (case sensitive)'
100 )
101 parser.add_argument(
102 '--cmap',
103 help='Specify which colormap to use for plotting'
104 )
105 parser.add_argument(
106 '--output',
107 help='output filename to store resulting image (png format)'
108 )
109 parser.add_argument(
110 "-v", "--verbose",
111 help="switch on verbose mode",
112 action="store_true")
113 args = parser.parse_args()
114
115 psymap_plot(args.input, args.proj, args.varname, args.cmap,
116 args.output, args.verbose)