Figure

class sofia_redux.visualization.display.figure.Figure(figure_widget, signals: Signals)[source]

Bases: object

Oversee the plot.

The Figure class is analogous to matplotlib.figure.Figure. It handles all plots generated. There is only one Figure instance created for the Eye. Each plot resides in a Pane object. The Figure receives commands from the View object and decides which Pane it applies to, as well as how it should be formatted. The Figure does not manage any Qt objects.

Parameters:
figure_widgetQtWidgets.QWidget

The widget in the Qt window containing the matplotlib canvas to display to.

signalssofia_redux.visualization.signals.Signals

Custom signals recognized by the Eye interface, used to trigger callbacks outside the Figure.

Attributes:
widgetQtWidgets.QWidget

The widget in the Qt window that Figure connects to.

figmatplotlib.figure.Figure

The Matplotlib Figure object contained in the Qt widget.

paneslist

A list of Pane objects.

gsgridspec.GridSpec

The gridspec that details how the panes are aligned and spaced out.

signalssofia_redux.visualization.signals.Signals

Collection of PyQt signals for passing on information to other parts of the Eye.

_current_panelist

List of indices of the currently selected panes in panes.

highlight_panebool

Flag to specify if the current pane should be highlighted.

layout{‘grid’, ‘rows’, ‘columns’}

Determines the layout in a plot.

color_cycle{‘spectral’, ‘tableau’, ‘accessible’}

Color cycle to set.

plot_type{‘line’, ‘step’, ‘scatter’}

Plot type to set.

show_markersbool

If set, markers will be shown.

show_gridbool

If set, a background grid is shown.

dark_modebool

If set, dark mode is enabled.

recordingbool

Status flag, indicating whether a cursor mode is active.

gallerygallery.Gallery

Gallery object tracking plot artists in the figure.

blitterblitting.Blitmanager

Blitting manager for the figure.

Attributes Summary

current_pane

list of int : Currently active panes.

Methods Summary

add_model_to_pane(model_[, panes])

Add model to current pane.

add_panes(n_dims[, n_panes])

Add new panes to the figure.

ap_order_state(target, model_ids)

Get the current aperture and order configuration.

assign_models(mode, models[, indices])

Assign models to panes.

change_axis_field(fields[, target])

Change the axis field for specified panes.

change_axis_limits(limits[, target])

Change the axis limits for specified panes.

change_axis_unit(units[, target])

Change the axis unit for specified panes.

change_current_pane(pane_id)

Set the current pane to the index provided.

clear_all()

Clear all artists and redraw panes.

clear_crosshair()

Clear any displayed crosshairs.

clear_lines(flags[, all_panes])

Clear all displayed guides.

crosshair(event)

Display a crosshair at the cursor position.

data_at_cursor(event)

Retrieve the plot data at the cursor position.

determine_pane_from_model(model_id[, order])

Determine pane containing specified model.

determine_selected_pane([ax, all_ax])

Determine what pane corresponds to a provided axes.

end_cursor_records([pane_index])

Complete zoom or fit interactions.

get_colors(model_id, pane_)

Get the colors in a pane.

get_current_pane()

Return the current pane.

get_fields([target])

Get the fields associated with a given pane selection.

get_markers(model_id, pane_)

Get the markers in a pane.

get_orders([target, enabled_only, model, ...])

Get the orders associated with a given pane selection.

get_scales([target])

Get the axis scales associated with a given pane selection.

get_selection_results()

Retrieve feature fit parameters.

get_units([target])

Get the units associated with a given pane selection.

model_backup(models, target)

Obtain the backup models and assign them to panes.

model_extensions(model_id[, pane_, pane_index])

Obtain an extension list of a model in a pane.

model_matches_pane(pane_, model_)

Check if a model is displayable in a specified pane.

models_per_pane()

Retrieve the number of models in each pane.

pane_count()

Retrieve the number of panes.

pane_details()

Compile summaries of all panes in the figure.

pane_layout()

Retrieve the current pane layout.

parse_pane_flag(flags)

Parse the specified panes from an input flag.

populated()

Check for pane existence.

record_cursor_location(event)

Store the current cursor location.

refresh(bg_full, bg_partial)

Refresh the figure canvas.

remove_all_panes()

Remove all panes.

remove_artists()

Remove all artists.

remove_model_from_pane([filename, model_id, ...])

Remove a model from one or more panes.

remove_pane([pane_id])

Remove a specified pane.

reset_artists()

Recreate all artists from models.

