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 |
|
Class which bring Python map API to hoc Maps |
|
Behavior similar to Hoc Vector |
- class neurodamus.utils.compat.List(iterable=(), /)¶
Behavior similar to Hoc List
- __module__ = 'neurodamus.utils.compat'¶
- __slots__ = ()¶
- count(obj=None)¶
Return number of occurrences of value.
- o(idx)¶
- class neurodamus.utils.compat.Map(wrapped_obj, *args, **kwargs)¶
Class which bring Python map API to hoc Maps
- String¶
- __abstractmethods__ = frozenset({})¶
- __contains__(item)¶
- __getitem__(item)¶
- __init__(hoc_map)¶
- __iter__()¶
- __len__()¶
- __module__ = 'neurodamus.utils.compat'¶
- static __new__(cls, wrapped_obj, *args, **kwargs)¶
If the wrapped entity is not an hoc map, but a Python dict then also wrap it using PyMap for a similar API
- __setitem__(key, value)¶
- __slots__ = ('_hoc_map', '_size', 'String')¶
- as_dict(parse_strings=False)¶
Creates a real dictionary from the Map.
- Parameters:
parse_strings – If true converts string objects in both key and values to real strings (xx.s) and attempts to convert values to float
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- property hoc_map¶
Returns the raw hoc map
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- update(other_map)¶
- values() an object providing a view on D's values ¶
- class neurodamus.utils.compat.PyMap¶
PyMap does basically the reverse of compat.Map: it’s a true dict but capable of getting a hoc map, built on the fly
- __module__ = 'neurodamus.utils.compat'¶
- __slots__ = ()¶
- as_dict(*_, **_kw)¶
- property hoc_map¶
Returns the raw hoc map
- class neurodamus.utils.compat.Vector(type_='I', array=[])¶
Behavior similar to Hoc Vector
- __add__(other)¶
Return self+value.
- __module__ = 'neurodamus.utils.compat'¶
- static __new__(cls, type_='I', array=[])¶
- __slots__ = ()¶
- as_hoc()¶
When API compat is not enough, convert to a true hov Vector
- 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)¶
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. |
|
A memory-efficient map, which accepts duplicates |
- class neurodamus.utils.multimap.GroupedMultiMap(np_keys, values, presorted=False)¶
A Multimap which groups values by key in a list.
- flat_values()¶
- flatten()¶
Transform the current Map to a plain Multimap, without groups.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- get_items(key)¶
An iterator over all the values of a key
- size()¶
Number of entries
- class neurodamus.utils.multimap.MultiMap(np_keys, values, presorted=False)¶
A memory-efficient map, which accepts duplicates
- static concat(v1, v2)¶
- data()¶
- exists(key)¶
- find(key)¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- get_items(key)¶
An iterator over all the values of a 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
- classmethod iteritems(iterable, **kw)¶
- classmethod itervalues(iterable, **kw)¶
- 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. |
|
Creates a generator for filtering elements in a dictionary |
|
Sanitizes docopt parsed key names |
Classes
|
Base class for configurations. |
Helper class for formatting console text. |
|
|
|
|
|
|
Creates a generator for filtering elements in a dictionary |
|
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¶
- apply(obj, subset=None, excludes=(), **overrides)¶
Applies the configuration to one or multiple objects (if tuple)
- as_dict(subset=None, excludes=())¶
- get(*args)¶
- classmethod set_defaults(**opts)¶
- 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()¶
- classmethod set_text_color(color)¶
- 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.
- class neurodamus.utils.pyutils.classproperty(getter)¶
- neurodamus.utils.pyutils.dict_filter(dic, filter)¶
Creates a generator for filtering elements in a dictionary
- 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