You can interact with this notebook online: Launch interactive version

Convergence Plots

The Convergence Plots consist of two Plotly FigureWidget Subplots, the plasma_plot and the t_inner_luminosities_plot. The plots are stored in the convergence_plots attribute of the simulation object sim and can be accessed using sim.convergence_plots.plasma_plot and sim.convergence_plots.t_inner_luminosities_plot.

The Convergence Plots are shown by default when you running TARDIS because show_convergence_plots parameter of the run_tardis() function is set to True. If you don’t want to do this, set it to False.

Note

You only need to include export_convergence_plots=True in the run_tardis function when you want to share the notebook. The function shows the plot using the Plotly notebook_connected renderer, which helps display the plot online. You don’t need to do it when running the notebook locally.

[1]:
from tardis import run_tardis
from tardis.io.atom_data.util import download_atom_data

# We download the atomic data needed to run the simulation
download_atom_data('kurucz_cd23_chianti_H_He')

# We run a simulation
sim = run_tardis('tardis_example.yml', export_convergence_plots=True)
/usr/share/miniconda3/envs/tardis/lib/python3.7/importlib/_bootstrap.py:219: QAWarning: pyne.data is not yet QA compliant.
  return f(*args, **kwds)
[py.warnings         ][WARNING]  /usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/traitlets/traitlets.py:3050: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  FutureWarning,
 (warnings.py:110)

Displaying Convergence Plots

You can also call the plots outside of run_tardis function.

[2]:
sim.convergence_plots.plasma_plot.show(renderer="notebook_connected")
[3]:
sim.convergence_plots.t_inner_luminosities_plot.show(renderer="notebook_connected")

Changing Line Colors

The default line-colors of the plasma plots can be changed by passing the name of the cmap in the plasma_cmap option.

sim = run_tardis("tardis_example.yml",plasma_cmap= "viridis")

Alongwith the cmap name, one can also provide a list of colors in rgb, hex or css-names format in the t_inner_luminosities_colors option to change the default colors of the luminosity and inner boundary temperature plots.

# hex colors example list
colors = [
    '#8c564b',  # chestnut brown
    '#e377c2',  # raspberry yogurt pink
    '#7f7f7f',  # middle gray
    '#bcbd22',  # curry yellow-green
    '#17becf'   # blue-teal
]

# rgb colors example list
colors = ['rgb(31, 119, 180)',
          'rgb(255, 127, 14)',
          'rgb(44, 160, 44)',
          'rgb(214, 39, 40)',
          'rgb(148, 103, 189)',]

# css colors
colors = ["indigo","lightseagreen", "midnightblue",  "pink", "teal"]

For more css-names please see this.

[4]:
sim = run_tardis(
    "tardis_example.yml",
    plasma_cmap= "viridis",
    t_inner_luminosities_colors = ['rgb(102, 197, 204)',
                         'rgb(246, 207, 113)',
                         'rgb(248, 156, 116)',
                         'rgb(220, 176, 242)',
                         'rgb(135, 197, 95)'],
    export_convergence_plots = True
)

Changing the default layout

You can override the default layout by passing dictionaries as arguments in t_inner_luminosities_config and plasma_plot_config in the run_tardis function. The dictionaries should have the format of plotly.graph_objects.FigureWidget().to_dict(). For more information on the structure of the dictionary, please see the plotly documentation.

For sake of simplicity, all properties in the data dictionary are applied equally across all traces, meaning traces-specific properties can’t be changed from the function. They however be changed after the simulation has finished, for example:

sim.convergence_plots.t_inner_luminosities_plot.data[0].line.dash = "dashdot"

You can investigate more about the layout/data of any plots by calling sim.convergence_plots.t_inner_luminosities_plot.layout or sim.convergence_plots.t_inner_luminosities_plot.data.

Here is an example:

