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

Integrate custom abundance widget as a full module #1751

Merged

Conversation

yuyizheng1112
Copy link
Contributor

@yuyizheng1112 yuyizheng1112 commented Jul 22, 2021

This PR integrates the codes of custom abundance widget from notebook to .py module. The notebook is in pr #1626.

Description

  • Add custom_abundance.py module to create widget object.
  • Add Custom Abundance Widget to using_widgets.rst to demonstrate how to use the widget. See the documentation page here.
  • Add abundance_widget.ipynb notebook to demonstrate how to generate the widget. See the documentation page here.

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 22, 2021

Codecov Report

Merging #1751 (8138381) into master (1c3322b) will decrease coverage by 4.24%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1751      +/-   ##
==========================================
- Coverage   62.65%   58.40%   -4.25%     
==========================================
  Files          65       66       +1     
  Lines        6036     6631     +595     
==========================================
+ Hits         3782     3873      +91     
- Misses       2254     2758     +504     
Impacted Files Coverage Δ
tardis/tardis/visualization/widgets/util.py 72.30% <0.00%> (-13.06%) ⬇️
tardis/tardis/simulation/base.py 83.17% <0.00%> (ø)
...dis/tardis/visualization/tools/convergence_plot.py 88.67% <0.00%> (ø)
...s/tardis/visualization/widgets/custom_abundance.py 13.83% <0.00%> (ø)

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 ea86abf...8138381. 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.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

@MarkMageeAstro MarkMageeAstro left a comment

Choose a reason for hiding this comment

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

Very nice work. I haven't looked at the code itself in detail because I have a few comments regarding bugs/design.

  1. Need units for the density in the plot. It should be g/cm3
  2. The description of the 'apply to other shells' function should be more descriptive. It looks like it only applies whichever ones are locked, is that true?
  3. The edit density functionality didn't work for me. The plot never updated to show the new density I had put in. This is true for editing the density of a single shell and using different functions to calculate the densities in multiple shells
  4. If I have more than 10 elements, the colours in the plot start to repeat, which makes it difficult to tell them apart. Can we have a different colour scheme? Maybe a gradient? Although even with a gradient, it'll be difficult to tell apart if there are many elements. Basically, I don't have a good solution to this.
  5. When calculating and plotting the densities, there must be some t0 assumed. This should also be the default value in the box where it asks you to put in a t0 and stated somewhere. Perhaps the y label should be 'Density at XX' where XX = t0.
  6. I think it makes sense to keep the points in the plot because then you can easily see where the cells change. If there are no points and I have a constant fractional abundance, then I can't see where each cell begins and ends
  7. There is still an issue with adding cells below the boundary. This is raised in issue Density calculated below photosphere for Branch W7 density #1734. Not sure what to do about it in the mean time.
  8. I think the output functionality should add the file extension. e.g. if I save file path = 'test' then it should save as 'test.csvy'
  9. If I overwrite existing cells and therefore change the number of cells in the model, the shell number box doesn't update to reflect that. For example, say I have a model with 20 cells as in the example and I highlight cell 2 in the plot. Then I update the model to overwrite all cells into one big cell. In this case I get an index error and it crashes

This may seem like a lot, but overall it's very impressive, good job!

@jaladh-singhal
Copy link
Member

@yuyizheng1112 black check workflow is failing. Also have you added changes we discussed to widget layout - I'm planning to review once that is done?

@yuyizheng1112
Copy link
Contributor Author

@MarkMageeAstro
2. That's true. Since it is a bit confusing, I am working on a new layout.
5. The calculation of density profile doesn't seem to require t_0, so I put it in output part.
6. Sure. I'll retain the markers.
And I'm working on the rest staff.

@yuyizheng1112 yuyizheng1112 force-pushed the abundance-widget-module branch from aaaca06 to 8cc5f88 Compare August 11, 2021 12:32
@yuyizheng1112 yuyizheng1112 marked this pull request as ready for review August 12, 2021 07:09
Copy link
Member

@wkerzendorf wkerzendorf left a comment

Choose a reason for hiding this comment

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

I would also suggest that we use the json schemas to see what types of density profiles exist.

tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
YAML_DELIMITER = "---"


class CustomYAML(yaml.YAMLObject):
Copy link
Member

Choose a reason for hiding this comment

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

why do we need a new YAML file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class generates a YAML object for writing YAML portion when saving the model file.

tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
CustomAbundanceWidget
"""
csvy_model_config, csvy_model_data = load_csvy(fpath)
base_dir = os.path.abspath(os.path.dirname(__file__))
Copy link
Member

Choose a reason for hiding this comment

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

lets use tardis.__path__ here as BASE_DIR at the beginning of the file.

Copy link
Member

Choose a reason for hiding this comment

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

and use pathlib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wkerzendorf I think I can use pathlib when writing CSVY output file, but why should we use pathlib in from_csvy method?


# Add YAML delimiter
splits = yaml_output.split("\n")
splits[0] = splits[-1] = YAML_DELIMITER
Copy link
Member

Choose a reason for hiding this comment

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

not clear what that line does (it might be right - just don't understand it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It replaces the first and the last line with --- in the CSVY file.
The original first line is a YAML tag: !!python/object:tardis.visualization.widgets.custom_abundance.CustomYAML and the original last line is blank, so I add this line to replace them and add yaml delimiter.

Copy link
Member

Choose a reason for hiding this comment

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

@yuyizheng1112 probably it'll be better to rename splits as yaml_output_snippets

@yuyizheng1112
Copy link
Contributor Author

I would also suggest that we use the json schemas to see what types of density profiles exist.

@wkerzendorf Can I do this in another new PR?

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 very excellent work @yuyizheng1112 - congratulations on writing such a huge module single-handedly. 🎉

Your code organisation is nice, you have righlty splitted functionality in appropriate methods, and I really liked the pattern you followed in naming so many widget components. The code documentation is also fairly good except for few changes that I commented. The docs also look great with the examples.

My comment count is really high 😅 but they are mostly small nitpicky requests that shouldn't take much time to address. Feel free to let me know if anything is unclear

tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
docs/io/visualization/using_widgets.rst Outdated Show resolved Hide resolved
docs/io/visualization/using_widgets.rst Outdated Show resolved Hide resolved
docs/io/visualization/using_widgets.rst Outdated Show resolved Hide resolved
docs/io/visualization/using_widgets.rst Show resolved Hide resolved
Comment on lines 30 to 31
abundance_widget
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Generating Widgets in a Notebook <generating_widgets>
abundance_widget
Generating Custom Abundance Widget <abundance_widget>
Generating Data Exploration Widgets <generating_widgets>

For now let's keep it this way.

Copy link
Member

Choose a reason for hiding this comment

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

Also can you edit the title of generating_widgets.ipynb to same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I edit the title of both generating_widgets.ipynb and abundance_widget.ipynb. I also clear the output and commented the cell that generates shell_info_widget from HDF file. Please tell me if you don't want to do that.

Copy link
Member

Choose a reason for hiding this comment

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

Since you edited the title there was no need of mentioning explicit title in TOC but NVM

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.

Thank you for addressing all of my comments - docstrings look much better now.

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 an extremely well-structured piece of code @yuyizheng1112 - fantastic work! I have no issues with merging this

tardis/visualization/widgets/custom_abundance.py Outdated Show resolved Hide resolved
@jamesgillanders jamesgillanders merged commit eb73057 into tardis-sn:master Aug 20, 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.

7 participants