Skip to content

Commit

Permalink
default species_list fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthak-dv committed Jul 10, 2024
1 parent af3eb1d commit cb161ee
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 58 deletions.
85 changes: 49 additions & 36 deletions docs/io/visualization/how_to_liv_plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Choosing what elements/ions to plot"
"## Static Plot (in matplotlib)\n",
"You can now call the `generate_plot_mpl()` method on your plotter object to create a highly informative and visually appealing Last Interaction Velocity plot using matplotlib."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You need to create a species_list for the species you want plotted in the Last Interaction Velocity Plot. Valid options include elements (e.g., Si), ions (specified in Roman numeral format, e.g., Si II), a range of ions (e.g., Si I-III), or any combination of these."
"### Virtual packets mode\n",
"By default, a Last Interaction Velocity plot is produced for the virtual packet population of the simulation."
]
},
{
Expand All @@ -95,23 +97,15 @@
"metadata": {},
"outputs": [],
"source": [
"species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Static Plot (in matplotlib)\n",
"You can now call the `generate_plot_mpl()` method on your plotter object to create a highly informative and visually appealing Last Interaction Velocity plot using matplotlib."
"plotter.generate_plot_mpl()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Virtual packets mode\n",
"By default, a Last Interaction Velocity plot is produced for the virtual packet population of the simulation."
"### Real packets mode\n",
"You can produce a Last Interaction Velocity plot for the real packet population of the simulation by setting `packets_mode=\"real\"` which is `\"virtual\"` by default."
]
},
{
Expand All @@ -120,15 +114,16 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_mpl(species_list)"
"plotter.generate_plot_mpl(packets_mode=\"real\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Real packets mode\n",
"You can produce the Last Interaction Velocity plot for the real packet population of the simulation by setting `packets_mode=\"real\"` which is `\"virtual\"` by default."
"### Choosing what elements/ions to plot\n",
"\n",
"You can pass a `species_list` for the species you want plotted in the Last Interaction Velocity Plot. Valid options include elements (e.g., Si), ions (specified in Roman numeral format, e.g., Si II), a range of ions (e.g., Si I-III), or any combination of these."
]
},
{
Expand All @@ -137,7 +132,7 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_mpl(species_list, packets_mode=\"real\")"
"plotter.generate_plot_mpl(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"])"
]
},
{
Expand All @@ -154,15 +149,15 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_mpl(species_list, num_bins=10)"
"plotter.generate_plot_mpl(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"], num_bins=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting on the Log Scale\n",
"You can plot on the log scale using `log_scale=True`, by default it is set to `False`."
"You can plot on the log scale on x-axis using `xlog_scale=True` and on y-axis using `ylog_scale=True` by default both are set to `False` which plots on a linear scale."
]
},
{
Expand All @@ -171,15 +166,15 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_mpl(species_list, log_scale=True)"
"plotter.generate_plot_mpl(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"], xlog_scale=True, ylog_scale=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting a specific velocity range\n",
"You can restrict the range of bins to plot in the last interaction velocity plot by specifying `velocity_range`."
"You can restrict the range of bins to plot in the Last Interaction Velocity Plot by specifying a valid `velocity_range`."
]
},
{
Expand All @@ -188,7 +183,7 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_mpl(species_list, velocity_range=(12500, 15050))"
"plotter.generate_plot_mpl(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"], velocity_range=(12500, 15050))"
]
},
{
Expand Down Expand Up @@ -238,15 +233,33 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_ply(species_list)"
"plotter.generate_plot_ply()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Real packets mode\n",
"You can produce the Last Interaction Velocity plot for the real packet population of the simulation by setting `packets_mode=\"real\"` which is `\"virtual\"` by default."
"You can produce a Last Interaction Velocity plot for the real packet population of the simulation by setting `packets_mode=\"real\"` which is `\"virtual\"` by default."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_ply(packets_mode=\"real\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Choosing what elements/ions to plot\n",
"\n",
"You can pass a `species_list` for the species you want plotted in the Last Interaction Velocity Plot. Valid options include elements (e.g., Si), ions (specified in Roman numeral format, e.g., Si II), a range of ions (e.g., Si I-III), or any combination of these."
]
},
{
Expand All @@ -255,7 +268,7 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_ply(species_list, packets_mode=\"real\")"
"plotter.generate_plot_ply(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"])"
]
},
{
Expand All @@ -272,15 +285,15 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_ply(species_list, num_bins=10)"
"plotter.generate_plot_ply(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"], num_bins=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting on the Log Scale\n",
"You can plot on the log scale using `log_scale=True`, by default it is set to `False`."
"You can plot on the log scale on x-axis using `xlog_scale=True` and on y-axis using `ylog_scale=True` by default both are set to `False`."
]
},
{
Expand All @@ -289,15 +302,15 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_ply(species_list, log_scale=True)"
"plotter.generate_plot_ply(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"], xlog_scale=True, ylog_scale=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting a specific velocity range\n",
"You can restrict the range of bins to plot in the last interaction velocity plot by specifying `velocity_range`."
"You can restrict the range of bins to plot in the Last Interaction Velocity Plot by specifying a valid `velocity_range`."
]
},
{
Expand All @@ -306,7 +319,7 @@
"metadata": {},
"outputs": [],
"source": [
"plotter.generate_plot_ply(species_list, velocity_range=(12500, 15050))"
"plotter.generate_plot_ply(species_list = [\"Si I-III\", \"O\", \"Ca\", \"S\"], velocity_range=(12500, 15050))"
]
},
{
Expand Down Expand Up @@ -361,7 +374,7 @@
"outputs": [],
"source": [
"# Static plot with virtual packets mode\n",
"# hdf_plotter.generate_plot_mpl(\"Si I-III\", \"Ca\", \"O\", \"S\"])"
"# hdf_plotter.generate_plot_mpl()"
]
},
{
Expand All @@ -371,7 +384,7 @@
"outputs": [],
"source": [
"# Static plot with real packets mode\n",
"#hdf_plotter.generate_plot_mpl([\"Si I-III\", \"Ca\", \"O\", \"S\"], packets_mode=\"real\")"
"#hdf_plotter.generate_plot_mpl(packets_mode=\"real\")"
]
},
{
Expand All @@ -380,8 +393,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Interactive plot with virtual packets mode\n",
"# hdf_plotter.generate_plot_ply([\"Si I-III\", \"Ca\", \"O\", \"S\"])"
"# Interactive plot with virtual packets mode and specific list of species\n",
"# hdf_plotter.generate_plot_ply(species_list=[\"Si I-III\", \"Ca\", \"O\", \"S\"])"
]
},
{
Expand All @@ -391,7 +404,7 @@
"outputs": [],
"source": [
"# Interactive plot with virtual packets mode and regrouped bins\n",
"# hdf_plotter.generate_plot_ply([\"Si I-III\", \"Ca\", \"O\", \"S\"], num_bins=10)"
"# hdf_plotter.generate_plot_ply(num_bins=10)"
]
}
],
Expand All @@ -411,7 +424,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
62 changes: 40 additions & 22 deletions tardis/visualization/tools/liv_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ def _prepare_plot_data(
new_bin_edges : np.ndarray
Array of bin edges for the velocity data.
"""
if species_list is None:
# Extract all unique elements from the packets data
species_in_model = np.unique(
self.data[packets_mode]
.packets_df_line_interaction["last_line_interaction_species"]
.values
)
species_list = [
f"{atomic_number2element_symbol(specie // 100)}"
for specie in species_in_model
]
self._parse_species_list(species_list)
species_in_model = np.unique(
self.data[packets_mode]
Expand Down Expand Up @@ -307,12 +318,13 @@ def _get_step_plot_data(self, data, bin_edges):

def generate_plot_mpl(
self,
species_list,
species_list=None,
packets_mode="virtual",
ax=None,
figsize=(11, 5),
cmapname="jet",
log_scale=False,
xlog_scale=False,
ylog_scale=False,
num_bins=None,
velocity_range=None,
):
Expand All @@ -321,8 +333,8 @@ def generate_plot_mpl(
Parameters
----------
species_list : list of str
List of species to plot.
species_list : list of str, optional
List of species to plot. Default is None which plots all species in the model.
packets_mode : str, optional
Packet mode, either 'virtual' or 'real'. Default is 'virtual'.
ax : matplotlib.axes.Axes, optional
Expand All @@ -331,10 +343,12 @@ def generate_plot_mpl(
Size of the figure. Default is (11, 5).
cmapname : str, optional
Colormap name. Default is 'jet'. A specific colormap can be chosen, such as "jet", "viridis", "plasma", etc.
log_scale : bool, optional
If True, both axes are scaled logarithmically. Default is False.
xlog_scale : bool, optional
If True, x-axis is scaled logarithmically. Default is False.
ylog_scale : bool, optional
If True, y-axis is scaled logarithmically. Default is False.
num_bins : int, optional
Number of bins for regrouping within the same range. Default is None
Number of bins for regrouping within the same range. Default is None.
velocity_range : tuple, optional
Limits for the x-axis. If specified, overrides any automatically determined limits.
Expand Down Expand Up @@ -367,14 +381,14 @@ def generate_plot_mpl(
)

self.ax.ticklabel_format(axis="y", scilimits=(0, 0))
self.ax.tick_params("both", labelsize=14)
self.ax.tick_params("both", labelsize=15)
self.ax.set_xlabel("Last Interaction Velocity (km/s)", fontsize=14)
self.ax.set_ylabel("Packet Count", fontsize=14)
self.ax.grid(True, which="both", linestyle="--", linewidth=0.5)
self.ax.set_ylabel("Packet Count", fontsize=15)
self.ax.legend(fontsize=15, bbox_to_anchor=(1.0, 1.0), loc="upper left")
self.ax.figure.tight_layout()
if log_scale:
if xlog_scale:
self.ax.set_xscale("log")
if ylog_scale:
self.ax.set_yscale("log")
if velocity_range:
self.ax.set_xlim(velocity_range[0], velocity_range[1])
Expand All @@ -383,12 +397,13 @@ def generate_plot_mpl(

def generate_plot_ply(
self,
species_list,
species_list=None,
packets_mode="virtual",
fig=None,
figsize=(1000, 500),
cmapname="jet",
log_scale=False,
xlog_scale=False,
ylog_scale=False,
num_bins=None,
velocity_range=None,
):
Expand All @@ -397,8 +412,8 @@ def generate_plot_ply(
Parameters
----------
species_list : list of str
List of species to plot.
species_list : list of str, optional
List of species to plot. Default is None which plots all species in the model.
packets_mode : str, optional
Packet mode, either 'virtual' or 'real'. Default is 'virtual'.
fig : plotly.graph_objects.Figure, optional
Expand All @@ -407,10 +422,12 @@ def generate_plot_ply(
Size of the figure. Default is (1000, 500).
cmapname : str, optional
Colormap name. Default is 'jet'. A specific colormap can be chosen, such as "jet", "viridis", "plasma", etc.
log_scale : bool, optional
If True, both axes are scaled logarithmically. Default is False.
xlog_scale : bool, optional
If True, x-axis is scaled logarithmically. Default is False.
ylog_scale : bool, optional
If True, y-axis is scaled logarithmically. Default is False.
num_bins : int, optional
Number of bins for regrouping within the same range. Default is None
Number of bins for regrouping within the same range. Default is None.
velocity_range : tuple, optional
Limits for the x-axis. If specified, overrides any automatically determined limits.
Expand Down Expand Up @@ -451,12 +468,13 @@ def generate_plot_ply(
height=figsize[1],
xaxis_title="Last Interaction Velocity (km/s)",
yaxis_title="Packet Count",
font=dict(size=14),
yaxis=dict(exponentformat="power" if log_scale else "e"),
xaxis=dict(exponentformat="power" if log_scale else "none"),
font=dict(size=15),
yaxis=dict(exponentformat="power" if ylog_scale else "e"),
xaxis=dict(exponentformat="power" if xlog_scale else "none"),
)
if log_scale:
if xlog_scale:
self.fig.update_xaxes(type="log")
if ylog_scale:
self.fig.update_yaxes(type="log", dtick=1)

if velocity_range:
Expand Down

0 comments on commit cb161ee

Please sign in to comment.