{ "cells": [ { "cell_type": "markdown", "id": "d5f95feb", "metadata": {}, "source": [ "# Convergence Plots" ] }, { "cell_type": "markdown", "id": "dc1a0c1f", "metadata": {}, "source": [ "The Convergence Plots consist of two Plotly FigureWidget Subplots, the `plasma_plot` and the `t_inner_luminosities_plot`. The plots can be displayed by setting the `show_convergence_plots` option in the `run_tardis` function to `True`. 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`." ] }, { "cell_type": "markdown", "id": "6db4edf2", "metadata": {}, "source": [ "
\n", "\n", "Note\n", " \n", "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.\n", "\n", "
" ] }, { "cell_type": "code", "execution_count": null, "id": "ba7cc7d2", "metadata": { "scrolled": false }, "outputs": [], "source": [ "from tardis import run_tardis\n", "from tardis.io.atom_data.util import download_atom_data\n", "\n", "# We download the atomic data needed to run the simulation\n", "download_atom_data('kurucz_cd23_chianti_H_He')\n", "\n", "# We run a simulation\n", "sim = run_tardis('tardis_example.yml', show_convergence_plots=True, export_convergence_plots=True)" ] }, { "cell_type": "markdown", "id": "ae1623d6", "metadata": {}, "source": [ "## Displaying Convergence Plots\n", "You can also call the plots outside of `run_tardis` function. " ] }, { "cell_type": "code", "execution_count": null, "id": "48768471", "metadata": {}, "outputs": [], "source": [ "sim.convergence_plots.plasma_plot.show(renderer=\"notebook_connected\")" ] }, { "cell_type": "code", "execution_count": null, "id": "9db6b395", "metadata": {}, "outputs": [], "source": [ "sim.convergence_plots.t_inner_luminosities_plot.show(renderer=\"notebook_connected\")" ] }, { "cell_type": "markdown", "id": "b1bf44fa", "metadata": {}, "source": [ "## Changing Line Colors\n", "The default line-colors of the plasma plots can be changed by passing the name of the cmap in the `plasma_cmap` option. \n", "\n", "```py\n", "sim = run_tardis(\"tardis_example.yml\", show_convergence_plots=True, plasma_cmap=\"viridis\")\n", "```\n", "\n", "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. \n", "```py\n", "# hex colors example list\n", "colors = [\n", " '#8c564b', # chestnut brown\n", " '#e377c2', # raspberry yogurt pink\n", " '#7f7f7f', # middle gray\n", " '#bcbd22', # curry yellow-green\n", " '#17becf' # blue-teal\n", "]\n", "\n", "# rgb colors example list\n", "colors = ['rgb(31, 119, 180)',\n", " 'rgb(255, 127, 14)',\n", " 'rgb(44, 160, 44)', \n", " 'rgb(214, 39, 40)',\n", " 'rgb(148, 103, 189)',]\n", " \n", "# css colors\n", "colors = [\"indigo\",\"lightseagreen\", \"midnightblue\", \"pink\", \"teal\"]\n", "```\n", "For more css-names please see [this](https://www.w3schools.com/colors/colors_names.asp). " ] }, { "cell_type": "code", "execution_count": null, "id": "9109967e", "metadata": { "scrolled": false }, "outputs": [], "source": [ "sim = run_tardis(\n", " \"tardis_example.yml\",\n", " show_convergence_plots=True,\n", " plasma_cmap= \"viridis\", \n", " t_inner_luminosities_colors = ['rgb(102, 197, 204)',\n", " 'rgb(246, 207, 113)',\n", " 'rgb(248, 156, 116)',\n", " 'rgb(220, 176, 242)',\n", " 'rgb(135, 197, 95)'],\n", " export_convergence_plots = True\n", ")" ] }, { "cell_type": "markdown", "id": "1f63c60a", "metadata": {}, "source": [ "## Changing the default layout" ] }, { "cell_type": "markdown", "id": "3a3bdc2d", "metadata": {}, "source": [ "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](https://plotly.com/python/figure-structure/). \n", "\n", "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:\n", "```py\n", "sim.convergence_plots.t_inner_luminosities_plot.data[0].line.dash = \"dashdot\"\n", "```\n", "\n", "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`. \n", "\n", "Here is an example:" ] }, { "cell_type": "code", "execution_count": null, "id": "548990c8", "metadata": { "scrolled": false }, "outputs": [], "source": [ "sim = run_tardis(\n", " \"tardis_example.yml\",\n", " show_convergence_plots=True,\n", " plasma_plot_config={\n", " \"layout\": {\n", " \"template\": \"ggplot2\",\n", " \"xaxis1\": {\n", " \"nticks\": 20\n", " },\n", " \"xaxis2\": {\n", " \"title\": {\"text\": \"new changed title of x axis2\"},\n", " \"nticks\": 20\n", " },\n", " },\n", " },\n", " t_inner_luminosities_config={\n", " \"data\": {\n", " \"line\":{\n", " \"dash\":\"dot\"\n", " },\n", " \"mode\": \"lines+markers\",\n", " },\n", " \"layout\": {\n", " \"template\": \"plotly_dark\",\n", " \"hovermode\":\"x\",\n", " \"xaxis\":{\"showgrid\":False},\n", " \"xaxis2\":{\"showgrid\":False},\n", " \"xaxis3\":{\"showgrid\":False},\n", " \n", " },\n", " },\n", " export_convergence_plots = True)" ] }, { "cell_type": "code", "execution_count": null, "id": "6ceaaa1e", "metadata": { "scrolled": false }, "outputs": [], "source": [ "from tardis.visualization import ConvergencePlots\n", "help(ConvergencePlots)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 5 }