Repository 'psy_maps'
hg clone https://toolshed.g2.bx.psu.edu/repos/climate/psy_maps

Changeset 1:706666d912d5 (2019-10-05)
Previous changeset 0:db8d76da4174 (2019-04-25) Next changeset 2:e6d1e9d6b399 (2024-09-26)
Commit message:
"planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/psy-maps commit 4803d769c7b0b37fa80c69bd7327f6789cd3c6bf"
modified:
psy-maps.xml
psymap_simple.py
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 db8d76da4174 -r 706666d912d5 psy-maps.xml
--- a/psy-maps.xml Thu Apr 25 18:11:49 2019 -0400
+++ b/psy-maps.xml Sat Oct 05 17:11:18 2019 -0400
[
@@ -1,23 +1,49 @@
-<tool id="psy_maps" name="map plot" version="1.2.0">
+<tool id="psy_maps" name="map plot" version="1.2.1">
     <description>gridded (lat/lon) netCDF data</description>
     <requirements>
         <requirement type="package" version="3">python</requirement>
+        <requirement type="package" version="1.2.1">psyplot</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>
+        <requirement type="package" version="1.4.2">netcdf4</requirement>
     </requirements>
     <command detect_errors="exit_code"><![CDATA[
+       HOME=`pwd`  &&
        python3 '$__tool_directory__/psymap_simple.py'
             '$ifilename' '$variable'
             --proj '$adv.projection'
             --cmap '$adv.colormap'
             --output image.png
+       #if str($adv.multiple_plot.selector) == 'yes'
+            --time '$adv.multiple_plot.time'
+            --format '$adv.multiple_plot.format'
+            --ncol '$adv.multiple_plot.ncol'
+            --nrow '$adv.multiple_plot.nrow'
+       #end if
+       #if str($adv.multiple_plot.title).strip()
+            --title '$adv.multiple_plot.title'
+       #end if
     ]]></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">
+            <conditional name="multiple_plot">
+                <param name="selector" type="select" label="multiple times">
+                    <option value="yes">yes</option>
+                    <option value="no" selected="true">no</option>
+                </param>
+                <when value="yes">
+                    <param name="time" type="text" value="0" label="comma separated list of indexes for fields to plot" />
+                    <param name="format" type="text" value="%Y-%m-%d %H:%M:%S" label="date and time format" />
+                    <param name="ncol" type="integer" value="1" min="1" max="4" label="number of columns for subplot grid" />
+                    <param name="nrow" type="integer" value="1" min="1" max="20" label="number of rows for subplot grid" />
+                    <param name="title" type="text" value="" label="subplot title (repeated on each subplot)" />
+                </when>
+                <when value="no">
+                    <param name="title" type="text" value="" label="plot title" />
+                </when>
+            </conditional>
             <param name="projection" type="select">
                 <option value="" selected="true">PlateCarree</option>
                 <option value="robin">Robinson</option>
@@ -55,6 +81,9 @@
                 <option value="RdBu">RdBu</option>
                 <option value="RdGy">RdGy</option>
                 <option value="RdPu">RdPu</option>
+                <option value="RdBu_r">RdBu_r</option>
+                <option value="RdGy_r">RdGy_r</option>
+                <option value="RdPu_r">RdPu_r</option>
                 <option value="RdYlBu">RdYlBu</option>
                 <option value="RdYlGn">RdYlGn</option>
                 <option value="Reds">Reds</option>
@@ -115,16 +144,16 @@
         <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" />
+            <param name="projection" value="" />
+            <param name="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"/>
+            <param name="projection" value="ortho" />
+            <param name="colormap" value="RdBu_r" />
+            <output name="ofilename" ftype="png" file="TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png" compare="sim_size" delta="500"/>
         </test>
     </tests>
     <help><![CDATA[
@@ -153,7 +182,8 @@
 
 ::
 
-  usage: psymap_simple.py [-h] [--proj PROJ] [--cmap CMAP] [--output OUTPUT] [-v] input varname
+  usage: psymap_simple.py [-h] [--proj PROJ] [--cmap CMAP] [--output OUTPUT] [--time TIME]
+                          [--format FORMAT] [--title TITLE] [--ncol NCOL] [--nrow NROW] [-v] input varname
 
 
 Positional arguments:
@@ -170,6 +200,11 @@
   --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
+  --time TIME      list of times to plot for multiple plots
+  --format FORMAT  format for date/time (default is Month d, yyyy)
+  --title TITLE    plot title
+  --ncol NCOL      number of columns for multiple plots
+  --nrow NROW      number of rows for multiple plots
 
 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 db8d76da4174 -r 706666d912d5 psymap_simple.py
--- a/psymap_simple.py Thu Apr 25 18:11:49 2019 -0400
+++ b/psymap_simple.py Sat Oct 05 17:11:18 2019 -0400
[
@@ -17,6 +17,11 @@
 #  --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)
+#  --time TIMES     time index from the file for multiple plots ("0 1 2 3")
+#  --nrow NROW      number of rows for multiple plot grid
+#  --ncol NCOL      number of columns for multiple plot grid
+#  --format         date format such as %Y (for year) %B (for month), etc.
+#  --title          plot or subplot title
 #  -v, --verbose    switch on verbose mode
 #
 
@@ -29,16 +34,34 @@
 from matplotlib import pyplot  # noqa: I202,E402
 
 import psyplot.project as psy  # noqa: I202,E402
+from psyplot import rcParams   # noqa: I202,E402
 
 
 class PsyPlot ():
-    def __init__(self, input, proj, varname, cmap, output,
-                 verbose=False
-                 ):
+    def __init__(self, input, proj, varname, cmap, output, verbose=False,
+                 time=[], nrow=1, ncol=1, format="%B %e, %Y",
+                 title=""):
         self.input = input
         self.proj = proj
         self.varname = varname
         self.cmap = cmap
+        self.time = time
+        if format is None:
+            self.format = ""
+        else:
+            self.format = format.replace('X', '%')
+        if title is None:
+            self.title = ""
+        else:
+            self.title = title
+        if ncol is None:
+            self.ncol = 1
+        else:
+            self.ncol = int(ncol)
+        if nrow is None:
+            self.nrow = 1
+        else:
+            self.nrow = int(nrow)
         if output is None:
             self.output = Path(input).stem + '.png'
         else:
@@ -49,37 +72,101 @@
             print("proj: ", self.proj)
             print("varname: ", self.varname)
             print("cmap: ", self.cmap)
+            print("time: ", self.time)
+            print("ncol: ", self.ncol)
+            print("nrow: ", self.nrow)
+            print("title: ", self.title)
+            print("date format: ", self.format)
             print("output: ", self.output)
 
     def plot(self):
+        if self.title and self.format:
+            title = self.title + "\n" + self.format
+        elif not self.title and self.format:
+            title = self.format
+        elif self.title and not self.format:
+            title = self.title
+        else:
+            title = '%(long_name)s'
+
         if self.cmap is None and self.proj is None:
-            print("op1")
             psy.plot.mapplot(self.input, name=self.varname,
+                             title=title,
                              clabel='{desc}')
-        elif self.proj is None or self.proj == '':
-            print("op2")
+        elif self.proj is None or not self.proj:
             psy.plot.mapplot(self.input, name=self.varname,
+                             title=title,
                              cmap=self.cmap, clabel='{desc}')
-        elif self.cmap is None or self.cmap == '':
-            print("op3")
+        elif self.cmap is None or not self.cmap:
             psy.plot.mapplot(self.input, name=self.varname,
                              projection=self.proj,
+                             title=title,
                              clabel='{desc}')
         else:
-            print("op4")
             psy.plot.mapplot(self.input, name=self.varname,
                              cmap=self.cmap,
                              projection=self.proj,
+                             title=title,
                              clabel='{desc}')
 
         pyplot.savefig(self.output)
 
+    def multiple_plot(self):
+        if not self.format:
+            self.format = "%B %e, %Y"
 
-def psymap_plot(input, proj, varname, cmap, output, verbose):
+        if not self.title:
+            title = self.format
+        else:
+            title = self.title + "\n" + self.format
+        mpl.rcParams['figure.figsize'] = [20, 8]
+        mpl.rcParams.update({'font.size': 8})
+        rcParams.update({'plotter.maps.grid_labelsize': 8.0})
+        if self.cmap is None and self.proj is None:
+            m = psy.plot.mapplot(self.input, name=self.varname,
+                                 title=title,
+                                 ax=(self.nrow, self.ncol),
+                                 time=self.time, sort=['time'],
+                                 clabel='{desc}')
+            m.share(keys='bounds')
+        elif self.proj is None or not self.proj:
+            m = psy.plot.mapplot(self.input, name=self.varname,
+                                 title=title,
+                                 ax=(self.nrow, self.ncol),
+                                 time=self.time, sort=['time'],
+                                 cmap=self.cmap, clabel='{desc}')
+            m.share(keys='bounds')
+        elif self.cmap is None or not self.cmap:
+            m = psy.plot.mapplot(self.input, name=self.varname,
+                                 projection=self.proj,
+                                 ax=(self.nrow, self.ncol),
+                                 time=self.time, sort=['time'],
+                                 title=title,
+                                 clabel='{desc}')
+            m.share(keys='bounds')
+        else:
+            m = psy.plot.mapplot(self.input, name=self.varname,
+                                 cmap=self.cmap,
+                                 projection=self.proj,
+                                 ax=(self.nrow, self.ncol),
+                                 time=self.time, sort=['time'],
+                                 title=title,
+                                 clabel='{desc}')
+            m.share(keys='bounds')
+
+        pyplot.savefig(self.output)
+
+
+def psymap_plot(input, proj, varname, cmap, output, verbose, time,
+                nrow, ncol, format, title):
     """Generate plot from input filename"""
 
-    p = PsyPlot(input, proj, varname, cmap, output, verbose)
-    p.plot()
+    p = PsyPlot(input, proj, varname, cmap, output, verbose, time,
+                nrow, ncol, format, title)
+    if len(time) == 0:
+        p.plot()
+    else:
+        p.multiple_plot()
 
 
 if __name__ == '__main__':
@@ -107,10 +194,35 @@
         help='output filename to store resulting image (png format)'
     )
     parser.add_argument(
+        '--time',
+        help='list of times to plot for multiple plots'
+    )
+    parser.add_argument(
+        '--format',
+        help='format for date/time (default is Month d, yyyy)'
+    )
+    parser.add_argument(
+        '--title',
+        help='plot title'
+    )
+    parser.add_argument(
+        '--ncol',
+        help='number of columns for multiple plots'
+    )
+    parser.add_argument(
+        '--nrow',
+        help='number of rows for multiple plots'
+    )
+    parser.add_argument(
         "-v", "--verbose",
         help="switch on verbose mode",
         action="store_true")
     args = parser.parse_args()
 
+    if args.time is None:
+        time = []
+    else:
+        time = list(map(int, args.time.split(",")))
     psymap_plot(args.input, args.proj, args.varname, args.cmap,
-                args.output, args.verbose)
+                args.output, args.verbose, time,
+                args.nrow, args.ncol, args.format, args.title)
b
diff -r db8d76da4174 -r 706666d912d5 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 db8d76da4174 -r 706666d912d5 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