annotate climate_stripes.py @ 2:abdc27e01dca draft default tip

planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
author climate
date Sat, 09 Jul 2022 09:02:01 +0000
parents c6f2435d680b
children
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):
2
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
75 if self.xname is not None:
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
76 self.data = pd.read_csv(self.input, sep='\t', index_col=self.xname, infer_datetime_format=True)
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
77 else:
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
78 self.data = pd.read_csv(self.input, sep='\t')
0
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
79
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
80 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
81 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
82 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
83 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
84 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
85 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
86 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
87 plt.pcolor(data, cmap=self.cmap,
1
c6f2435d680b "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit 78edbd356193b8a8701ff7a28b7979c7047c0c5b"
climate
parents: 0
diff changeset
88 vmin=self.data[self.valname].quantile(q=0.01),
c6f2435d680b "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit 78edbd356193b8a8701ff7a28b7979c7047c0c5b"
climate
parents: 0
diff changeset
89 vmax=self.data[self.valname].quantile(q=0.99))
0
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
90 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
91 plt.title(self.title)
2
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
92 if self.xname is not None:
0
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
93 nrange = self.data.index.values
2
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
94 date_list = pd.to_datetime(nrange[::int(self.nxsplit)], format=self.format)
0
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]
2
abdc27e01dca planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit e4c144851549600ffde5bcf875304d5edd98e2b1
climate
parents: 1
diff changeset
96 ax.set_xticks(np.arange(0, len(nrange), int(self.nxsplit)), date_list)
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_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
98 else:
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
99 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
100 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
101 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
102 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
103
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
104
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
105 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
106 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
107 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
108 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
109 'input',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
110 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
111 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
112 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
113 'varname',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
114 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
115 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
116 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
117 '--cmap',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
118 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
119 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
120 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
121 '--output',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
122 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
123 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
124 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
125 '--xname',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
126 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
127 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
128 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
129 '--format_plot',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
130 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
131 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
132 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
133 '--format_date',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
134 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
135 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
136 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
137 '--title',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
138 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
139 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
140 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
141 '--nxsplit',
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
142 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
143 )
fec3147b0206 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3"
climate
parents:
diff changeset
144 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
145 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
146 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
147 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
148 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
149 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
150 stripes.create_stripes()