annotate climate_stripes.py @ 0:fec3147b0206 draft

"planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
author climate
date Sat, 05 Oct 2019 17:03:08 -0400
parents
children c6f2435d680b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
1 #!/usr/bin/env python3
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
2 #
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
3 #
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
4 # usage: climate_stripes.py [-h] [--cmap CMAP]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
5 # [--output OUTPUT]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
6 # [--xname XNAME]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
7 # [--format_plot FORMAT_PLOT]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
8 # [--format_date FORMAT_DATE]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
9 # [--title TITLE]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
10 # [--nxsplit NXSPLIT]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
11 # input varname
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
12 #
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
13 # positional arguments:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
14 # input input filename with timeseries (tabular format)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
15 # varname column name to use for plotting (case sensitive)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
16 #
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
17 # optional arguments:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
18 # -h, --help show this help message and exit
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
19 # --cmap CMAP Specify which colormap to use for plotting
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
20 # --output OUTPUT output filename to store resulting image (png format)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
21 # --xname XNAME column name to use for x-axis
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
22 # --format_plot FORMAT_PLOT
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
23 # format for plotting dates on the x-axis
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
24 # --format_date FORMAT_DATE
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
25 # format for input date/time column
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
26 # --title TITLE plot title
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
27 # --nxsplit NXSPLIT number of ticks on the x-axis
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
28 #
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
29
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
30 import argparse
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
31 import warnings
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
32
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
33 import matplotlib as mpl
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
34 mpl.use('Agg')
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
35
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
36 import matplotlib.pyplot as plt # noqa: I202,E402
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
37
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
38 import numpy as np # noqa: I202,E402
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
39
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
40 import pandas as pd # noqa: I202,E402
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
41
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
42
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
43 class Stripes ():
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
44 def __init__(self, input, valname, cmap, output, xname="",
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
45 date_format='%Y%m',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
46 plot_format='%Y',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
47 nxsplit=10,
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
48 title=""):
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
49 self.input = input
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
50 self.valname = valname
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
51 self.xname = xname
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
52 if not nxsplit:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
53 self.nxsplit = 10
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
54 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
55 self.nxsplit = nxsplit
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
56 if not cmap:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
57 self.cmap = 'RdBu_r'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
58 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
59 self.cmap = cmap
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
60 if not output:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
61 self.output = "stripes.png"
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
62 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
63 self.output = output
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
64 self.title = title
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
65 if not date_format:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
66 self.format = '%Y%m'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
67 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
68 self.format = date_format.replace('X', '%')
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
69 if not plot_format:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
70 self.plot_format = self.format
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
71 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
72 self.plot_format = plot_format.replace('X', '%')
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
73
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
74 def read_data(self):
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
75 self.data = pd.read_csv(self.input, sep='\t')
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
76
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
77 def create_stripes(self):
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
78 data = np.zeros((2, self.data[self.valname].shape[0]), dtype='float')
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
79 data[:] = np.NaN
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
80 data[0, :] = self.data[self.valname]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
81 data[1, :] = self.data[self.valname]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
82 fig = plt.figure(figsize=(10, 2))
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
83 ax = plt.subplot(111)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
84 plt.pcolor(data, cmap=self.cmap,
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
85 vmin=self.data[self.valname].min(),
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
86 vmax=self.data[self.valname].max())
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
87 if self.title:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
88 plt.title(self.title)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
89 if self.xname:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
90 nrange = self.data.index.values
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
91 n = int(np.floor((nrange.max() - nrange.min())/int(self.nxsplit)))
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
92 date_list = self.data[self.xname].loc[::n].apply(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
93 lambda x: pd.to_datetime(str(x),
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
94 format=self.format))
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
95 date_list = [i.strftime(self.plot_format) for i in date_list]
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
96 nval = int(self.data[self.xname].loc[::n].shape[0])
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
97 ax.xaxis.set_major_locator(plt.MaxNLocator(nval))
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
98 ax.xaxis.set_ticklabels(date_list)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
99 ax.xaxis.set_tick_params(rotation=45)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
100 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
101 ax.set_xticks([])
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
102 ax.set_yticks([])
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
103 fig.tight_layout()
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
104 fig.savefig(self.output)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
105
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
106
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
107 if __name__ == '__main__':
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
108 warnings.filterwarnings("ignore")
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
109 parser = argparse.ArgumentParser()
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
110 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
111 'input',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
112 help='input filename with geographical coordinates (netCDF format)'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
113 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
114 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
115 'varname',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
116 help='column name to use for plotting (case sensitive)'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
117 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
118 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
119 '--cmap',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
120 help='Specify which colormap to use for plotting'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
121 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
122 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
123 '--output',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
124 help='output filename to store resulting image (png format)'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
125 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
126 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
127 '--xname',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
128 help='column name to use for x-axis'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
129 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
130 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
131 '--format_plot',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
132 help='format for plotting dates on the x-axis'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
133 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
134 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
135 '--format_date',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
136 help='format for input date/time column (default is Month d, yyyy)'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
137 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
138 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
139 '--title',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
140 help='plot title'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
141 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
142 parser.add_argument(
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
143 '--nxsplit',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
144 help='number of ticks on the x-axis'
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
145 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
146 args = parser.parse_args()
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
147 stripes = Stripes(args.input, args.varname, args.cmap, args.output,
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
148 xname=args.xname, date_format=args.format_date,
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
149 plot_format=args.format_plot, title=args.title,
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
150 nxsplit=args.nxsplit)
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
151 stripes.read_data()
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
152 stripes.create_stripes()