Neurodamus.utils Sub-Modules¶
neurodamus.utils.compat¶
Compatibility Classes to work similar to HOC types, recreating or wrapping them
Classes
|
Behavior similar to Hoc List |
|
Behavior similar to Hoc Vector |
- class neurodamus.utils.compat.List(iterable=(), /)¶
Behavior similar to Hoc List
- __annotate_func__ = None¶
- __annotations_cache__ = {}¶
- __firstlineno__ = 28¶
- __module__ = 'neurodamus.utils.compat'¶
- __slots__ = ()¶
- __static_attributes__ = ()¶
- count(obj=None)¶
Return number of occurrences of value.
- o(idx)¶
- class neurodamus.utils.compat.Vector(type_='I', array=None)¶
Behavior similar to Hoc Vector
- __add__(other)¶
Return self+value.
- __annotate_func__ = None¶
- __annotations_cache__ = {}¶
- __firstlineno__ = 6¶
- __module__ = 'neurodamus.utils.compat'¶
- static __new__(cls, type_='I', array=None)¶
- __slots__ = ()¶
- __static_attributes__ = ()¶
- size()¶
- property x¶
- neurodamus.utils.compat.hoc_vector(np_array)¶
neurodamus.utils.logging¶
Loggeers init & Formatters
Functions
|
Shortcut to log a messge with the STAGE level |
|
Shortcut to log a messge with the VERBOSE level |
|
Setup neurodamus logging. |
- neurodamus.utils.logging.log_all(level, msg, *args)¶
Like logging.log, but always displays. Level is used for style only
- neurodamus.utils.logging.log_stage(msg, *args)¶
Shortcut to log a messge with the STAGE level
- neurodamus.utils.logging.log_verbose(msg, *args)¶
Shortcut to log a messge with the VERBOSE level
- neurodamus.utils.logging.setup_logging(loglevel, logfile=None, rank=None, use_color=True)¶
Setup neurodamus logging. Features tabs and colors output to stdout and pydamus.log
- Parameters:
loglevel (int) – minimum loglevel for emitting messages
logfile – The destination for log messages besides stdout
rank – A tag so warnings/errors are correctly identified in case of MPI
neurodamus.utils.multimap¶
A collection of Pure-Python MultiMaps
Classes
|
A Multimap which groups values by key in a list. |
- class neurodamus.utils.multimap.GroupedMultiMap(np_keys, values)¶
A Multimap which groups values by key in a list.
- exists(key)¶
- find(key)¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None.¶
- get_items(key)¶
- items() a set-like object providing a view on D's items¶
- keys() a set-like object providing a view on D's keys¶
- static sort_together(np_keys, values)¶
- values() an object providing a view on D's values¶
neurodamus.utils.progressbar¶
Classes to represent a task’s progress in the form of a progress bar.
Here is some basic usage with the default options:
>>> from progressbar import ProgressBar
>>> p = ProgressBar()
>>> print p
[>............] 0%
>>> p + 1
>>> print p
[=>...........] 10%
>>> p + 9
>>> print p
[============>] 0%
And here another example with different options:
>>> from progressbar import ProgressBar
>>> custom_options = {
... 'end': 100,
... 'width': 20,
... 'fill': '#',
... 'format': '%(progress)s%% [%(fill)s%(blank)s]'
... }
>>> p = ProgressBar(**custom_options)
>>> print p
0% [....................]
>>> p + 5
>>> print p
5% [#...................]
>>> p + 9
>>> print p
100% [####################]
Classes
|
Progress class holds the progress information. |
|
ProgressBar implements a fully visual text-based representation of a progress. |
- class neurodamus.utils.progressbar.Progress(end, start=0, **kw)¶
Progress class holds the progress information.
It can be queried for the current progress, and overloads __repr__ for a simple display. It can be managed manually, via ‘+=’ and -= operators, or automatically by consuming iterables.
- property completion_ratio¶
- classmethod iter(iterable, end=None, start=0, **kw)¶
Consumes (a slice of) an iterable.
- Parameters:
iterable – the iterable to consume and monitor progress
end – The end index. Alternatively None will automatically detect size, while False instructs to not compute size -> spinner
start – in which position to start iterating
- property progress¶
- reset()¶
Resets the current progress to the start point
- property time_taken¶
- class neurodamus.utils.progressbar.ProgressBar(end, start=0, width=60, fill='=', blank='.', stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, clear=None, fmt='[%(fill)s>%(blank)s] %(progress)s', tty_bar=None, name='')¶
ProgressBar implements a fully visual text-based representation of a progress. and may be any file-object to which send the progress status.
- property progress¶
- show_progress()¶
neurodamus.utils.pyutils¶
Collection of generic Python utilities.
Functions
|
Performs binary search in a container, retrieving the index where key should be inserted to keep ordering. |
|
Sanitizes docopt parsed key names |
Classes
|
Base class for configurations. |
Helper class for formatting console text. |
|
|
|
|
Filters a dict and converts the keys according to a given map |
- class neurodamus.utils.pyutils.ConfigT(opt_dict=None, **opts)¶
Base class for configurations.
This class serves as a base for set of configurations. By inheriting and setting several class-level attributes, instances will be able to initialize from kwargs and dictionaries with the same keys, effectively working as validators of fields with default values. Furthermore, for validation of values, the attributes may be Enums.
class RunConfig(ConfigT): # NOTE: Enum fields: the FIRST value is the default mode = Enum("Mode", "BUILD_SIMULATE BUILD_ONLY") model_path = None
- REQUIRED = <neurodamus.utils.pyutils.ConfigT._ConfigFlag object>¶
- property all¶
- as_dict(subset=None, excludes=())¶
- get(*args)¶
- class neurodamus.utils.pyutils.ConsoleColors¶
Helper class for formatting console text.
- BLACK = 30¶
- BLINK = 1024¶
- BLUE = 34¶
- BOLD = 256¶
- CYAN = 36¶
- DEFAULT = 39¶
- DIM = 512¶
- GREEN = 32¶
- HIDDEN = 1536¶
- INVERTED = 1280¶
- MAGENTA = 35¶
- NORMAL = 0¶
- RED = 31¶
- UNDERLINED = 768¶
- WHITE = 37¶
- YELLOW = 33¶
- classmethod format_text(text, color, style=None)¶
- classmethod reset()¶
- exception neurodamus.utils.pyutils.CumulativeError(errors=None)¶
- append(func_name, err)¶
- raise_if_any()¶
- class neurodamus.utils.pyutils.StrEnumBase(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
- classmethod default()¶
- classmethod from_string(s: str)¶
- to_string() str¶
- class neurodamus.utils.pyutils.WeakList(iterable=(), /)¶
- append(item)¶
Append object to the end of the list.
- neurodamus.utils.pyutils.append_recarray(target_array, record)¶
Append a np.record to a np.recarray
- neurodamus.utils.pyutils.bin_search(container, key, keyf=None)¶
Performs binary search in a container, retrieving the index where key should be inserted to keep ordering. Accepts a key function to be applied to each element of the container.
- Parameters:
container – The container to be searched through
key – The key to look for
keyf – (Optional) the function transforming container elements into comparable keys
Returns: The position where the element is to be inserted to keep ordering.
- neurodamus.utils.pyutils.cache_errors(func)¶
Decorator that catches exceptions and appends (func name, exception) to cumulative_error if provided.
- neurodamus.utils.pyutils.dict_filter_map(dic, mapp)¶
Filters a dict and converts the keys according to a given map
- neurodamus.utils.pyutils.docopt_sanitize(docopt_opts)¶
Sanitizes docopt parsed key names
- neurodamus.utils.pyutils.gen_ranges(limit, blocklen, low=0, block_increase_rate=1)¶
Generates ranges in block intervals for a given length block_increase_rate may be >1 in case we want the block to get increasingly large
- neurodamus.utils.pyutils.rmtree(path)¶
Recursively remove a path
Note: shutils.rmtree wouldn’t complete for directories with many files. See: https://github.com/openbraininstitute/neurodamus/pull/247/files/e9d12100b22bf512fdcd624022d9d999cb50db77#r2079776328 # noqa: E501