reset_data_points()

Reset any displayed cursor markers.

reset_zoom([all_panes, targets])

Reset axis limits to defaults.

save(filename, **kwargs)

Save the current figure to a file.

set_all_enabled(pane_id, state)

Enable or disable all models in a pane.

set_block_current_pane_signal([value])

Set the flag to block the current_pane signal.

set_color_cycle(cycle_name)

Set the color cycle in all panes.

set_cursor_mode(mode)

Set the cursor mode.

set_dark_mode([state])

Set a dark background in all panes.

set_enabled(pane_id, model_id, state)

Enable or disable a specified model.

set_error([state])

Set the error range visibility in all panes.

set_grid([state])

Set the grid visibility in all panes.

set_layout_style([value])

Set the layout style.

set_markers([state])

Set the marker visibility in all panes.

set_orders(orders[, enable, aperture])

Enable specified orders.

set_overplot_state(state[, target])

Set the pane overplot flag.

set_pane_highlight_flag(state)

Set the visibility for a pane highlight border.

set_plot_type(plot_type)

Set the plot type in all panes.

set_scales(scales[, target])

Set the axis scale for specified panes.

stale_fit_artists(fits)

Recreate fit artists for a list of model fits.

toggle_fits_visibility(fits)

Update fit artist visibility.

unload_reference_model(models)

Unload the reference model.

update_reference_lines(models)

Remove and replot reference lines.

valid_pane(index, pane_count)

Check if a pane index is valid.

Attributes Documentation

current_pane

list of int : Currently active panes.

Methods Documentation

add_model_to_pane(model_: MT, panes: PT | List[PT] | None = None) None[source]

Add model to current pane.

If there are currently no panes, create one. If there are panes but the model is not compatible with them, create a new one and add the model there.

Parameters:
model_sofia_redux.visualization.models.high_model.HighModel

Model to add.

panessofia_redux.visualization.display.pane.Pane, Optional

A list of panes to which we add model. If not provided, add to current pane.

add_panes(n_dims: int | Tuple | List, n_panes: int = 1) None[source]

Add new panes to the figure.

Parameters:
n_dimsint, list-like

Specifies the number of dimensions for the new panes, which determines if they are for spectra or images. If multiple panes are being added, this can be a single value that will apply to all new panes, or a list-like object that specifies the dimensions for each new pane.

n_panesint

Number of panes to be added.

Raises:
RuntimeError

If inconsistent or invalid options are given.

ap_order_state(target, model_ids)[source]

Get the current aperture and order configuration.

Parameters:
targetstr, None, list of int, or list of Panes

Panes to examine.

model_idslist of UUID

Model IDs to examine.

Returns:
apertures, ordersdict, dict

Keys are pane index for which the specified model was found. Values are numbers of apertures and orders displayed, respectively, for that pane.

assign_models(mode: str, models: Dict[str, MT], indices: List[int] | None = None) int[source]

Assign models to panes.

Parameters:
mode[‘split’, ‘first’, ‘last’, assigned’]

Specifies how to arrange the models on the panes. ‘Split’ divides the models as evenly as possible across all present panes. ‘First’ assigns all the models to the first pane, while ‘last’ assigns all the models to the last pane. ‘Assigned’ attaches each model to the pane index provided in indices.

modelsdict

Dictionary of models to add. Keys are the model ID, with the values being the models themselves.

indiceslist of int, optional

A list of integers with the same length of models. Only used for assigned mode. Specifies the index of the desired pane for the model.

Raises:
RuntimeError

If an invalid mode is provided.

change_axis_field(fields: Dict[str, str], target: Any | None = None) None[source]

Change the axis field for specified panes.

Parameters:
fieldsdict

Keys are ‘x’, ‘y’. Values are the field names to change to.

targetstr, None, list of int, or list of Pane objects

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of ints or Pane objects.

change_axis_limits(limits: Dict[str, float], target: Any | None = None) None[source]

Change the axis limits for specified panes.

Parameters:
limitsdict

Keys are ‘x’, ‘y’. Values are [low, high] limits for the axis.

targetstr, None, dict, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane objects

change_axis_unit(units: Dict[str, str], target: Any | None = None) None[source]

Change the axis unit for specified panes.

If incompatible units are specified, the current units are left unchanged.

Parameters:
unitsdict

Keys are ‘x’, ‘y’. Values are the units to convert to.

targetstr, None, dict, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of

change_current_pane(pane_id: List[int]) bool[source]

