Block Library

class reip.blocks.misc.Iterator(iterator, **kw)[source]

Yield each element in an iterator one at a time.

process(meta=None)[source]

Process data.

class reip.blocks.misc.Interval(seconds=2, initial=None, **kw)[source]

Emit every X seconds.

init()[source]

Initialize the block.

process(meta=None)[source]

Process data.

class reip.blocks.misc.Time(**kw)[source]

Add system time to metadata.

process(x, meta)[source]

Process data.

class reip.blocks.misc.Meta(meta, **kw)[source]

Add arbitrary data to metadata.

process(x, meta=None)[source]

Process data.

class reip.blocks.misc.Glob(*paths, recursive=True, atonce=False, **kw)[source]

Outputs files matching glob patterns.

init()[source]

Initialize the block.

process(meta=None)[source]

Process data.

class reip.blocks.misc.AsDict(*columns, prepare=<function AsDict.<lambda>>, meta=None, **kw)[source]

Merge block outputs into a dict.

process(*xs, meta=None)[source]

Process data.

class reip.blocks.misc.Constant(value, *a, **kw)[source]

Yields a constant value.

process(meta)[source]

Process data.

class reip.blocks.misc.Increment(start=None, stop=None, step=1, **kw)[source]

Yield an incrementing (or decrementing) value.

class reip.blocks.misc.Debug(message=None, level=None, convert=None, value=False, compact=False, summary=False, period=None, name=None, border=False, log_level=None, **kw)[source]

Debug the output of a block.

process(*xs, meta=None)[source]

Process data.

class reip.blocks.misc.Results(squeeze=True, **kw)[source]

Gather the results in lists as self.results and self.meta

init()[source]

Initialize the block.

process(*xs, meta=None)[source]

Process data.

class reip.blocks.misc.Lambda(func=None, name=None, init=None, finish=None, n_inputs=None, **kw)[source]

An inline way to create a block from a regular function. Input and output formats are the same.

init()[source]

Initialize the block.

process(*xs, meta=None)[source]

Process data.

finish()[source]

Cleanup.

class reip.blocks.misc.Interleave(sort_key=None, **kw)[source]

Interleave the block inputs to a single output.

process(*xs, meta=None)[source]

Process data.

class reip.blocks.misc.Separate(bins, **kw)[source]

Separate out a single input into multiple outputs based on a condition per output.

process(x, meta=None)[source]

Process data.

class reip.blocks.misc.Gather(size=None, reduce=None, squeeze=True, **kw)[source]
init()[source]

Initialize the block.

process(*xs, meta=None)[source]

Process data.

finish()[source]

Cleanup.

Buffering

class reip.blocks.buffer.Rebuffer(size=None, duration=None, *a, sr_key='sr', **kw)[source]

Collect numpy arrays and convert them to a different resolution

init()[source]

Initialize the block.

process(x, meta)[source]

Process data.

class reip.blocks.buffer.FastRebuffer(size=None, **kw)[source]
init()[source]

Initialize the block.

process(x, meta)[source]

Process data.

class reip.blocks.buffer.GatedRebuffer(sampler, size=10, **kw)[source]

Rebuffer while also sampling sparsely in time. For example, sampling audio files while leaving gaps between them for privacy reasons.

init()[source]

Initialize the block.

finish()[source]

Cleanup.

process(x, meta)[source]

Process data.

reip.blocks.buffer.temporal_coverage(clip_duration=10, coverage=0.5, min_silence=5.0, sampling='normal')[source]

Given a clip_duration and desired coverage fraction, compute how long the silence between clips needs to be to satisfy the desired coverage and add some random variance to the silence based so that it gives values sampled from the distribution specified by sampling.

Parameters
  • clip_duration (float) – Duration of non-silent clip in seconds

  • coverage (float) – Fraction of time to be recorded (non-silence), must be in range (0,1].

  • min_silence (float) – Minimum silence allowed between clips, in seconds

  • sampling (str) – The distribution from which silence durations will be sampled, must be ‘uniform’ or ‘normal’.

Returns

The amount of silence to insert between the current

and next clip, in seconds.

Return type

silence (float)

Shell

class reip.blocks.shell.Shell(cmd, astype=<class 'str'>, **kw)[source]

Run a shell command on the input data. See reip.util.shell.run() for information about command formatting.

process(*xs, meta)[source]

Process data.

class reip.blocks.shell.ShellProcess(cmd, **kw)[source]

Spawn a shell process while this block is running. There is currently no support for passing data to and from the process, but their outputs are available via self.stdout and self.stderr.

init()[source]

Initialize the block.

finish()[source]

Cleanup.

