10. Block Library Reference

10.1. Submodules

10.2. bifrost.blocks.accumulate module

A simple block that accepts 1 frame at a time and accumulates them nframe times before outputting the accumulated result.

class bifrost.blocks.accumulate.AccumulateBlock(iring, nframe, dtype=None, gulp_nframe=1, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for each input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.accumulate.accumulate(iring, nframe, dtype=None, *args, **kwargs)[source]

Accumulate nframe frames of data, one at a time, before outputting.

bifrost.blocks.accumulate.iring

Input data source.

Type

Ring or Block

bifrost.blocks.accumulate.nframe

Number of frames to accumulate before outputting.

Type

int

bifrost.blocks.accumulate.dtype

Output datatype. If None, input datatype is used.

Type

string

\*args

Arguments to bifrost.pipeline.TransformBlock.

\*\*kwargs

Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics
----------------
bifrost.blocks.accumulate.Input
Type

[…, ‘time’, …], dtype = any, space = CUDA

bifrost.blocks.accumulate.Output
Type

[…, ‘time’/nframe, …], dtype = any, space = CUDA

Returns

Return type

AccumulateBlock

10.3. bifrost.blocks.audio module

10.4. bifrost.blocks.binary_io module

# binary_file_io.py

Basic file I/O blocks for reading and writing data.

class bifrost.blocks.binary_io.BinaryFileRead(filename, gulp_size, dtype)[source]

Bases: object

Simple file-like reading object for pipeline testing

Parameters
  • filename (str) – Name of file to open

  • dtype (np.dtype or str) – datatype of data, e.g. float32. This should be a numpy dtype, not a bifrost.ndarray dtype (eg. float32, not f32)

  • gulp_size (int) – How much data to read per gulp, (i.e. sub-array size)

close()[source]
read()[source]
class bifrost.blocks.binary_io.BinaryFileReadBlock(filenames, gulp_size, gulp_nframe, dtype, *args, **kwargs)[source]

Bases: bifrost.pipeline.SourceBlock

create_reader(filename)[source]

Return an object to use for reading source data

on_data(reader, ospans)[source]

Process data from from ispans to ospans and return the number of frames to commit for each output.

on_sequence(ireader, filename)[source]

Return header for each output

class bifrost.blocks.binary_io.BinaryFileWriteBlock(iring, file_ext='out', *args, **kwargs)[source]

Bases: bifrost.pipeline.SinkBlock

on_data(ispan)[source]

Return nothing

on_sequence(iseq)[source]

Return islice or None to use simple striding

bifrost.blocks.binary_io.binary_read(filenames, gulp_size, gulp_nframe, dtype, *args, **kwargs)[source]

Block for reading binary data from file and streaming it into a bifrost pipeline

Parameters
  • filenames (list) – A list of filenames to open

  • gulp_size (int) – Number of elements in a gulp (i.e. sub-array size)

  • gulp_nframe (int) – Number of frames in a gulp. (Ask Ben / Miles for good explanation)

  • dtype (bifrost dtype string) – dtype, e.g. f32, cf32

bifrost.blocks.binary_io.binary_write(iring, file_ext='out', *args, **kwargs)[source]

Write ring data to a binary file

Parameters

file_ext (str) – Output file extension. Defaults to ‘.out’

Notes

output filename is generated from the header ‘name’ keyword + file_ext

10.5. bifrost.blocks.convert_visibilities module

class bifrost.blocks.convert_visibilities.ConvertVisibilitiesBlock(iring, fmt, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.convert_visibilities.convert_visibilities(iring, fmt, *args, **kwargs)[source]

Convert visibility data to a new format.

Supported values of ‘fmt’ are:

matrix, storage

Parameters
  • iring (Ring or Block) – Input data source.

  • fmt (str) – The desired output format: matrix, storage.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  ['time', 'freq', 'station_i', 'pol_i', 'station_j', 'pol_j'], dtype = any complex, space = CUDA
fmt = 'matrix' (produces a fully-filled matrix from a lower-filled one)
Output: ['time', 'freq', 'station_i', 'pol_i', 'station_j', 'pol_j'], dtype = any complex, space = CUDA
fmt = 'storage' (suitable for common on-disk data formats such as UVFITS, FITS-IDI, MS etc.)
Output: ['time', 'baseline', 'freq', 'stokes'], dtype = any complex, space = CUDA

Input:  ['time', 'baseline', 'freq', 'stokes'], dtype = any complex, space = CUDA
fmt = 'matrix' (fully-filled matrix suitable for linear algebra operations)
Output: ['time', 'freq', 'station_i', 'pol_i', 'station_j', 'pol_j'], dtype = any complex, space = CUDA
Returns

A new block instance.

Return type

ConvertVisibilitiesBlock

10.6. bifrost.blocks.copy module

class bifrost.blocks.copy.CopyBlock(iring, space=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.copy.copy(iring, space=None, *args, **kwargs)[source]

Copy data, possibly to another space.

Use this block to copy data between different

spaces, such as from system memory to GPU memory. The output header for this block is identical to the input header.

Parameters
  • iring (Ring or Block) – Input data source.

  • space (str) – Output data space (e.g., ‘cuda’ or ‘system’). Default space is same as input.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • *kwargs – Keyword arguments to bifrost.pipeline.TransformBlock.

Returns

A new block instance.

Return type

CopyBlock

Tensor semantics:

Input:  [...], dtype = any, space = any
Output: [...], dtype = same as input, space = any

10.7. bifrost.blocks.correlate module

class bifrost.blocks.correlate.CorrelateBlock(iring, nframe_per_integration, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_output_nframes(input_nframe)[source]

Return output nframe, given input_nframes.

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.correlate.correlate(iring, nframe_per_integration, *args, **kwargs)[source]

Cross-multiply different stations and accumulate in time

This is the X step of an FX correlator.

Parameters
  • iring (Ring or Block) – Input data source.

  • nframe_per_integration (int) – No. frames to integrate before producing an output frame of visibilities.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  ['time', 'freq', 'station', 'pol'], dtype = any complex, space = CUDA
Output: ['time', 'freq', 'station_i', 'pol_i', 'station_j', 'pol_j'] (lower triangle filled), dtype = cf32, space = CUDA
Returns

A new block instance.

Return type

CorrelateBlock

References

This block is backed by a fast GPU kernel based on the one in the xGPU library; see 2.

2

M. A. Clark, P. C. La Plante, and L. J. Greenhill, “Accelerating Radio Astronomy Cross-Correlation with Graphics Processing units”, [arXiv:1107.4264 [astro-ph]].

https://github.com/GPU-correlators/xGPU

10.8. bifrost.blocks.detect module

class bifrost.blocks.detect.DetectBlock(iring, mode, axis=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for each input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.detect.detect(iring, mode, axis=None, *args, **kwargs)[source]

Apply square-law detection to create polarization products.

Parameters
  • iring (Ring or Block) – Input data source.

  • mode (string) –

    'scalar': x   -> real x.x*

    'jones':  x,y -> complex x.x* + 1j*y.y*, x.y*

    'stokes': x,y -> real I, Q, U, V

  • axis – Integer or string specifying the polarization axis. Defaults to ‘pol’. Not used if mode = ‘scalar’.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [..., 'pol', ...], dtype = any complex, space = CUDA
Output: [..., 'pol', ...], dtype = real or complex, space = CUDA
Returns

A new block instance.

Return type

DetectBlock

10.9. bifrost.blocks.fdmt module

class bifrost.blocks.fdmt.FdmtBlock(iring, max_dm=None, max_delay=None, max_diagonal=None, exponent=- 2.0, negative_delays=False, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_input_overlap_nframe(iseq)[source]

Return no. input frames that should overlap between successive spans.

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.fdmt.fdmt(iring, max_dm=None, max_delay=None, max_diagonal=None, exponent=- 2.0, negative_delays=False, *args, **kwargs)[source]

Apply the Fast Dispersion Measure Transform (FDMT).

This uses the GPU. It is used in pulsar and fast radio burst (FRB) search pipelines for dedispersing channelised data.

Parameters
  • iring (Ring or Block) – Input data source.

  • max_dm (float) – Max dispersion measure to search up to (in units of pc/cm^3).

  • max_delay (int) – Max dispersion delay across the band to search up to (in units of time samples).

  • max_diagonal (float) – Max dispersion delay across the band to search up to (in units of the number of frequency channels).

  • exponent (float) – Frequency power law to search (-2.0 for interstellar dispersion).

  • negative_delays (bool) – If True, the transform applies dispersions in the range (-max_dm, 0] instead of [0, max_dm).

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  ['pol', 'freq',       'time'], dtype = any real, space = CUDA
Output: ['pol', 'dispersion', 'time'], dtype = f32, space = CUDA
Returns

A new block instance.

Return type

FdmtBlock

References

This is based on Barak Zackay’s FDMT algorithm, see 1.

1

Zackay, Barak, and Eran O. Ofek. “An accurate and efficient algorithm for detection of radio bursts with an unknown dispersion measure, for single dish telescopes and interferometers.” arXiv preprint arXiv:1411.5373 (2014).

Note

Only one of max_dm, max_delay, or max_diagonal may be specified. In the case of max_dm, the number of dispersion measure trials (delays) computed by this algorithm depends on the value of max_dm and the time and frequency scales of the input data. The bifrost.blocks.print_header block can be used to check the output dimensions if needed.

10.10. bifrost.blocks.fft module

class bifrost.blocks.fft.FftBlock(iring, axes, inverse=False, real_output=False, axis_labels=None, apply_fftshift=False, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.fft.fft(iring, axes, inverse=False, real_output=False, axis_labels=None, apply_fftshift=False, *args, **kwargs)[source]

Apply a GPU FFT to the input ring data.

This block produces an N-dimensional FFT of the input data stream. The transform can be over any set of dimensions except the frame (time) dimension. Transforms over the frame dimension can be achieved by first reshaping the input data stream using bifrost.views.split_axis.

Axis scales are automatically updated to reflect the Fourier-transformed axes.

Parameters
  • iring (Ring or Block) – Input data source.

  • axes (list) – List of integers or strings indicating axes to be transformed.

  • inverse (bool) – If True, the inverse Fourier transform is applied.

  • real_output (bool) – If True, a complex-to-real inverse Fourier transform is applied (input data must be complex).

  • axis_labels (list) – A list of strings specifying a new label to give each transformed axis. If None, the output labels are copied from the input labels.

  • apply_fftshift (bool) – If True, the zero-frequency component is shifted to the center of the spectrum. For forward (inverse) transforms, this is equivalent to a positive (negative) cyclic shift of each output (input) axis by floor(axis_length / 2).

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [...], dtype = any real or complex, space = CUDA
Output: [...], dtype = [f32, cf32, f64, or cf64], space = CUDA
Returns

A new block instance.

Return type

FftBlock

10.11. bifrost.blocks.fftshift module

class bifrost.blocks.fftshift.FftShiftBlock(iring, axes, inverse=False, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.fftshift.fftshift(iring, axes, inverse=False, *args, **kwargs)[source]

Apply an FFT shift to data along specified axes.

This operation shifts the data of an array so the central element is moved to the start of the array.

Parameters
  • iring (Ring or Block) – Input data source.

  • axes – (List of) strings or integers specifying axes to shift.

  • inverse (bool) – If True, axes are shifted in the reverse direction.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [...], dtype = any, space = CUDA
Output: [...], dtype = any, space = CUDA
Returns

A new block instance.

Return type

FftShiftBlock

10.12. bifrost.blocks.guppi_raw module

class bifrost.blocks.guppi_raw.GuppiRawSourceBlock(sourcenames, gulp_nframe=1, *args, **kwargs)[source]

Bases: bifrost.pipeline.SourceBlock

create_reader(sourcename)[source]

Return an object to use for reading source data

on_data(reader, ospans)[source]

Process data from from ispans to ospans and return the number of frames to commit for each output.

on_sequence(reader, sourcename)[source]

Return header for each output

bifrost.blocks.guppi_raw.read_guppi_raw(filenames, gulp_nframe=1, *args, **kwargs)[source]

Read in a GUPPI format raw data file.

Parameters
  • filenames (list) – List of strings containing filenames.

  • gulp_nframe (int) – No. frames (aka. blocks) to process at a time.

  • *args – Arguments to bifrost.pipeline.SourceBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.SourceBlock.

Tensor semantics:

Output: ['time', 'freq', 'fine_time', 'pol'], dtype = ci*, space = SYSTEM
Returns

A new block instance.

Return type

GuppiRawSourceBlock

References

https://github.com/UCBerkeleySETI/breakthrough/blob/master/doc/RAW-File-Format.md

10.13. bifrost.blocks.print_header module

class bifrost.blocks.print_header.PrintHeaderBlock(iring, *args, **kwargs)[source]

Bases: bifrost.pipeline.SinkBlock

lock = <unlocked _thread.lock object>
on_data(ispan)[source]

Return nothing

on_sequence(iseq)[source]

Return islice or None to use simple striding

on_sequence_end(iseq)[source]

Do any necessary cleanup

bifrost.blocks.print_header.print_header(iring, *args, **kwargs)[source]

Prints out the header of each new sequence of a ring.

Use this for testing purposes to have a quick look at the contents of a ring when you are unsure. This is done using the simple python print statement, without any modification to the dictionary.

bifrost.blocks.print_header.iring

A derivative of a Block object.

Type

Block

\*args

Arguments to bifrost.pipeline.TransformBlock.

\*\*kwargs

Keyword Arguments to bifrost.pipeline.TransformBlock.

Returns

Return type

PrintHeaderBlock

10.14. bifrost.blocks.psrdada module

10.15. bifrost.blocks.quantize module

class bifrost.blocks.quantize.QuantizeBlock(iring, dtype, scale=1.0, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for each input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.quantize.quantize(iring, dtype, scale=1.0, *args, **kwargs)[source]

Apply a requantization of bit depth for the data.

Parameters
  • iring (Ring or Block) – Input data source.

  • dtype – Output data type or number of bits.

  • scale (float) – Scale factor to apply before quantizing.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [...], dtype = [c]f32, space = SYSTEM
Output: [...], dtype = any (complex) integer type, space = SYSTEM
Returns

A new block instance.

Return type

QuantizeBlock

10.16. bifrost.blocks.reduce module

class bifrost.blocks.reduce.ReduceBlock(iring, axis, factor=None, op='sum', *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_output_nframes(input_nframe)[source]

Return number of frames that will be produced given input_nframe

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.reduce.reduce(iring, axis, factor=None, op='sum', *args, **kwargs)[source]

Reduce data along an axis by factor using op.

Parameters
  • iring (Ring or Block) – Input data source.

  • axis (int or str) – The axis to reduce. Can be an integer index or a string label.

  • factor (int) – The factor by which the axis should be reduced. If None, the whole axis is reduced. Must divide the size of the axis (or the gulp_size in the case where the axis is the frame axis).

  • op (str) – The operation with which the data should be reduced. One of: sum, mean, min, max, stderr [stderr=sum/sqrt(n)], pwrsum [magnitude squared sum], pwrmean, pwrmin, pwrmax, or pwrstderr. Note: min and max are not supported for complex valued data.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [..., N, ...], dtype = float, space = CUDA
op = any
Output: [..., N / factor, ...], dtype = f32, space = CUDA

Input:  [..., N, ...], dtype = complex, space = CUDA
op = 'sum', 'mean', 'stderr'
Output: [..., N / factor, ...], dtype = cf32, space = CUDA

Input:  [..., N, ...], dtype = complex, space = CUDA
op = 'pwrsum', 'pwrmean', 'pwrmin', 'pwrmax', 'pwrstderr'
Output: [..., N / factor, ...], dtype = f32, space = CUDA
Returns

A new block instance.

Return type

ReduceBlock

10.17. bifrost.blocks.reverse module

class bifrost.blocks.reverse.ReverseBlock(iring, axes, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for the input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.reverse.reverse(iring, axes, *args, **kwargs)[source]

Reverse data along an axis or set of axes.

Parameters
  • iring (Ring or Block) – Input data source.

  • axes – (List of) strings or integers specifying axes to reverse.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [...], dtype = any, space = CUDA
Output: [...], dtype = any, space = CUDA
Returns

A new block instance.

Return type

ReverseBlock

10.18. bifrost.blocks.scrunch module

class bifrost.blocks.scrunch.ScrunchBlock(iring, factor, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_output_nframes(input_nframe)[source]

Return output nframe for each output, given input_nframes.

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for each input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.scrunch.scrunch(iring, factor, *args, **kwargs)[source]

Average factor incoming frames into one output frame.

This works on system memory.

bifrost.blocks.scrunch.iring

A derivative of a Block object.

Type

Block

bifrost.blocks.scrunch.factor

The number of input frames to accumulate.

Type

int

\*args

Arguments to bifrost.pipeline.TransformBlock.

\*\*kwargs

Keyword Arguments to bifrost.pipeline.TransformBlock.

Returns

Return type

ScrunchBlock

10.19. bifrost.blocks.serialize module

class bifrost.blocks.serialize.BifrostReader(basename)[source]

Bases: object

readinto(buf, frame_nbyte)[source]
class bifrost.blocks.serialize.DeserializeBlock(filenames, gulp_nframe, *args, **kwargs)[source]

Bases: bifrost.pipeline.SourceBlock

create_reader(sourcename)[source]

Return an object to use for reading source data

on_data(reader, ospans)[source]

Process data from from ispans to ospans and return the number of frames to commit for each output.

on_sequence(ireader, sourcename)[source]

Return header for each output

class bifrost.blocks.serialize.SerializeBlock(iring, path, max_file_size=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.SinkBlock

on_data(ispan)[source]

Return nothing

on_sequence(iseq)[source]

Return islice or None to use simple striding

on_sequence_end(iseq)[source]

Do any necessary cleanup

bifrost.blocks.serialize.deserialize(filenames, gulp_nframe, *args, **kwargs)[source]

Deserializes a data stream from a set of files using a simple data format

Sequence headers are read as JSON files, and sequence data are read directly as binary from separate files.

The actual header and data files must have the following general form:

# Header
<filename>.json

# Single-ringlet data
<filename>.<frame_offset>.dat

# Multi-ringlet data
<filename>.<frame_offset>.<ringlet>.dat

See also: serialize

Parameters
  • filenames (list) – List of input filenames (each ending with ‘.bf’)

  • gulp_nframe (int) – No. frames to read at a time.

  • *args – Arguments to bifrost.pipeline.SourceBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.SourceBlock.

Tensor semantics:

Input:  One data file per sequence
Output: [frame, ...], dtype = any, space = SYSTEM

Input:  One data file per ringlet
Output: [ringlet, frame, ...], dtype = any, space = SYSTEM
Returns

A new block instance.

Return type

DeserializeBlock

bifrost.blocks.serialize.serialize(iring, path=None, max_file_size=None, *args, **kwargs)[source]

Serializes a data stream to a set of files using a simple data format

Sequence headers are written as JSON files, and sequence data are written directly as binary to separate files.

Filenames begin with the sequence name if present, or the time tag if not. The general form is:

# Header
<name_or_time_tag>.bf.json

# Single-ringlet data
<name_or_time_tag>.bf.<frame_offset>.dat

# Multi-ringlet data
<name_or_time_tag>.bf.<frame_offset>.<ringlet>.dat
Parameters
  • iring (Ring or Block) – Input data source.o

  • path (str) – Path specifying where to write output files.

  • max_file_size (int) – Max no. bytes to write to a single file. If set to -1, no limit is applied.

  • *args – Arguments to bifrost.pipeline.SinkBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.SinkBlock.

Tensor semantics:

Input:  [frame, ...], dtype = any, space = SYSTEM
Output: One data file per sequence

Input:  [ringlet, frame, ...], dtype = any, space = SYSTEM
Output: One data file per ringlet
Returns

A new block instance.

Return type

SerializeBlock

10.20. bifrost.blocks.sigproc module

class bifrost.blocks.sigproc.SigprocSinkBlock(iring, path=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.SinkBlock

on_data(ispan)[source]

Return nothing

on_sequence(iseq)[source]

Return islice or None to use simple striding

on_sequence_end(iseq)[source]

Do any necessary cleanup

class bifrost.blocks.sigproc.SigprocSourceBlock(filenames, gulp_nframe, unpack=True, *args, **kwargs)[source]

Bases: bifrost.pipeline.SourceBlock

create_reader(sourcename)[source]

Return an object to use for reading source data

on_data(reader, ospans)[source]

Process data from from ispans to ospans and return the number of frames to commit for each output.

on_sequence(ireader, sourcename)[source]

Return header for each output

bifrost.blocks.sigproc.read_sigproc(filenames, gulp_nframe, unpack=True, *args, **kwargs)[source]

Read SIGPROC data files.

Capable of reading filterbank, time series, and dedispersed subband data.

Parameters
  • filenames (list) – List of input filenames.

  • gulp_nframe (int) – No. frames to read at a time.

  • unpack (bool) – If True, 1-4 bit data are unpacked to 8 bits.

  • *args – Arguments to bifrost.pipeline.SourceBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.SourceBlock.

Tensor semantics:

Output: ['time', 'pol', 'freq'], dtype = u/i*, space = SYSTEM
Returns

A new block instance.

Return type

SigprocSourceBlock

bifrost.blocks.sigproc.write_sigproc(iring, path=None, *args, **kwargs)[source]

Write data as Sigproc files.

Parameters
  • iring (Ring or Block) – Input data source.

  • path (str) – Path specifying where to write output files.

  • *args – Arguments to bifrost.pipeline.SinkBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.SinkBlock.

Tensor semantics:

Input:  [time, pol, freq], dtype = any, space = SYSTEM
Output: Filterbank, one file per sequence

Input:  [beam, time, pol, freq], dtype = any, space = SYSTEM
Output: Filterbank, one file per beam

Input:  [time, pol], dtype = any, space = SYSTEM
Output: Time series, one file per sequence

Input:  [dispersion, time, pol], dtype = any, space = SYSTEM
Output: Time series, one file per dispersion measure trial

Input:  [pol, freq, phase], dtype = any, space = SYSTEM
Output: Pulse profile, one file per frame
Returns

A new block instance.

Return type

SigprocSinkBlock

10.21. bifrost.blocks.transpose module

class bifrost.blocks.transpose.TransposeBlock(iring, axes, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.transpose.transpose(iring, axes, *args, **kwargs)[source]

Transpose (permute) axes of the data.

Parameters
  • iring (Ring or Block) – Input data source.

  • axes (list) – List of integers or strings indicating order of output axes.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [...], dtype = any , space = SYSTEM or CUDA
Output: [axes[...]], dtype = same as input, space = same as input
Returns

A new block instance.

Return type

TransposeBlock

10.22. bifrost.blocks.unpack module

class bifrost.blocks.unpack.UnpackBlock(iring, dtype, align_msb=False, *args, **kwargs)[source]

Bases: bifrost.pipeline.TransformBlock

define_valid_input_spaces()[source]

Return set of valid spaces (or ‘any’) for each input

on_data(ispan, ospan)[source]

Return the number of output frames to commit, or None to commit all

on_sequence(iseq)[source]

Return oheader

bifrost.blocks.unpack.unpack(iring, dtype, *args, **kwargs)[source]

Unpack data to a larger data type.

Parameters
  • iring (Ring or Block) – Input data source.

  • dtype – Output data type.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input:  [...], dtype = one of: i/u2, i/u4, ci2, ci4, space = SYSTEM
Output: [...], dtype = i8 or ci8 (matching input), space = SYSTEM
Returns

A new block instance.

Return type

UnpackBlock

10.23. bifrost.blocks.wav module

class bifrost.blocks.wav.WavSinkBlock(iring, path=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.SinkBlock

on_data(ispan)[source]

Return nothing

on_sequence(iseq)[source]

Return islice or None to use simple striding

on_sequence_end(iseq)[source]

Do any necessary cleanup

class bifrost.blocks.wav.WavSourceBlock(sourcenames, gulp_nframe, space=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.SourceBlock

create_reader(sourcename)[source]

Return an object to use for reading source data

on_data(reader, ospans)[source]

Process data from from ispans to ospans and return the number of frames to commit for each output.

on_sequence(reader, sourcename)[source]

Return header for each output

bifrost.blocks.wav.read_wav(sourcefiles, gulp_nframe, *args, **kwargs)[source]

Read Wave files (.wav).

Parameters
  • sourcefiles (list) – List of input filenames.

  • gulp_nframe (int) – No. frames to read at a time.

  • *args – Arguments to bifrost.pipeline.SourceBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.SourceBlock.

Tensor semantics:

Output: ['time', 'pol'], dtype = u8 or i*, space = SYSTEM
Returns

A new block instance.

Return type

WavSourceBlock

bifrost.blocks.wav.wav_read_chunk_desc(f)[source]
bifrost.blocks.wav.wav_read_header(f)[source]
bifrost.blocks.wav.wav_read_subchunk_desc(f)[source]
bifrost.blocks.wav.wav_read_subchunk_fmt(f, size)[source]
bifrost.blocks.wav.wav_write_header(f, hdr, chunk_size=0, data_size=0)[source]
bifrost.blocks.wav.write_wav(iring, path=None, *args, **kwargs)[source]

Write data as Wave files (.wav).

Parameters
  • iring (Ring or Block) – Input data source.

  • path (str) – Path specifying where to write output files.

  • *args – Arguments to bifrost.pipeline.TransformBlock.

  • **kwargs – Keyword Arguments to bifrost.pipeline.TransformBlock.

Tensor semantics:

Input: [time, pol], dtype = u8 or i*, space = SYSTEM
Output: Wave file, one file per sequence

Input: [batch, time, pol], dtype = u8 or i*, space = SYSTEM
Output: Wave file, one file per batch element
Returns

A new block instance.

Return type

WavSinkBlock

Note

The chunk_size and data_size entries in the output wav header are written as zero values because they are not known a-priori in a streaming setting. VLC still plays the files just fine, but any subchunks that appear after the data will be misinterpreted as data.

10.24. Module contents