Set the current pane to the index provided.

Parameters:
pane_idint

Index of the new current pane.

Returns:
changedbool

True if current pane has changed; False if the new current pane is the same as the old current pane.

clear_all() None[source]

Clear all artists and redraw panes.

clear_crosshair() None[source]

Clear any displayed crosshairs.

clear_lines(flags: str | List[str], all_panes: bool | None = False) None[source]

Clear all displayed guides.

Parameters:
flagsstr

Type of guides to clear.

all_panesbool, optional

If True, all panes will be updated. Otherwise, only the current pane will be updated.

crosshair(event: MouseEvent) None[source]

Display a crosshair at the cursor position.

Parameters:
eventmatplotlib.backend_bases.MouseEvent

Mouse motion event.

data_at_cursor(event: MouseEvent) Dict[source]

Retrieve the plot data at the cursor position.

Parameters:
eventmatplotlib.backend_bases.MouseEvent

Mouse motion event.

Returns:
data_pointdict

Keys are filenames; values are lists of dicts containing ‘order’, ‘bin’, ‘bin_x’, ‘bin_y’, ‘x_field’, ‘y_field’, ‘color’, and ‘visible’ values for the displayed models.

determine_pane_from_model(model_id: str, order: int | None = None) List[PT][source]

Determine pane containing specified model.

Parameters:
model_idstr

Specific model_id associated with the model to be found.

orderint, optional

Specific order (aperture number) to be found.

Returns:
foundlist[(int,sofia_redux.visualization.display.pane.Pane)]

List of panes containing given model_id and order number.

determine_selected_pane(ax: Axes | None = None, all_ax: bool | None = False) List[int][source]

Determine what pane corresponds to a provided axes.

Parameters:
axmatplotlib.axes.Axes

The axes to find.

all_axbool

True if all axis are to be selected.

Returns:
indexint, None

The pane index of the correct pane, or None if the axes were not found.

end_cursor_records(pane_index: int | None = None) None[source]

Complete zoom or fit interactions.

User specified locations are used to either set axis limits or else display a new fit to a plot feature.

Parameters:
pane_indexint

Index of the pane to update.

get_colors(model_id, pane_)[source]

Get the colors in a pane.

Parameters:
model_iduuid.UUID

Unique id associated with an HDUL

pane_sofia_redux.visualization.display.pane.Pane

The pane object from which colors are to be obtained.

Returns:
colorslist

A list of colors in a pane for a model_id

get_current_pane() List[PT] | None[source]

Return the current pane.

Returns:
panesofia_redux.visualization.display.pane.Pane, None

The current pane if a current pane exists; None otherwise.

get_fields(target: Any | None = None) List[source]

Get the fields associated with a given pane selection.

Parameters:
targetstr, None, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane indices to modify.

Returns:
fieldslist

List of fields for corresponding to pane selection provided.

get_markers(model_id, pane_)[source]

Get the markers in a pane.

Parameters:
model_iduuid.UUID

Unique id associated with an HDUL

pane_sofia_redux.visualization.display.pane.Pane

The pane object from which markers are to be obtained.

Returns:
markerslist

A list of markers in a pane for a model_id

get_orders(target: Any | None = None, enabled_only: bool | None = True, model: MT | None = None, filename: str | None = None, model_id: IDT | None = None, group_by_model: bool | None = True, kind: str | None = 'order') Dict[source]

Get the orders associated with a given pane selection.

Parameters:
targetstr, None, dict, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane indices to modify.

enabled_onlybool, optional

Determines if an order is going to be visible or not.

modelhigh_model.HighModel, optional

Target model

filenamestr

Name of file

model_iduuid.UUID

Unique UUID for an HDUL.

group_by_modelbool, optional.

If set, return a dictionary with the keys are model names and the values are the orders for that model. Otherwise, return a list of all model orders combined.

Returns:
ordersdict

Dictionary of orders for corresponding to pane selection provided. Keys are the indices of the panes.

get_scales(target: Any | None = None) List[source]

Get the axis scales associated with a given pane selection.

Parameters:
targetstr, None, dict, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane indices to modify.

Returns:
scaleslist

List of axes scales for corresponding to pane selection provided.

get_selection_results() List[ModelFit][source]

Retrieve feature fit parameters.

Returns:
fit_paramslist of ModelFit

Models fit to spectral selections.

get_units(target: Any | None = None) List[source]

Get the units associated with a given pane selection.

Parameters:
targetstr, None, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane indices to modify.

