Mercurial > repos > climate > climate_stripes
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:c6f2435d680b | 2:abdc27e01dca |
---|---|
70 self.plot_format = self.format | 70 self.plot_format = self.format |
71 else: | 71 else: |
72 self.plot_format = plot_format.replace('X', '%') | 72 self.plot_format = plot_format.replace('X', '%') |
73 | 73 |
74 def read_data(self): | 74 def read_data(self): |
75 self.data = pd.read_csv(self.input, sep='\t') | 75 if self.xname is not None: |
76 self.data = pd.read_csv(self.input, sep='\t', index_col=self.xname, infer_datetime_format=True) | |
77 else: | |
78 self.data = pd.read_csv(self.input, sep='\t') | |
76 | 79 |
77 def create_stripes(self): | 80 def create_stripes(self): |
78 data = np.zeros((2, self.data[self.valname].shape[0]), dtype='float') | 81 data = np.zeros((2, self.data[self.valname].shape[0]), dtype='float') |
79 data[:] = np.NaN | 82 data[:] = np.NaN |
80 data[0, :] = self.data[self.valname] | 83 data[0, :] = self.data[self.valname] |
84 plt.pcolor(data, cmap=self.cmap, | 87 plt.pcolor(data, cmap=self.cmap, |
85 vmin=self.data[self.valname].quantile(q=0.01), | 88 vmin=self.data[self.valname].quantile(q=0.01), |
86 vmax=self.data[self.valname].quantile(q=0.99)) | 89 vmax=self.data[self.valname].quantile(q=0.99)) |
87 if self.title: | 90 if self.title: |
88 plt.title(self.title) | 91 plt.title(self.title) |
89 if self.xname: | 92 if self.xname is not None: |
90 nrange = self.data.index.values | 93 nrange = self.data.index.values |
91 n = int(np.floor((nrange.max() - nrange.min())/int(self.nxsplit))) | 94 date_list = pd.to_datetime(nrange[::int(self.nxsplit)], format=self.format) |
92 date_list = self.data[self.xname].loc[::n].apply( | |
93 lambda x: pd.to_datetime(str(x), | |
94 format=self.format)) | |
95 date_list = [i.strftime(self.plot_format) for i in date_list] | 95 date_list = [i.strftime(self.plot_format) for i in date_list] |
96 nval = int(self.data[self.xname].loc[::n].shape[0]) | 96 ax.set_xticks(np.arange(0, len(nrange), int(self.nxsplit)), date_list) |
97 ax.xaxis.set_major_locator(plt.MaxNLocator(nval)) | |
98 ax.xaxis.set_ticklabels(date_list) | |
99 ax.xaxis.set_tick_params(rotation=45) | 97 ax.xaxis.set_tick_params(rotation=45) |
100 else: | 98 else: |
101 ax.set_xticks([]) | 99 ax.set_xticks([]) |
102 ax.set_yticks([]) | 100 ax.set_yticks([]) |
103 fig.tight_layout() | 101 fig.tight_layout() |