From f5c0f2c4df4dfdd8f8a89004073629ce8daea647 Mon Sep 17 00:00:00 2001 From: Matthias Frey Date: Fri, 21 May 2021 15:50:21 +0200 Subject: [PATCH 1/2] add plot_parcel_number --- python-scripts/plot-diagnostics.py | 9 ++++++-- python-scripts/tools/plots.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/python-scripts/plot-diagnostics.py b/python-scripts/plot-diagnostics.py index 9b590ab0d..da82cafce 100644 --- a/python-scripts/plot-diagnostics.py +++ b/python-scripts/plot-diagnostics.py @@ -4,7 +4,8 @@ plot_rms_volume_error, \ plot_max_volume_error, \ plot_aspect_ratio, \ - plot_parcel_volume + plot_parcel_volume, \ + plot_parcel_number import os import sys @@ -19,7 +20,8 @@ 'rms-volume-error', 'max-volume-error', 'aspect-ratio', - 'parcel-volume' + 'parcel-volume', + 'parcel-number' ] @@ -66,6 +68,9 @@ elif args.kind == kinds[3]: for fname in args.filenames: plot_parcel_volume(fname, show=args.show, fmt=args.fmt) + elif args.kind == kinds[3]: + for fname in args.filenames: + plot_parcel_number(fname, show=args.show, fmt=args.fmt) else: raise ValuError("Plot '" + args.kind + "' not supported!") diff --git a/python-scripts/tools/plots.py b/python-scripts/tools/plots.py index bb85e164b..a9fbbd179 100644 --- a/python-scripts/tools/plots.py +++ b/python-scripts/tools/plots.py @@ -321,6 +321,41 @@ def plot_aspect_ratio(fname, show=False, fmt="png"): plt.close() +def plot_parcel_number(fname, show=False, fmt="png"): + """ + Plot the number of parcels in simulation. + """ + h5reader = H5Reader() + h5reader.open(fname) + + nsteps = h5reader.get_num_steps() + + nparcels = np.zeros(nsteps) + + for step in range(nsteps): + nparcels[step] = h5reader.get_num_parcels(step) + + h5reader.close() + + plt.figure() + plt.plot(nparcels, color='blue') + plt.grid(linestyle='dashed', zorder=-1) + + plt.xlabel(r'number of iterations') + plt.ylabel(r'parcel count$') + + plt.legend(loc='upper center', ncol=3, bbox_to_anchor=(0.5, 1.25)) + + plt.tight_layout() + + if show: + plt.show() + else: + prefix = os.path.splitext(fname)[0] + plt.savefig(prefix + '_parcel_number_profile.' + fmt, bbox_inches='tight') + plt.close() + + def plot_parcel_volume(fname, show=False, fmt="png"): """ Plot the mean and standard deviation of the parcel volume From df8ba1670fc47fc771131f7d6a1fd6edd57c0272 Mon Sep 17 00:00:00 2001 From: Matthias Frey Date: Fri, 21 May 2021 15:55:58 +0200 Subject: [PATCH 2/2] fix Python script bugs --- python-scripts/plot-diagnostics.py | 2 +- python-scripts/tools/plots.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/python-scripts/plot-diagnostics.py b/python-scripts/plot-diagnostics.py index da82cafce..de63819a9 100644 --- a/python-scripts/plot-diagnostics.py +++ b/python-scripts/plot-diagnostics.py @@ -68,7 +68,7 @@ elif args.kind == kinds[3]: for fname in args.filenames: plot_parcel_volume(fname, show=args.show, fmt=args.fmt) - elif args.kind == kinds[3]: + elif args.kind == kinds[4]: for fname in args.filenames: plot_parcel_number(fname, show=args.show, fmt=args.fmt) else: diff --git a/python-scripts/tools/plots.py b/python-scripts/tools/plots.py index a9fbbd179..0dc0c1888 100644 --- a/python-scripts/tools/plots.py +++ b/python-scripts/tools/plots.py @@ -342,10 +342,7 @@ def plot_parcel_number(fname, show=False, fmt="png"): plt.grid(linestyle='dashed', zorder=-1) plt.xlabel(r'number of iterations') - plt.ylabel(r'parcel count$') - - plt.legend(loc='upper center', ncol=3, bbox_to_anchor=(0.5, 1.25)) - + plt.ylabel(r'parcel count') plt.tight_layout() if show: