From efd1e7485b4a20fa3d0cb0d0afa00410f03bd823 Mon Sep 17 00:00:00 2001 From: Sarthak Srivastava Date: Mon, 4 Mar 2024 01:17:48 -0500 Subject: [PATCH 1/4] Change convergence plots to step plots --- tardis/visualization/tools/convergence_plot.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tardis/visualization/tools/convergence_plot.py b/tardis/visualization/tools/convergence_plot.py index 16e588f5e76..01292abf505 100644 --- a/tardis/visualization/tools/convergence_plot.py +++ b/tardis/visualization/tools/convergence_plot.py @@ -332,6 +332,7 @@ def update_plasma_plots(self): x=velocity_km_s, y=self.iterable_data["t_rad"], line_color=self.plasma_colorscale[self.current_iteration - 1], + line_shape="hv", row=1, col=1, name=self.current_iteration, @@ -346,6 +347,7 @@ def update_plasma_plots(self): x=velocity_km_s, y=self.iterable_data["w"], line_color=self.plasma_colorscale[self.current_iteration - 1], + line_shape="hv", row=1, col=2, legendgroup=f"group-{self.current_iteration}", From cfca84cfdbb82d67f7bdd9d154b055c87034b3d9 Mon Sep 17 00:00:00 2001 From: Sarthak Srivastava Date: Tue, 12 Mar 2024 20:11:14 -0400 Subject: [PATCH 2/4] - Add dummy x-point while plotting convergence plots, to draw the last step correctly - Rebase master - Run black formatter on convergence_plot.py --- .../visualization/tools/convergence_plot.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tardis/visualization/tools/convergence_plot.py b/tardis/visualization/tools/convergence_plot.py index 01292abf505..8c6d1617b94 100644 --- a/tardis/visualization/tools/convergence_plot.py +++ b/tardis/visualization/tools/convergence_plot.py @@ -1,7 +1,9 @@ """Convergence Plots to see the convergence of the simulation in real time.""" + from collections import defaultdict import matplotlib.cm as cm import matplotlib.colors as clr +import numpy as np import plotly.graph_objects as go from IPython.display import display import matplotlib as mpl @@ -330,7 +332,9 @@ def update_plasma_plots(self): # add a radiation temperature vs shell velocity trace to the plasma plot self.plasma_plot.add_scatter( x=velocity_km_s, - y=self.iterable_data["t_rad"], + y=np.append( + self.iterable_data["t_rad"], self.iterable_data["t_rad"][-1:] + ), line_color=self.plasma_colorscale[self.current_iteration - 1], line_shape="hv", row=1, @@ -345,7 +349,7 @@ def update_plasma_plots(self): # add a dilution factor vs shell velocity trace to the plasma plot self.plasma_plot.add_scatter( x=velocity_km_s, - y=self.iterable_data["w"], + y=np.append(self.iterable_data["w"], self.iterable_data["w"][-1:]), line_color=self.plasma_colorscale[self.current_iteration - 1], line_shape="hv", row=1, @@ -367,9 +371,9 @@ def update_t_inner_luminosities_plot(self): self.t_inner_luminosities_plot.data[0].y = self.value_data[ "t_inner" ] - self.t_inner_luminosities_plot.data[ - 0 - ].hovertemplate = "%{y:.3f} at X = %{x:,.0f}Inner Boundary Temperature" # trace name in extra tag to avoid new lines in hoverdata + self.t_inner_luminosities_plot.data[0].hovertemplate = ( + "%{y:.3f} at X = %{x:,.0f}Inner Boundary Temperature" # trace name in extra tag to avoid new lines in hoverdata + ) # the next three for emitted, absorbed and requested luminosities for index, luminosity in zip(range(1, 4), self.luminosities): @@ -391,9 +395,9 @@ def update_t_inner_luminosities_plot(self): self.t_inner_luminosities_plot.data[4].x = x self.t_inner_luminosities_plot.data[4].y = y - self.t_inner_luminosities_plot.data[ - 4 - ].hovertemplate = "%{y:.2f}% at X = %{x:,.0f}" + self.t_inner_luminosities_plot.data[4].hovertemplate = ( + "%{y:.2f}% at X = %{x:,.0f}" + ) def update(self, export_convergence_plots=False, last=False): """ From efa604a9d42ea06491c699c1a9cff15bc2d5c3a2 Mon Sep 17 00:00:00 2001 From: Sarthak Srivastava Date: Sat, 6 Apr 2024 21:44:51 -0400 Subject: [PATCH 3/4] Fix convergence plot tests --- .../visualization/tools/tests/test_convergence_plot.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tardis/visualization/tools/tests/test_convergence_plot.py b/tardis/visualization/tools/tests/test_convergence_plot.py index 79751b15c72..bb69e23e68b 100644 --- a/tardis/visualization/tools/tests/test_convergence_plot.py +++ b/tardis/visualization/tools/tests/test_convergence_plot.py @@ -1,4 +1,5 @@ """Tests for Convergence Plots.""" + from copy import deepcopy import pytest @@ -143,7 +144,9 @@ def test_update_plasma_plots(convergence_plots): # check values for t_rad subplot assert convergence_plots.plasma_plot.data[index].xaxis == "x" assert convergence_plots.plasma_plot.data[index].yaxis == "y" - assert convergence_plots.plasma_plot.data[index].y == tuple(t_rad_val) + assert ( + convergence_plots.plasma_plot.data[index].y[:-1] == tuple(t_rad_val) + ).all() assert convergence_plots.plasma_plot.data[index].x == tuple( velocity.to(u.km / u.s).value ) @@ -152,7 +155,9 @@ def test_update_plasma_plots(convergence_plots): # check values for w subplot assert convergence_plots.plasma_plot.data[index].xaxis == "x2" assert convergence_plots.plasma_plot.data[index].yaxis == "y2" - assert convergence_plots.plasma_plot.data[index].y == tuple(w_val) + assert ( + convergence_plots.plasma_plot.data[index].y[:-1] == tuple(w_val) + ).all() assert convergence_plots.plasma_plot.data[index].x == tuple( velocity.to(u.km / u.s).value ) From e91101e7ead120e28680704ed5a4bd61f9e64e6d Mon Sep 17 00:00:00 2001 From: Sarthak Srivastava Date: Sat, 6 Apr 2024 21:58:10 -0400 Subject: [PATCH 4/4] Run black formatter --- tardis/visualization/tools/convergence_plot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tardis/visualization/tools/convergence_plot.py b/tardis/visualization/tools/convergence_plot.py index 8c6d1617b94..baac3ea0722 100644 --- a/tardis/visualization/tools/convergence_plot.py +++ b/tardis/visualization/tools/convergence_plot.py @@ -371,9 +371,9 @@ def update_t_inner_luminosities_plot(self): self.t_inner_luminosities_plot.data[0].y = self.value_data[ "t_inner" ] - self.t_inner_luminosities_plot.data[0].hovertemplate = ( - "%{y:.3f} at X = %{x:,.0f}Inner Boundary Temperature" # trace name in extra tag to avoid new lines in hoverdata - ) + self.t_inner_luminosities_plot.data[ + 0 + ].hovertemplate = "%{y:.3f} at X = %{x:,.0f}Inner Boundary Temperature" # trace name in extra tag to avoid new lines in hoverdata # the next three for emitted, absorbed and requested luminosities for index, luminosity in zip(range(1, 4), self.luminosities): @@ -395,9 +395,9 @@ def update_t_inner_luminosities_plot(self): self.t_inner_luminosities_plot.data[4].x = x self.t_inner_luminosities_plot.data[4].y = y - self.t_inner_luminosities_plot.data[4].hovertemplate = ( - "%{y:.2f}% at X = %{x:,.0f}" - ) + self.t_inner_luminosities_plot.data[ + 4 + ].hovertemplate = "%{y:.2f}% at X = %{x:,.0f}" def update(self, export_convergence_plots=False, last=False): """