ModelFitting#
- class jdaviz.configs.default.plugins.model_fitting.model_fitting.ModelFitting(*args, **kwargs)[source]#
Bases:
PluginTemplateMixin,DatasetSelectMixin,SpectralSubsetSelectMixin,DatasetSpectralSubsetValidMixin,NonFiniteUncertaintyMismatchMixin,AddResultsMixin,TableMixinSee the Model Fitting Plugin Documentation for more details.
Only the following attributes and methods are available through the public plugin API:
cube_fitOnly exposed for Cubeviz. Whether to fit the model to the cube instead of to the collapsed spectrum.dataset(DatasetSelect): Dataset to fit the model.spectral_subset(SubsetSelect)model_component(SelectPluginComponent)poly_ordermodel_component_label(AutoTextField)equation(AutoTextField)add_results(AddResults)residuals_calculate(bool) Whether to calculate and expose the residuals (model minus data).residuals(AutoTextField) Label of the residuals to apply when callingcalculate_fit()ifresiduals_calculateisTrue.
Public constructor
Attributes Summary
A trait for unicode strings.
A boolean (True, False) trait.
A trait for unicode strings.
A trait for unicode strings.
An instance of a Python list.
A boolean (True, False) trait.
A boolean (True, False) trait.
A boolean (True, False) trait.
A boolean (True, False) trait.
List of the labels of model components in the current equation
Dictionary of all previously fitted models.
A trait which allows any value.
An instance of a Python list.
An instance of a Python dict.
A trait for unicode strings.
A boolean (True, False) trait.
An instance of a Python list.
A trait for unicode strings.
List of the labels of existing model components
A trait for unicode strings.
A boolean (True, False) trait.
A trait for unicode strings.
A trait for unicode strings.
An instance of a Python dict.
Mixin to handle empty integer field.
A trait for unicode strings.
A boolean (True, False) trait.
A trait for unicode strings.
A boolean (True, False) trait.
A trait for unicode strings.
A trait for unicode strings.
List of the labels of existing valid (due to display units) model components
Methods Summary
calculate_fit([add_data])Calculate the fit.
create_model_component([model_component, ...])Add a new model component to the list of available model components
get_fitter_parameter(key)Get the value of a fitter parameter.
get_model_component(model_component_label[, ...])Get a (read-only) dictionary representation of an existing model component.
get_model_parameters([model_label, x, y])Convert each parameter of model inside models into a coordinate that maps the model name and parameter name to a
astropy.units.Quantityobject.get_models([models, model_label, x, y])Loop through all models and output models of the label model_label.
reestimate_model_parameters([...])Re-estimate all free parameters in a given model component given the currently selected data and subset selections.
remove_model_component(model_component_label)Remove an existing model component.
set_fitter_parameter(key, value)Set the value of a fitter parameter.
set_model_component(model_component_label, ...)Set the value or fixed attribute of a parameter in an existing model component.
vue_add_model(event)vue_apply(event)vue_remove_model(event)Attributes Documentation
- comp_label#
A trait for unicode strings.
- comp_label_auto#
A boolean (True, False) trait.
- comp_label_default#
A trait for unicode strings.
- comp_label_invalid_msg#
A trait for unicode strings.
- component_models#
An instance of a Python list.
- cube_fit#
A boolean (True, False) trait.
- dialog#
A boolean (True, False) trait.
- display_order#
A boolean (True, False) trait.
- eq_error#
A boolean (True, False) trait.
- equation_components#
List of the labels of model components in the current equation
- fitted_models#
Dictionary of all previously fitted models.
- fitter_component#
- fitter_error#
A trait which allows any value.
- fitter_items#
An instance of a Python list.
- fitter_parameters#
An instance of a Python dict.
One or more traits can be passed to the constructor to validate the keys and/or values of the dict. If you need more detailed validation, you may use a custom validator method.
Changed in version 5.0: Added key_trait for validating dict keys.
Changed in version 5.0: Deprecated ambiguous
trait,traitsargs in favor ofvalue_trait,per_key_traits.
- fitter_selected#
A trait for unicode strings.
- form_valid_model_component#
A boolean (True, False) trait.
- model_comp_items#
An instance of a Python list.
- model_comp_selected#
A trait for unicode strings.
- model_components#
List of the labels of existing model components
- model_equation#
A trait for unicode strings.
- model_equation_auto#
A boolean (True, False) trait.
- model_equation_default#
A trait for unicode strings.
- model_equation_invalid_msg#
A trait for unicode strings.
- parameter_hints#
An instance of a Python dict.
One or more traits can be passed to the constructor to validate the keys and/or values of the dict. If you need more detailed validation, you may use a custom validator method.
Changed in version 5.0: Added key_trait for validating dict keys.
Changed in version 5.0: Deprecated ambiguous
trait,traitsargs in favor ofvalue_trait,per_key_traits.
- poly_order#
Mixin to handle empty integer field.
- poly_order_invalid_msg#
A trait for unicode strings.
- residuals_calculate#
A boolean (True, False) trait.
- residuals_label#
A trait for unicode strings.
- residuals_label_auto#
A boolean (True, False) trait.
- residuals_label_default#
A trait for unicode strings.
- residuals_label_invalid_msg#
A trait for unicode strings.
- template_file = ('/home/docs/checkouts/readthedocs.org/user_builds/jdaviz/envs/3978/lib/python3.11/site-packages/jdaviz/configs/default/plugins/model_fitting/model_fitting.py', 'model_fitting.vue')#
- user_api#
- valid_model_components#
List of the labels of existing valid (due to display units) model components
Methods Documentation
- calculate_fit(add_data=True)[source]#
Calculate the fit.
- Parameters:
- add_databool
Whether to add the resulting spectrum/cube to the app as a data entry according to
add_results.
- Returns:
- fitted model
- fitted spectrum/cube
- residuals (if
residuals_calculateis set toTrue)
- create_model_component(model_component=None, model_component_label=None, poly_order=None)[source]#
Add a new model component to the list of available model components
- Parameters:
- model_componentstr
Type of model component to add. If not provided, will default according to
model_component.- model_component_labelstr
Name of the model component to add. If not provided, will default according to
model_component_label(ifmodel_component_label.autois True andmodel_componentis passed as an argument, then the default label will be recomputed rather than applying the current value).- poly_orderint
Order of the polynomial if
model_componentis (or defaults to) “Polynomial1D”. Will raise an error if provided andmodel_componentis not “Polynomial1D”. If not provided, will default according topoly_order.
- get_fitter_parameter(key)[source]#
Get the value of a fitter parameter.
- Parameters:
- keystr
The name of the fitter parameter to retrieve. Available parameters depend on the selected fitter. Common parameters include:
maxiter: Maximum number of iterations (available for most fitters)filter_non_finiteWhether to filter non-finite values(available for most fitters)
calc_uncertaintiesWhether to calculate uncertainties(available for most fitters)
- Returns:
- valueint, float, bool, or None
The current value of the parameter, or None if the parameter does not exist for the selected fitter.
Examples
>>> from jdaviz import Specviz >>> specviz = Specviz() >>> plugin = specviz.plugins['Model Fitting'] >>> plugin.fitter.selected = 'LevMarLSQFitter' >>> max_iterations = plugin.get_fitter_parameter('maxiter') >>> print(max_iterations) 100
- get_model_component(model_component_label, parameter=None)[source]#
Get a (read-only) dictionary representation of an existing model component.
- Parameters:
- model_component_labelstr
The label given to the existing model component
- parameterstr
Optional. The name of a valid parameter in the model component, in which case only the information on that parameter is returned.
- get_model_parameters(model_label=None, x=None, y=None)[source]#
Convert each parameter of model inside models into a coordinate that maps the model name and parameter name to a
astropy.units.Quantityobject.- Parameters:
- model_labelstr
Get model parameters for a particular model by inputting its label.
- xint
The x coordinate of the model spaxels that will be returned from get_models.
- yint
The y coordinate of the model spaxels that will be returned from get_models.
- Returns:
- dict:
a dictionary of the form {model name: {parameter name: [[
astropy.units.Quantity]]}} for 3d models or {model name: {parameter name:astropy.units.Quantity}} where the Quantity object represents the parameter value and unit of one of spaxel models or the 1d models, respectively.
- get_models(models=None, model_label=None, x=None, y=None)[source]#
Loop through all models and output models of the label model_label. If x or y is set, return model_labels of those (x, y) coordinates. If x and y are None, print all models regardless of coordinates.
- Parameters:
- modelsdict
A dict of models, with the key being the label name and the value being an
astropy.modeling.CompoundModelobject. Defaults tofitted_modelsif no parameter is provided.- model_labelstr
The name of the model that will be found and returned. If it equals default, every model present will be returned.
- xint
The x coordinate of the model spaxels that will be returned.
- yint
The y coordinate of the model spaxels that will be returned.
- Returns:
- selected_modelsdict
Dictionary of the selected models.
- reestimate_model_parameters(model_component_label=None)[source]#
Re-estimate all free parameters in a given model component given the currently selected data and subset selections.
- Parameters:
- model_component_labelstr or None.
The label given to the existing model component. If None, will iterate over all model components.
- remove_model_component(model_component_label)[source]#
Remove an existing model component.
- Parameters:
- model_component_labelstr
The label given to the existing model component
- set_fitter_parameter(key, value)[source]#
Set the value of a fitter parameter.
- Parameters:
- keystr
The name of the fitter parameter to set. Available parameters depend on the selected fitter. Common parameters include:
maxiter: Maximum number of iterations (available for most fitters)filter_non_finiteWhether to filter non-finite values(available for most fitters)
calc_uncertaintiesWhether to calculate uncertainties(available for most fitters)
- valueint, float, or bool
The new value for the parameter. The type should match the parameter’s expected type.
Examples
>>> from jdaviz import Specviz >>> specviz = Specviz() >>> plugin = specviz.plugins['Model Fitting'] >>> plugin.fitter.selected = 'LevMarLSQFitter' >>> plugin.set_fitter_parameter('maxiter', 200) >>> plugin.set_fitter_parameter('filter_non_finite', False)
- set_model_component(model_component_label, parameter, value=None, fixed=None)[source]#
Set the value or fixed attribute of a parameter in an existing model component.
- Parameters:
- model_component_labelstr
The label given to the existing model component
- parameterstr
The name of a valid parameter in the model component.
- valuefloat
Optional. The new initial value of the parameter. If not provided or None, will remain unchanged.
- fixedbool
Optional. The new state of the fixed attribute of the parameter. If not provided or None, will remain unchanged.
- Returns:
- updated dictionary of the parameter representation