Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved _parse_species_list function to tardis.io.util.py #2837

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,5 @@ Israel Roldan <israel.alberto.rv@gmail.com> AirvZxf <israel.alberto.rv@gmail.com
Israel Roldan <israel.alberto.rv@gmail.com> airv_zxf <israel.alberto.rv@gmail.com>

Michael Zingale <michael.zingale@stonybrook.edu>

Rudraksh Nalbalwar <nalbalwarrudraksh@gmail.com>
45 changes: 45 additions & 0 deletions tardis/io/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,51 @@ def yaml_load_file(filename, loader=yaml.Loader):
return yaml.load(stream, Loader=loader)


def _parse_species_list(self, species_list, packets_mode, nelements=None):
rudrakshnalbalwar marked this conversation as resolved.
Show resolved Hide resolved
"""
Parse user requested species list and create list of species ids to be used.

Parameters
----------
species_list : list of species to plot
List of species (e.g. Si II, Ca II, etc.) that the user wants to show as unique colours.
Species can be given as an ion (e.g. Si II), an element (e.g. Si), a range of ions
(e.g. Si I - V), or any combination of these (e.g. species_list = [Si II, Fe I-V, Ca])
packets_mode : str, optional
Packet mode, either 'virtual' or 'real'. Default is 'virtual'.
nelements : int, optional
Number of elements to include in plot. The most interacting elements are included. If None, displays all elements.

Raises
------
ValueError
If species list contains invalid entries.

"""
from tardis.util.base import atomic_number2element_symbol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be here

self.sdec_plotter._parse_species_list(species_list)
self._species_list = self.sdec_plotter._species_list
self._species_mapped = self.sdec_plotter._species_mapped
self._keep_colour = self.sdec_plotter._keep_colour

if nelements:
interaction_counts = (
self.data[packets_mode]
.packets_df_line_interaction["last_line_interaction_species"]
.value_counts()
)
interaction_counts.index = interaction_counts.index // 100
element_counts = interaction_counts.groupby(
interaction_counts.index
).sum()
top_elements = element_counts.nlargest(nelements).index
top_species_list = [
atomic_number2element_symbol(element)
for element in top_elements
]
self._parse_species_list(top_species_list, packets_mode)


def traverse_configs(base, other, func, *args):
"""
Recursively traverse a base dict or list along with another one
Expand Down
43 changes: 0 additions & 43 deletions tardis/visualization/tools/liv_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,49 +99,6 @@ def from_hdf(cls, hdf_fpath):
velocity,
)

def _parse_species_list(self, species_list, packets_mode, nelements=None):
"""
Parse user requested species list and create list of species ids to be used.

Parameters
----------
species_list : list of species to plot
List of species (e.g. Si II, Ca II, etc.) that the user wants to show as unique colours.
Species can be given as an ion (e.g. Si II), an element (e.g. Si), a range of ions
(e.g. Si I - V), or any combination of these (e.g. species_list = [Si II, Fe I-V, Ca])
packets_mode : str, optional
Packet mode, either 'virtual' or 'real'. Default is 'virtual'.
nelements : int, optional
Number of elements to include in plot. The most interacting elements are included. If None, displays all elements.

Raises
------
ValueError
If species list contains invalid entries.

"""
self.sdec_plotter._parse_species_list(species_list)
self._species_list = self.sdec_plotter._species_list
self._species_mapped = self.sdec_plotter._species_mapped
self._keep_colour = self.sdec_plotter._keep_colour

if nelements:
interaction_counts = (
self.data[packets_mode]
.packets_df_line_interaction["last_line_interaction_species"]
.value_counts()
)
interaction_counts.index = interaction_counts.index // 100
element_counts = interaction_counts.groupby(
interaction_counts.index
).sum()
top_elements = element_counts.nlargest(nelements).index
top_species_list = [
atomic_number2element_symbol(element)
for element in top_elements
]
self._parse_species_list(top_species_list, packets_mode)

def _make_colorbar_labels(self):
"""
Generate labels for the colorbar based on species.
Expand Down
Loading