From c7e9efe9aca6df8f7872407033c68bc96dc65170 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 3 May 2022 11:53:58 +0200 Subject: [PATCH] Diff between multiple olaflow results --- olaflow/processing/diff.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 olaflow/processing/diff.py diff --git a/olaflow/processing/diff.py b/olaflow/processing/diff.py new file mode 100644 index 0000000..8d23ba5 --- /dev/null +++ b/olaflow/processing/diff.py @@ -0,0 +1,59 @@ +import argparse +import gzip +from itertools import starmap +import logging +from multiprocessing import pool +import pathlib +import pickle + +from cycler import cycler +import matplotlib.pyplot as plt +import matplotlib.gridspec as gridspec +import numpy as np +from scipy import interpolate + +from .olaflow import OFModel + +parser = argparse.ArgumentParser(description="Post-process olaflow results") +parser.add_argument("-v", "--verbose", action="count", default=0) +parser.add_argument( + "-o", + "--output", + action="append", + type=pathlib.Path, + help="Post-processing directory", + required=True, +) +args = parser.parse_args() + +logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) +log = logging.getLogger("ola_post") + +log.info("Plotting comparison of model output") + + +def get_pickle(out): + with ( + path.open("rb") + if (path := out.joinpath("pickle")).exists() + else gzip.open(path.with_suffix(".gz"), "rb") + ) as f: + return pickle.load(f) + + +models = list(map(get_pickle, args.output)) + +fig, ax = plt.subplots(len(models), constrained_layout=True) +for i, (_ax, _model) in enumerate(zip(ax, models)): + _ax.contour( + _model.t, + _model.post_fields["graphUniform"]["x_alpha.water"], + _model.post_fields["graphUniform"]["alpha.water"].T, + (0.5,), + colors="k", + ) + + _ax.set(xlabel="t (s)", ylabel="z (m)", title=f"Case {i}") + _ax.grid() + +fig.savefig(args.output[0].joinpath(f"diff_{'_'.join([o.name for o in args.output])}.pdf"))