Skip to content

Commit

Permalink
Fixing issues and added further test
Browse files Browse the repository at this point in the history
  • Loading branch information
pixalytics committed Sep 24, 2024
1 parent 5bb882a commit 8abdef5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
12 changes: 10 additions & 2 deletions tools/psy-maps/psy-maps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
</when>
</conditional>
<param name="logscale" type="select" label="log scale the data">
<option value="True">yes</option>
<option value="False" selected="true">no</option>
<option value="yes">yes</option>
<option value="no" selected="true">no</option>
</param>
<param name="projection" type="select">
<option value="" selected="true">PlateCarree</option>
Expand Down Expand Up @@ -167,6 +167,14 @@
<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>
<test>
<param name="ifilename" value="ESACCI-OC-L3S-CHLOR_A-20220601-RESIZED-fv6.0.nc" />
<param name="variable" value="chlor_a" />
<param name="projection" value="" />
<param name="colormap" value="jet" />
<param name="logscale" value="yes" />
<output name="ofilename" ftype="png" file="ESACCI-OC-L3S-CHLOR_A-20220601-RESIZED-fv6.0.png" compare="sim_size" delta="1500"/>
</test>
</tests>
<help><![CDATA[
Expand Down
55 changes: 43 additions & 12 deletions tools/psy-maps/psymap_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
import argparse
import warnings
from pathlib import Path
import math
import xarray

import matplotlib as mpl
mpl.use('Agg')
from matplotlib import pyplot # noqa: I202,E402

import psyplot
import psyplot.project as psy # noqa: I202,E402
from psyplot import rcParams # noqa: I202,E402

Expand All @@ -44,15 +47,36 @@ def __init__(self, input, varname, output=None, logscale=False, cmap=None,
proj=None, verbose=False, time=None, nrow=None, ncol=None,
format=None, title=None):
self.input = input

self.varname = varname
self.proj = proj if proj is not None else "cyl"
if proj is None or proj == "":
self.proj = "cyl"
else:
self.proj = proj
self.cmap = cmap if cmap is not None else "jet"
self.time = time if time is not None else []
self.title = title if title is not None else ""
self.ncol = int(ncol) if ncol is not None else int(1)
self.nrow = int(nrow) if nrow is not None else int(1)

# Open dataset
ds = xarray.open_dataset(input)[varname]
minv = math.log2(ds.data.min())
maxv = math.log2(ds.data.max())
if title is not None:
self.title = title
else:
self.title = ds.long_name
if len(self.title) > 60:
self.title = ds.standard_name
del ds

if logscale:
self.bounds = ['log', 2]
# Check that data range is sufficient for log scaling
if maxv < (minv * (10.0 ** 2.0)):
print("Not possible to log scale, switching to linear scale")
self.bounds = None
else:
self.bounds = ['log', 2]
else:
self.bounds = None
if format is None:
Expand All @@ -73,30 +97,32 @@ def __init__(self, input, varname, output=None, logscale=False, cmap=None,
print("nrow: ", self.nrow)
print("title: ", self.title)
print("date format: ", self.format)
print("logscale: ",self.bounds)
print("output: ", self.output)

def plot(self):
clabel = '{desc}'
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'

clabel = self.title

# Plot with chosen options
if self.bounds is None:
psy.plot.mapplot(self.input, name=self.varname,
cmap=self.cmap,
projection=self.proj,
title=title,
clabel='{desc}')
clabel=clabel)
else:
psy.plot.mapplot(self.input, name=self.varname,
cmap=self.cmap, bounds = self.bounds,
projection=self.proj,
title=title,
clabel='{desc}')
clabel=clabel)


pyplot.savefig(self.output)
Expand All @@ -109,6 +135,7 @@ def multiple_plot(self):
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})
Expand Down Expand Up @@ -166,9 +193,8 @@ def psymap_plot(input, proj, varname, logscale, cmap, output, verbose, time,
help='Specify which variable to plot (case sensitive)'
)
parser.add_argument(
"-l", "--logscale",
help='Plot the log scaled data',
action="store_true"
"--logscale",
help='Plot the log scaled data'
)
parser.add_argument(
'--cmap',
Expand Down Expand Up @@ -208,7 +234,12 @@ def psymap_plot(input, proj, varname, logscale, cmap, output, verbose, time,
time = []
else:
time = list(map(int, args.time.split(",")))

if args.logscale == 'no':
logscale = False
else:
logscale = True

psymap_plot(args.input, args.proj, args.varname, args.logscale, args.cmap,
psymap_plot(args.input, args.proj, args.varname, logscale, args.cmap,
args.output, args.verbose, time,
args.nrow, args.ncol, args.format, args.title)
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8abdef5

Please sign in to comment.