Skip to content

core_utils

Class representing a failed run.

Source code in navis/core/core_utils.py
494
495
496
497
498
499
500
501
502
503
504
505
506
507
class FailedRun:
    """Class representing a failed run."""
    def __init__(self, func, args, kwargs, exception='NA'):
        self.args = args
        self.func = func
        self.kwargs = kwargs
        self.exception = exception

    def __repr__(self):
        return self.__str__()

    def __str__(self):
        return (f'Failed run(function={self.func}, args={self.args}, '
                f'kwargs={self.kwargs}, exception={self.exception})')

Add neuron units (if present) to output of function.

Source code in navis/core/core_utils.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def add_units(compact=True, power=1):
    """Add neuron units (if present) to output of function."""
    def outer(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            self = args[0]
            res = func(*args, **kwargs)

            if config.add_units and self.has_units and not self.units.dimensionless:
                res = res * np.power(self.units, power)
                if compact:
                    res = res.to_compact()

            return res
        return wrapper
    return outer

Check if neuron is stale. Clear cached temporary attributes if it is.

Source code in navis/core/core_utils.py
45
46
47
48
49
50
51
52
53
54
55
def temp_property(func):
    """Check if neuron is stale. Clear cached temporary attributes if it is."""
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        self = args[0]
        # Do nothing if neurons is locked
        if not self.is_locked:
            if self.is_stale:
                self._clear_temp_attr()
        return func(*args, **kwargs)
    return wrapper