From d681acb703556d5fdb142a0090d087fa53ee6f28 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 4 May 2022 10:52:40 +0200 Subject: [PATCH] Update arguments for animate + black reformat --- olaflow/processing/animate.py | 23 ++++++++++++----------- olaflow/processing/animateU.py | 16 ++++++++-------- olaflow/processing/diff.py | 4 +++- olaflow/processing/olaflow.py | 9 ++++++--- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/olaflow/processing/animate.py b/olaflow/processing/animate.py index 3cb3692..4873e99 100644 --- a/olaflow/processing/animate.py +++ b/olaflow/processing/animate.py @@ -1,5 +1,4 @@ import argparse -import configparser import gzip import logging import multiprocessing as mp @@ -16,16 +15,20 @@ from .olaflow import OFModel parser = argparse.ArgumentParser(description="Post-process olaflow results") parser.add_argument("-v", "--verbose", action="count", default=0) -parser.add_argument("-c", "--config", default="config.ini") +parser.add_argument( + "-o", + "--output", + type=pathlib.Path, + help="Output directory for pickled data", + required=True, +) args = parser.parse_args() logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) log = logging.getLogger("ola_post") log.info("Animating olaFlow output") -config = configparser.ConfigParser() -config.read(args.config) -out = pathlib.Path(config.get("post", "out")) +out = args.output out.mkdir(parents=True, exist_ok=True) with ( @@ -35,8 +38,6 @@ with ( ) as f: model = pickle.load(f) -x0 = config.getfloat("post", "x") -z0 = config.getfloat("post", "z") i0 = np.argmin(np.abs((model.x - x0) + 1j * (model.z - z0))) x0, idx0 = np.unique(model.x.astype(np.half), return_inverse=True) @@ -54,7 +55,7 @@ U = np.full((model.t.size, *X.shape), np.nan) U[:, idz0, idx0] = np.linalg.norm(model.fields["U"], axis=1) fig = plt.figure(figsize=(19.2, 10.8), dpi=100) -gs = GridSpec(3, 1, figure=fig, height_ratios=[1, .05, .05]) +gs = GridSpec(3, 1, figure=fig, height_ratios=[1, 0.05, 0.05]) ax = fig.add_subplot(gs[0]) cax1 = fig.add_subplot(gs[1]) cax2 = fig.add_subplot(gs[2]) @@ -92,7 +93,7 @@ def anim(i): figU = plt.figure(figsize=(19.2, 10.8), dpi=100) -gsU = GridSpec(3, 1, figure=figU, height_ratios=[1, .05, .05]) +gsU = GridSpec(3, 1, figure=figU, height_ratios=[1, 0.05, 0.05]) axU = figU.add_subplot(gsU[0]) caxu1 = figU.add_subplot(gsU[1]) caxu2 = figU.add_subplot(gsU[2]) @@ -140,8 +141,8 @@ def animU(i): ur_m.set_alpha(1 - np.nan_to_num(AW[i]).clip(0, 1)) -ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1/24) -aniU = animation.FuncAnimation(figU, animU, frames=model.t.size, interval=1/24) +ani = animation.FuncAnimation(fig, anim, frames=model.t.size, interval=1 / 24) +aniU = animation.FuncAnimation(figU, animU, frames=model.t.size, interval=1 / 24) ani.save(out.joinpath("anim.mp4"), fps=24) aniU.save(out.joinpath("animU.mp4"), fps=24) diff --git a/olaflow/processing/animateU.py b/olaflow/processing/animateU.py index 18c7298..5a356b1 100644 --- a/olaflow/processing/animateU.py +++ b/olaflow/processing/animateU.py @@ -1,5 +1,4 @@ import argparse -import configparser import gzip import logging import multiprocessing as mp @@ -16,16 +15,20 @@ from .olaflow import OFModel parser = argparse.ArgumentParser(description="Post-process olaflow results") parser.add_argument("-v", "--verbose", action="count", default=0) -parser.add_argument("-c", "--config", default="config.ini") +parser.add_argument( + "-o", + "--output", + type=pathlib.Path, + help="Output directory for pickled data", + required=True, +) args = parser.parse_args() logging.basicConfig(level=max((10, 20 - 10 * args.verbose))) log = logging.getLogger("ola_post") log.info("Animating olaFlow output") -config = configparser.ConfigParser() -config.read(args.config) -out = pathlib.Path(config.get("post", "out")) +out = args.output out.mkdir(parents=True, exist_ok=True) with ( @@ -35,9 +38,6 @@ with ( ) as f: model = pickle.load(f) -x0 = config.getfloat("post", "x") -z0 = config.getfloat("post", "z") - flt = np.where((model.x >= -60) & (model.x <= -20) & (model.z >= 0) & (model.z <= 10))[ 0 ] diff --git a/olaflow/processing/diff.py b/olaflow/processing/diff.py index 8d23ba5..6cf0025 100644 --- a/olaflow/processing/diff.py +++ b/olaflow/processing/diff.py @@ -56,4 +56,6 @@ for i, (_ax, _model) in enumerate(zip(ax, models)): _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")) +fig.savefig( + args.output[0].joinpath(f"diff_{'_'.join([o.name for o in args.output])}.pdf") +) diff --git a/olaflow/processing/olaflow.py b/olaflow/processing/olaflow.py index f83c58d..30329e8 100644 --- a/olaflow/processing/olaflow.py +++ b/olaflow/processing/olaflow.py @@ -53,7 +53,9 @@ class OFModel: return _field def read_post(self, func, field): - _ft = lambda _d: self._root.joinpath("postProcessing", func, _d, f"line_{field}.xy") + _ft = lambda _d: self._root.joinpath( + "postProcessing", func, _d, f"line_{field}.xy" + ) _res_0 = np.loadtxt(_ft(self._t_dirs[0])) _x = _res_0[:, 0] _res = np.empty((self._t.size, _x.size)) @@ -64,9 +66,10 @@ class OFModel: f"x_{field}": _x, field: _res, } - if func not in self._post_fields.keys(): self._post_fields[func] = {} + if func not in self._post_fields.keys(): + self._post_fields[func] = {} self._post_fields[func] |= _dict - return _dict + return _dict def write_field(self, field, values): with open(self._root.joinpath("0", field), "r") as aw_file: