OneDimPane

class sofia_redux.visualization.display.pane.OneDimPane(signals: Signals, ax: Axes | None = None)[source]

Bases: Pane

Single axis pane, for one-dimensional plots.

This class is primarily intended to support spectral flux plots, but may be used for any one-dimensional line or scatter plot.

Parameters:
axmatplotlib.axes.Axes, optional

Plot axes to display in the pane.

Attributes:
ordersdict

Enabled spectral orders.

plot_kindstr

Kind of plot displayed (e.g. ‘spectrum’).

fieldsdict

Keys are axis names; values are currently displayed fields.

unitsdict

Keys are axis names; values are currently displayed units.

scaledict

Keys are axis names; values are currently displayed plot scales.

limitsdict

Keys are axis names; values are currently displayed plot limits.

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

The currently displayed plot line type.

show_markersbool

Flag for marker visibility.

show_gridbool

Flag for grid visibility.

show_errorbool

Flag for error range visibility.

colorsdict

Current plot colors. Keys are model IDs; values are color hex values.

markersdict

Current plot markers. Keys are model IDs; values are marker symbol names.

ref_color: str

Color value used for all reference line overlays.

guide_line_styledict

Style parameters for guide line overlays.

data_changedbool

Flag to indicate that data has changed recently.

signalssofia_redux.visualization.signals.Signals

Custom signals, used to pass information to the controlling Figure.

Methods Summary

add_model(model)

Add a model to the pane.

apply_configuration()

Update limits, scales, and labels for the plot.

calculate_fit(x_data, y_data, fit, bounds)

Calculate the fit to a dataset.

contains_model(model_id[, order])

Check if a specified model exists in the pane.

create_artists_from_current_models()

Create new artists from all current models.

current_units()

Determine the current units for the current fields.

data_at_cursor(event)

Retrieve the model data at the cursor location.

feature_fit(feature, background, limits)

Fit a spectral feature.

generate_fit_artists(model_fits[, x_data])

Generate fit artists for a pane

get_axis_limits([axis])

Get the current axis limits.

get_axis_scale()

Get the axis scale setting.

get_color(model_id)

Return colors for a model.

get_field([axis])

Get the currently displayed field.

get_marker(model_id)

Get the plot markers for a given model_id.

get_orders([enabled_only, by_model, ...])

Get the orders available for the models in this pane.

get_scale([axis])

Get the currently displayed scale.

get_unit([axis])

Get the currently displayed unit.

get_unit_string(axis)

Get the current unit string for the plot label.

get_xy_data(model, order, aperture)

Get copies of the low model data for x and y axes.

initialize_models(feature, background, ...)

Initialize fitting models.

model_summaries()

Summarize the models contained in this pane.

perform_fit(kind, limits)

Perform a fit to a plot feature.

perform_zoom(zoom_points, direction)

Perform a zoom action.

plot_crosshair([cursor_pos])

Create crosshair artists to show the cursor location.

plot_fit(x, style[, fit_obj, fit, model_id, ...])

Create overlay artists representing a fit to a plot feature.

plot_guides(cursor_pos, kind)

Create guide gallery.

possible_units()

Determine the possible units for the current fields.

remove_model([filename, model_id, model])

Remove a model from the pane.

reset_alt_axes([remove])

Remove or reset the alternate axis.

reset_zoom()

Reset plot limits to the full range for current data.

set_all_models_enabled(state)

Mark all model as enabled (visible) or disabled (hidden).

set_default_units_for_fields()

Set default unit values for current fields.

set_error(state)

Set the plot error range visibility.

set_fields(fields)

Set the plot fields.

set_grid(state)

Set the plot grid visibility.

set_legend()

Set a legend for the plot.

set_limits(limits)

Set the plot limits.

set_markers(state)

Set plot marker symbols.

set_model_enabled(model_id, state)

Mark a model as enabled (visible) or disabled (hidden).

set_orders(orders[, enable, aperture, ...])

Enable specified orders.

set_overplot(state)

Enable/disable overplot, dependent axes, field, and limits.

set_plot_type(plot_type)

Set the plot line type.

