Parameter

class qef.widgets.parameter.ParameterCallbacksMixin[source]

Bases: object

Implement relationships between the different components of an ipywidget exposing all or some of the parameter attributes

The methods in this Mixin expects attribute facade, a dictionary whose keys coincide with tuple widget_names and whose values are either None or references to ipywidgets. Attribute facade can be created with function add_widget_facade().

expr_value_change(change)[source]

enable/disable min, max, and value

inf = inf

Representation of infinity value

initialize_callbacks()[source]

Register callbacks to sync widget components

max_value_change(change)[source]

Notify other widgets if min changes.

  1. Reject change if max becomes smaller than min
  2. Uncheck nomax if new value is entered in max

2. Update value.value if it becomes bigger than max.value

min_value_change(change)[source]

Notify other widgets if min changes.

  1. Reject change if min becomes bigger than max
  2. Uncheck nomin if new value is entered in min
  3. Update value.value if it becomes smaller than min.value
nomax_value_change(change)[source]

Set max to \(\infty\) if nomax is checked

nomin_value_change(change)[source]

Set min to \(-\infty\) if nomin is checked

validate_facade()[source]

Ascertain that keys of facade attribute are contained in widget_names

value_value_change(change)[source]

Validate value is within bounds. Otherwise set value as the closest bound value

vary_value_change(change)[source]

enable/disable editing of min, max, value, and expr

widget_names = ('nomin', 'min', 'value', 'nomax', 'max', 'vary', 'expr')
class qef.widgets.parameter.ParameterWidget(show_header=True)[source]

Bases: ipywidgets.widgets.widget_box.Box

One possible representation of a fitting parameter. Inherits from ipywidgets.widgets.widget_box.Box

Parameters:show_header (Bool) – Hide or show names of the widget components min, value,…
class qef.widgets.parameter.ParameterWithTraits(name=None, value=None, vary=True, min=-inf, max=inf, expr=None, brute_step=None, user_data=None)[source]

Bases: lmfit.parameter.Parameter, traitlets.traitlets.HasTraits

Wrapper of Parameter with TraitType allows synchronization with ipywidgets

Same signature for initialization as that of Parameter.

Parameters:
  • name (str, optional) – Name of the Parameter.
  • value (float, optional) – Numerical Parameter value.
  • vary (bool, optional) – Whether the Parameter is varied during a fit (default is True).
  • min (float, optional) – Lower bound for value (default is -numpy.inf, no lower bound).
  • max (float, optional) – Upper bound for value (default is numpy.inf, no upper bound).
  • expr (str, optional) – Mathematical expression used to constrain the value during the fit.
  • brute_step (float, optional) – Step size for grid points in the brute method.
  • user_data (optional) – User-definable extra attribute used for a Parameter.
classmethod attr_to_trait(attr)[source]

From Parameter attribute name to TraitType name

classmethod feature_to_trait(feature)[source]

From Parameter feature name to TraitType name

Link the value of a single ipywidget to one trait, or the values of the element widgets of a composite ipywidget to different traits. The specific traits can be specified with the mapping argument.

Parameters:
  • widget (ipywidgets.widgets.widget.Widget)
  • mapping (str, dict, or None) – if str, mapping denotes the widget name to be associated with the widget. If dict, then mapping values are attribute names of widget, referencing the simple ipywidgets to be associated to standard widget_names. The widget names are the keys of mapping. If None, an inspection of widget attributes will be performed, looking for names that coincide with standard widget_names. If the inspection is unsuccessful, the widget will be associated with the standard widget name ‘value’ to represent the values taken by the fitting parameter.
param_attrs = ('_val', 'min', 'max', 'vary', '_expr')

Parameter attribute names

param_features = ('value', 'min', 'max', 'vary', 'expr')

Parameter feature names

texpr

Unicode trailet wrapping Parameter attribute _expr

tmax

Float trailet wrapping Parameter attribute min

tmin

Float trailet wrapping Parameter attribute _val

trait_names = ('tvalue', 'tmin', 'tmax', 'tvary', 'texpr')

TraitType instances in sync with Parameter attributes

classmethod trait_to_attr(name)[source]

From TraitType name to Parameter attribute name

tvalue

Float trailet wrapping Parameter attribute value

tvary

Bool trailet wrapping Parameter attribute vary

qef.widgets.parameter.add_widget_callbacks(widget, mapping=None)[source]

Extend the widget’s type with ParameterCallbacksMixin

Parameters:
  • widget (ipywidgets.widgets.widget.Widget)
  • mapping (str, dict, or None) – if str, mapping denotes the widget name to be associated with the widget. If dict, then mapping values are attribute names of widget, referencing the simple ipywidgets to be associated to standard widget_names. The widget names are the keys of mapping. If None, an inspection of widget attributes will be performed, looking for names that coincide with standard widget_names. If the inspection is unsuccessful, the widget will be associated with the standard widget name ‘value’ to represent the values taken by the fitting parameter.
qef.widgets.parameter.add_widget_facade(widget, mapping=None)[source]

Create facade dictionary where keys are standard widget_names and whose values are simple ipywidgets that control the fitting parameter attributes denoted by the standard widget_names. This dictionary is added to the input widget as an attribute.

Parameters:
  • widget (ipywidgets.widgets.widget.Widget)
  • mapping (str, dict, or None) – if str, mapping denotes the widget name to be associated with the widget. If dict, then mapping values are attribute names of widget, referencing the simple ipywidgets to be associated to standard widget names. The widget names are the keys of mapping. If None, an inspection of widget attributes will be performed, looking for names that coincide with standard widget names. If the inspection is unsuccessful, the widget will be associated with the standard widget name ‘value’ to represent the values taken by the fitting parameter.
Returns:

widget – Reference to input widget

Return type:

Widget

qef.widgets.parameter.create_facade(widget, mapping=None)[source]

Create facade dictionary where keys are standard widget_names and whose values are simple ipywidgets that control the fitting parameter attributes denoted by the standard widget_names.

Parameters:
  • widget (ipywidgets.widgets.widget.Widget)
  • mapping (str, dict, or None) – if str, mapping denotes the widget name to be associated with the widget. If dict, then mapping values are attribute names of widget, referencing the simple ipywidgets to be associated to standard widget names. The widget names are the keys of mapping. If None, an inspection of widget attributes will be performed, looking for names that coincide with standard widget names. If the inspection is unsuccessful, the widget will be associated with the standard widget name ‘value’ to represent the values taken by the fitting parameter.
Returns:

facade

Return type:

dict