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
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4355d7b
Integrate custom abundance widget as a full module
yuyizheng1112 Jul 22, 2021
f56e215
Add docstrings
yuyizheng1112 Jul 30, 2021
f7e196d
Fix minor bugs
yuyizheng1112 Aug 3, 2021
387b3ce
Change the plot to step graph
yuyizheng1112 Aug 3, 2021
eb9c576
Fix adding element bug
yuyizheng1112 Aug 3, 2021
1fc4e5d
Add documentation
yuyizheng1112 Aug 3, 2021
391e79a
Add radio buttons to switch apply type
yuyizheng1112 Aug 4, 2021
a2d7970
Adjust the layout
yuyizheng1112 Aug 6, 2021
121a62f
Fix density plot bug
yuyizheng1112 Aug 6, 2021
838dd92
Fix shell overwriting bug
yuyizheng1112 Aug 6, 2021
20f2892
Fix density interpolation
yuyizheng1112 Aug 6, 2021
55841ce
Add colorscale, add multi-shell selection in plot, load t_0
yuyizheng1112 Aug 10, 2021
a54308b
Add docstrings to new methods
yuyizheng1112 Aug 10, 2021
c6adf31
Add documentation
yuyizheng1112 Aug 11, 2021
8cc5f88
Black format
yuyizheng1112 Aug 11, 2021
08d77fe
Add new documentation
yuyizheng1112 Aug 12, 2021
7bc3fd3
Add images for documentation
yuyizheng1112 Aug 12, 2021
de7414f
[build docs]
yuyizheng1112 Aug 12, 2021
c9a5244
[build docs]
yuyizheng1112 Aug 12, 2021
a340577
Clear widget output and add GIF
yuyizheng1112 Aug 12, 2021
0591907
Use pathlib and made minor changes
yuyizheng1112 Aug 13, 2021
fedac9c
Update tardis/visualization/widgets/custom_abundance.py
yuyizheng1112 Aug 13, 2021
d8eb86d
Move Timer class and chang docstrings
yuyizheng1112 Aug 13, 2021
7a28d08
Rename some functions and variables
yuyizheng1112 Aug 13, 2021
05f3474
docstring changes to util.py
yuyizheng1112 Aug 13, 2021
264d3f7
Edit documentation and notebook title
yuyizheng1112 Aug 13, 2021
3eecf9f
Perform black format
yuyizheng1112 Aug 13, 2021
fa0b2ef
[build docs]
yuyizheng1112 Aug 13, 2021
a6829fe
Correct the section name
yuyizheng1112 Aug 13, 2021
3d4d029
[build docs]
yuyizheng1112 Aug 13, 2021
8138381
Change docstring of time_0
yuyizheng1112 Aug 20, 2021
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
Binary file added docs/io/images/cus_abund_add_element.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/io/images/cus_abund_add_shell.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/io/images/cus_abund_edit_abundance.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/io/images/cus_abund_edit_density.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/io/images/cus_abund_norm.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/io/images/custom_abundance_widget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 183 additions & 0 deletions docs/io/visualization/abundance_widget.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generating Custom Abundance Widget"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook demonstrates how to generate and display Custom Abundance Widget."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, import `CustomAbundanceWidget` module from `visualization` subpackage to create the widget."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tardis.visualization import CustomAbundanceWidget"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Initialize the GUI "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are four ways to generate the widget. You can generate it from `.yml`/`.csvy` configuration files before running any simulation."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using a YAML file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"widget = CustomAbundanceWidget.from_yml(\"tardis_example.yml\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using a CSVY file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# widget = CustomAbundanceWidget.from_csvy(\"demo.csvy\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, you can generate the widget after the simulation from a Simulation instance or a saved simulation (HDF file)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using a Simulation object"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# sim = run_tardis(\"tardis_example.yml\")\n",
"# widget = CustomAbundanceWidget.from_sim(sim)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using a HDF file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# widget = CustomAbundanceWidget.from_hdf(\"demo.hdf\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Display the GUI"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"No matter which way you use to initialize the widget, you can call `.display()` to display the GUI easily."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"widget.display()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The image below is just a screenshot of the GUI for a demonstration purpose. If you want to interact with the GUI, please run the code in the notebook.\n",
"\n",
"![Custom Abundance Widget Demo](../images/custom_abundance_widget.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "42180fb7a26743e791b9c1155ac51f7e87399be241c0afbd4c0781c11826afd9"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
10,743 changes: 12 additions & 10,731 deletions docs/io/visualization/generating_widgets.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/io/visualization/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ Jupyter Notebooks, making data exploration much easier.
:maxdepth: 2