[5]:
sim = run_tardis(
    "tardis_example.yml",
    plasma_plot_config={
        "layout": {
            "template": "ggplot2",
            "xaxis1": {
                "nticks": 20
            },
            "xaxis2": {
                "title": {"text": "new changed title of x axis2"},
                "nticks": 20
            },
        },
    },
    t_inner_luminosities_config={
        "data": {
            "line":{
                "dash":"dot"
            },
            "mode": "lines+markers",
        },
        "layout": {
            "template": "plotly_dark",
            "hovermode":"x",
            "xaxis":{"showgrid":False},
            "xaxis2":{"showgrid":False},
            "xaxis3":{"showgrid":False},

        },
    },
    export_convergence_plots = True)
[6]:
from tardis.visualization import ConvergencePlots
help(ConvergencePlots)
Help on class ConvergencePlots in module tardis.visualization.tools.convergence_plot:

class ConvergencePlots(builtins.object)
 |  ConvergencePlots(iterations, **kwargs)
 |
 |  Create and update convergence plots for visualizing convergence of the simulation.
 |
 |  Parameters
 |  ----------
 |  iterations : int
 |      iteration number
 |  **kwargs : dict, optional
 |      Additional keyword arguments. These arguments are defined in the Other Parameters section.
 |
 |  Other Parameters
 |  ----------------
 |  plasma_plot_config : dict, optional
 |      Dictionary used to override default plot properties of plasma plots.
 |  t_inner_luminosities_config : dict, optional
 |      Dictionary used to override default plot properties of the inner boundary temperature and luminosity plots.
 |  plasma_cmap : str, default: 'jet', optional
 |      String defining the cmap used in plasma plots.
 |  t_inner_luminosities_colors : str or list, optional
 |      String defining cmap for luminosity and inner boundary temperature plot.
 |      The list can be a list of colors in rgb, hex or css-names format as well.
 |  export_convergence_plots : bool, default: False, optional
 |      If True, plots are displayed again using the `notebook_connected` renderer. This helps
 |      to display the plots in the documentation or in platforms like nbviewer.
 |
 |  Notes
 |  -----
 |      When overriding plot's configuration using the `plasma_plot_config` and the
 |      `t_inner_luminosities_config` dictionaries, data related properties are
 |      applied equally accross all traces.
 |      The dictionary should have a structure like that of `plotly.graph_objs.FigureWidget.to_dict()`,
 |      for more information please see https://plotly.com/python/figure-structure/
 |
 |  Methods defined here:
 |
 |  __init__(self, iterations, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  build(self, display_plot=True)
 |      Create empty convergence plots and display them.
 |
 |      Parameters
 |      ----------
 |      display_plot : bool, default: True, optional
 |          Displays empty plots.
 |
 |  create_plasma_plot(self)
 |      Create an empty plasma plot.
 |
 |  create_t_inner_luminosities_plot(self)
 |      Create an empty t_inner and luminosity plot.
 |
 |  fetch_data(self, name=None, value=None, item_type=None)
 |      Fetch data from the Simulation class.
 |
 |      Parameters
 |      ----------
 |      name : string
 |          name of the data
 |      value : string or array
 |          string or an array of quantities
 |      item_type : string
 |          either iterable or value
 |
 |  override_plot_parameters(self, fig, parameters)
 |      Override default plot properties.
 |
 |      Any property inside the data dictionary is however, applied equally across all traces.
 |      This means trace-specific data properties can't be changed using this function.
 |
 |      Parameters
 |      ----------
 |      fig : go.FigureWidget
 |          FigureWidget object to be updated
 |      parameters : dict
 |          Dictionary used to update the default plot style.
 |
 |  update(self, export_convergence_plots=False, last=False)
 |      Update the convergence plots every iteration.
 |
 |      Parameters
 |      ----------
 |      export_convergence_plots : bool, default: False, optional
 |          Displays the convergence plots again using plotly's `notebook_connected` renderer.
 |          This helps to display the plots in notebooks when shared on platforms like nbviewer.
 |          Please see https://plotly.com/python/renderers/ for more information.
 |      last : bool, default: False, optional
 |          True if it's last iteration.
 |
 |  update_plasma_plots(self)
 |      Update plasma convergence plots every iteration.
 |
 |  update_t_inner_luminosities_plot(self)
 |      Update the t_inner and luminosity convergence plots every iteration.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)