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]¶
- 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.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)
- class bifrost.blocks.binary_io.BinaryFileReadBlock(filenames, gulp_size, gulp_nframe, dtype, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SourceBlock
- class bifrost.blocks.binary_io.BinaryFileWriteBlock(iring, file_ext='out', *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SinkBlock
- 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
10.5. bifrost.blocks.convert_visibilities module¶
- class bifrost.blocks.convert_visibilities.ConvertVisibilitiesBlock(iring, fmt, *args, **kwargs)[source]¶
- 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
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
10.6. bifrost.blocks.copy module¶
- 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
- Returns
A new block instance.
- Return type
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]¶
- 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
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
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]].
10.8. bifrost.blocks.detect module¶
- bifrost.blocks.detect.detect(iring, mode, axis=None, *args, **kwargs)[source]¶
Apply square-law detection to create polarization products.
- Parameters
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
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]¶
- 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
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
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 ofmax_dm
and the time and frequency scales of the input data. Thebifrost.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]¶
- 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
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
10.11. bifrost.blocks.fftshift module¶
- 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
Tensor semantics:
Input: [...], dtype = any, space = CUDA Output: [...], dtype = any, space = CUDA
- Returns
A new block instance.
- Return type
10.12. bifrost.blocks.guppi_raw module¶
- class bifrost.blocks.guppi_raw.GuppiRawSourceBlock(sourcenames, gulp_nframe=1, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SourceBlock
- 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
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>¶
- 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.
- \*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¶
- bifrost.blocks.quantize.quantize(iring, dtype, scale=1.0, *args, **kwargs)[source]¶
Apply a requantization of bit depth for the data.
- Parameters
Tensor semantics:
Input: [...], dtype = [c]f32, space = SYSTEM Output: [...], dtype = any (complex) integer type, space = SYSTEM
- Returns
A new block instance.
- Return type
10.16. bifrost.blocks.reduce module¶
- class bifrost.blocks.reduce.ReduceBlock(iring, axis, factor=None, op='sum', *args, **kwargs)[source]¶
- bifrost.blocks.reduce.reduce(iring, axis, factor=None, op='sum', *args, **kwargs)[source]¶
Reduce data along an axis by factor using op.
- Parameters
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
10.17. bifrost.blocks.reverse module¶
10.18. bifrost.blocks.scrunch module¶
- class bifrost.blocks.scrunch.ScrunchBlock(iring, factor, *args, **kwargs)[source]¶
- 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.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.DeserializeBlock(filenames, gulp_nframe, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SourceBlock
- class bifrost.blocks.serialize.SerializeBlock(iring, path, max_file_size=None, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SinkBlock
- 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
- 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
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
10.20. bifrost.blocks.sigproc module¶
- class bifrost.blocks.sigproc.SigprocSinkBlock(iring, path=None, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SinkBlock
- class bifrost.blocks.sigproc.SigprocSourceBlock(filenames, gulp_nframe, unpack=True, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SourceBlock
- 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
- bifrost.blocks.sigproc.write_sigproc(iring, path=None, *args, **kwargs)[source]¶
Write data as Sigproc files.
- Parameters
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
10.21. bifrost.blocks.transpose module¶
10.22. bifrost.blocks.unpack module¶
- bifrost.blocks.unpack.unpack(iring, dtype, *args, **kwargs)[source]¶
Unpack data to a larger data type.
- Parameters
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
10.23. bifrost.blocks.wav module¶
- class bifrost.blocks.wav.WavSinkBlock(iring, path=None, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SinkBlock
- class bifrost.blocks.wav.WavSourceBlock(sourcenames, gulp_nframe, space=None, *args, **kwargs)[source]¶
Bases:
bifrost.pipeline.SourceBlock
- 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
- bifrost.blocks.wav.write_wav(iring, path=None, *args, **kwargs)[source]¶
Write data as Wave files (.wav).
- Parameters
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
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.