From 0f62651374d4fe88e683eb9f1943c226dc496127 Mon Sep 17 00:00:00 2001 From: Miikka Vaisala Date: Tue, 18 Jun 2019 14:50:35 +0800 Subject: [PATCH] Easier time series plotting. --- analysis/python/astar/data/read.py | 1 + analysis/python/astar/visual/__init__.py | 1 + analysis/python/astar/visual/lineplot.py | 93 +++++++++++++++++++ .../python/jupyter/notebook_example.ipynb | 46 ++++++++- analysis/python/samples/readtest.py | 61 +----------- 5 files changed, 139 insertions(+), 63 deletions(-) create mode 100644 analysis/python/astar/visual/lineplot.py diff --git a/analysis/python/astar/data/read.py b/analysis/python/astar/data/read.py index 79b4e52..270263f 100644 --- a/analysis/python/astar/data/read.py +++ b/analysis/python/astar/data/read.py @@ -118,6 +118,7 @@ def parse_ts(fdir, fname): line[i] = line[i].replace('_total', "tot") line[i] = line[i].replace('A', "aa") line[i] = line[i].replace('LNRHO', "lnrho") + line[i] = line[i].replace('ENTROPY', "ss") line[i] = line[i].replace('X', "x") line[i] = line[i].replace('Y', "y") line[i] = line[i].replace('Z', "z") diff --git a/analysis/python/astar/visual/__init__.py b/analysis/python/astar/visual/__init__.py index 44eca95..e48bf3a 100644 --- a/analysis/python/astar/visual/__init__.py +++ b/analysis/python/astar/visual/__init__.py @@ -19,3 +19,4 @@ from . import slices +from . import lineplot diff --git a/analysis/python/astar/visual/lineplot.py b/analysis/python/astar/visual/lineplot.py new file mode 100644 index 0000000..f33d75d --- /dev/null +++ b/analysis/python/astar/visual/lineplot.py @@ -0,0 +1,93 @@ +''' + Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae. + + This file is part of Astaroth. + + Astaroth is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Astaroth is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Astaroth. If not, see . +''' +import pylab as plt +import numpy as np +import matplotlib.gridspec as gridspec +import matplotlib.colors as colors + +CM_INFERNO = plt.get_cmap('inferno') + +end_rm = -1 #-35#-40 + +def plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3): + plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis1][:end_rm], label=yaxis1) + plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis2][:end_rm], label=yaxis2) + plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis3][:end_rm], label=yaxis3) + plt.xlabel(xaxis) + plt.legend() + +def plot_ts(ts, show_all=False, lnrho=False, uutot=False, uux=False, uuy=False, uuz=False, ss=False): + + if show_all: + lnrho=True + uutot=True + uux=True + uuy=True + uuz=True + ss=True + + if lnrho: + plt.figure() + xaxis = 't_step' + yaxis1 = 'lnrho_rms' + yaxis2 = 'lnrho_min' + yaxis3 = 'lnrho_max' + plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3) + + if uutot: + plt.figure() + xaxis = 't_step' + yaxis1 = 'uutot_rms' + yaxis2 = 'uutot_min' + yaxis3 = 'uutot_max' + plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3) + + if uux: + plt.figure() + xaxis = 't_step' + yaxis1 = 'uux_rms' + yaxis2 = 'uux_min' + yaxis3 = 'uux_max' + plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3) + + if uuy: + plt.figure() + xaxis = 't_step' + yaxis1 = 'uuy_rms' + yaxis2 = 'uuy_min' + yaxis3 = 'uuy_max' + plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3) + + if uuz: + plt.figure() + xaxis = 't_step' + yaxis1 = 'uuz_rms' + yaxis2 = 'uuz_min' + yaxis3 = 'uuz_max' + plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3) + + if ss: + plt.figure() + xaxis = 't_step' + yaxis1 = 'ss_rms' + yaxis2 = 'ss_min' + yaxis3 = 'ss_max' + plot_min_man_rms(ts, xaxis, yaxis1, yaxis2, yaxis3) + + plt.show() diff --git a/analysis/python/jupyter/notebook_example.ipynb b/analysis/python/jupyter/notebook_example.ipynb index d1ed7e9..b968762 100644 --- a/analysis/python/jupyter/notebook_example.ipynb +++ b/analysis/python/jupyter/notebook_example.ipynb @@ -14,7 +14,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Here we read data from the run directory" + "### Here we read data from the run directory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "meshdir = \"/scratch/data/mvaisala/iotest/\"" ] }, { @@ -24,7 +33,6 @@ "outputs": [], "source": [ "imesh = 0\n", - "meshdir = \"/scratch/data/mvaisala/iotest/\"\n", "mesh = ad.read.Mesh(imesh, fdir=meshdir)" ] }, @@ -32,7 +40,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Example visualization funtion call. " + "### Example visualization funtion call. " ] }, { @@ -46,6 +54,38 @@ "vis.slices.plot_3(mesh, mesh.uu[0], title = r'$u_x$', bitmap = False, fname = 'uux')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Ploting time series" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ts = ad.read.TimeSeries(fdir=meshdir)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "vis.lineplot.plot_ts(ts, lnrho=1, uutot=1, uux=1, ss=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, diff --git a/analysis/python/samples/readtest.py b/analysis/python/samples/readtest.py index e3bf8c3..81f7512 100644 --- a/analysis/python/samples/readtest.py +++ b/analysis/python/samples/readtest.py @@ -199,65 +199,6 @@ if 'sl' in sys.argv: if 'ts' in sys.argv: ts = ad.read.TimeSeries(fdir=meshdir) - - end_rm = -1 #-35#-40 - - plt.figure() - xaxis = 't_step' - yaxis1 = 'lnrho_rms' - yaxis2 = 'lnrho_min' - yaxis3 = 'lnrho_max' - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis1][:end_rm], label=yaxis1) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis2][:end_rm], label=yaxis2) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis3][:end_rm], label=yaxis3) - plt.xlabel(xaxis) - plt.legend() - - plt.figure() - xaxis = 't_step' - yaxis1 = 'uutot_rms' - yaxis2 = 'uutot_min' - yaxis3 = 'uutot_max' - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis1][:end_rm], label=yaxis1) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis2][:end_rm], label=yaxis2) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis3][:end_rm], label=yaxis3) - plt.xlabel(xaxis) - plt.legend() - - plt.figure() - xaxis = 't_step' - yaxis1 = 'uux_rms' - yaxis2 = 'uux_min' - yaxis3 = 'uux_max' - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis1][:end_rm], label=yaxis1) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis2][:end_rm], label=yaxis2) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis3][:end_rm], label=yaxis3) - plt.xlabel(xaxis) - plt.legend() - - plt.figure() - xaxis = 't_step' - yaxis1 = 'uuy_rms' - yaxis2 = 'uuy_min' - yaxis3 = 'uuy_max' - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis1][:end_rm], label=yaxis1) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis2][:end_rm], label=yaxis2) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis3][:end_rm], label=yaxis3) - plt.xlabel(xaxis) - plt.legend() - - plt.figure() - xaxis = 't_step' - yaxis1 = 'uuz_rms' - yaxis2 = 'uuz_min' - yaxis3 = 'uuz_max' - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis1][:end_rm], label=yaxis1) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis2][:end_rm], label=yaxis2) - plt.plot(ts.var[xaxis][:end_rm], ts.var[yaxis3][:end_rm], label=yaxis3) - plt.xlabel(xaxis) - plt.legend() - - - plt.show() + vis.lineplot.plot_ts(ts, lnrho=1, uutot=1, uux=1, ss=1)