pulse2percept.utils.base¶
PrettyPrint
, Frozen
, Data
, bijective26_name
, cached
, gamma
,
unique
Functions
bijective26_name (i) |
Bijective base-26 numeration |
cached (f) |
Cached property decorator |
freeze_class (set) |
Freezes a class Raise an error when trying to set an undeclared name, or when calling from a method other than Frozen.__init__ or the __init__ method of a class derived from Frozen |
gamma (n, tau, tsample[, tol]) |
Returns the impulse response of n cascaded leaky integrators |
Classes
Data (data[, axes, metadata]) |
N-dimensional data container |
Frozen |
“Frozen” classes (and subclasses) do not allow for new class attributes to be set outside the constructor. |
PrettyPrint |
An abstract class that provides a way to prettyprint all class attributes, inspired by scikit-learn. |
Exceptions
FreezeError |
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.
Data
(data, axes=None, metadata=None)[source]¶ N-dimensional data container
New in version 0.6.
Parameters:
-
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.
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
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.
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_params
method 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)
-
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 (string) – Alphabetic number Examples
>>> bijective26_name(0) 'A'
>>> bijective26_name(26) 'AA'
-
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_active
flag set to True or False.New in version 0.7.
-
pulse2percept.utils.base.
freeze_class
(set)[source]¶ Freezes a class Raise an error when trying to set an undeclared name, or when calling from a method other than
Frozen.__init__
or the__init__
method of a class derived from Frozen
-
pulse2percept.utils.base.
gamma
(n, tau, tsample, tol=0.01)[source]¶ Returns the impulse response of
n
cascaded leaky integratorsThis function calculates the impulse response of
n
cascaded 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
tol
of the peak value.