# HG changeset patch # User climate # Date 1556230309 14400 # Node ID db8d76da417411278ca481dce53734022a0c5ec3 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/psy-maps commit c1362af034361b6fb869411f1ea928388f230d72 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 @@ -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/ 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 @@ -0,0 +1,180 @@ + + gridded (lat/lon) netCDF data + + python + psy-maps + psy-reg + psyplot-gui + netcdf4 + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + +
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) diff -r 000000000000 -r db8d76da4174 test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc has changed diff -r 000000000000 -r db8d76da4174 test-data/TS.f2000.T31T31.control.cam.h0.0014-12.png Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.png has changed diff -r 000000000000 -r db8d76da4174 test-data/TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12_ortho.png has changed