ModelFit¶
- class sofia_redux.visualization.utils.model_fit.ModelFit(params=None)[source]¶
Bases:
object
Hold parameters and descriptions of generic model fits.
- Parameters:
- paramsdict, optional
A nested dictionary that describes a single fit to data. The top level key is the
model_id
and the corresponding value is a dictionary whose only key is theorder
. The values of the inner dictionary are the actual parameters of the fit. If not provided, an empty instance ofModelFit
with default values is returned.
- Attributes:
- id_tagstr
Represents the model fit ID number.
- model_iduuid.UUID
The name of the data model the fit was made to. Typically, the name of a FITS file.
- filenamestr
Name of the file
- featurestr
Name of the model used to fit the feature.
- background: str
Name of the model used to fit the background. Typical examples are ‘constant’ or ‘linear’.
- fit_typelist
Strings describing the base model fit to the data. Typical values include ‘gauss’, ‘moffat’, ‘const’, ‘linear’. Often composite models are fit to data, in which case all valid descriptions are included. The fit_type is used to define the parameter names to include.
- orderint
Order number of the
model_id
data set that the model was fit to.- apertureint
Aperture number of the
model_id
data set that the model was fit to.- statusstr
Status of the last attempted fit. May be ‘pass’ or ‘fail’.
- fitam.Model
The actual fit to the data.
- axis_nameslist
Names for the fit axes, used as keys for several other attributes.
- unitsdict
Name of the units used for each axis.
- limitsdict
The upper and lower selection bounds of the data fit.
- fieldsdict
Field names for each axis.
- datasetdict
Data arrays for each axis.
- axisma.Axes
The axes object the fit has been plotted on.
- visiblebool
Flag to indicate visibility of the fit plot.
- columnsarray-like
Column values corresponding to the x-axis data.
- colorstr
Color hex value for the fit plot.
- param_namesdict
Names of the parameters for each type of fitted model.
Attributes Summary
int : ID iteration value.
Methods Summary
Get the aperture number.
get_axis
()Get the fitting axis.
Get the background name for the model fitting
Determine the baseline of the feature.
Get the plot color for the fit artist.
Get the columns array.
Get the data set to fit to.
Get the feature name for the model fitting.
get_fields
([axis])Retrieve field names for a given axis.
Get the filename.
get_fit
()Obtain a copy of a fit.
Get the fit type.
get_fwhm
()Determine the FWHM of the feature.
get_id
()Get the ID for the current fit model.
get_limits
([limit])Obtain the limit values.
Determine the midpoint of the feature.
Determine the midpoint of the feature in column number.
Get the model ID.
Get the order number.
Get the last fit status.
get_units
([key])Obtain the units.
Get the visibility of the fitting model.
load_parameters
(parameters)Parse model fit parameters.
Fit parameters in dictionary form for returning to the View.
Format all fitting details as HTML for display in text view.
Fit parameters in a list structure for writing to disk.
Format all fitting details as strings for display in table.
scale_parameters
(x_scale, y_scale)Scale parameters after a fit.
set_aperture
(aperture)Set an aperture number.
set_axis
(axis)Set the fitting axis.
set_background
(background)Set the background name for the model fitting.
set_color
(color)Set the plot color for the fit artist.
set_columns
(columns)Set column data.
set_dataset
([dataset, x, y])Set a data set to fit to.
set_feature
(feature)Set the feature name for the model fitting.
set_fields
(fields)Set field names.
set_filename
(filename)Set the filename.
set_fit
(fit)Set the fitting model to a given fit.
set_fit_type
([fit_type, feature, background])Set the type of fit used.
set_limits
(limits[, key])Set the limit values.
set_model_id
(model_id)Set a model ID.
set_order
(order)Set an order number.
set_status
(status)Set the last fit status.
set_units
(units)Set the units of the fitting model
set_visibility
(state)Set the visibility of a fit.
Attributes Documentation
- id_iter = count(0)¶
int : ID iteration value.
Methods Documentation
- get_background() str [source]¶
Get the background name for the model fitting
- Returns:
- background: str
Name of the model used to fit the background. Typical examples are ‘constant’ or ‘linear’.
- get_baseline() float [source]¶
Determine the baseline of the feature.
- Returns:
- baselinefloat
Baseline of the feature of the fit. If not found, return NaN.
- get_dataset() Dict[str, Iterable | None] [source]¶
Get the data set to fit to.
- Returns:
- dict
Keys are axis names, values are data arrays.
- get_feature() str [source]¶
Get the feature name for the model fitting.
- Returns:
- featurestr
Name of the model used to fit the feature.
- get_fields(axis: str | None = None) str | Dict[str, str] | None [source]¶
Retrieve field names for a given axis.
- Parameters:
- axisstr, optional
Names of the axes to be used as keys for fields.
- Returns:
- fieldsstr or dict
If an axis has been provided, the corresponding value is returned. Otherwise, a dictionary containing all values is returned.
- get_fit()[source]¶
Obtain a copy of a fit.
- Returns:
- fitastropy.modeling.Model
A simple, non-compound, astropy model. Returns None if there is no fitting model.
- get_fit_types() List[str] [source]¶
Get the fit type.
- Returns:
- list of str
Fit types as [feature, background].
- get_fwhm() float [source]¶
Determine the FWHM of the feature.
- Returns:
- fwhmfloat
FWHM of the feature of the fit. If not found, return NaN.
- get_limits(limit: str | None = None) float | Dict[str, float | None] | None [source]¶
Obtain the limit values.
- Parameters:
- limitstr, optional
May be ‘upper’ or ‘lower’.
- Returns:
- float or dict
If a valid limit name is specified, only that value is returned. If an invalid limit is specified, None is returned. Otherwise, the limits dictionary is returned.
- get_mid_point() float [source]¶
Determine the midpoint of the feature.
- Returns:
- mid_pointfloat
Midpoint of the feature of the fit. If not found, return NaN.
- get_mid_point_column() float [source]¶
Determine the midpoint of the feature in column number.
- Returns:
- mid_pointfloat
Midpoint of the feature of the fit in pixels. If not found, return NaN.
- get_units(key: str | None = None) str | Dict[str, str] | None [source]¶
Obtain the units.
- Parameters:
- keystr, optional
Obtain the unit for a given key (axis).
- Returns:
- unitsstr or Dict
A str if valid key is provided. For an invalid key it returns None. If no key is provided, it returns a dict.
- get_visibility() bool [source]¶
Get the visibility of the fitting model.
- Returns:
- visiblebool
True, if the fitting is going to visible otherwise False.
- load_parameters(parameters: Dict[str, Dict]) None [source]¶
Parse model fit parameters.
- Parameters:
- parametersdict
A nested dictionary that describes a single fit to data. The top level key is the
model_id
and the corresponding value is a dictionary whose only key is theorder
. The values of the inner dictionary are the actual parameters of the fit. If not provided, an empty instance ofModelFit
with default values is returned.
- parameters_as_dict() Dict[str, Any] [source]¶
Fit parameters in dictionary form for returning to the View.
- Returns:
- paramdict
Keys are the names of each parameter and values are the corresponding values.
- parameters_as_html() Dict[str, str] [source]¶
Format all fitting details as HTML for display in text view.
- Returns:
- paramdict
Dictionary with parameter names for keys and string formatted parameter values for values.
- parameters_as_list() List[Any] [source]¶
Fit parameters in a list structure for writing to disk.
- Returns:
- paramslist
List of all fit parameter values. Parameter names are not included.
- parameters_as_string() Dict[str, str] [source]¶
Format all fitting details as strings for display in table.
- Returns:
- paramdict
Dictionary with parameter names for keys and string formatted parameter values for values.
- scale_parameters(x_scale: float, y_scale: float) None [source]¶
Scale parameters after a fit.
This is used to restore a baseline scale, after fitting to normalized data.
- Parameters:
- x_scalefloat
Value to scale the x data.
- y_scalefloat
Value to scale the y data
- set_aperture(aperture: int) None [source]¶
Set an aperture number.
- Parameters:
- apertureint
The aperture number to set.
- set_axis(axis: Axis) None [source]¶
Set the fitting axis.
- Parameters:
- axismatplotlib.Axes
Assign the fitting axis
- set_background(background: str) None [source]¶
Set the background name for the model fitting.
- Parameters:
- background: str
Name of the model used to fit the background. Typical examples are ‘constant’ or ‘linear’.
- set_color(color: str) None [source]¶
Set the plot color for the fit artist.
- Parameters:
- colorstr
The color hex value to set.
- set_columns(columns: ArrayLike) None [source]¶
Set column data.
- Parameters:
- columnsarray-like
The column data to set.
- set_dataset(dataset: Dict[str, Iterable] | None = None, x: Iterable | None = None, y: Iterable | None = None) None [source]¶
Set a data set to fit to.
- Parameters:
- datasetdict, optional
If provided, must have axis names for keys and data arrays for values.
- xarray-like, optional
Directly specifies the x-axis data values.
- yarray-like, optional
Directly specifies the y-axis data values.
- Raises:
- EyeError
If all expected axes are not provided.
- set_feature(feature: str) None [source]¶
Set the feature name for the model fitting.
- Parameters:
- featurestr
Name of the model used to fit the feature.
- set_fields(fields: Dict[str, str]) None [source]¶
Set field names.
- Parameters:
- fieldsdict
Keys are axis names; values are field names.
- set_filename(filename: str) None [source]¶
Set the filename.
- Parameters:
- filenamestr
Filename to set.
- set_fit(fit) None [source]¶
Set the fitting model to a given fit.
- Parameters:
- fitastropy.modeling.Model
A simple, non-compound, astropy model.
- set_fit_type(fit_type: str | List[str] | None = None, feature: str | None = None, background: str | None = None)[source]¶
Set the type of fit used.
- Parameters:
- fit_typelist, optional
If given,
self.fits
will be set to it directly. If not given, the fit type will be parsed fromfeature
andbackground
.- featurestr, optional
Name of the model used to fit the feature. Typical examples are ‘gaussian’ or ‘moffat’.
- backgroundstr, optional
Name of the model used to fit the background. Typical examples are ‘constant’ or ‘linear’.
- Raises:
- EyeError
If no arguments are given.
- set_limits(limits: float | Dict[str, float] | List[List[float]], key: str | None = None) None [source]¶
Set the limit values.
- Parameters:
- limitsfloat, dict, or list of list
If key is provided, should be specified as a float. Otherwise, should contain both lower and upper limits. If provided as a list, it is assumed the lower limit is the first element in the first list and the upper limit is the second element in the first list.
- keystr, optional
May be ‘upper’ or ‘lower’.
- set_model_id(model_id: UUID) None [source]¶
Set a model ID.
- Parameters:
- model_iduuid.UUID
Unique model ID to set.