Next changeset 1:706666d912d5 (2019-10-05) |
Commit message:
planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/psy-maps commit c1362af034361b6fb869411f1ea928388f230d72 |
added:
README.md psy-maps.xml psymap_simple.py test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc test-data/TS.f2000.T31T31.control.cam.h0.0014-12.png test-data/TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png |
b |
diff -r 000000000000 -r db8d76da4174 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Apr 25 18:11:49 2019 -0400 |
b |
@@ -0,0 +1,8 @@ + +# psy-map + +This tools creates an image (png format) corresponding to the visualization on a geographical map of a variable extracted from a +netCDF file (input file). By default, the projection is ``PlateCarree`` and colormap is ``jet``. These settings can be changed in *Advanced settings*. + +It uses psy-maps, a python package to generate plots. More information about +psyplot and psy-maps can be found at https://psyplot.readthedocs.io/projects/psy-maps/en/latest/ |
b |
diff -r 000000000000 -r db8d76da4174 psy-maps.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/psy-maps.xml Thu Apr 25 18:11:49 2019 -0400 |
[ |
b'@@ -0,0 +1,180 @@\n+<tool id="psy_maps" name="map plot" version="1.2.0">\n+ <description>gridded (lat/lon) netCDF data</description>\n+ <requirements>\n+ <requirement type="package" version="3">python</requirement>\n+ <requirement type="package" version="1.2.0">psy-maps</requirement>\n+ <requirement type="package" version="1.2.0">psy-reg</requirement>\n+ <requirement type="package" version="1.2.2">psyplot-gui</requirement>\n+ <requirement type="package" version="1.4.1">netcdf4</requirement>\n+ </requirements>\n+ <command detect_errors="exit_code"><![CDATA[\n+ python3 \'$__tool_directory__/psymap_simple.py\'\n+ \'$ifilename\' \'$variable\'\n+ --proj \'$adv.projection\'\n+ --cmap \'$adv.colormap\'\n+ --output image.png\n+ ]]></command>\n+ <inputs>\n+ <param name="ifilename" type="data" format="netcdf" label="input with geographical coordinates (netCDF format)"></param>\n+ <param name="variable" type="text" value="TS" label="variable name as given in the netCDF file" />\n+ <section name="adv" title="Advanced Options" expanded="false">\n+ <param name="projection" type="select">\n+ <option value="" selected="true">PlateCarree</option>\n+ <option value="robin">Robinson</option>\n+ <option value="moll">Mollweide</option>\n+ <option value="geo">Geostationary</option>\n+ <option value="northpole">NorthPolarStereo</option>\n+ <option value="southpole">SouthPolarStereo</option>\n+ <option value="ortho">Orthographic</option>\n+ <option value="stereo">Stereographic</option>\n+ <option value="near">NearsidePerspective</option>\n+ </param>\n+ <param name="colormap" type="select">\n+ <option value="Accent">Accent</option>\n+ <option value="Blues">Blues</option>\n+ <option value="BrBG">BrBG</option>\n+ <option value="BuGn">BuGn</option>\n+ <option value="BuPu">BuPu</option>\n+ <option value="CMRmap">CMRmap</option>\n+ <option value="Dark2">Dark2</option>\n+ <option value="GnBu">GnBu</option>\n+ <option value="Greens">Greens</option>\n+ <option value="Greys">Greys</option>\n+ <option value="OrRd">OrRd</option>\n+ <option value="Oranges">Oranges</option>\n+ <option value="PRGn">PRGn</option>\n+ <option value="Paired">Paired</option>\n+ <option value="Pastel1">Pastel1</option>\n+ <option value="Pastel2">Pastel2</option>\n+ <option value="PiYG">PiYG</option>\n+ <option value="PuBu">PuBu</option>\n+ <option value="PuBuGn">PuBuGn</option>\n+ <option value="PuOr">PuOr</option>\n+ <option value="PuRd">PuRd</option>\n+ <option value="Purples">Purples</option>\n+ <option value="RdBu">RdBu</option>\n+ <option value="RdGy">RdGy</option>\n+ <option value="RdPu">RdPu</option>\n+ <option value="RdYlBu">RdYlBu</option>\n+ <option value="RdYlGn">RdYlGn</option>\n+ <option value="Reds">Reds</option>\n+ <option value="Set1">Set1</option>\n+ <option value="Set2">Set2</option>\n+ <option value="Set3">Set3</option>\n+ <option value="Spectral">Spectral</option>\n+ <option value="Wistia">Wistia</option>\n+ <option value="YlGn">YlGn</option>\n+ <option value="YlGnBu">YlGnBu</option>\n+ <option value="YlOrBr">YlOrBr</option>\n+ <option value="YlOrRd">YlOrRd</option>\n+ <option value="afmhot">afmhot</option>\n+ <option value="autumn">autumn</option>\n+ <option value="binary"'..b'ption value="gist_stern">gist_stern</option>\n+ <option value="gist_yarg">gist_yarg</option>\n+ <option value="gnuplot">gnuplot</option>\n+ <option value="gnuplot2">gnuplot2</option>\n+ <option value="gray">gray</option>\n+ <option value="hot">hot</option>\n+ <option value="hsv">hsv</option>\n+ <option value="jet" selected="true">jet</option>\n+ <option value="nipy_spectral">nipy_spectral</option>\n+ <option value="ocean">ocean</option>\n+ <option value="pink">pink</option>\n+ <option value="prism">prism</option>\n+ <option value="rainbow">rainbow</option>\n+ <option value="seismic">seismic</option>\n+ <option value="spring">spring</option>\n+ <option value="summer">summer</option>\n+ <option value="tab10">tab10</option>\n+ <option value="tab20">tab20</option>\n+ <option value="tab20b">tab20b</option>\n+ <option value="tab20c">tab20c</option>\n+ <option value="terrain">terrain</option>\n+ <option value="winter">winter</option>\n+ </param>\n+ </section>\n+ </inputs>\n+ <outputs>\n+ <data name="ofilename" format="png" from_work_dir="image.png"/>\n+ </outputs>\n+ <tests>\n+ <test>\n+ <param name="ifilename" value="TS.f2000.T31T31.control.cam.h0.0014-12.nc" />\n+ <param name="variable" value="TS" />\n+ <param name="adv.projection" value="" />\n+ <param name="adv.colormap" value="jet" />\n+ <output name="ofilename" ftype="png" file="TS.f2000.T31T31.control.cam.h0.0014-12.png" compare="sim_size" delta="500"/>\n+ </test>\n+ <test>\n+ <param name="ifilename" value="TS.f2000.T31T31.control.cam.h0.0014-12.nc" />\n+ <param name="variable" value="TS" />\n+ <param name="adv.projection" value="ortho" />\n+ <param name="adv.colormap" value="jet" />\n+ <output name="ofilename" ftype="png" file="TS.f2000.T31T31.control.cam.h0.0014-12.png" compare="sim_size" delta="500"/>\n+ </test>\n+ </tests>\n+ <help><![CDATA[\n+\n+**Visualization on a map with psyplot**\n+=========================================\n+\n+This tool wraps the functionality of ``psyplot.plot.mapplot``.\n+\n+\n+.. class:: infomark\n+\n+ The wrappers aims at providing the same functionality as ``psyplot.plot.mapplot`` but it has some limitations.\n+ The input file must be in netCDF format and must contain 2D arrays with geographical coordinatates\n+ (latitudes, longitudes) given in degrees.\n+ TODO: Fill in help.\n+\n+**What it does**\n+----------------\n+\n+This tools creates an image (png format) corresponding to the visualization on a geographical map of a variable extracted from a\n+netCDF file (input file). By default, the projection is ``PlateCarree`` and colormap is ``jet``. These settings can be changed in *Advanced settings*.\n+\n+\n+**Usage**\n+\n+::\n+\n+ usage: psymap_simple.py [-h] [--proj PROJ] [--cmap CMAP] [--output OUTPUT] [-v] input varname\n+\n+\n+Positional arguments:\n+~~~~~~~~~~~~~~~~~~~~~\n+\n+- **input**: input filename with geographical coordinates (netCDF format)\n+- **varname**: Specify which variable to plot (case sensitive)\n+\n+Optional arguments:\n+~~~~~~~~~~~~~~~~~~~~~\n+\n+ -h, --help show this help message and exit\n+ --proj PROJ Specify the projection on which we draw\n+ --cmap CMAP Specify which colormap to use for plotting\n+ --output OUTPUT output filename to store resulting image (png format)\n+ -v, --verbose switch on verbose mode\n+\n+It uses psy-maps, a python package to generate plots. More information about\n+psyplot and psy-maps can be found at https://psyplot.readthedocs.io/projects/psy-maps/en/latest/\n+\n+ ]]></help>\n+ <citations>\n+ </citations>\n+</tool>\n' |
b |
diff -r 000000000000 -r db8d76da4174 psymap_simple.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/psymap_simple.py Thu Apr 25 18:11:49 2019 -0400 |
[ |
@@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +# +# +# usage: psymap_simple.py [-h] [--proj PROJ] +# [--cmap CMAP] +# [--output OUTPUT] +# [-v] +# input varname +# +# positional arguments: +# input input filename with geographical coordinates (netCDF +# format) +# varname Specify which variable to plot (case sensitive) +# +# optional arguments: +# -h, --help show this help message and exit +# --proj PROJ Specify the projection on which we draw +# --cmap CMAP Specify which colormap to use for plotting +# --output OUTPUT output filename to store resulting image (png format) +# -v, --verbose switch on verbose mode +# + +import argparse +import warnings +from pathlib import Path + +import matplotlib as mpl +mpl.use('Agg') +from matplotlib import pyplot # noqa: I202,E402 + +import psyplot.project as psy # noqa: I202,E402 + + +class PsyPlot (): + def __init__(self, input, proj, varname, cmap, output, + verbose=False + ): + self.input = input + self.proj = proj + self.varname = varname + self.cmap = cmap + if output is None: + self.output = Path(input).stem + '.png' + else: + self.output = output + self.verbose = verbose + if verbose: + print("input: ", self.input) + print("proj: ", self.proj) + print("varname: ", self.varname) + print("cmap: ", self.cmap) + print("output: ", self.output) + + def plot(self): + if self.cmap is None and self.proj is None: + print("op1") + psy.plot.mapplot(self.input, name=self.varname, + clabel='{desc}') + elif self.proj is None or self.proj == '': + print("op2") + psy.plot.mapplot(self.input, name=self.varname, + cmap=self.cmap, clabel='{desc}') + elif self.cmap is None or self.cmap == '': + print("op3") + psy.plot.mapplot(self.input, name=self.varname, + projection=self.proj, + clabel='{desc}') + else: + print("op4") + psy.plot.mapplot(self.input, name=self.varname, + cmap=self.cmap, + projection=self.proj, + clabel='{desc}') + + pyplot.savefig(self.output) + + +def psymap_plot(input, proj, varname, cmap, output, verbose): + """Generate plot from input filename""" + + p = PsyPlot(input, proj, varname, cmap, output, verbose) + p.plot() + + +if __name__ == '__main__': + warnings.filterwarnings("ignore") + parser = argparse.ArgumentParser() + parser.add_argument( + 'input', + help='input filename with geographical coordinates (netCDF format)' + ) + + parser.add_argument( + '--proj', + help='Specify the projection on which we draw' + ) + parser.add_argument( + 'varname', + help='Specify which variable to plot (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( + "-v", "--verbose", + help="switch on verbose mode", + action="store_true") + args = parser.parse_args() + + psymap_plot(args.input, args.proj, args.varname, args.cmap, + args.output, args.verbose) |
b |
diff -r 000000000000 -r db8d76da4174 test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc |
b |
Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc has changed |
b |
diff -r 000000000000 -r db8d76da4174 test-data/TS.f2000.T31T31.control.cam.h0.0014-12.png |
b |
Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.png has changed |
b |
diff -r 000000000000 -r db8d76da4174 test-data/TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png |
b |
Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png has changed |