tardis.visualization.widgets.custom_abundance module

Class to create and display Custom Abundance Widget.

class tardis.visualization.widgets.custom_abundance.CustomAbundanceWidget(widget_data)[source]

Bases: object

Widget to edit abundances and densities of simulation model graphically.

It generates a GUI based on input data. The GUI has a plot section to visualize the profile, an edit section to allow the user directly edit abundance and density profile, and an output section to output the model to CSVY file.

Attributes:
shell_noint

The selected shell number.

no_of_shellsint

The number of shells in the model.

no_of_elementsint

The number of elements in the model.

checked_listlist of bool

A list of bool to record whether the checkbox is checked. The index of the bool corresponds to the index of checkbox.

figplotly.graph_objs._figurewidget.FigureWidget

The figure object of abundance density plot.

plot_cmapstr, default: “jet”, optional

String defines the colormap used in abundance density plot.

_triggerbool

If False, disable the callback when abundance input is changed.

Initialize CustomAbundanceWidget with data and generate the widgets and plot.

Parameters:
widget_dataCustomAbundanceWidgetData
apply_to_multiple_shells(item_index)[source]

Apply the changed abundances to specified range of shell(s).

Parameters:
item_indexint

The index of the widget in the list of abundance inputs.

bound_locked_sum_to_1(index)[source]

Ensure the sum of locked abundances is no more than 1. If the locked sum is more than 1, calculate the maximum with the sum no more than 1 and return it.

Parameters:
indexint

The index of the widget in the list of abundance inputs.

check_eventhandler(obj)[source]

Triggered if the checkbox is changed.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

property checked_list
create_widgets()[source]

Create widget components in GUI and register callbacks for widgets.

display(cmap='jet')[source]

Display the GUI.

Parameters:
cmapstr, default: “jet”, optional

String defines the colormap used in abundance density plot.

Returns:
ipywidgets.widgets.widget_box.VBox

A box that contains all the widgets in the GUI.

dpd_shell_no_eventhandler(obj)[source]

Make the data in widgets correspond with the selected shell. Triggered if the dropdown value is changed.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

error_view = Output()
classmethod from_csvy(fpath)[source]

Create a new CustomAbundanceWidget instance with data from CSVY file.

Parameters:
fpathstr

the path of CSVY file.

Returns:
CustomAbundanceWidget
classmethod from_hdf(fpath)[source]

Create a new CustomAbundanceWidget instance with data from HDF file.

Parameters:
fpathstr

the path of HDF file.

Returns:
CustomAbundanceWidget
classmethod from_simulation(sim)[source]

Create a new CustomAbundanceWidget instance from a Simulation object.

Parameters:
simSimulation
Returns:
CustomAbundanceWidget
classmethod from_yml(fpath)[source]

Create a new CustomAbundanceWidget instance with data from YAML file.

Parameters:
fpathstr

The path of YAML file.

Returns:
CustomAbundanceWidget
generate_abundance_density_plot()[source]

Generate abundance and density plot in different shells.

input_item_eventhandler(obj)[source]

Update the data and the widget when it gets new abundance input. Triggered if the abundance input is changed.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

input_symb_eventhandler(**kwargs)
input_v_eventhandler(obj)[source]

Judge whether the input velocity range is valid. Triggered if the velocity input is changed.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

irs_shell_range_eventhandler(obj)[source]

Select the velocity range of new shell and highlight the range in the plot. Triggered if the shell range slider is changed.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

property no_of_elements
property no_of_shells
on_btn_add_element(obj)[source]

Add new element and update the display in the front end. Triggered if the add button is clicked.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

on_btn_add_shell(obj)[source]

Add new shell with given boundary velocities. Triggered if the button is clicked.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

on_btn_next(obj)[source]

Move to next shell.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

on_btn_norm(obj)[source]

Normalize unlocked abundances to 1. Triggered if the normalize button is clicked.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

on_btn_output(obj)[source]

Triggered if the output button is clicked.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

on_btn_prev(obj)[source]

Move to previous shell.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

overwrite_existing_shells(v_0, v_1)[source]

Judge whether the existing shell(s) will be overwritten when inserting a new shell within the entered velocity range.

Parameters:
v_0float

The velocity of inner boundary.

v_1float

The velocity of outer boundary.

Returns:
bool

True if the existing shell will be overwritten, False otherwise.

rbs_multi_apply_eventhandler(obj)[source]

Switch to multi-shells editing mode. Triggered if the second radio button is selected.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

rbs_single_apply_eventhandler(obj)[source]

Switch to single shell editing mode. Triggered if the first radio button is selected.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

read_abundance()[source]

Read abundances data in DataFrame to input items box when shell No. changes.

property shell_no
tbs_scale_eventhandler(obj)[source]

Switch the scale type of y axis between linear mode and log mode. Triggered if the toggle button is changed.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

to_csvy(path, overwrite)[source]

Output CSVY file on the specified path.

Parameters:
pathstr

Output path.

overwritebool

True if overwriting, False otherwise.

update_abundance_plot(index)[source]