set_scales(scales)

Set the plot scale.

set_units(units, axes)

Set the plot units.

unload_ref_model()

Unload the reference data.

update_colors()

Update plot colors for current loaded data.

update_model(models)

Update a pre-existing model with a copy of the original model.

update_reference_data([reference_models, plot])

Update the reference data.

update_visibility([error])

Update plot visibility for current loaded data.

xy_at_cursor(event)

Retrieve the x and y data at the cursor location.

Methods Documentation

add_model(model: MT) List[DT][source]

Add a model to the pane.

The model is copied before adding so the data can be manipulated without changing the root model.

If the model already exists in the pane, no action is taken.

Parameters:
modelhigh_model.HighModel

Model object to add.

Returns:
new_lineslist

Keys are model IDs; values are dicts with order number keys and dict values, containing new artists added to the Pane axes.

apply_configuration() None[source]

Update limits, scales, and labels for the plot.

static calculate_fit(x_data, y_data, fit, bounds)[source]

Calculate the fit to a dataset.

Parameters:
x_datanp.ndarray

x-axis data

y_datanp.ndarray

y-axis data

fitastropy.modeling.Model

Initial fitted model.

boundstuple[list,list]

List of allowed upper bounds and lowers bounds to the fitting parameters. Empty when feature is not available but [-np.inf,np.inf] for just the background.

Returns:
fitastropy.modeling.Model

The fit model.

contains_model(model_id: str, order: int | None = None) bool[source]

Check if a specified model exists in the pane.

Parameters:
model_idstr

Model to be inspected.

orderint, optional

Order number to match. If provided, the order’s presence in the pane is verified. If not, only the model’s presence is verified.

Returns:
bool

True if the model/order are present; False otherwise.

create_artists_from_current_models() List[DT][source]

Create new artists from all current models.

Returns:
new_artistslist

A list of reference_model.ReferenceData objects associated with the current model.

current_units() Dict[str, str][source]

Determine the current units for the current fields.

Returns:
unitsdict

Keys are axis names; values are unit names.

data_at_cursor(event: MouseEvent) Dict[str, List[Dict]][source]

Retrieve the model data at the cursor location.

Parameters:
eventmatplotlib.backend_bases.Event

Mouse motion event.

Returns:
data_coordsdict

Keys are model IDs; values are lists of dicts containing ‘order’, ‘bin’, ‘bin_x’, ‘bin_y’, ‘x_field’, ‘y_field’, ‘color’, and ‘visible’ values to display.

feature_fit(feature: str, background: str, limits: Sequence[Sequence[Num]]) Tuple[Dict, Dict][source]

Fit a spectral feature.

Parameters:
feature{‘moffat’, ‘gaussian’, ‘gauss’}

Feature model to fit.

background{‘linear’, ‘constant’}

Baseline model to fit (Const1D or Linear1D).

limitslist of list

Low and high limits for data to fit, as [[low_x, low_y], [high_x, high_y]]. Currently only the x values are used.

Returns:
fit_artists, fit_paramsTuple[list, list]

fit_artists - a list of drawing.Drawing objects for fits fit_params - a list of fitting parameters objects for fits

generate_fit_artists(model_fits: ModelFit | List[ModelFit], x_data: ArrayLike | None = None) List[DT][source]

Generate fit artists for a pane

Parameters:
model_fitsmodel_fit.ModelFit or list of model_fit.ModelFit

Models to plot.

x_dataarray-like, optional

Data to plot fit y-values on. If not provided, data is retrieved from the low model.

get_axis_limits(axis: str | None = None) Dict[str, List[Num]] | List[Num][source]

Get the current axis limits.

Parameters:
axisstr, optional

The axis name to retrieve limits from. If not provided, both axis limits for the axes are returned.

Returns:
limitslist or dict

If axis is specified, only the limits for that axis are returned. Otherwise, a dictionary with axis name keys and limit values is returned. Limit values are [low, high].

get_axis_scale() Dict[str, str][source]

Get the axis scale setting.

Returns:
scaledict

Keys are axis names; values are ‘log’ or ‘linear’.