File Watching

File System Events

Watchdog API Reference: https://pythonhosted.org/watchdog/api.html

Note

from experience, I’ve found file watchers can be a bit unreliable - (potentially due to my own misuse !).

Additionally, many times (for example file upload) watching file events may not actually be what you want, and you may be better off polling file lists using glob as that will reduce the number of missed files and is resilient to reboots.

class reip.blocks.os_watch.Watch(*patterns, path='./', event_types=None, recursive=False, **kw)[source]

A Generic File Watcher

init()[source]

Initialize the block.

process(meta)[source]

Process data.

finish()[source]

Cleanup.

class reip.blocks.os_watch.Created(*patterns, path='./', event_types=None, recursive=False, **kw)[source]

Outputs any created files.

class reip.blocks.os_watch.Modified(*patterns, path='./', event_types=None, recursive=False, **kw)[source]

Outputs any modified files.

class reip.blocks.os_watch.Deleted(*patterns, path='./', event_types=None, recursive=False, **kw)[source]

Outputs any deleted files.

class reip.blocks.os_watch.Moved(*patterns, path='./', event_types=None, recursive=False, **kw)[source]

Outputs any moved files.

File Postprocessing

class reip.blocks.archive.Tar(filename='{time}.tar', remove_files=False, gz=None, **kw)[source]

Archive files in a .tar file.

process(*files, meta)[source]

Process data.

class reip.blocks.archive.TarGz(filename='{time}.tgz', **kw)[source]
class reip.blocks.encrypt.TwoStageEncrypt(filename, rsa_key, remove_files=False, extra_files=None, is_rsa_key_file=True, **kw)[source]

Encrypt a file with a fresh generated key, then encrypt the key with the root key. Then tar the encrypted file and the encrypted key together.

process(file, meta)[source]

Encrypt file with AES 4096. :param file: name of the file to be encrypted :param path: Location to save encrypted file :param default: current dir

class reip.blocks.encrypt.TwoStageDecrypt(filename, rsa_key, remove_files=False, **kw)[source]

Decrypt a file encrypted with TwoStepEncryptFile.

process(file, meta=None)[source]

Process data.

decrypt(msg, enc_key)[source]

Decrypt file with AES 4096.

Audio

Video

class reip.blocks.video.core.Video(index=None, file=None, fps=30, size=None, **kw)[source]
init()[source]

Initialize the block.

process(x=None, meta=None)[source]

Process data.

finish()[source]

Cleanup.

class reip.blocks.video.core.VideoWriter(filename, **kw)[source]
init()[source]

Initialize the block.

process(X, meta)[source]

Process data.

finish()[source]

Cleanup.

class reip.blocks.video.effects.OpticalFlow(pyr_scale=0.5, levels=3, winsize=15, iterations=3, poly_n=5, poly_sigma=1.2, flags=0, resize=(256, 256), draw_mag_scale=10, draw=None, **kw)[source]

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_video/py_lucas_kanade/py_lucas_kanade.html#dense-optical-flow-in-opencv

init()[source]

Initialize the block.

process(frame, meta)[source]

Process data.

Video Machine Learning

Machine Learning

Disk Monitor

class reip.blocks.diskmonitor.DiskMonitor(root='/', deleter=None, threshold=0.95, padding=0.1, interval=60, **kw)[source]

Monitors the disk usage in a certain directory and will selectively delete files from that directory.

# define the file deleter

@B.diskmonitor.Diskmonitor.deleter
def Diskmon(block, offset=1, skip=3, chunksize=5):
    # select some subset of the files
    files = block.get_files('audio')[offset::skip]
    # randomly delete files in chunks of 5 until
    # under the desired storage limit
    block.delete_while_full(files, chunksize)

# instantiate the block
with reip.Graph():
    Diskmon('/data')
process(*files, meta)[source]

Process data.

Dummy

class reip.blocks.dummy.Array(shape, **kw)[source]
init()[source]

Initialize the block.

process(meta)[source]

Process data.

finish()[source]

Cleanup.

reip.blocks.dummy.SomeArray

alias of reip.blocks.dummy.Array

class reip.blocks.dummy.Op(offset=0, **kw)[source]
process(*data, meta=None)[source]

Process data.

reip.blocks.dummy.SomeTransform

alias of reip.blocks.dummy.Op

class reip.blocks.dummy.TimeBomb(t_minus=5, min_rate=0.001, **kw)[source]
init()[source]

Initialize the block.

process(*xs, meta)[source]

Process data.

class reip.blocks.dummy.TextFile(content, fname=None, **kw)[source]
process(*xs, meta)[source]

Process data.