# HG changeset patch # User climate # Date 1570309363 14400 # Node ID 2ea0576cb062eb0ad53160779d3e6e34aab163d4 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/climate-stripes commit aa08ea46712c1cfbaac2e6fcd07c93097751cad3" diff -r 000000000000 -r 2ea0576cb062 climate-stripes.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/climate-stripes.xml Sat Oct 05 17:02:43 2019 -0400 @@ -0,0 +1,162 @@ + + from timeseries + + python + matplotlib + pandas + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
diff -r 000000000000 -r 2ea0576cb062 climate_stripes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/climate_stripes.py Sat Oct 05 17:02:43 2019 -0400 @@ -0,0 +1,152 @@ +#!/usr/bin/env python3 +# +# +# usage: climate_stripes.py [-h] [--cmap CMAP] +# [--output OUTPUT] +# [--xname XNAME] +# [--format_plot FORMAT_PLOT] +# [--format_date FORMAT_DATE] +# [--title TITLE] +# [--nxsplit NXSPLIT] +# input varname +# +# positional arguments: +# input input filename with timeseries (tabular format) +# varname column name to use for plotting (case sensitive) +# +# optional arguments: +# -h, --help show this help message and exit +# --cmap CMAP Specify which colormap to use for plotting +# --output OUTPUT output filename to store resulting image (png format) +# --xname XNAME column name to use for x-axis +# --format_plot FORMAT_PLOT +# format for plotting dates on the x-axis +# --format_date FORMAT_DATE +# format for input date/time column +# --title TITLE plot title +# --nxsplit NXSPLIT number of ticks on the x-axis +# + +import argparse +import warnings + +import matplotlib as mpl +mpl.use('Agg') + +import matplotlib.pyplot as plt # noqa: I202,E402 + +import numpy as np # noqa: I202,E402 + +import pandas as pd # noqa: I202,E402 + + +class Stripes (): + def __init__(self, input, valname, cmap, output, xname="", + date_format='%Y%m', + plot_format='%Y', + nxsplit=10, + title=""): + self.input = input + self.valname = valname + self.xname = xname + if not nxsplit: + self.nxsplit = 10 + else: + self.nxsplit = nxsplit + if not cmap: + self.cmap = 'RdBu_r' + else: + self.cmap = cmap + if not output: + self.output = "stripes.png" + else: + self.output = output + self.title = title + if not date_format: + self.format = '%Y%m' + else: + self.format = date_format.replace('X', '%') + if not plot_format: + self.plot_format = self.format + else: + self.plot_format = plot_format.replace('X', '%') + + def read_data(self): + self.data = pd.read_csv(self.input, sep='\t') + + def create_stripes(self): + data = np.zeros((2, self.data[self.valname].shape[0]), dtype='float') + data[:] = np.NaN + data[0, :] = self.data[self.valname] + data[1, :] = self.data[self.valname] + fig = plt.figure(figsize=(10, 2)) + ax = plt.subplot(111) + plt.pcolor(data, cmap=self.cmap, + vmin=self.data[self.valname].min(), + vmax=self.data[self.valname].max()) + if self.title: + plt.title(self.title) + if self.xname: + nrange = self.data.index.values + n = int(np.floor((nrange.max() - nrange.min())/int(self.nxsplit))) + date_list = self.data[self.xname].loc[::n].apply( + lambda x: pd.to_datetime(str(x), + format=self.format)) + date_list = [i.strftime(self.plot_format) for i in date_list] + nval = int(self.data[self.xname].loc[::n].shape[0]) + ax.xaxis.set_major_locator(plt.MaxNLocator(nval)) + ax.xaxis.set_ticklabels(date_list) + ax.xaxis.set_tick_params(rotation=45) + else: + ax.set_xticks([]) + ax.set_yticks([]) + fig.tight_layout() + fig.savefig(self.output) + + +if __name__ == '__main__': + warnings.filterwarnings("ignore") + parser = argparse.ArgumentParser() + parser.add_argument( + 'input', + help='input filename with geographical coordinates (netCDF format)' + ) + parser.add_argument( + 'varname', + help='column name to use for plotting (case sensitive)' + ) + parser.add_argument( + '--cmap', + help='Specify which colormap to use for plotting' + ) + parser.add_argument( + '--output', + help='output filename to store resulting image (png format)' + ) + parser.add_argument( + '--xname', + help='column name to use for x-axis' + ) + parser.add_argument( + '--format_plot', + help='format for plotting dates on the x-axis' + ) + parser.add_argument( + '--format_date', + help='format for input date/time column (default is Month d, yyyy)' + ) + parser.add_argument( + '--title', + help='plot title' + ) + parser.add_argument( + '--nxsplit', + help='number of ticks on the x-axis' + ) + args = parser.parse_args() + stripes = Stripes(args.input, args.varname, args.cmap, args.output, + xname=args.xname, date_format=args.format_date, + plot_format=args.format_plot, title=args.title, + nxsplit=args.nxsplit) + stripes.read_data() + stripes.create_stripes() diff -r 000000000000 -r 2ea0576cb062 test-data/T2Mclimatology.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/T2Mclimatology.txt Sat Oct 05 17:02:43 2019 -0400 @@ -0,0 +1,489 @@ +Month global +197901 -0.2309 +197902 -0.4906 +197903 -0.2922 +197904 -0.3259 +197905 -0.2858 +197906 -0.258 +197907 -0.3306 +197908 -0.2336 +197909 -0.1801 +197910 -0.1248 +197911 -0.147 +197912 0.0667 +198001 -0.1084 +198002 -0.0513 +198003 -0.0826 +198004 -0.0015 +198005 0.0697 +198006 -0.0799 +198007 -0.0425 +198008 -0.1085 +198009 -0.1715 +198010 -0.216 +198011 -0.192 +198012 -0.2736 +198101 0.0171 +198102 -0.0524 +198103 0.0305 +198104 -0.0305 +198105 -0.069 +198106 -0.0755 +198107 -0.0747 +198108 -0.0603 +198109 -0.1398 +198110 -0.1792 +198111 -0.1878 +198112 -0.0359 +198201 -0.3861 +198202 -0.2909 +198203 -0.4431 +198204 -0.3551 +198205 -0.2111 +198206 -0.2463 +198207 -0.1711 +198208 -0.2779 +198209 -0.2693 +198210 -0.2803 +198211 -0.2834 +198212 -0.0342 +198301 0.0396 +198302 0.004 +198303 0.006 +198304 -0.0941 +198305 0.0277 +198306 -0.092 +198307 -0.1496 +198308 -0.0738 +198309 -0.0007 +198310 -0.2356 +198311 -0.1167 +198312 -0.2251 +198401 -0.2111 +198402 -0.3605 +198403 -0.1985 +198404 -0.2865 +198405 -0.0539 +198406 -0.3321 +198407 -0.3649 +198408 -0.2626 +198409 -0.2898 +198410 -0.2823 +198411 -0.4153 +198412 -0.4044 +198501 -0.2315 +198502 -0.4976 +198503 -0.3365 +198504 -0.2901 +198505 -0.276 +198506 -0.2926 +198507 -0.3687 +198508 -0.2183 +198509 -0.3246 +198510 -0.4071 +198511 -0.3566 +198512 -0.3469 +198601 -0.2416 +198602 -0.1812 +198603 -0.2186 +198604 -0.1174 +198605 -0.1084 +198606 -0.2742 +198607 -0.2816 +198608 -0.2613 +198609 -0.3307 +198610 -0.3542 +198611 -0.264 +198612 -0.2482 +198701 -0.1421 +198702 -0.092 +198703 -0.2871 +198704 -0.1516 +198705 -0.1118 +198706 -0.0174 +198707 0.0778 +198708 -0.0949 +198709 -0.0279 +198710 -0.1066 +198711 -0.1359 +198712 0.0729 +198801 0.0599 +198802 -0.136 +198803 0.0022 +198804 -0.0064 +198805 0.0585 +198806 0.017 +198807 -0.0303 +198808 0.0094 +198809 0.0089 +198810 -0.1119 +198811 -0.3316 +198812 -0.1708 +198901 -0.4052 +198902 -0.1396 +198903 -0.1631 +198904 -0.1324 +198905 -0.2464 +198906 -0.2324 +198907 -0.0708 +198908 -0.1457 +198909 -0.0867 +198910 -0.1352 +198911 -0.2527 +198912 -0.041 +199001 -0.0391 +199002 -0.0777 +199003 0.2671 +199004 0.1302 +199005 0.1443 +199006 -0.0106 +199007 0.0889 +199008 0.0098 +199009 -0.0343 +199010 0.0814 +199011 0.1168 +199012 0.0494 +199101 0.0252 +199102 0.0746 +199103 -0.0587 +199104 0.0598 +199105 -0.0158 +199106 0.2017 +199107 0.1192 +199108 0.0362 +199109 -0.0056 +199110 -0.1087 +199111 -0.1209 +199112 -0.1381 +199201 -0.0193 +199202 -0.0535 +199203 -0.0529 +199204 -0.237 +199205 -0.1777 +199206 -0.1489 +199207 -0.2948 +199208 -0.3124 +199209 -0.4129 +199210 -0.3618 +199211 -0.3805 +199212 -0.2644 +199301 -0.1167 +199302 -0.1113 +199303 -0.1695 +199304 -0.1434 +199305 -0.1343 +199306 -0.1288 +199307 -0.1836 +199308 -0.2087 +199309 -0.3204 +199310 -0.1906 +199311 -0.3052 +199312 -0.154 +199401 -0.2047 +199402 -0.4391 +199403 -0.2242 +199404 -0.0979 +199405 -0.1875 +199406 -0.0802 +199407 -0.1083 +199408 -0.2086 +199409 -0.0425 +199410 -0.0524 +199411 -0.012 +199412 -0.0731 +199501 0.0619 +199502 0.2626 +199503 -0.0415 +199504 0.0632 +199505 -0.0742 +199506 0.0877 +199507 0.0624 +199508 0.0688 +199509 -0.0044 +199510 0.0447 +199511 0.0131 +199512 -0.1416 +199601 -0.1686 +199602 -0.0248 +199603 -0.1161 +199604 -0.1619 +199605 -0.2063 +199606 -0.142 +199607 -0.04 +199608 0.0642 +199609 -0.1313 +199610 -0.2007 +199611 0.0178 +199612 -0.0471 +199701 -0.1784 +199702 -0.1172 +199703 0.024 +199704 -0.1454 +199705 -0.0915 +199706 0.0938 +199707 -0.0057 +199708 0.0417 +199709 0.1316 +199710 0.1868 +199711 0.2191 +199712 0.151 +199801 0.143 +199802 0.3514 +199803 0.1589 +199804 0.3034 +199805 0.3391 +199806 0.357 +199807 0.2881 +199808 0.3172 +199809 0.1434 +199810 0.062 +199811 -0.0017 +199812 0.1115 +199901 -0.036 +199902 0.1493 +199903 -0.1965 +199904 -0.121 +199905 -0.1364 +199906 -0.0584 +199907 -0.0356 +199908 -0.0618 +199909 -0.0044 +199910 -0.0617 +199911 -0.0657 +199912 -0.0247 +200001 -0.1986 +200002 0.0608 +200003 -0.0243 +200004 0.0999 +200005 -0.0597 +200006 -0.0701 +200007 -0.0714 +200008 0.0007 +200009 -0.0425 +200010 -0.1561 +200011 -0.1091 +200012 -0.1434 +200101 -0.0388 +200102 -0.0855 +200103 0.0351 +200104 0.0292 +200105 0.1151 +200106 0.0628 +200107 0.1458 +200108 0.1248 +200109 0.1181 +200110 0.1336 +200111 0.3371 +200112 0.229 +200201 0.2862 +200202 0.1891 +200203 0.3853 +200204 0.1189 +200205 0.2409 +200206 0.197 +200207 0.2003 +200208 0.1291 +200209 0.2015 +200210 0.1587 +200211 0.1827 +200212 0.0767 +200301 0.2975 +200302 0.1098 +200303 0.0283 +200304 0.0625 +200305 0.1472 +200306 0.035 +200307 0.1191 +200308 0.2217 +200309 0.27 +200310 0.3437 +200311 0.1999 +200312 0.3762 +200401 0.1492 +200402 0.2243 +200403 0.1831 +200404 0.1682 +200405 -0.0494 +200406 0.0804 +200407 -0.1095 +200408 0.0141 +200409 0.1562 +200410 0.2464 +200411 0.3085 +200412 0.1032 +200501 0.3385 +200502 0.2033 +200503 0.2828 +200504 0.2531 +200505 0.2305 +200506 0.2503 +200507 0.2517 +200508 0.2053 +200509 0.3259 +200510 0.4115 +200511 0.3688 +200512 0.3 +200601 0.1472 +200602 0.2867 +200603 0.1829 +200604 0.1127 +200605 0.0892 +200606 0.255 +200607 0.1697 +200608 0.2467 +200609 0.2443 +200610 0.3775 +200611 0.3384 +200612 0.3942 +200701 0.5542 +200702 0.2852 +200703 0.195 +200704 0.3563 +200705 0.2448 +200706 0.15 +200707 0.1727 +200708 0.157 +200709 0.1064 +200710 0.2256 +200711 0.1986 +200712 0.1096 +200801 -0.1371 +200802 -0.1236 +200803 0.2131 +200804 0.0559 +200805 0.0557 +200806 -0.0246 +200807 0.1429 +200808 0.0967 +200809 0.1662 +200810 0.2767 +200811 0.2888 +200812 0.1549 +200901 0.2507 +200902 0.1625 +200903 0.0731 +200904 0.1225 +200905 0.1569 +200906 0.1782 +200907 0.304 +200908 0.2209 +200909 0.3 +200910 0.3196 +200911 0.3783 +200912 0.2669 +201001 0.3847 +201002 0.4194 +201003 0.4633 +201004 0.435 +201005 0.3593 +201006 0.2604 +201007 0.2182 +201008 0.2218 +201009 0.2953 +201010 0.356 +201011 0.3712 +201012 0.0971 +201101 0.1006 +201102 0.0213 +201103 0.1357 +201104 0.1962 +201105 0.1192 +201106 0.1943 +201107 0.3094 +201108 0.2865 +201109 0.2436 +201110 0.2692 +201111 0.1428 +201112 0.1609 +201201 0.0255 +201202 0.0183 +201203 0.0581 +201204 0.2369 +201205 0.3344 +201206 0.2933 +201207 0.2066 +201208 0.2521 +201209 0.3091 +201210 0.4587 +201211 0.4333 +201212 0.1667 +201301 0.3378 +201302 0.2129 +201303 0.2182 +201304 0.1461 +201305 0.1823 +201306 0.2813 +201307 0.1413 +201308 0.2304 +201309 0.3659 +201310 0.291 +201311 0.3871 +201312 0.3255 +201401 0.318 +201402 0.1015 +201403 0.2849 +201404 0.2921 +201405 0.3443 +201406 0.246 +201407 0.232 +201408 0.3116 +201409 0.3807 +201410 0.4032 +201411 0.2885 +201412 0.387 +201501 0.3835 +201502 0.396 +201503 0.4229 +201504 0.2391 +201505 0.3376 +201506 0.3601 +201507 0.32 +201508 0.4178 +201509 0.4631 +201510 0.6809 +201511 0.6232 +201512 0.738 +201601 0.742 +201602 0.885 +201603 0.8201 +201604 0.7121 +201605 0.5762 +201606 0.435 +201607 0.5268 +201608 0.5768 +201609 0.554 +201610 0.5812 +201611 0.6422 +201612 0.5341 +201701 0.5945 +201702 0.6967 +201703 0.6938 +201704 0.5108 +201705 0.5335 +201706 0.3757 +201707 0.4319 +201708 0.4715 +201709 0.4758 +201710 0.599 +201711 0.4853 +201712 0.5705 +201801 0.4317 +201802 0.4598 +201803 0.4674 +201804 0.4877 +201805 0.4128 +201806 0.3989 +201807 0.4446 +201808 0.384 +201809 0.3957 +201810 0.5942 +201811 0.4755 +201812 0.5296 +201901 0.4753 +201902 0.5056 +201903 0.702 +201904 0.6198 +201905 0.5177 +201906 0.5424 +201907 0.5631 +201908 0.5316 diff -r 000000000000 -r 2ea0576cb062 test-data/T2Mstripes.png Binary file test-data/T2Mstripes.png has changed diff -r 000000000000 -r 2ea0576cb062 test-data/T2Mstripes_with_axis.png Binary file test-data/T2Mstripes_with_axis.png has changed