get_color(model_id)[source]

Return colors for a model.

Parameters:
model_iduuid.UUID

Unique id of HDUL

Returns:
colorslist

List of colors

get_field(axis: str | None = None) Dict[str, str] | str[source]

Get the currently displayed field.

Parameters:
axisstr, optional

If provided, retrieves the field only for the specified axis.

Returns:
fieldstr or dict

If axis is specified, only the field name for that axis is returned. Otherwise, a dictionary with axis name keys and field name values is returned.

get_marker(model_id: List[IDT] | IDT) List[str][source]

Get the plot markers for a given model_id.

Parameters:
model_iduuid.UUID or list of uuid.UUID

Unique id associated with an HDUL

Returns:
markerslist

A list of markers for the model_id

get_orders(enabled_only: bool = False, by_model: bool = False, target_model: MT | None = None, filename: str | None = None, model_id: IDT | None = None, kind: str | None = 'order') Dict[str, List] | List[source]

Get the orders available for the models in this pane.

Parameters:
enabled_onlybool, optional

If set, only return the enabled orders. Otherwise, return all orders. Default is False.

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.

target_modelhigh_model.HighModel, optional

Target model

filenamestr, optional

Name of file

model_iduuid.UUID, optional

Unique UUID for an HDUL.

kindstr, optional

If ‘aperture’, only apertures are returned. If ‘order’, only orders are returned. Otherwise, both are returned.

Returns:
orderslist, dict

Format and details depend on arguments.

get_scale(axis: str | None = None) str | Dict[str, str][source]

Get the currently displayed scale.

Parameters:
axisstr, optional

If provided, retrieves the scale only for the specified axis.

Returns:
scalestr or dict

If axis is specified, only the scale name for that axis is returned. Otherwise, a dictionary with axis name keys and scale name values is returned.

get_unit(axis: str | None = None) str | Dict[str, str][source]

Get the currently displayed unit.

Parameters:
axisstr, optional

If provided, retrieves the unit only for the specified axis.

Returns:
unitstr or dict

If axis is specified, only the unit name for that axis is returned. Otherwise, a dictionary with axis name keys and unit name values is returned.

get_unit_string(axis: str) str[source]

Get the current unit string for the plot label.

Parameters:
axisstr

The axis name to retrieve units from.

Returns:
unit_namestr

The unit label.

get_xy_data(model, order, aperture)[source]

Get copies of the low model data for x and y axes.

Parameters:
modelhigh_model.HighModel

The model to be copied.

orderint

The spectral order to retrieve.

apertureint

The aperture to retrieve.

Returns:
x_modelmodels.high_model.Grism

A copy of model along the x-axis

y_modelmodels.high_model.Grism

A copy of model along the y-axis

initialize_models(feature, background, x_data, y_data, limits)[source]

Initialize fitting models.

Parameters:
feature{‘moffat’, ‘gaussian’, ‘gauss’}

Feature model to fit.

background{‘linear’, ‘constant’}

Baseline model to fit (Const1D or Linear1D).

x_datanp.ndarray

x-axis data

y_datanp.ndarray

y-axis data

limitslist of lists

Low and high limits for data to fit, as [[low_x, low_y], [high_x, high_y]]. Currently only the x values are used.

Returns:
xvalnp.nparray

X-array within the given limits.

yvalnp.nparray

Y-array within the given limits.

fit_initastropy.modeling.Model

The combined fit to the data and background.

boundstuple[list,list]

List of allowed upper bounds and lowers bounds to the fitting parameters. Empty when feature is not available but [-np.inf,np.inf] for just the background.

model_summaries() Dict[str, Dict[str, str | bool]][source]

Summarize the models contained in this pane.

Returns:
detailsdict

Keys and value types are ‘filename’: str, ‘extension’: str, ‘model_id’: str, ‘enabled’: bool, ‘color’: str, ‘marker’: str.

perform_fit(kind: str, limits: Sequence[Sequence[Num]]) Tuple[Dict | None, Dict | None][source]

Perform a fit to a plot feature.

Parameters:
kindstr

