pyloggrid.Libs.misc
Misc small libraries that help with various tasks, too small to fit in their own library file
Module Contents
Classes
Keep track of elapsed time. Supports nesting. |
Functions
|
Compose several decorators into one. |
|
Convert n bytes into a human readable string based on format. |
|
Pad a 2D+ array with zeros. |
- composed_decs(*decs)
Compose several decorators into one.
Example
@composed(dec_1, dec_2) def f(...)
is equivalent to
@dec_1 @dec_2 def f(...)
- bytes2human(n, format_='%(value).1f %(symbol)s', symbols='customary')
Convert n bytes into a human readable string based on format. symbols can be either “customary”, “customary_ext”, “iec” or “iec_ext”, see: https://goo.gl/kTQMs
Example
> bytes2human(0) '0.0 B' > bytes2human(0.9) '0.0 B' > bytes2human(1) '1.0 B' > bytes2human(1.9) '1.0 B' > bytes2human(1024) '1.0 K' > bytes2human(1048576) '1.0 M' > bytes2human(1099511627776127398123789121) '909.5 Y' > bytes2human(9856, symbols="customary") '9.6 K' > bytes2human(9856, symbols="customary_ext") '9.6 kilo' > bytes2human(9856, symbols="iec") '9.6 Ki' > bytes2human(9856, symbols="iec_ext") '9.6 kibi' > bytes2human(10000, "%(value).1f %(symbol)s/sec") '9.8 K/sec' > # precision can be adjusted by playing with %f operator > bytes2human(10000, format_="%(value).5f %(symbol)s") '9.76562 K'
- class TimeTracker(initdict: dict = None)
Keep track of elapsed time. Supports nesting.
How to use:
to start a timer, use
timer.start_timer(key)wherekeyis a unique identifierto stop a timer and add the elapsed time to the total for the key, use
timer.stop_timer(key)to stop and immediately restart (used for storing the current value) a timer use
timer.tick_timer(key)
Wherever possible, prefer wrapping you code in a with block:
with timer(key): ...
- __enter__()
- __exit__(*args)
- __repr__()
Return repr(self).
- rightpad_array_2D(a: pyloggrid.Libs.singlethread_numpy.np.ndarray, Nx: int, Ny: int) pyloggrid.Libs.singlethread_numpy.np.ndarray
Pad a 2D+ array with zeros.
The padding is done at the large coordinate edge (it is not centered).
- Parameters:
a – array to pad
Nx – amount of pixels to pad in first dimension
Ny – amount of pixels to pad in second dimension