using_widgets
Generating Widgets in a Notebook <generating_widgets>
Generating Custom Abundance Widget <abundance_widget>
Generating Data Exploration Widgets <generating_widgets>
78 changes: 77 additions & 1 deletion docs/io/visualization/using_widgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,87 @@ Using TARDIS Widgets

This page describes what each TARDIS Widget has to offer and how you can make
the best use of it. If you're looking for the code to generate widgets, head
over to `Generating TARDIS Widgets <generating_widgets>`_ section and see the
over to `Generating Custom Abundance Widget <abundance_widget>`_ section or
`Generating Data Exploration Widgets <generating_widgets>`_ section to see the
notebook in action.

Currently, TARDIS supports the following widgets:

Custom Abundance Widget
#######################
This widget (or GUI) allows you to develop custom model compositions
graphically and output the model to a new file.

.. image:: ../images/custom_abundance_widget.png
:alt: Demo of Custom Abundance Widget

The GUI consists of three parts:

1. **Visualization plot** - An interactive step graph that shows abundances
and densities as a function of velocity.

2. **Data editor** - An interface to edit abundances, densities and velocity
shells.

3. **File output** - An output module to save the model compositions as a CSVY
file.

Interacting with the GUI
========================

You can interact with this GUI in the following ways:

Edit Abundances
---------------
There are two radio buttons which allow you to edit either single shell or
mutiple shells. The new input will be applied to selected shell(s) immediately
and the plot is updated at the same time. If you want to edit multiple shells
at a time, remember to choose the second radio button and set the range of
shell number using int slider. The selected shell(s) is highlighted in the
plot.

.. image:: ../images/cus_abund_edit_abundance.gif
yuyizheng1112 marked this conversation as resolved.
Show resolved Hide resolved
:alt: Demo of editing abundances

Normalize Abundances
--------------------
Click `Normalize` button to normalize the abundances on selected shell(s) to
1. If you wish to keep the abundance of a certain element unchanged during the
normalization, you can select the checkbox near that element to lock it.
The normalization will be applied to other elements and the sum of the
abundances still remains at 1.

.. image:: ../images/cus_abund_norm.gif
:alt: Demo of normalization

Edit Densities
--------------
In `Edit Density` tab, you also can edit either single shell or the whole
density profile. To calculate a new profile, you need to choose the density
type and input required parameters.

.. image:: ../images/cus_abund_edit_density.gif
:alt: Demo of editing densities

Add New Element
---------------
At the bottom of the editor, the symbol input box allows you to add new element
or isotope to the model. It automatically recognizes whether the symbol exists
or whether the element is already in the model.

.. image:: ../images/cus_abund_add_element.gif
:alt: Demo of adding new element

Add New Shell
-------------
Another important functionality is to add new shell to the model. You need to
specify the velocity range of the new shell and abundances at that new shell
will be set to 0. Note that the existing shell(s) will be resized smartly if
the new shell overlaps with it.

jaladh-singhal marked this conversation as resolved.
Show resolved Hide resolved
.. image:: ../images/cus_abund_add_shell.gif
:alt: Demo of adding new shell

Shell Info Widget
#################

Expand Down
1 change: 1 addition & 0 deletions tardis/visualization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
shell_info_from_hdf,
)
from tardis.visualization.widgets.line_info import LineInfoWidget
from tardis.visualization.widgets.custom_abundance import CustomAbundanceWidget
from tardis.visualization.tools.sdec_plot import SDECPlotter
Loading