Parameters and Objects#
Descriptors#
- class easyscience.Objects.Variable.Descriptor(name, value, units=None, unique_name=None, description=None, url=None, display_name=None, callback=<property object>, enabled=True, parent=None)[source]#
This is the base of all variable descriptions for models. It contains all information to describe a single unique property of an object. This description includes a name and value as well as optionally a unit, description and url (for reference material). Also implemented is a callback so that the value can be read/set from a linked library object.
A Descriptor is typically something which describes part of a model and is non-fittable and generally changes the state of an object.
Units are provided by pint: hgrecco/pint
- Parameters:
name (
str
) – Name of this objectvalue (
Any
) – Value of this objectunits (
Union
[str
,Unit
,None
]) – This object can have a physical unit associated with itdescription (
Optional
[str
]) – A brief summary of what this object isurl (
Optional
[str
]) – Lookup url for documentation/informationcallback (
Optional
[property
]) – The property which says how the object is linked to another oneparent (
Optional
[Any
]) – The object which is the parent to this one
from easyscience.Objects.Base import Descriptor # Describe a color by text color_text = Descriptor('fav_colour', 'red') # Describe a color by RGB color_num = Descriptor('fav_colour', [1, 0, 0])
Note
Undo/Redo functionality is implemented for the attributes value, unit and display name.
- property compatible_units: List[str]#
Returns all possible units for which the current unit can be converted.
- Returns:
Possible conversion units
- convert_unit(unit_str)[source]#
Convert the value from one unit system to another. You will should use compatible_units to see if your new unit is compatible.
- Parameters:
unit_str (
str
) – New unit in string form
- property enabled: bool#
Logical property to see if the objects value can be directly set.
- Returns:
Can the objects value be set
- property raw_value: Any#
Return the raw value of self without a unit.
- Returns:
The raw value of self
- property unit: UnitRegistry#
Get the unit associated with the object.
- Returns:
Unit associated with self in pint form.
Parameters#
- class easyscience.Objects.Variable.Parameter(name, value, error=0.0, min=-inf, max=inf, fixed=False, **kwargs)[source]#
This class is an extension of a
EasyScience.Object.Base.Descriptor
. Where the descriptor was for static objects, a Parameter is for dynamic objects. A parameter has the ability to be used in fitting and has additional fields to facilitate this.- Parameters:
from easyscience.Objects.Base import Parameter # Describe a phase phase_basic = Parameter('phase', 3) # Describe a phase with a unit phase_unit = Parameter('phase', 3, units,='rad/s')
Note
Undo/Redo functionality is implemented for the attributes value, error, min, max, fixed
- as_data_dict(skip=None)#
Returns a dictionary containing just the data of an EasyScience object.
- as_dict(skip=None)#
Convert an EasyScience object into a full dictionary using DictSerializer. This is a shortcut for
`obj.encode(encoder=DictSerializer)`
- property bounds: Tuple[Number, Number]#
Get the bounds of the parameter.
- Returns:
Tuple of the parameters minimum and maximum values
- property builtin_constraints: mappingproxy[str, C]#
Get the built in constrains of the object. Typically these are the min/max
- Returns:
Dictionary of constraints which are built into the system
- property compatible_units: List[str]#
Returns all possible units for which the current unit can be converted.
- Returns:
Possible conversion units
- convert_unit(new_unit)[source]#
Perform unit conversion. The value, max and min can change on unit change.
- Parameters:
new_unit (
str
) – new unit- Returns:
None
- classmethod decode(obj, decoder=None)#
Re-create an EasyScience object from the output of an encoder. The default decoder is DictSerializer.
- property enabled: bool#
Logical property to see if the objects value can be directly set.
- Returns:
Can the objects value be set
- encode(skip=None, encoder=None, **kwargs)#
Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using DictSerializer.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the encoded objectencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DictSerializerkwargs – Any additional key word arguments to be passed to the encoder
- Return type:
- Returns:
encoded object containing all information to reform an EasyScience object.
- encode_data(skip=None, encoder=None, **kwargs)#
Returns just the data in an EasyScience object win the format specified by an encoder.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the dictionaryencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DataDictSerializerkwargs – Any additional keywords to pass to the encoder when encoding
- Return type:
- Returns:
encoded object containing just the data of an EasyScience object.
- property error: float#
The error associated with the parameter.
- Returns:
Error associated with parameter
- property fixed: bool#
Can the parameter vary while fitting?
- Returns:
True = fixed, False = can vary
- Return type:
- classmethod from_dict(obj_dict)#
Re-create an EasyScience object from a full encoded dictionary.
- property raw_value: Any#
Return the raw value of self without a unit.
- Returns:
The raw value of self
- to_obj_type(data_type, *kwargs)#
Convert between a Parameter and a Descriptor.
- property unit: UnitRegistry#
Get the unit associated with the object.
- Returns:
Unit associated with self in pint form.
- unsafe_hash()#
Returns an hash of the current object. This uses a generic but low performance method of converting the object to a dictionary, flattening any nested keys, and then performing a hash on the resulting object
- Return type:
openssl_sha1
Super Classes and Collections#
Super Classes#
- class easyscience.Objects.ObjectClasses.BasedBase(name, interface=None, unique_name=None)[source]#
- as_data_dict(skip=None)#
Returns a dictionary containing just the data of an EasyScience object.
- as_dict(skip=None)#
Convert an EasyScience object into a full dictionary using DictSerializer. This is a shortcut for
`obj.encode(encoder=DictSerializer)`
- classmethod decode(obj, decoder=None)#
Re-create an EasyScience object from the output of an encoder. The default decoder is DictSerializer.
- encode(skip=None, encoder=None, **kwargs)#
Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using DictSerializer.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the encoded objectencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DictSerializerkwargs – Any additional key word arguments to be passed to the encoder
- Return type:
- Returns:
encoded object containing all information to reform an EasyScience object.
- encode_data(skip=None, encoder=None, **kwargs)#
Returns just the data in an EasyScience object win the format specified by an encoder.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the dictionaryencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DataDictSerializerkwargs – Any additional keywords to pass to the encoder when encoding
- Return type:
- Returns:
encoded object containing just the data of an EasyScience object.
- classmethod from_dict(obj_dict)#
Re-create an EasyScience object from a full encoded dictionary.
- generate_bindings()[source]#
Generate or re-generate bindings to an interface (if exists)
- Raises:
AttributeError
- property interface: iF#
Get the current interface of the object
- unsafe_hash()#
Returns an hash of the current object. This uses a generic but low performance method of converting the object to a dictionary, flattening any nested keys, and then performing a hash on the resulting object
- Return type:
openssl_sha1
- class easyscience.Objects.ObjectClasses.BaseObj(name, unique_name=None, *args, **kwargs)[source]#
Set up the base class.
- Parameters:
- as_data_dict(skip=None)#
Returns a dictionary containing just the data of an EasyScience object.
- as_dict(skip=None)#
Convert an EasyScience object into a full dictionary using DictSerializer. This is a shortcut for
`obj.encode(encoder=DictSerializer)`
- classmethod decode(obj, decoder=None)#
Re-create an EasyScience object from the output of an encoder. The default decoder is DictSerializer.
- encode(skip=None, encoder=None, **kwargs)#
Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using DictSerializer.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the encoded objectencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DictSerializerkwargs – Any additional key word arguments to be passed to the encoder
- Return type:
- Returns:
encoded object containing all information to reform an EasyScience object.
- encode_data(skip=None, encoder=None, **kwargs)#
Returns just the data in an EasyScience object win the format specified by an encoder.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the dictionaryencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DataDictSerializerkwargs – Any additional keywords to pass to the encoder when encoding
- Return type:
- Returns:
encoded object containing just the data of an EasyScience object.
- classmethod from_dict(obj_dict)#
Re-create an EasyScience object from a full encoded dictionary.
- generate_bindings()#
Generate or re-generate bindings to an interface (if exists)
- Raises:
AttributeError
- get_fit_parameters()#
Get all objects which can be fitted (and are not fixed) as a list.
- get_parameters()#
Get all parameter objects as a list.
- property interface: iF#
Get the current interface of the object
- switch_interface(new_interface_name)#
Switch or create a new interface.
- unsafe_hash()#
Returns an hash of the current object. This uses a generic but low performance method of converting the object to a dictionary, flattening any nested keys, and then performing a hash on the resulting object
- Return type:
openssl_sha1
Collections#
- class easyscience.Objects.Groups.BaseCollection(name, *args, interface=None, unique_name=None, **kwargs)[source]#
Set up the base collection class.
- Parameters:
- append(value)#
S.append(value) – append value to the end of the sequence
- as_data_dict(skip=None)#
Returns a dictionary containing just the data of an EasyScience object.
- as_dict(skip=None)#
Convert an EasyScience object into a full dictionary using DictSerializer. This is a shortcut for
`obj.encode(encoder=DictSerializer)`
- clear() None -- remove all items from S #
- count(value) integer -- return number of occurrences of value #
- property data: Tuple#
The data function returns a tuple of the keyword arguments passed to the constructor. This is useful for when you need to pass in a dictionary of data to other functions, such as with matplotlib’s plot function.
- Parameters:
self – Access attributes of the class within the method
- Returns:
The values of the attributes in a tuple
- Doc-author:
Trelent
- classmethod decode(obj, decoder=None)#
Re-create an EasyScience object from the output of an encoder. The default decoder is DictSerializer.
- encode(skip=None, encoder=None, **kwargs)#
Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using DictSerializer.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the encoded objectencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DictSerializerkwargs – Any additional key word arguments to be passed to the encoder
- Return type:
- Returns:
encoded object containing all information to reform an EasyScience object.
- encode_data(skip=None, encoder=None, **kwargs)#
Returns just the data in an EasyScience object win the format specified by an encoder.
- Parameters:
skip (
Optional
[List
[str
]]) – List of field names as strings to skip when forming the dictionaryencoder (
Optional
[Type
[TypeVar
(EC
, bound=BaseEncoderDecoder
)]]) – The encoder to be used for encoding the data. Default is DataDictSerializerkwargs – Any additional keywords to pass to the encoder when encoding
- Return type:
- Returns:
encoded object containing just the data of an EasyScience object.
- extend(values)#
S.extend(iterable) – extend sequence by appending elements from the iterable
- classmethod from_dict(obj_dict)#
Re-create an EasyScience object from a full encoded dictionary.
- generate_bindings()#
Generate or re-generate bindings to an interface (if exists)
- Raises:
AttributeError
- get_fit_parameters()#
Get all objects which can be fitted (and are not fixed) as a list.
- get_parameters()#
Get all parameter objects as a list.
- index(value[, start[, stop]]) integer -- return first index of value. #
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- insert(index, value)[source]#
Insert an object into the collection at an index.
- Parameters:
index (int) – Index for EasyScience object to be inserted.
value (Union[BasedBase, Descriptor]) – Object to be inserted.
- Returns:
None
- Return type:
None
- property interface: iF#
Get the current interface of the object
- pop([index]) item -- remove and return item at index (default last). #
Raise IndexError if list is empty or index is out of range.
- remove(value)#
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()#
S.reverse() – reverse IN PLACE
- switch_interface(new_interface_name)#
Switch or create a new interface.
- unsafe_hash()#
Returns an hash of the current object. This uses a generic but low performance method of converting the object to a dictionary, flattening any nested keys, and then performing a hash on the resulting object
- Return type:
openssl_sha1
Data Containers#
- class easyscience.Datasets.xarray.EasyScienceDataarrayAccessor(xarray_obj)[source]#
Accessor to extend an xarray DataArray to EasyScience. These functions can be accessed by obj.EasyScience.func.
- property compute_func: Callable#
Get the computational function which will be executed during a fit
- Returns:
Computational function applied to the DataArray
- Return type:
Callable
- property core_object#
Get the core object associated to a DataArray. Note that this is called from a weakref. If the EasyScience obj is garbage collected, None will be returned.
- Returns:
EasyScience object associated with the DataArray
- Return type:
Any
- fit(fitter, *args, fit_kwargs=None, fn_kwargs=None, vectorize=False, dask='forbidden', **kwargs)[source]#
Perform a fit on the given DataArray. This fit utilises a given fitter from EasyScience.fitting.Fitter, though there are a few differences to a standard EasyScience fit. In particular, key-word arguments to control the optimisation algorithm go in the fit_kwargs dictionary, fit function key-word arguments go in the fn_kwargs and given key-word arguments control the xarray.apply_ufunc function.
- Parameters:
fitter (EasyScience.fitting.Fitter) – Fitting object which controls the fitting
args (Any) – Arguments to go to the fit function
dask (str) – Dask control string. See xarray.apply_ufunc documentation
fit_kwargs (dict) – Dictionary of key-word arguments to be supplied to the Fitting control
fn_kwargs (dict) – Dictionary of key-words to be supplied to the fit function
vectorize (bool) – Should the fit function be given dependents in a single object or split
kwargs (Any) – Key-word arguments for xarray.apply_ufunc. See xarray.apply_ufunc documentation
- Returns:
Results of the fit
- Return type:
FitResults
- fit_prep(func_in, bdims=None, dask_chunks=None)[source]#
Generate broadcasted coordinates for fitting and reform the fitting function into one which can handle xarrays.
- Parameters:
func_in (Callable) – Function to be wrapped and made xarray fitting compatible.
bdims (xarray.DataArray) – Optional precomputed broadcasted dimensions.
dask_chunks (Tuple[int..]) – How to split the broadcasted dimensions for dask.
- Returns:
Tuple of broadcasted fit arrays and wrapped fit function.
- Return type:
xarray.DataArray, Callable
- generate_points()[source]#
Generate an expanded DataArray of points which corresponds to broadcasted dimensions (all_x) which have been concatenated along the second axis (fit_dim).
- Returns:
Broadcasted and concatenated coordinates
- Return type:
- class easyscience.Datasets.xarray.EasyScienceDatasetAccessor(xarray_obj)[source]#
This is called whenever you access obj.EasyScience, hence the attributes in the obj should only be written if they have not been previously instantiated.
- Parameters:
xarray_obj (xarray.Dataset) – DataSet which is called by obj.EasyScience
- add_coordinate(coordinate_name, coordinate_values, unit='')[source]#
Add a coordinate to the DataSet. This can be then be assigned to one or more DataArrays.
- add_variable(variable_name, variable_coordinates, variable_values, variable_sigma=None, unit='', auto_sigma=False)[source]#
Create a DataArray from known coordinates and data, assign it to the dataset under a given name. Variances can be calculated assuming gaussian distribution to 1 sigma.
- Parameters:
variable_name (str) – Name of the DataArray which will be created and added to the dataset
variable_coordinates (str, List[str]) – List of coordinates used in the supplied data array.
variable_values (Union[numpy.ndarray, list]) – Numpy or list of data which will be assigned to the DataArray
variable_sigma (Union[numpy.ndarray, list]) – If the sigmas of the dataset are known, they can be supplied here.
unit (str) – Unit associated with the DataArray
auto_sigma (bool) – Should the sigma DataArray be automatically calculated assuming gaussian probability?
- Returns:
None
- Return type:
None
- property core_object#
Get the core object associated to a DataSet. Note that this is called from a weakref. If the EasyScience obj is garbage collected, None will be returned.
- Returns:
EasyScience object associated with the DataSet
- Return type:
Any
- property description: str#
Get a description of the DataSet
- Returns:
Description of the DataSet
- Return type:
- fit(fitter, data_arrays, *args, dask='forbidden', fit_kwargs=None, fn_kwargs=None, vectorized=False, **kwargs)[source]#
Perform a fit on one or more DataArrays. This fit utilises a given fitter from EasyScience.fitting.Fitter, though there are a few differences to a standard EasyScience fit. In particular, key-word arguments to control the optimisation algorithm go in the fit_kwargs dictionary, fit function key-word arguments go in the fn_kwargs and given key-word arguments control the xarray.apply_ufunc function.
- Parameters:
fitter (EasyScience.fitting.Fitter) – Fitting object which controls the fitting
args (Any) – Arguments to go to the fit function
dask (str) – Dask control string. See xarray.apply_ufunc documentation
fit_kwargs (dict) – Dictionary of key-word arguments to be supplied to the Fitting control
fn_kwargs (dict) – Dictionary of key-words to be supplied to the fit function
vectorized (bool) – Should the fit function be given dependents in a single object or split
kwargs (Any) – Key-word arguments for xarray.apply_ufunc. See xarray.apply_ufunc documentation
- Returns:
Results of the fit
- Return type:
List[FitResults]
- generate_points(coordinates)[source]#
- Return type:
-
Generate an expanded DataArray of points which corresponds to broadcasted dimensions (all_x) which have been concatenated along the second axis (fit_dim).
x = [1, 2], y = [3, 4] d = xr.DataArray() d.EasyScience.add_coordinate('x', x) d.EasyScience.add_coordinate('y', y) points = d.EasyScience.generate_points(['x', 'y']) print(points)
- property name: str#
Get the common name of the DataSet.
- Returns:
Common name of the DataSet
- Return type:
- remove_coordinate(coordinate_name)[source]#
Remove a coordinate from the DataSet. Note that this will not remove the coordinate from DataArrays which have already used the it!
- Parameters:
coordinate_name (str) – Name of the coordinate to be removed
- Returns:
None
- Return type:
None
- remove_variable(variable_name)[source]#
Remove a DataArray from the DataSet by supplied name.
- Parameters:
variable_name (str) – Name of DataArray to be removed
- Returns:
None
- Return type:
None
- sigma_attach(variable_label, sigma_values, label_prefix=None)[source]#
Attach an array of sigmas to the DataSet.
- Parameters:
- Returns:
None
- Return type:
None
- sigma_generator(variable_label, sigma_func=<function EasyScienceDatasetAccessor.<lambda>>, label_prefix=None)[source]#
Generate sigmas off of a DataArray based on a function.
- Parameters:
variable_label (str) – Name of the DataArray to perform the calculation on
sigma_func (Callable) – Function to generate the sigmas. Must be of the form f(x) and return an array of the same shape as the input. Default sqrt(|x|)
label_prefix (str) – What prefix should be used to designate a sigma DataArray from a data DataArray
- Returns:
None
- Return type:
None