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

Add ion contributions to SDEC plotter #1539

Merged
merged 21 commits into from
Apr 23, 2021

Conversation

MarkMageeAstro
Copy link
Contributor

This is a port of existing code in TARDIS analysis. SDEC now has the ability to plot individual ions or elements that are requested by the user.

Description
This PR adds a new argument for the SDEC plotter: species_list. This is a list of ions, elements, or both provided by the user. The list is read and parsed by the code, and compared against what species are present in the model. Each requested species that is also in the model is given a unique colour in the plot.

species_list can take arguments as either individual ions, elements, a range of ions, or any combination of these. For example species_list = ['Si II', 'S I-V', 'Ca']. In this example, Si II interacting packets will be plotted as a single colour. All packets that interacted with any ion of Ca will be plotted as a single colour. Finally, the code will determine which ions from S I-V are present in the model and give each of those their own colour.

Motivation and context
Brings back existing functionality in TARDIS analysis.

How has this been tested?

  • Testing pipeline.
  • Other.
    Comparisons with older versions of the code and packets in model.

Examples
The following plot was generated using:
plotter.generate_plot_mpl(packet_wvl_range=[3000, 9000] * u.AA, species_list=['Si I-III', 'S II', 'Ca']);
Screenshot 2021-04-14 at 23 55 53

Type of change

  • Bug fix.
  • New feature.
  • Breaking change.
  • None of the above.

Checklist

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
    • (optional) I have built the documentation on my fork following the instructions.
  • I have assigned and requested two reviewers for this pull request.

The elements coloured in the plot are determined via the absorption and emission. It's possible however, that these elements are not the same, e.g. if you specify a limited wavelength range. This could give an error if you try to plot an element not in the emission dataframe, for example. This adds a try statement to catch this case
Added a new column to the packet dataframe that gives the species id. This combines the atomic and ion numbers into a unique id that will be used to group species later.
Added parser to convert request species list into ids to be used by plotter
Call species list parser function
Rearranged parser so it didn't crash if species_list was none
Added in the ion contribution stuff for the mpl plotting.
Also added a new function to get the colorbar labels. This is necessary to determine how many unique colours there should be
Added colouring for ion contributions in plotly figures
Fixed bug in the absorption and emission df calculations. Now they elements should be handled correctly so there won't be errors if a species appears in emission and not absorption, and vice versa

Added comments throughout
@codecov
Copy link

codecov bot commented Apr 14, 2021

Codecov Report

Merging #1539 (c5362f7) into master (a15551c) will decrease coverage by 1.13%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1539      +/-   ##
==========================================
- Coverage   69.06%   67.92%   -1.14%     
==========================================
  Files          68       68              
  Lines        6106     6217     +111     
==========================================
+ Hits         4217     4223       +6     
- Misses       1889     1994     +105     
Impacted Files Coverage Δ
tardis/tardis/visualization/tools/sdec_plot.py 11.29% <0.00%> (-2.88%) ⬇️
tardis/tardis/montecarlo/spectrum.py 70.90% <0.00%> (-0.79%) ⬇️
tardis/tardis/io/decay.py 90.16% <0.00%> (ø)
tardis/tardis/util/base.py 77.77% <0.00%> (ø)
tardis/tardis/plasma/base.py 56.17% <0.00%> (ø)
tardis/tardis/io/model_reader.py 97.70% <0.00%> (ø)
tardis/tardis/simulation/base.py 85.71% <0.00%> (ø)
tardis/tardis/io/atom_data/base.py 90.80% <0.00%> (ø)
tardis/tardis/io/atom_data/util.py 47.05% <0.00%> (ø)
tardis/tardis/plasma/exceptions.py 87.50% <0.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a15551c...c5362f7. Read the comment docs.

@andrewfullard
Copy link
Contributor

Why is Si II repeated twice in the colourbar of the example?

@MarkMageeAstro
Copy link
Contributor Author

Why is Si II repeated twice in the colourbar of the example?

It isn't. There's Si II, Si III, S II, and Ca.

Copy link
Member

@jamesgillanders jamesgillanders left a comment

Choose a reason for hiding this comment

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

this is a really nicely written and well-presented bit of code. I have a few tests I want to finish before I approve the PR, but see comments below for minor corrections. As discussed in the meeting last week, if parts of the plotting code could be grouped into some form of function to reduce duplication, that would be amazing

tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
Added a new function to work out what colours will be plotted. This was originally repeated multiple times in the code, but now it's a single function that's called multiple times

Also fixed a bug in the absorption luminosities dataframe
Change name of some variables and fixed some typos.
Copy link
Member

@jaladh-singhal jaladh-singhal left a comment

Choose a reason for hiding this comment

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

This looks much better than your initial version @MarkMageeAstro - excellent job in restructuring the code in functions. 🎉

I've few comments that shouldn't take much time to be addressed.

tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
@jaladh-singhal jaladh-singhal merged commit 2c845d8 into tardis-sn:master Apr 23, 2021
atharva-2001 pushed a commit to atharva-2001/tardis that referenced this pull request Oct 1, 2021
* Add catch for missing elements

The elements coloured in the plot are determined via the absorption and emission. It's possible however, that these elements are not the same, e.g. if you specify a limited wavelength range. This could give an error if you try to plot an element not in the emission dataframe, for example. This adds a try statement to catch this case

* Fixed typo

* Black formatting

* Fixed typo

* Add species column to packet df

Added a new column to the packet dataframe that gives the species id. This combines the atomic and ion numbers into a unique id that will be used to group species later.

* Added species list parser

Added parser to convert request species list into ids to be used by plotter

* Implement parser call

Call species list parser function

* Fixed parser

Rearranged parser so it didn't crash if species_list was none

* Implement MPL ion contributions

Added in the ion contribution stuff for the mpl plotting.
Also added a new function to get the colorbar labels. This is necessary to determine how many unique colours there should be

* Changed order of functions

* Implement plotly ion contributions

Added colouring for ion contributions in plotly figures

* Remove print statements

* Fixed df bug and added comments

Fixed bug in the absorption and emission df calculations. Now they elements should be handled correctly so there won't be errors if a species appears in emission and not absorption, and vice versa

Added comments throughout

* Black formatting

* Added colour function

Added a new function to work out what colours will be plotted. This was originally repeated multiple times in the code, but now it's a single function that's called multiple times

Also fixed a bug in the absorption luminosities dataframe

* Address review comments

Change name of some variables and fixed some typos.

* Change print to logger

* Black formatting

* Updated variable names and string formatting

* Black formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants