-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Changes from all commits
11a771a
c7d0f59
493380f
73a5678
d15a8e8
23fff3e
a265f30
f3b31dd
8b00774
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,3 +283,5 @@ Israel Roldan <[email protected]> AirvZxf <[email protected] | |
Israel Roldan <[email protected]> airv_zxf <[email protected]> | ||
|
||
Michael Zingale <[email protected]> | ||
|
||
Rudraksh Nalbalwar <[email protected]> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,57 @@ def yaml_load_file(filename, loader=yaml.Loader): | |
return yaml.load(stream, Loader=loader) | ||
|
||
|
||
def parse_species_list(sdec_plotter, data, 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. | ||
|
||
""" | ||
from tardis.util.base import atomic_number2element_symbol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this import defined here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is defined inside the function to break the circular dependency between tardis.io.util and tardis.util.base There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and in the below sdec_plot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imports should be defined at the start of the file right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but importing this statement at the start of the file creates a circular dependency. Specifically, atomic_number2element_symbol is imported from tardis.util.base, and within tardis.util.base, get_internal_data_path is imported from util.py, which triggers a circular loop. Refactoring the functions to avoid this would increase code complexity and could introduce new errors. |
||
sdec_plotter.parse_species_list(species_list) | ||
_species_list = sdec_plotter._species_list | ||
_species_mapped = sdec_plotter._species_mapped | ||
_keep_colour = sdec_plotter._keep_colour | ||
|
||
if nelements: | ||
interaction_counts = ( | ||
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 | ||
] | ||
sub_species_list, sub_species_mapped, sub_keep_colour = parse_species_list( | ||
sdec_plotter, data, top_species_list, packets_mode | ||
) | ||
_species_list = sub_species_list | ||
_species_mapped = sub_species_mapped | ||
_keep_colour = sub_keep_colour | ||
|
||
return _species_list, _species_mapped, _keep_colour | ||
|
||
def traverse_configs(base, other, func, *args): | ||
""" | ||
Recursively traverse a base dict or list along with another one | ||
|
@@ -160,7 +211,7 @@ def traverse_configs(base, other, func, *args): | |
traverse_configs(base[k], other[k], func, *args) | ||
elif ( | ||
isinstance(base, collections_abc.Iterable) | ||
and not isinstance(base, basestring) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the change was made to ensure that function is compatible with python 3 |
||
and not isinstance(base, str) | ||
and not hasattr(base, "shape") | ||
): | ||
for val1, val2 in zip(base, other): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it take a plotter argument? What is the purpose of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it relies on some methods and attributes within sdec_plotter to parse and organize the species list.