Update the abundance line of certain element in the plot.

Parameters:
indexint

The index of the widget in the list of abundance inputs.

update_bar_diagonal()[source]

Update bar diagonal (and shell no dropdown) when the range of shells changed.

update_front_end()[source]

Update checkbox widgets, input widgets and plot in the front end when selected shell No. is changed.

update_input_item_value(index, value)[source]

Update the value of the widget in the list of abundance inputs.

Keep two decimal places for displayed value and disable input_item_eventhandler while changing the value.

Parameters:
indexint

The index of the widget in the list of abundance inputs.

valuefloat

New abundance value.

update_line_color()[source]

Update line color in the plot according to colormap.

write_csv_portion(path)[source]

Write the CSV portion of the output file.

Parameters:
pathpathlib.PosixPath
write_yaml_portion(path)[source]

Write the YAML portion of the output file.

Parameters:
pathpathlib.PosixPath
class tardis.visualization.widgets.custom_abundance.CustomAbundanceWidgetData(density_t_0, density, abundance, velocity)[source]

Bases: object

The model information and data that required in custom abundance widget.

Attributes:
elementslist of str

A list of elements or isotopes’ symbols.

Initialize CustomAbundanceWidgetData with model information.

Parameters:
density_t_0astropy.units.quantity.Quantity

Initial time for the density in the model.

densityastropy.units.quantity.Quantity
abundancepd.DataFrame
velocityastropy.units.quantity.Quantity
classmethod from_csvy(fpath)[source]

Create a new CustomAbundanceWidgetData instance with data from CSVY file.

Parameters:
fpathstr

the path of CSVY file.

Returns:
CustomAbundanceWidgetData
classmethod from_hdf(fpath)[source]

Create a new CustomAbundanceWidgetData instance with data from HDF file.

Parameters:
fpathstr

the path of HDF file.

Returns:
CustomAbundanceWidgetData
classmethod from_simulation(sim)[source]

Create a new CustomAbundanceWidgetData instance from a Simulation object.

Parameters:
simSimulation
Returns:
CustomAbundanceWidgetData
classmethod from_yml(fpath, atom_data=None)[source]

Create a new CustomAbundanceWidgetData instance with data from YAML file.

Parameters:
fpathstr

The path of YAML file.

Returns:
CustomAbundanceWidgetData
get_symbols()[source]

Get symbol string from atomic number and mass number.

class tardis.visualization.widgets.custom_abundance.CustomYAML(name, d_time_0, i_time_0, v_inner_boundary, v_outer_boundary)[source]

Bases: YAMLObject

A custom YAML object generated by required properties.

Initialize CustomYAML object with given properties.

Parameters:
namestr

Name of the YAML file.

d_time_0astropy.units.quantity.Quantity

Initial time for the density in the model.

i_time_0astropy.units.quantity.Quantity

Initial time for isotope decay. Set to 0 for no isotopes.

v_inner_boundaryastropy.units.quantity.Quantity

Velocity of the inner boundary.

v_outer_boundaryastropy.units.quantity.Quantity

Velocity of the outer boundary.

create_fields_dict(elements)[source]

Create a dictionary to store the items in ‘fields’ part.

Parameters:
elementslist of str

A list of elements or isotopes’ symbols.

class tardis.visualization.widgets.custom_abundance.DensityEditor(widget_data, fig, shell_no_widget)[source]

Bases: object

Widget to edit density profile of the model.

It provides an interface to allow the user directly change the density, or calculate the density with given type and parameters.

Attributes:
shell_noint

The selected shell number.

_triggerbool

If False, disable the callback when density input is changed.

Initialize DensityEditor with data and widget components.

Parameters:
widget_dataCustomAbundanceWidgetData

Data in the custom abundance widget.

figplotly.graph_objs._figurewidget.FigureWidget

The figure object of density plot.

shell_no_widgetipywidgets.widgets.widget_selection.Dropdown

A widget to record the selected shell number.

create_widgets()[source]

Create widget components in density editor GUI and register callbacks for widgets.

display()[source]

Display the GUI.

Returns:
ipywidgets.widgets.widget_box.VBox

A box that contains all the widgets in the GUI.

dpd_dtype_eventhandler(obj)[source]

Display the input boxes of the specified density type. Triggered if the density type dropdown is changed.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

Returns:
ipywidgets.widgets.widget_box.VBox

A box widget that contains the input boxes of certain density type parameters.

dtype_out = Output()
input_d_eventhandler(obj)[source]

Update the data and the widgets when the widget gets new density input.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

input_d_time_0_eventhandler(obj)[source]

Update density time 0 data when the widget gets new input.

Parameters:
objtraitlets.utils.bunch.Bunch

A dictionary holding the information about the change.

on_btn_calculate(obj)[source]

Calculate density according to density parameters input. Triggered if the density calculate button is clicked.

Parameters:
objipywidgets.widgets.widget_button.Button

The clicked button instance.

read_density()[source]

Read density data in DataFrame to density input box when shell No. changes.

property shell_no
update_density_plot()[source]

Update the density line in the plot.