Returns:
unitslist

List of units for corresponding to pane selection provided.

model_backup(models: MT, target)[source]

Obtain the backup models and assign them to panes.

Parameters:
modelshigh_model.HighModel

HighModels to be loaded into pane

targetstr, None, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane indices to modify.

model_extensions(model_id, pane_=None, pane_index: int | None = None) List[str][source]

Obtain an extension list of a model in a pane.

Parameters:
model_iduuid.UUID

Unique model id associated with an HDUL

pane_sofia_redux.visualization.spectrum.panes.Pane, optional

Pane object containing the model. If not provided, all panes will be checked.

pane_indexint, optional

Index of the pane from which model extensions are desired when no pane has been specified.

Returns:
extlist

List of extensions.

model_matches_pane(pane_: PID, model_: MT) bool[source]

Check if a model is displayable in a specified pane.

Currently always returns True.

Parameters:
pane_Pane

The pane to test against.

model_Model

The model to test.

Returns:
bool

True if model can be added to pane_

models_per_pane() List[int][source]

Retrieve the number of models in each pane.

Returns:
countlist of int

The number of models in each existing pane.

pane_count() int[source]

Retrieve the number of panes.

Returns:
int

The pane count.

pane_details() Dict[str, Dict[str, Any]][source]

Compile summaries of all panes in the figure.

Returns:
dict

Keys are ‘pane_{i}’, where i is the pane index. Values are the model summary dicts for the pane.

pane_layout() None | Tuple[int, int][source]

Retrieve the current pane layout.

Returns:
geometrytuple of int, or None

If there is an active layout, (nrow, ncol) is returned. Otherwise, None.

parse_pane_flag(flags: List | Dict | List[int | PID] | None) Tuple[List[PT], str][source]

Parse the specified panes from an input flag.

Parameters:
flagsstr, None, list of int, or list of Panes

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of ints or Pane objects.

Returns:
panes, axislist, str

List of panes corresponding to input flag and corresponding axis

populated() bool[source]

Check for pane existence.

Returns:
bool

True if any panes exist, else False.

record_cursor_location(event: MouseEvent) None[source]

Store the current cursor location.

Depending on the current user interaction in zoom or fit mode, either a guide is displayed at the location (first click), or all guides are cleared and the stored cursor locations are passed to the end_cursor_records method (second click).

Parameters:
eventmatplotlib.backend_bases.MouseEvent

Mouse motion event.

refresh(bg_full: bool, bg_partial: bool) None[source]

Refresh the figure canvas.

Parameters:
bg_fullbool

If True, the full background will be redrawn, including the plot axes.

bg_partialbool

If True and bg_full is False, the background will be redrawn, but the axes will remain the same.

remove_all_panes() None[source]

Remove all panes.

remove_artists() None[source]

Remove all artists.

remove_model_from_pane(filename: str | None = None, model_id: IDT | None = None, model_: MT | None = None, panes: PT | List[PT] | None = None) None[source]

Remove a model from one or more panes.

The model to remove can be specified by either its filename or the model itself.

Parameters:
filenamestr, optional

Name of the file to remove

model_iduuid.UUID

Unique Id associated with an HDUL

model_sofia_redux.visualization.spectrum.model.Model, optional

Model object to remove

panessofia_redux.visualization.spectrum.panes.Pane, optional

A list of pane objects to remove the model from. If not provided, the model will be removed from all panes.

Raises:
RuntimeError

If neither filename nor model are provided.

remove_pane(pane_id: List[int] | None = None) None[source]

Remove a specified pane.

Parameters:
pane_idlist of int

List of pane indices to remove.

reset_artists() None[source]

Recreate all artists from models.

reset_data_points() None[source]

Reset any displayed cursor markers.

reset_zoom(all_panes: bool | None = False, targets: Dict | None = None) None[source]

Reset axis limits to defaults.

Parameters:
all_panesbool, optional

If True, all axes will be reset. Otherwise, only the current pane will be reset.

targetsdict, optional

Specific panes to reset, specified as a list of int under the ‘pane’ key in the input dictionary.

save(filename: str, **kwargs) None[source]

Save the current figure to a file.

Parameters:
filenamestr

Full file path to save the image to.

kwargsdict, optional

Additional keyword arguments to pass to matplotlib.figure.Figure.savefig.

set_all_enabled(pane_id: int, state: bool) None[source]

Enable or disable all models in a pane.

Parameters:
pane_idint

