changeset 0:db8d76da4174 draft

planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/psy-maps commit c1362af034361b6fb869411f1ea928388f230d72
author climate
date Thu, 25 Apr 2019 18:11:49 -0400
parents
children 706666d912d5
files 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
diffstat 6 files changed, 304 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Thu Apr 25 18:11:49 2019 -0400
@@ -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/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/psy-maps.xml	Thu Apr 25 18:11:49 2019 -0400
@@ -0,0 +1,180 @@
+<tool id="psy_maps" name="map plot" version="1.2.0">
+    <description>gridded (lat/lon) netCDF data</description>
+    <requirements>
+        <requirement type="package" version="3">python</requirement>
+        <requirement type="package" version="1.2.0">psy-maps</requirement>
+        <requirement type="package" version="1.2.0">psy-reg</requirement>
+        <requirement type="package" version="1.2.2">psyplot-gui</requirement>
+        <requirement type="package" version="1.4.1">netcdf4</requirement>
+    </requirements>
+    <command detect_errors="exit_code"><![CDATA[
+       python3 '$__tool_directory__/psymap_simple.py'
+            '$ifilename' '$variable'
+            --proj '$adv.projection'
+            --cmap '$adv.colormap'
+            --output image.png
+    ]]></command>
+    <inputs>
+        <param name="ifilename" type="data" format="netcdf" label="input with geographical coordinates (netCDF format)"></param>
+        <param name="variable" type="text" value="TS" label="variable name as given in the netCDF file" />
+        <section name="adv" title="Advanced Options" expanded="false">
+            <param name="projection" type="select">
+                <option value="" selected="true">PlateCarree</option>
+                <option value="robin">Robinson</option>
+                <option value="moll">Mollweide</option>
+                <option value="geo">Geostationary</option>
+                <option value="northpole">NorthPolarStereo</option>
+                <option value="southpole">SouthPolarStereo</option>
+                <option value="ortho">Orthographic</option>
+                <option value="stereo">Stereographic</option>
+                <option value="near">NearsidePerspective</option>
+            </param>
+            <param name="colormap" type="select">
+                <option value="Accent">Accent</option>
+                <option value="Blues">Blues</option>
+                <option value="BrBG">BrBG</option>
+                <option value="BuGn">BuGn</option>
+                <option value="BuPu">BuPu</option>
+                <option value="CMRmap">CMRmap</option>
+                <option value="Dark2">Dark2</option>
+                <option value="GnBu">GnBu</option>
+                <option value="Greens">Greens</option>
+                <option value="Greys">Greys</option>
+                <option value="OrRd">OrRd</option>
+                <option value="Oranges">Oranges</option>
+                <option value="PRGn">PRGn</option>
+                <option value="Paired">Paired</option>
+                <option value="Pastel1">Pastel1</option>
+                <option value="Pastel2">Pastel2</option>
+                <option value="PiYG">PiYG</option>
+                <option value="PuBu">PuBu</option>
+                <option value="PuBuGn">PuBuGn</option>
+                <option value="PuOr">PuOr</option>
+                <option value="PuRd">PuRd</option>
+                <option value="Purples">Purples</option>
+                <option value="RdBu">RdBu</option>
+                <option value="RdGy">RdGy</option>
+                <option value="RdPu">RdPu</option>
+                <option value="RdYlBu">RdYlBu</option>
+                <option value="RdYlGn">RdYlGn</option>
+                <option value="Reds">Reds</option>
+                <option value="Set1">Set1</option>
+                <option value="Set2">Set2</option>
+                <option value="Set3">Set3</option>
+                <option value="Spectral">Spectral</option>
+                <option value="Wistia">Wistia</option>
+                <option value="YlGn">YlGn</option>
+                <option value="YlGnBu">YlGnBu</option>
+                <option value="YlOrBr">YlOrBr</option>
+                <option value="YlOrRd">YlOrRd</option>
+                <option value="afmhot">afmhot</option>
+                <option value="autumn">autumn</option>
+                <option value="binary">binary</option>
+                <option value="bone">bone</option>
+                <option value="brg">brg</option>
+                <option value="bwr">bwr</option>
+                <option value="cool">cool</option>
+                <option value="coolwarm">coolwarm</option>
+                <option value="copper">copper</option>
+                <option value="cubehelix">cubehelix</option>
+                <option value="flag">flag</option>
+                <option value="gist_earth">gist_earth</option>
+                <option value="gist_gray">gist_gray</option>
+                <option value="gist_heat">gist_heat</option>
+                <option value="gist_ncar">gist_ncar</option>
+                <option value="gist_rainbow">gist_rainbow</option>
+                <option value="gist_stern">gist_stern</option>
+                <option value="gist_yarg">gist_yarg</option>
+                <option value="gnuplot">gnuplot</option>
+                <option value="gnuplot2">gnuplot2</option>
+                <option value="gray">gray</option>
+                <option value="hot">hot</option>
+                <option value="hsv">hsv</option>
+                <option value="jet" selected="true">jet</option>
+                <option value="nipy_spectral">nipy_spectral</option>
+                <option value="ocean">ocean</option>
+                <option value="pink">pink</option>
+                <option value="prism">prism</option>
+                <option value="rainbow">rainbow</option>
+                <option value="seismic">seismic</option>
+                <option value="spring">spring</option>
+                <option value="summer">summer</option>
+                <option value="tab10">tab10</option>
+                <option value="tab20">tab20</option>
+                <option value="tab20b">tab20b</option>
+                <option value="tab20c">tab20c</option>
+                <option value="terrain">terrain</option>
+                <option value="winter">winter</option>
+            </param>
+        </section>
+    </inputs>
+    <outputs>
+        <data name="ofilename" format="png" from_work_dir="image.png"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="ifilename" value="TS.f2000.T31T31.control.cam.h0.0014-12.nc" />
+            <param name="variable" value="TS" />
+            <param name="adv.projection" value="" />
+            <param name="adv.colormap" value="jet" />
+            <output name="ofilename" ftype="png" file="TS.f2000.T31T31.control.cam.h0.0014-12.png" compare="sim_size" delta="500"/>
+        </test>
+        <test>
+            <param name="ifilename" value="TS.f2000.T31T31.control.cam.h0.0014-12.nc" />
+            <param name="variable" value="TS" />
+            <param name="adv.projection" value="ortho" />
+            <param name="adv.colormap" value="jet" />
+            <output name="ofilename" ftype="png" file="TS.f2000.T31T31.control.cam.h0.0014-12.png" compare="sim_size" delta="500"/>
+        </test>
+    </tests>
+    <help><![CDATA[
+
+**Visualization on a map with psyplot**
+=========================================
+
+This tool wraps the functionality of ``psyplot.plot.mapplot``.
+
+
+.. class:: infomark
+
+        The wrappers aims at providing the same functionality as ``psyplot.plot.mapplot`` but it has some limitations.
+        The input file must be in netCDF format and must contain 2D arrays with geographical coordinatates
+        (latitudes, longitudes) given in degrees.
+        TODO: Fill in help.
+
+**What it does**
+----------------
+
+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*.
+
+
+**Usage**
+
+::
+
+  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
+
+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/
+
+    ]]></help>
+    <citations>
+    </citations>
+</tool>
--- /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)
Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc has changed
Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.png has changed
Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png has changed