Kind is formatted as ‘fit_{feature model}_{baseline mode}’ Current features available are Gaussian1D and Moffat1D. Current baselines available are Const1D and Linear1D. If a baseline or feature is not desired, the corresponding field is set to ‘none’.

limitslist of list

Low and high limits for data to fit, as [[low_x, low_y], [high_x, high_y]]. Currently only the x values are used.

Returns:
fit_artists, fit_paramsdict, dict

The fit_artists dict contains overlay gallery showing the center line and model shape for the fit to data. Keys are {model.id}_fit_line and {model.id}_fit_center. The fit_params dict contains the fit parameters, for display in a separate table widget. Keys are model IDs.

perform_zoom(zoom_points: Sequence[Sequence[Num]], direction: str) Dict[str, List[float]][source]

Perform a zoom action.

Parameters:
zoom_pointslist

User selected cursor positions, defining the zoom limits.

direction[‘x’, ‘y’, ‘b’]

Direction of the zoom.

Returns:
limitsdict

Keys are axis names (‘x’ and ‘y’); values are the new axis limits.

plot_crosshair(cursor_pos: Tuple | List | None = None) List[DT][source]

Create crosshair artists to show the cursor location.

Parameters:
cursor_postuple or list, optional

Current cursor position [x, y]. If not specified, the cursor is initially set near the center of the plot.

Returns:
crosshairlist

Two element list containing the vertical and horizontal crosshair drawings.

plot_fit(x: ArrayLike, style: str, fit_obj: ModelFit | None = None, fit: Model | None = None, model_id: str | None = '', order: int | None = 0, aperture: int | None = 0, feature: str | None = '') Tuple[Line2D, Line2D][source]

Create overlay artists representing a fit to a plot feature.

Overlay colors are grayscale representations of the displayed model colors.

Parameters:
xarray-like

Independent coordinates for the fit overlay.

stylestr

Line style for the overlay.

fit_objmodel_fit.ModelFit, optional

If provided, fit, model, orderm aperture, and feature are retrieved from the provided object instead of the input parameters.

fitastropy.modeling.Model, optional

The callable model, fit to the data.

model_idstr, optional

Model ID associated with the fit.

orderint, optional

Order number associated with the fit.

apertureint, optional

Aperture associated with the fit.

featurestr, optional

Feature type for the fit.

Returns:
model, centroidtuple of Line2D

The model artist, plotted over the input x data, and a vertical line artist representing the centroid position.

plot_guides(cursor_pos: Tuple | List, kind: str) List[DT][source]

Create guide gallery.

Guides are lines that stretch the full width or height of the axes, depending on the direction. They are used to denote the edges of ranges of interest, such as new zoom limits or the limits for data to fit a curve to.

Parameters:
cursor_postuple or list

Current cursor position [x, y].

kind[‘horizontal’, ‘vertical’, ‘cross’, ‘x’, ‘y’, ‘b’]

For ‘horizontal’, ‘y’, ‘cross’, or ‘b’, a horizontal guide will be created. For ‘vertical’, ‘x’, ‘cross’, or ‘b’, a vertical guide will be created.

Returns:
guideslist

Guide drawings corresponding to plotted lines.

possible_units() Dict[str, List[str]][source]

Determine the possible units for the current fields.

Returns:
unitsdict

Keys are axis names; values are lists of unit names.

remove_model(filename: str | None = None, model_id: IDT | None = None, model: MT | None = None) None[source]

Remove a model from the pane.

The model can be specified by either its filename or the model directly.

Parameters:
filenamestr, optional

Name of the file corresponding to the model to remove.

model_idstr, optional

Specific id to a model object (high_model.HighModel).

modelhigh_model.HighModel, optional

Model object to remove.

reset_alt_axes(remove=False)[source]

Remove or reset the alternate axis.

Replaces the ax_alt attribute with None and resets fields, scale, and limit for the ‘y_alt’ axis to empty values.

Parameters:
removebool, optional

If set, an attempt is made to remove the alternate axis from the plot before resetting it.

reset_zoom() None[source]

Reset plot limits to the full range for current data.

set_all_models_enabled(state: bool) None[source]