Pane ID to update.

statebool

If True, models will be enabled (shown). If False, models will be disabled (hidden).

set_block_current_pane_signal(value: bool = True) None[source]

Set the flag to block the current_pane signal.

Parameters:
valuebool, optional

True to block the current_pane signal; False to allow it to propagate.

set_color_cycle(cycle_name: str) None[source]

Set the color cycle in all panes.

Parameters:
cycle_name: [‘spectral’, ‘tableau’, ‘accessible’]

Color cycle to set.

set_cursor_mode(mode: str) None[source]

Set the cursor mode.

Cursor modes are used to manage zoom and feature fit interactions.

Parameters:
mode[‘x_zoom’, ‘y_zoom’, ‘b_zoom’, ‘fit’, ‘’]

The mode to set.

set_dark_mode(state: bool = True) None[source]

Set a dark background in all panes.

Parameters:
state: bool, optional

If True, dark mode will be enabled. If False, it will be disabled.

set_enabled(pane_id: int, model_id: str, state: bool) None[source]

Enable or disable a specified model.

Parameters:
pane_idint

Pane ID to update.

model_idstr

Model ID to modify.

statebool

If True, model will be enabled (shown). If False, model will be disabled (hidden).

set_error(state: bool = True) None[source]

Set the error range visibility in all panes.

Parameters:
state: bool, optional

If True, error ranges will be shown. If False, they will be hidden.

set_grid(state: bool = True) None[source]

Set the grid visibility in all panes.

Parameters:
state: bool, optional

If True, gridlines will be shown. If False, they will be hidden.

set_layout_style(value: str = 'grid') None[source]

Set the layout style.

Parameters:
value[‘grid’, ‘rows’, ‘columns’], optional

The layout to set.

set_markers(state: bool = True) None[source]

Set the marker visibility in all panes.

Parameters:
state: bool, optional

If True, markers will be shown. If False, they will be hidden.

set_orders(orders: Dict[int, Dict[IDT, List[int]]], enable: bool | None = True, aperture: bool | None = False) None[source]

Enable specified orders.

Parameters:
ordersdict

Keys are indices for the panes to update. Values are dicts, with model ID keys, order list values.

enablebool, optional

If set enable the orders, otherwise disable orders. Defaults to True.

aperturebool, optional

If set the order numbers in orders are actually aperture numbers. Defaults to False.

set_overplot_state(state: bool, target: Any | None = None) None[source]

Set the pane overplot flag.

Parameters:
statebool

True to show overplot; False to hide

targetstr, None, or list of int

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of pane indices to modify.

set_pane_highlight_flag(state: bool) None[source]

Set the visibility for a pane highlight border.

Parameters:
statebool

True to show; False to hide.

set_plot_type(plot_type: str) None[source]

Set the plot type in all panes.

Parameters:
plot_type: [‘line’, ‘step’, ‘scatter’]

Plot type to set.

set_scales(scales: Dict[str, str], target: Any | None = None) None[source]

Set the axis scale for specified panes.

Parameters:
scalesdict

Keys are ‘x’, ‘y’. Values are ‘linear’ or ‘log’.

targetstr, None, list of int, or list of Pane objects

May be set to ‘all’ to apply to all panes, None to apply only to the current pane, or a list of ints or Pane objects.

stale_fit_artists(fits: List[ModelFit])[source]

Recreate fit artists for a list of model fits.

Removes all Drawing instances for fits on a given pane and makes them anew. It accommodates any changes (unit, scale, etc) that doesn’t change the data at all but does invalidate the current artists (which are now marked “stale”).

Parameters:
fitslist of ModelFit

Models fit to spectral selections.

toggle_fits_visibility(fits: List[ModelFit]) None[source]

Update fit artist visibility.

If failure, loop over panes. Ask each one to make new drawing for fit. If model, order, fields don’t match, pane does nothing. Else remake fit drawing and return them. Then add new drawing to Gallery.

Parameters:
fitslist of ModelFit

Models fit to spectral selections.

unload_reference_model(models)[source]

Unload the reference model.

update_reference_lines(models: RT)[source]

Remove and replot reference lines.

Parameters:
modelsreference_model.ReferenceData

reference_model.ReferenceData objects for the reference lines.

static valid_pane(index: Any, pane_count: int) bool[source]

Check if a pane index is valid.

Parameters:
indexint

Index of a pane

pane_countint

Total number of panes

Returns:
bool

If the index is an int and less than pane_count, returns True otherwise False.