pulse2percept.utils.base
PrettyPrint,
Frozen,
Parametrized,
Data,
bijective26_name,
cached,
gamma,
unique
Functions
Bijective base-26 numeration |
|
|
Cached property decorator |
|
Freezes a class |
|
Returns the impulse response of |
|
Return whether |
Classes
|
N-dimensional data container |
|
"Frozen" classes (and subclasses) do not allow for new class attributes to be set outside the constructor. |
|
Base class for objects with user-settable parameters. |
An abstract class that provides a way to prettyprint all class attributes, inspired by scikit-learn. |
Exceptions
Exception class used to raise when trying to add attributes to Frozen Classes of type Frozen do not allow for new attributes to be set outside the constructor. |
- class pulse2percept.utils.base.PrettyPrint[source]
An abstract class that provides a way to prettyprint all class attributes, inspired by scikit-learn.
Classes deriving from PrettyPrint are required to implement a
_pprint_paramsmethod that returns a dictionary containing all the attributes to prettyprint.Examples
>>> from pulse2percept.utils import PrettyPrint >>> class MyClass(PrettyPrint): ... def __init__(self, a, b): ... self.a = a ... self.b = b ... ... def _pprint_params(self): ... return {'a': self.a, 'b': self.b} >>> MyClass(1, 2) MyClass(a=1, b=2)
- exception pulse2percept.utils.base.FreezeError[source]
Exception class used to raise when trying to add attributes to Frozen Classes of type Frozen do not allow for new attributes to be set outside the constructor.
- add_note(object, /)
Exception.add_note(note) – add a note to the exception
- name
attribute name
- obj
object
- with_traceback(object, /)
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- pulse2percept.utils.base.has_own_attr(obj, name)[source]
Return whether
objownsnamewithout invoking its getter.Unlike
hasattr, this avoids triggering properties such as deprecated aliases.
- pulse2percept.utils.base.freeze_class(set, normalize=None)[source]
Freezes a class
Raise an error when trying to set an undeclared name from anywhere but the object’s own constructor.
- Parameters:
set (callable) – The
__setattr__to delegate to once the assignment is allowed.normalize (callable, optional) –
normalize(self, name, value), called before the assignment whenvaluecarries a physical unit, and returning the value to store. See_normalize_param, which dispatches to the object’s own_normalize_param_value.
- class pulse2percept.utils.base.Frozen[source]
“Frozen” classes (and subclasses) do not allow for new class attributes to be set outside the constructor. On attempting to add a new attribute, the class will raise a FreezeError.
- class pulse2percept.utils.base.Parametrized(**params)[source]
Base class for objects with user-settable parameters.
Parameters are declared by
get_default_params(); subclasses may declare their storage units withget_param_units().Frozenprevents adding new attributes after construction.Added in version 0.10.0.
- class pulse2percept.utils.base.Data(data, axes=None, metadata=None)[source]
N-dimensional data container
Added in version 0.6.
- pulse2percept.utils.base.gamma(n, tau, tsample, tol=0.01)[source]
Returns the impulse response of
ncascaded leaky integratorsThis function calculates the impulse response of
ncascaded leaky integrators with constant of proportionality 1/tau: y = (t/theta).^(n-1).*exp(-t/theta)/(theta*factorial(n-1))- Parameters:
n (int) – Number of cascaded leaky integrators
tau (float) – Decay constant of leaky integration (seconds). Equivalent to the inverse of the constant of proportionality.
tsample (float) – Sampling time step (seconds).
tol (float) – Cut the kernel to size by ignoring function values smaller than a fraction
tolof the peak value.
- pulse2percept.utils.base.cached(f)[source]
Cached property decorator
Decorator can be added to the property of a class to maintain a cache. This is useful when computing the property is computationall expensive. The property will only be computed on first call, and subsequent calls will refer to the cached result.
Important
When making use of a cached property, the class should also maintain a
_cache_activeflag set to True or False.Added in version 0.7.
- pulse2percept.utils.base.bijective26_name(i)[source]
Bijective base-26 numeration
Creates the “alphabetic number” for a given integer i following bijective base-26 numeration: A-Z, AA-AZ, BA-BZ, … ZA-ZZ, AAA-AAZ, ABA-ABZ, …
- Parameters:
i (int) – Regular number to be translated into an alphabetic number
- Returns:
name – Alphabetic number
- Return type:
string
Examples
>>> bijective26_name(0) 'A'
>>> bijective26_name(26) 'AA'