Mark all model as enabled (visible) or disabled (hidden).

Parameters:
statebool

If True, enable all models. If False, disable all models.

set_default_units_for_fields() None[source]

Set default unit values for current fields.

set_error(state: bool) None[source]

Set the plot error range visibility.

Parameters:
statebool

True for enabling error-bars, otherwise False.

set_fields(fields: Dict[str, str]) None[source]

Set the plot fields.

Parameters:
fieldsdict

Keys are axis names; values are fields to set.

set_grid(state: bool) None[source]

Set the plot grid visibility.

Parameters:
statebool

True for enabling grid, otherwise False.

set_legend()[source]

Set a legend for the plot.

Not yet implemented.

set_limits(limits: Dict[str, Sequence[Num]]) None[source]

Set the plot limits.

Parameters:
limitsdict

Keys are axis names; values are limits to set.

set_markers(state: bool) List[DT][source]

Set plot marker symbols.

Only applies to non-scatter plots. Scatter plots will accept the new state but not update any artists.

Parameters:
statebool

Defines the visibility of the makers. True will make the markers visible, False will hide the markers.

Returns:
updateslist

List of drawings describing the changes for each model.

set_model_enabled(model_id: str, state: bool) None[source]

Mark a model as enabled (visible) or disabled (hidden).

Parameters:
model_idstr

The ID for the model to enable.

statebool

If True, enable the model. If False, disable the model.

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

Enable specified orders.

Parameters:
ordersdict

Keys are model IDs; values are lists of orders to enable.

enablebool, optional

Set to True to enable; False to disable.

aperturebool, optional

True if apertures are present; False otherwise.

return_updatesbool, optional

If set, an update structure is returned.

Returns:
updateslist, optional

Order visibility updates applied.

set_overplot(state: bool) None[source]

Enable/disable overplot, dependent axes, field, and limits.

Parameters:
statebool

A boolean which is assigned to the state of show_overplot.

set_plot_type(plot_type: str) List[DT][source]

Set the plot line type.

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

The plot type to set.

Returns:
updateslist

A list of dictionaries that each describe the change to a single model.

set_scales(scales: Dict[str, str]) None[source]

Set the plot scale.

Parameters:
scalesdict

Keys are axis names; values are scales to set (‘log’ or ‘linear’).

set_units(units: Dict[str, str], axes: str) List[DT][source]

Set the plot units.

Parameters:
unitsdict

Keys are axis names; values are units to set.

axes: ‘primary’, ‘alt’, ‘both’, ‘all’

Which Axes object to pull data from.

Returns:
updateslist

A list of all artists for plotting the changes in units. May not return anything when unable to convert units.

unload_ref_model()[source]

Unload the reference data.

update_colors() List[DT][source]

Update plot colors for current loaded data.

Returns:
updateslist of drawing.Drawing

Drawing objects containing all color updates.

update_model(models: MT)[source]

Update a pre-existing model with a copy of the original model.

The model is copied so that the data can be manipulated without changing the root model.

Parameters:
modelshigh_model.HighModel

Model object to add.

update_reference_data(reference_models: RT | None = None, plot: bool | None = True) List[DT | Dict] | None[source]

Update the reference data.

Parameters:
reference_modelsreference_model.ReferenceData, optional

Reference models to update.

plotbool

If set, reference data is (re)plotted. Otherwise, current reference options are returned.

Returns:
reference_artistslist

A list of drawing.Drawing objects when plot is True. A list of dictionaries when plot is False. If the inputs are invalid then None is returned.

update_visibility(error: Optional = False) List[DT][source]

Update plot visibility for current loaded data.

Parameters:
errorbool, optional

If set, visibility update is applied to error range plots only.

Returns:
updateslist of drawing.Drawing

Drawing objects containing all visibility updates.

xy_at_cursor(event: MouseEvent) Tuple[float, float][source]

Retrieve the x and y data at the cursor location.

Ignores the secondary y-axis, if present.

Parameters:
eventmatplotlib.backend_bases.Event

Mouse motion event.

Returns:
data_coordstuple of float

(x, y) values for the primary axis.