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 option to add Observed Spectrum #1761

Merged
merged 7 commits into from
Oct 4, 2021

Conversation

atharva-2001
Copy link
Member

@atharva-2001 atharva-2001 commented Jul 29, 2021

This PR adds an option to plot an observed spectrum in the SDEC plot.

Description

The option asks for a tuple of Astropy quantities, containing the wavelength and the luminosity for the observed spectrum and adds a line plot displaying the Observed Spectrum.

Motivation and context

How has this been tested?

  • Testing pipeline.
  • Other.

Examples

image

image
image
documentation: https://atharva-2001.github.io/tardis/branch/observed_spectrum/io/visualization/sdec_plot.html
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.

@codecov
Copy link

codecov bot commented Jul 29, 2021

Codecov Report

Merging #1761 (907785d) into master (e6a8af2) will decrease coverage by 0.13%.
The diff coverage is n/a.

❗ Current head 907785d differs from pull request most recent head c737c2d. Consider uploading reports for the commit c737c2d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1761      +/-   ##
==========================================
- Coverage   58.38%   58.25%   -0.14%     
==========================================
  Files          66       66              
  Lines        6705     6721      +16     
==========================================
  Hits         3915     3915              
- Misses       2790     2806      +16     
Impacted Files Coverage Δ
tardis/tardis/visualization/tools/sdec_plot.py 9.52% <0.00%> (-0.43%) ⬇️

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 e6a8af2...c737c2d. Read the comment docs.

@tardis-bot
Copy link
Contributor

Before a pull request is accepted, it must meet the following criteria:

  • Is the necessary information provided?
  • Is this a duplicate PR?
    • If a new PR is clearly a duplicate, ask how this PR is different from the original PR?
    • If this PR is about to be merged, close the original PR with a link to this new PR that solved the issue.
  • Does it pass existing tests and are new tests provided if required?
    • The test coverage should not decrease, and for new features should be close to 100%.
  • Is the code tidy?
    • No unnecessary print lines or code comments.

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 is a good start @atharva-2001 but I think there are few things unclear at your end - feel free to ask.

Also can you document this in SDEC notebook so that we can try this functionalities out?

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
Copy link
Member

Black check pipeline fails

@atharva-2001 atharva-2001 force-pushed the observed_spectrum branch 4 times, most recently from 3ee40ac to bae1e3c Compare August 13, 2021 11:58
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@atharva-2001 atharva-2001 force-pushed the observed_spectrum branch 2 times, most recently from e726ec0 to b039368 Compare August 16, 2021 15:06
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.

We also need to think about the colour scheme, as cyan does not look great for the observed spectrum

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 Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Show resolved Hide resolved
@review-notebook-app
Copy link

View / edit / reply to this conversation on ReviewNB

jaladh-singhal commented on 2021-09-17T11:21:23Z
----------------------------------------------------------------

Instead of this long cell, put these numbers in a csv/ascii file named "demo_observed_spectrum.csv" (at same level as demo.hdf) and read from there using pandas and then create quantitites


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.

Good job @atharva-2001, colors look nice to me - it's closer to be merged.

You need to resolve merge conflict and address my comment about putting data in a file instead of cell.

docs/io/visualization/sdec_plot.ipynb Show resolved Hide resolved
@@ -13,8 +13,8 @@
"execution_count": null,
Copy link
Member

Choose a reason for hiding this comment

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

Why not directly assign vertical slices of data to both observed_spectrum_wavelength and observed_spectrum_flux. Please look into ways of indexing ndarray to learn how to do it. If that's not possible with numpy, there's always pandas to do read almost all file formats. then you can just assign series to both variables.

Always remember, iterating is the last we should do with numpy & pandas as it reduces speed.


Reply via ReviewNB

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.

@atharva-2001 thank you for reading it from file - it's much cleaner now.

I've some concerns about your implementation of reading - I guess it should be quick to address. You can always take help related to this on computing channel if you want.

PS: You forgot to hit re-request review button this time too but I did review it 😅 - make sure to remember this time.

@atharva-2001 atharva-2001 force-pushed the observed_spectrum branch 2 times, most recently from fc6d526 to 8a0b575 Compare September 28, 2021 13:28
@sourcery-ai
Copy link

sourcery-ai bot commented Sep 28, 2021

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 1.32%.

Quality metrics Before After Change
Complexity 8.79 🙂 9.23 🙂 0.44 👎
Method Length 159.52 😞 163.74 😞 4.22 👎
Working memory 14.88 😞 15.08 😞 0.20 👎
Quality 45.69% 😞 44.37% 😞 -1.32% 👎
Other metrics Before After Change
Lines 1737 1797 60
Changed files Quality Before Quality After Quality Change
tardis/visualization/tools/sdec_plot.py 45.69% 😞 44.37% 😞 -1.32% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
tardis/visualization/tools/sdec_plot.py SDECPlotter._calculate_plotting_data 14 🙂 634 ⛔ 21 ⛔ 23.78% ⛔ Try splitting into smaller methods. Extract out complex expressions
tardis/visualization/tools/sdec_plot.py SDECPlotter._parse_species_list 26 😞 186 😞 17 ⛔ 27.78% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tardis/visualization/tools/sdec_plot.py SDECPlotter.generate_plot_ply 10 🙂 268 ⛔ 17 ⛔ 34.73% 😞 Try splitting into smaller methods. Extract out complex expressions
tardis/visualization/tools/sdec_plot.py SDECData.from_hdf 3 ⭐ 291 ⛔ 32 ⛔ 34.76% 😞 Try splitting into smaller methods. Extract out complex expressions
tardis/visualization/tools/sdec_plot.py SDECPlotter.generate_plot_mpl 10 🙂 223 ⛔ 16 ⛔ 38.11% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@atharva-2001
Copy link
Member Author

atharva-2001 commented Sep 28, 2021

@jaladh-singhal Thank you for reviewing it!
I am sorry for not requesting reviews, I was about to do it once the docs were built but then forgot about it. There seems to be a small problem with my documentation build, I would request reviews once that's fixed!

@atharva-2001 atharva-2001 force-pushed the observed_spectrum branch 5 times, most recently from 84f01a0 to cb30a3a Compare October 1, 2021 12:07
@jaladh-singhal
Copy link
Member

jaladh-singhal commented Oct 1, 2021

I am sorry for not requesting reviews, I was about to do it once the docs were built but then forgot about it. There seems to be a small problem with my documentation build, I would request reviews once that's fixed!

@atharva-2001 You don't really need to wait for docs to build. First, because we don't reviewe immediately anyways 😄 and second because we (atleast I) review rendered notebook using nbreview - docs build is just sanity check in this case.

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.

Looks neater now! Good work!

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.

Looks good to me - if you fix the few minor comments then I'd be happy to merge!

tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
tardis/visualization/tools/sdec_plot.py Outdated Show resolved Hide resolved
@atharva-2001 atharva-2001 force-pushed the observed_spectrum branch 2 times, most recently from 907785d to 835477b Compare October 2, 2021 03:22
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.

looks good

@jamesgillanders jamesgillanders merged commit 45bb948 into tardis-sn:master Oct 4, 2021
jamesgillanders pushed a commit that referenced this pull request Oct 4, 2021
jamesgillanders pushed a commit that referenced this pull request Oct 4, 2021
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.

4 participants