neuroglancer_scripts.utils module¶
Miscellaneous utility functions.
- neuroglancer_scripts.utils.LENGTH_UNITS = {'km': 1e-12, 'm': 1e-09, 'mm': 1e-06, 'nm': 1.0, 'pm': 1000.0, 'um': 0.001}¶
List of physical units of length.
- neuroglancer_scripts.utils.ceil_div(a, b)[source]¶
Ceil integer division (
ceil(a / b)using integer arithmetic).
- neuroglancer_scripts.utils.format_length(length_nm, unit)[source]¶
Format a length according to the provided unit (input in nanometres).
- neuroglancer_scripts.utils.invert_permutation(p)[source]¶
Invert a permutation.
- Parameters:
p – a permutation (sequence of integers between
0andlen(p) - 1)- Returns:
an array
s, wheres[i]gives the index ofiinp- Return type:
- neuroglancer_scripts.utils.permute(seq, p)[source]¶
Permute the elements of a sequence according to a permutation.
- Parameters:
seq – a sequence to be permuted
p – a permutation (sequence of integers between
0andlen(seq) - 1)
- Returns:
tuple(seq[i] for i in p)- Return type:
- neuroglancer_scripts.utils.readable_count(count)[source]¶
Format a number to a human-readable string with an IEC binary prefix.
The resulting string has a minimum of 2 significant digits. It is never longer than 6 characters, unless the input exceeds 2**60. You are expected to concatenate the result with the relevant unit (e.g. B for bytes):
>>> readable_count(512) + "B" '512 B' >>> readable_count(1e10) + "B" '9.3 GiB'