easyscience.Objects
Groups
BaseCollection
Bases: BasedBase
, MutableSequence
This is the base class for which all higher level classes are built off of.
NOTE: This object is serializable only if parameters are supplied as:
BaseObj(a=value, b=value)
. For Parameter
or Descriptor
objects we can
cheat with BaseObj(*[Descriptor(...), Parameter(...), ...])
.
data
property
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.
:param self: Access attributes of the class within the method :return: The values of the attributes in a tuple :doc-author: Trelent
__delitem__(key)
Try to delete an idem by key.
:param key: :type key: :return: :rtype:
__getitem__(idx)
Get an item in the collection based on its index.
:param idx: index or slice of the collection.
:type idx: Union[int, slice]
:return: Object at index idx
:rtype: Union[Parameter, Descriptor, BaseObj, 'BaseCollection']
__init__(name, *args, interface=None, unique_name=None, **kwargs)
Set up the base collection class.
:param name: Name of this object :type name: str :param args: selection of :param _kwargs: Fields which this class should contain :type _kwargs: dict
__len__()
Get the number of items in this collection
:return: Number of items in this collection. :rtype: int
__setitem__(key, value)
Set an item via it's index.
:param key: Index in self. :type key: int :param value: Value which index key should be set to. :type value: Any
insert(index, value)
Insert an object into the collection at an index.
:param index: Index for EasyScience object to be inserted. :type index: int :param value: Object to be inserted. :type value: Union[BasedBase, DescriptorBase] :return: None :rtype: None
sort(mapping, reverse=False)
Sort the collection according to the given mapping.
:param mapping: mapping function to sort the collection. i.e. lambda parameter: parameter.value :type mapping: Callable :param reverse: Reverse the sorting. :type reverse: bool
Inferface
InterfaceFactoryTemplate
This class allows for the creation and transference of interfaces.
available_interfaces
property
Return all available interfaces.
:return: List of available interface names :rtype: List[str]
current_interface
property
Returns the constructor for the currently selected interface.
:return: Interface constructor :rtype: InterfaceTemplate
current_interface_name
property
Returns the constructor name for the currently selected interface.
:return: Interface constructor name :rtype: str
fit_func
property
Pass through to the underlying interfaces fitting function.
:param x_array: points to be calculated at
:type x_array: np.ndarray
:param args: positional arguments for the fitting function
:type args: Any
:param kwargs: key/value pair arguments for the fitting function.
:type kwargs: Any
:return: points calculated at positional values x
:rtype: np.ndarray
create(*args, **kwargs)
Create an interface to a calculator from those initialized. Interfaces can be selected
by interface_name
where interface_name
is one of obj.available_interfaces
. This
interface can now be accessed by obj().
:param interface_name: name of interface to be created :type interface_name: str :return: None :rtype: noneType
generate_bindings(model, *args, ifun=None, **kwargs)
Automatically bind a Parameter
to the corresponding interface.
:param name: parameter name
:type name: str
:return: binding property
:rtype: property
return_name(this_interface)
staticmethod
Return an interfaces name
switch(new_interface, fitter=None)
Changes the current interface to a new interface. The current interface is destroyed and all ComponentSerializer parameters carried over to the new interface. i.e. pick up where you left off.
:param new_interface: name of new interface to be created :type new_interface: str :param fitter: Fitting interface which contains the fitting object which may have bindings which will be updated. :type fitter: EasyScience.fitting.Fitter :return: None :rtype: noneType
ObjectClasses
BaseObj
Bases: BasedBase
This is the base class for which all higher level classes are built off of.
NOTE: This object is serializable only if parameters are supplied as:
BaseObj(a=value, b=value)
. For Parameter
or Descriptor
objects we can
cheat with BaseObj(*[Descriptor(...), Parameter(...), ...])
.
__init__(name, unique_name=None, *args, **kwargs)
Set up the base class.
:param name: Name of this object :param args: Any arguments? :param kwargs: Fields which this class should contain
BasedBase
Bases: ComponentSerializer
interface
property
writable
Get the current interface of the object
name
property
writable
Get the common name of the object.
:return: Common name of the object
unique_name
property
writable
Get the unique name of the object.
__copy__()
Return a copy of the object.
__dir__()
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto-completion
__reduce__()
Make the class picklable. Due to the nature of the dynamic class definitions special measures need to be taken.
:return: Tuple consisting of how to make the object :rtype: tuple
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.
:return: List of Parameter
objects which can be used in fitting.
get_parameters()
Get all parameter objects as a list.
:return: List of Parameter
objects.
switch_interface(new_interface_name)
Switch or create a new interface.
core
ComponentSerializer
This is the base class for all EasyScience objects and deals with the data conversion to other formats via the encode
and decode
functions. Shortcuts for dictionary and data dictionary encoding is also present.
as_data_dict(skip=None)
Returns a dictionary containing just the data of an EasyScience object.
:param skip: List of field names as strings to skip when forming the dictionary :return: 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)
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
decode(obj, decoder=None)
classmethod
Re-create an EasyScience object from the output of an encoder. The default decoder is DictSerializer
.
:param obj: encoded EasyScience object :param decoder: decoder to be used to reform the EasyScience object :return: Reformed EasyScience object
encode(skip=None, encoder=None, **kwargs)
Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using DictSerializer
.
:param skip: List of field names as strings to skip when forming the encoded object
:param encoder: The encoder to be used for encoding the data. Default is DictSerializer
:param kwargs: Any additional key word arguments to be passed to the encoder
:return: 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.
:param skip: List of field names as strings to skip when forming the dictionary
:param encoder: The encoder to be used for encoding the data. Default is DataDictSerializer
:param kwargs: Any additional keywords to pass to the encoder when encoding
:return: encoded object containing just the data of an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from DictSerializer
) of an EasyScience object
:return: Reformed EasyScience 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
job
analysis
AnalysisBase
experiment
ExperimentBase
job
JobBase
theoreticalmodel
TheoreticalModelBase
variable
descriptor_any_type
DescriptorAnyType
Bases: DescriptorBase
A Descriptor
for any type that does not fit the other Descriptors. Should be avoided when possible.
It was created to hold the symmetry operations used in the SpaceGroup class of EasyCrystallography.
value
property
writable
Get the value.
:return: Value of self.
__init__(name, value, unique_name=None, description=None, url=None, display_name=None, parent=None)
Constructor for the DescriptorAnyType class
param name: Name of the descriptor
param value: Value of the descriptor
param description: Description of the descriptor
param url: URL of the descriptor
param display_name: Display name of the descriptor
param parent: Parent of the descriptor
.. note:: Undo/Redo functionality is implemented for the attributes variance
, error
, unit
and value
.
__repr__()
Return a string representation of the DescriptorAnyType, showing its name and value.
descriptor_base
DescriptorBase
Bases: ComponentSerializer
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.
description
property
writable
Get the description of the object.
:return: description of the object.
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
name
property
writable
Get the name of the object.
:return: name of the object.
unique_name
property
writable
Get the unique name of this object.
:return: Unique name of this object
url
property
writable
Get the url of the object.
:return: url of the object.
value
abstractmethod
property
writable
Get the value of the object.
__copy__()
Return a copy of the object.
__init__(name, unique_name=None, description=None, url=None, display_name=None, parent=None)
This is the base of variables for models. It contains all information to describe a single unique property of an object. This description includes a name, description and url (for reference material).
A Descriptor
is typically something which describes part of a model and is non-fittable and generally changes
the state of an object.
:param name: Name of this object :param description: A brief summary of what this object is :param url: Lookup url for documentation/information :param display_name: A pretty name for the object :param parent: The object which this descriptor is attached to
.. note:: Undo/Redo functionality is implemented for the attributes name
and display name
.
__repr__()
abstractmethod
Return printable representation of the object.
descriptor_bool
DescriptorBool
Bases: DescriptorBase
A Descriptor
for boolean values.
value
property
writable
Get the value of self.
:return: Value of self
__repr__()
Return printable representation.
descriptor_number
DescriptorNumber
Bases: DescriptorBase
A Descriptor
for Number values with units. The internal representation is a scipp scalar.
error
property
writable
The standard deviation for the parameter.
:return: Error associated with parameter
full_value
property
writable
Get the value of self as a scipp scalar. This is should be usable for most cases.
:return: Value of self with unit.
unit
property
writable
Get the unit.
:return: Unit as a string.
value
property
writable
Get the value. This should be usable for most cases. The full value can be obtained from obj.full_value
.
:return: Value of self with unit.
variance
property
writable
Get the variance.
:return: variance.
__init__(name, value, unit='', variance=None, unique_name=None, description=None, url=None, display_name=None, parent=None)
Constructor for the DescriptorNumber class
param name: Name of the descriptor
param value: Value of the descriptor
param unit: Unit of the descriptor
param variance: Variance of the descriptor
param description: Description of the descriptor
param url: URL of the descriptor
param display_name: Display name of the descriptor
param parent: Parent of the descriptor
.. note:: Undo/Redo functionality is implemented for the attributes variance
, error
, unit
and value
.
__repr__()
Return printable representation.
convert_unit(unit_str)
Convert the value from one unit system to another.
:param unit_str: New unit in string form
from_scipp(name, full_value, **kwargs)
classmethod
Create a DescriptorNumber from a scipp constant.
:param name: Name of the descriptor :param value: Value of the descriptor as a scipp scalar :param kwargs: Additional parameters for the descriptor :return: DescriptorNumber
descriptor_str
DescriptorStr
Bases: DescriptorBase
A Descriptor
for string values.
value
property
writable
Get the value of self.
:return: Value of self with unit.
__repr__()
Return printable representation.
parameter
Parameter
Bases: DescriptorNumber
A Parameter is a DescriptorNumber which can be used in fitting. It has additional fields to facilitate this.
bounds
property
writable
Get the bounds of the parameter.
:return: Tuple of the parameters minimum and maximum values
builtin_constraints
property
Get the built in constrains of the object. Typically these are the min/max
:return: Dictionary of constraints which are built into the system
enabled
property
writable
Logical property to see if the objects value can be directly set.
:return: Can the objects value be set
fixed
property
writable
Can the parameter vary while fitting?
:return: True = fixed, False = can vary
full_value
property
writable
Get the value of self as a scipp scalar. This is should be usable for most cases.
If a scipp scalar is not acceptable then the raw value can be obtained through obj.value
.
:return: Value of self with unit and variance.
max
property
writable
Get the maximum value for fitting.
:return: maximum value
min
property
writable
Get the minimum value for fitting.
:return: minimum value
user_constraints
property
writable
Get the user specified constrains of the object.
:return: Dictionary of constraints which are user supplied
value
property
writable
Get the value of self as a Number.
:return: Value of self without unit.
value_no_call_back
property
Get the currently hold value of self suppressing call back.
:return: Value of self without unit.
__init__(name, value, unit='', variance=0.0, min=-np.inf, max=np.inf, fixed=False, unique_name=None, description=None, url=None, display_name=None, callback=property(), enabled=True, parent=None)
This class is an extension of a DescriptorNumber
. 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.
:param name: Name of this object :param value: Value of this object :param unit: This object can have a physical unit associated with it :param variance: The variance of the value :param min: The minimum value for fitting :param max: The maximum value for fitting :param fixed: Can the parameter vary while fitting? :param description: A brief summary of what this object is :param url: Lookup url for documentation/information :param display_name: The name of the object as it should be displayed :param enabled: Can the objects value be set :param parent: The object which is the parent to this one
.. note::
Undo/Redo functionality is implemented for the attributes value
, variance
, error
, min
, max
, bounds
, fixed
, unit
__repr__()
Return printable representation of a Parameter object.
convert_unit(unit_str)
Perform unit conversion. The value, max and min can change on unit change.
:param new_unit: new unit :return: None