11. Python Reference

11.2. Submodules

11.3. bifrost.DataType module

i: signed integer u: unsigned integer f: floating point ci: complex signed integer cf: complex floating pointer

i4: 4-bit signed integer f16: 16-bit floating point ci4: 4+4-bit complex signed integer cf32: 32+32-bit complex floating point

class bifrost.DataType.DataType(t=None)[source]

Bases: object

as_BFdtype()[source]
as_complex()[source]
as_floating_point()[source]

Returns the smallest floating-point type that can represent all values that self can.

as_integer(nbit=None)[source]
as_nbit(nbit)[source]
as_numpy_dtype()[source]
as_real()[source]
as_vector(veclen)[source]
is_complex
is_floating_point
is_integer
is_real
is_signed
itemsize
itemsize_bits
bifrost.DataType.is_vector_structure(dtype)[source]

11.4. bifrost.GPUArray module

11.5. bifrost.Space module

class bifrost.Space.Space(s)[source]

Bases: object

as_BFspace()[source]

11.6. bifrost.address module

class bifrost.address.Address(address, port, family=None)[source]

Bases: bifrost.libbifrost.BifrostObject

address
family
mtu
port

11.7. bifrost.affinity module

bifrost.affinity.get_core()[source]
bifrost.affinity.set_core(core)[source]
bifrost.affinity.set_openmp_cores(cores)[source]

11.8. bifrost.block module

@package block This file defines a generic block class.

Right now the only possible block type is one of a simple transform which works on a span by span basis.

class bifrost.block.CopyBlock(gulp_size=1048576)[source]

Bases: bifrost.block.TransformBlock

Copies input ring’s data to the output ring

main(input_rings, output_rings)[source]

Iterate through first ring, copying to each output ring

class bifrost.block.DedisperseBlock(ring, core=-1, gulp_size=4096)[source]

Bases: object

This block calculates the dedispersion of sigproc-formatted data in a ring, and tags it in the headers

dedisperse()[source]

Dedisperse on input ring, tagging the output ring. This dedispersion algorithm simply adjusts the start time for each channel in the header.

main()[source]

Initiate the block’s processing

class bifrost.block.FFTBlock(gulp_size)[source]

Bases: bifrost.block.TransformBlock

Performs complex to complex 1D FFT on input ring data

load_settings(input_header)[source]
main(input_rings, output_rings)[source]
@param[in] input_rings First ring in this list will be used for
data
@param[out] output_rings First ring in this list will be used for
data output.
class bifrost.block.FoldBlock(bins, period=0.001, gulp_size=1048576, dispersion_measure=0, core=-1)[source]

Bases: bifrost.block.TransformBlock

This block folds a signal into a histogram

calculate_bin_indices(tstart, tsamp, data_size)[source]
Calculate the bin that each time sample should be
added to

@param[in] tstart Time of the first element (s) @param[in] tsamp Difference between the times of

consecutive elements (s)

@param[in] data_size Number of elements @return Which bin each sample is folded into

calculate_delay(frequency, reference_frequency)[source]

Calculate the time delay because of frequency dispersion @param[in] frequency The current channel’s frequency(MHz) @param[in] reference_frequency The frequency of the

channel we will hold at zero time delay(MHz)
load_settings(input_header)[source]
main(input_rings, output_rings)[source]

Generate a histogram from the input ring data @param[in] input_rings List with first ring containing

data of interest. Must terminate before histogram is generated.
@param[out] output_rings First ring in this list
will contain the output histogram
class bifrost.block.IFFTBlock(gulp_size)[source]

Bases: bifrost.block.TransformBlock

Performs complex to complex 1D IFFT on input ring data

load_settings(input_header)[source]
main(input_rings, output_rings)[source]
@param[in] input_rings First ring in this list will be used for
data input.
@param[out] output_rings First ring in this list will be used for
data output.
class bifrost.block.KurtosisBlock(gulp_size=1048576, core=-1)[source]

Bases: bifrost.block.TransformBlock

This block performs spectral kurtosis and cleaning on sigproc-formatted data in rings

load_settings(input_header)[source]
main(input_rings, output_rings)[source]

Calls a kurtosis algorithm and uses the result to clean the input data of RFI, and move it to the output ring.

class bifrost.block.MultiAddBlock(*args, **kwargs)[source]

Bases: bifrost.block.MultiTransformBlock

Block which adds two input rings

main()[source]

Iterate through the inputs, and add them to the output

ring_names = {‘out_sum’: ‘Result of add. List of floats.’, ‘in_1’: ‘First input to add. List of floats’, ‘in_2’: ‘Second input to add. List of floats’}
class bifrost.block.MultiTransformBlock[source]

Bases: object

Defines functions and attributes for a block with multi input/output

flatten(*args)[source]

Flatten a nested tuple/list of tuples/lists

izip(*iterables)[source]

Iterate through multpile iterators This differs from itertools in that this izip combines list generators into a single list generator

load_settings()[source]

Set by user to interpret input rings

read(*args)[source]

Iterate over selection of input rings

write(*args)[source]

Iterate over selection of output rings

class bifrost.block.NumpyBlock(function, inputs=1, outputs=1)[source]

Bases: bifrost.block.MultiTransformBlock

Perform an arbitrary N ndarray -> M ndarray numpy function Inside of a pipeline. This block will calculate all of the necessary information for Bifrost based on the passed function.

calculate_output_headers(out_arrays)[source]

Generate headers based on numpy arrays @param[in] out_arrays The arrays to measure

create_ring_names()[source]

Generate dummy ring descriptions

did_header_change(old_header)[source]

See if the new headers are different @param[in] old_header The previous headers

load_settings()[source]

Generate empty arrays based on input headers.

main()[source]

Call self.function on all of the input spans

reshape_inspans(inspans)[source]

Fit the input spans to their headers @param[in] inspans The input spans.

class bifrost.block.NumpySourceBlock(generator, outputs=1, grab_headers=False, changing=True)[source]

Bases: bifrost.block.MultiTransformBlock

Simulate an incoming stream of data on a ring using an arbitrary generator. This block will calculate all of the necessary information for Bifrost based on the passed function.

calculate_output_settings(arrays)[source]

Calculate the outgoing header settings based on the output arrays @param[in] arrays The arrays outputted by self.generator

load_user_headers(headers, arrays)[source]

Load in user defined headers @param[in] headers List of dictionaries from self.generator

for each ring’s sequence header
main()[source]

Call self.generator and output the arrays into the output

class bifrost.block.Pipeline(blocks)[source]

Bases: object

Class which connects blocks linearly, with one ring between each block. Does this by creating one ring for each input/output ‘port’ of each block, and running data through the rings.

main()[source]

Start the pipeline, and finish when all threads exit

unique_ring_names()[source]

Return a list of unique ring indices

class bifrost.block.SigprocReadBlock(filename, gulp_nframe=4096, core=-1)[source]

Bases: bifrost.block.SourceBlock

This block reads in a sigproc filterbank (.fil) file into a ring buffer

main(output_ring)[source]

Read in the sigproc file to output_ring @param[in] output_ring Ring to write to

class bifrost.block.SinkBlock(gulp_size=4096)[source]

Bases: object

Defines the structure for a sink block

iterate_ring_read(input_ring)[source]

Iterate through one input ring @param[in] input_ring Ring to read through

load_settings(input_header)[source]

Load in settings from input ring header

class bifrost.block.SourceBlock(gulp_size=4096)[source]

Bases: object

Defines the structure for a source block

iterate_ring_write(output_ring, sequence_name=’‘, sequence_time_tag=0)[source]

Iterate over output ring @param[in] output_ring Ring to write to @param[in] sequence_name Name to label sequence @param[in] sequence_time_tag Time tag to label sequence

class bifrost.block.SplitterBlock(sections)[source]

Bases: bifrost.block.MultiTransformBlock

Block which splits up a ring into two

load_settings()[source]

Set the gulp sizes appropriate to the input ring

main()[source]

Split the incoming ring into the outputs rings

ring_names = {‘out_1’: ‘Gets first share of the ring. List of floats’, ‘out_2’: ‘Gets second share of the ring. List of floats’, ‘in’: ‘Input to split. List of floats’}
class bifrost.block.TestingBlock(test_array, complex_numbers=False)[source]

Bases: bifrost.block.SourceBlock

Block for debugging purposes. Allows you to pass arbitrary N-dimensional arrays in initialization, which will be outputted into a ring buffer

main(output_ring)[source]

Put the test array onto the output ring @param[in] output_ring Holds the flattend test array in a single span

class bifrost.block.TransformBlock(gulp_size=4096)[source]

Bases: object

Defines the structure for a transform block

iterate_ring_read(input_ring)[source]

Iterate through one input ring

iterate_ring_write(output_ring, sequence_name=’‘, sequence_time_tag=0, sequence_nringlet=1)[source]

Iterate through one output ring

load_settings(input_header)[source]

Load in input header and set up block attributes @param[in] input_header Header sent from input ring

ring_transfer(input_ring, output_ring)[source]

Iterate through two rings span-by-span

class bifrost.block.WaterfallBlock(ring, imagename, core=-1, gulp_nframe=4096)[source]

Bases: object

This block creates a waterfall block based on the data in a ring, and stores it in the headers

generate_waterfall_matrix()[source]

Create a matrix for a waterfall image based on the ring’s data

main()[source]

Initiate the block’s processing

save_waterfall_plot(waterfall_matrix)[source]
Save an image of the waterfall plot using
thread-safe backend for pyplot, and labelling the plot using the header information from the ring
@param[in] waterfall_matrix x axis is frequency and
y axis is time. Values should be power.
class bifrost.block.WriteAsciiBlock(filename, gulp_size=1048576)[source]

Bases: bifrost.block.SinkBlock

Copies input ring’s data into ascii format in a text file.

load_settings(input_header)[source]
main(input_ring)[source]

Initiate the writing to filename @param[in] input_rings First ring in this list will be used for

data

@param[out] output_rings This list of rings won’t be used.

class bifrost.block.WriteHeaderBlock(filename)[source]

Bases: bifrost.block.SinkBlock

Prints the header of a ring to a file

load_settings(input_header)[source]

Load the header from json @param[in] input_header The header from the ring

main(input_ring)[source]

Put the header into the file @param[in] input_ring Contains the header in question

bifrost.block.insert_zeros_evenly(input_data, number_zeros)[source]
Insert zeros evenly in input_data.
These zeros are distibuted evenly throughout the function, to help for binning of oddly shaped arrays.

@param[in] input_data 1D array to contain zeros. @param[out] number_zeros Number of zeros that need

to be added.

@returns input_data with extra zeros

11.9. bifrost.block_chainer module

class bifrost.block_chainer.BlockChainer[source]

Bases: object

Convenient tool for constructing linear chains of blocks and views

Examples:

bc = bf.BlockChainer()
bc.blocks.read_sigproc("foo.fil", gulp_nframe=1)
bc.blocks.copy('cuda')
bc.views.split_axis('freq', 2, 'fine_freq')
bc.views.merge_axes('freq', 'fine_freq')
bc.blocks.copy('cuda_host')
bc.custom(my_block)(arg1, arg2, ...)
bc.blocks.write_sigproc()
print bc.last_block # The last added block (this can also be set)
blocks
custom(func)[source]
print_header(*args, **kwargs)[source]
views

11.10. bifrost.core module

bifrost.core.cuda_enabled()[source]
bifrost.core.debug_enabled()[source]
bifrost.core.status_string(status)[source]

11.11. bifrost.device module

bifrost.device.get_device()[source]
bifrost.device.set_device(device)[source]
bifrost.device.set_devices_no_spin_cpu()[source]

Sets a flag on all GPU devices that tells them not to spin the CPU when synchronizing. This is useful for reducing CPU load in GPU pipelines.

This function must be called _before_ any GPU devices are initialized (i.e., at the start of the process).

bifrost.device.stream_synchronize()[source]

11.12. bifrost.dtype module

i: signed integer u: unsigned integer f: floating point ci: complex signed integer cu: complex unsigned integer cf: complex floating pointer

i4: 4-bit signed integer f16: 16-bit floating point ci4: 4+4-bit complex signed integer cf32: 32+32-bit complex floating point

bifrost.dtype.from_complex64(f, dtype)[source]
bifrost.dtype.name_nbit2numpy(name, nbit)[source]
bifrost.dtype.numpy2bifrost(dtype)[source]
bifrost.dtype.numpy2string(dtype)[source]
bifrost.dtype.split_name_nbit(dtype_str)[source]

Splits a dtype string into (name, nbit)

bifrost.dtype.string2numpy(dtype_str)[source]
bifrost.dtype.to_complex64(q)[source]

11.13. bifrost.fdmt module

class bifrost.fdmt.Fdmt[source]

Bases: bifrost.libbifrost.BifrostObject

execute(idata, odata, negative_delays=False)[source]
execute_workspace(idata, odata, workspace_ptr, workspace_size, negative_delays=False)[source]
get_workspace_size(idata, odata)[source]
init(nchan, max_delay, f0, df, exponent=-2.0, space=’cuda’)[source]

11.14. bifrost.fft module

class bifrost.fft.Fft[source]

Bases: bifrost.libbifrost.BifrostObject

execute(iarray, oarray, inverse=False)[source]
execute_workspace(iarray, oarray, workspace_ptr, workspace_size, inverse=False)[source]
init(iarray, oarray, axes=None, apply_fftshift=False)[source]

11.15. bifrost.fir module

class bifrost.fir.Fir[source]

Bases: bifrost.libbifrost.BifrostObject

execute(idata, odata)[source]
init(coeffs, decim=1, space=’cuda’)[source]
reset_state()[source]
set_coeffs(coeffs)[source]

11.16. bifrost.guppi_raw module

GUPPI Raw format Headers:

Records are 80 chars, padded with spaces Keywords are truncated/padded with spaces to 8 chars “keyword1= <value>” String values are enclosed in single-quotes Numerical values typically not enclosed in quotes, but sometimes may be Final record is always ‘END’ + ‘ ‘*77
Header keywords:

DIRECTIO: If present and non-zero, headers are padded to a 512-byte boundary NBITS: No. bits per real component (e.g., 4 => 4+4-bit complex values);

typical values: 8,4,2 (particularly 8)

BLOCSIZE: No. bytes per binary data block OBSNCHAN (or NCHAN?) NPOL: Single-pol if 1 else dual-pol OBSFREQ: Centre freq of data OBSBW: Bandwidth of data (may be negative to indicate high->low channel

ordering)

BACKEND: ‘GUPPI’ for guppi/BL data [CHAN_BW]

NTIME = BLOCSIZE * 8 / (2 * NPOL * NCHAN * NBITS)

Binary data:
[chan][time][pol][complex]
bifrost.guppi_raw.read_header(f)[source]

11.17. bifrost.header_standard module

@package header_standard This file enforces a standard header for rings.

Required parameters:

(parameter type definition) nchans int “Number of frequency channels. 1+” nifs int “Number of separate IF channels. 1+” nbits int “Number of bits per value. 1+” fch1 float “Center frequency of first channel given in buffer (MHz). >0” foff float “Bandwidth of each channel (MHz). Negative values used for when

first channel specified has the largest frequency.”

tstart float “Time stamp in MJD of first sample (seconds). >0” tsamp float “Time interval between samples (seconds). >0”

Optional parameters (which some blocks require):

bifrost.header_standard.enforce_header_standard(header_dict)[source]

Raise an error if the header dictionary passed does not fit the standard specified above.

11.18. bifrost.libbifrost module

class bifrost.libbifrost.BifrostObject(constructor, destructor, *args)[source]

Bases: object

Base class for simple objects with create/destroy functions

11.19. bifrost.libbifrost_generated module

Wrapper for address.h

Generated with: /usr/local/bin/ctypesgen.py -lbifrost -I../src ../src/bifrost/address.h ../src/bifrost/affinity.h ../src/bifrost/array.h ../src/bifrost/common.h ../src/bifrost/cuda.h ../src/bifrost/fdmt.h ../src/bifrost/fft.h ../src/bifrost/fir.h ../src/bifrost/linalg.h ../src/bifrost/map.h ../src/bifrost/memory.h ../src/bifrost/proclog.h ../src/bifrost/quantize.h ../src/bifrost/reduce.h ../src/bifrost/ring.h ../src/bifrost/transpose.h ../src/bifrost/udp_capture.h ../src/bifrost/udp_socket.h ../src/bifrost/udp_transmit.h ../src/bifrost/unpack.h -o bifrost/libbifrost_generated.py

Do not modify this file.

bifrost.libbifrost_generated.BFaddress

alias of LP_struct_sockaddr

bifrost.libbifrost_generated.BFarray

alias of struct_BFarray_

bifrost.libbifrost_generated.BFarray_

alias of struct_BFarray_

bifrost.libbifrost_generated.BFcomplex

alias of c_float_Array_2

bifrost.libbifrost_generated.BFfdmt

alias of LP_struct_BFfdmt_impl

bifrost.libbifrost_generated.BFfdmt_impl

alias of struct_BFfdmt_impl

bifrost.libbifrost_generated.BFfft

alias of LP_struct_BFfft_impl

bifrost.libbifrost_generated.BFfft_impl

alias of struct_BFfft_impl

bifrost.libbifrost_generated.BFfir

alias of LP_struct_BFfir_impl

bifrost.libbifrost_generated.BFfir_impl

alias of struct_BFfir_impl

bifrost.libbifrost_generated.BFlinalg

alias of LP_struct_BFlinalg_impl

bifrost.libbifrost_generated.BFlinalg_impl

alias of struct_BFlinalg_impl

bifrost.libbifrost_generated.BFproclog

alias of LP_struct_BFproclog_impl

bifrost.libbifrost_generated.BFproclog_impl

alias of struct_BFproclog_impl

bifrost.libbifrost_generated.BFring

alias of LP_struct_BFring_impl

bifrost.libbifrost_generated.BFring_impl

alias of struct_BFring_impl

bifrost.libbifrost_generated.BFrsequence

alias of LP_struct_BFrsequence_impl

bifrost.libbifrost_generated.BFrsequence_impl

alias of struct_BFrsequence_impl

bifrost.libbifrost_generated.BFrspan

alias of LP_struct_BFrspan_impl

bifrost.libbifrost_generated.BFrspan_impl

alias of struct_BFrspan_impl

bifrost.libbifrost_generated.BFsequence

alias of LP_struct_BFsequence_wrapper

bifrost.libbifrost_generated.BFsequence_info

alias of struct_BFsequence_info_

bifrost.libbifrost_generated.BFsequence_info_

alias of struct_BFsequence_info_

bifrost.libbifrost_generated.BFsequence_wrapper

alias of struct_BFsequence_wrapper

bifrost.libbifrost_generated.BFspan

alias of LP_struct_BFspan_impl

bifrost.libbifrost_generated.BFspan_impl

alias of struct_BFspan_impl

bifrost.libbifrost_generated.BFspan_info

alias of struct_BFspan_info_

bifrost.libbifrost_generated.BFspan_info_

alias of struct_BFspan_info_

bifrost.libbifrost_generated.BFudpcapture

alias of LP_struct_BFudpcapture_impl

bifrost.libbifrost_generated.BFudpcapture_impl

alias of struct_BFudpcapture_impl

bifrost.libbifrost_generated.BFudpsocket

alias of LP_struct_BFudpsocket_impl

bifrost.libbifrost_generated.BFudpsocket_impl

alias of struct_BFudpsocket_impl

bifrost.libbifrost_generated.BFudptransmit

alias of LP_struct_BFudptransmit_impl

bifrost.libbifrost_generated.BFudptransmit_impl

alias of struct_BFudptransmit_impl

bifrost.libbifrost_generated.BFwsequence

alias of LP_struct_BFwsequence_impl

bifrost.libbifrost_generated.BFwsequence_impl

alias of struct_BFwsequence_impl

bifrost.libbifrost_generated.BFwspan

alias of LP_struct_BFwspan_impl

bifrost.libbifrost_generated.BFwspan_impl

alias of struct_BFwspan_impl

class bifrost.libbifrost_generated.DarwinLibraryLoader[source]

Bases: bifrost.libbifrost_generated.LibraryLoader

getdirs(libname)[source]

Implements the dylib search as specified in Apple documentation:

http://developer.apple.com/documentation/DeveloperTools/Conceptual/
DynamicLibraries/Articles/DynamicLibraryUsageGuidelines.html

Before commencing the standard search, the method first checks the bundle’s Frameworks directory if the application is running within a bundle (OS X .app).

getplatformpaths(libname)[source]
name_formats = [‘lib%s.dylib’, ‘lib%s.so’, ‘lib%s.bundle’, ‘%s.dylib’, ‘%s.so’, ‘%s.bundle’, ‘%s’]
class bifrost.libbifrost_generated.LibraryLoader[source]

Bases: object

getpaths(libname)[source]

Return a list of paths where the library might be found.

getplatformpaths(libname)[source]
load(path)[source]

Given a path to a library, load it.

load_library(libname)[source]

Given the name of a library, load it.

class bifrost.libbifrost_generated.MutableString(string=’‘)[source]

Bases: bifrost.libbifrost_generated.UserString

mutable string objects

Python strings are immutable objects. This has the advantage, that strings may be used as dictionary keys. If this property isn’t needed and you insist on changing string values in place instead, you may cheat and use MutableString.

But the purpose of this class is an educational one: to prevent people from inventing their own mutable string class derived from UserString and than forget thereby to remove (override) the __hash__ method inherited from UserString. This would lead to errors that would be very hard to track down.

A faster and better solution is to rewrite your program using lists.

immutable()[source]
bifrost.libbifrost_generated.POINTER_not_used(obj)[source]
class bifrost.libbifrost_generated.PosixLibraryLoader[source]

Bases: bifrost.libbifrost_generated.LibraryLoader

getplatformpaths(libname)[source]
bifrost.libbifrost_generated.ReturnString_not_used(obj, func=None, arguments=None)[source]
class bifrost.libbifrost_generated.String_not_used(obj=’‘)[source]

Bases: bifrost.libbifrost_generated.MutableString, _ctypes.Union

data

Structure/Union member

classmethod from_param(obj)[source]
raw

Structure/Union member

bifrost.libbifrost_generated.UNCHECKED(type)[source]
class bifrost.libbifrost_generated.UserString(seq)[source]
capitalize()[source]
center(width, *args)[source]
count(sub, start=0, end=9223372036854775807)[source]
decode(encoding=None, errors=None)[source]
encode(encoding=None, errors=None)[source]
endswith(suffix, start=0, end=9223372036854775807)[source]
expandtabs(tabsize=8)[source]
find(sub, start=0, end=9223372036854775807)[source]
index(sub, start=0, end=9223372036854775807)[source]
isalnum()[source]
isalpha()[source]
isdecimal()[source]
isdigit()[source]
islower()[source]
isnumeric()[source]
isspace()[source]
istitle()[source]
isupper()[source]
join(seq)[source]
ljust(width, *args)[source]
lower()[source]
lstrip(chars=None)[source]
partition(sep)[source]
replace(old, new, maxsplit=-1)[source]
rfind(sub, start=0, end=9223372036854775807)[source]
rindex(sub, start=0, end=9223372036854775807)[source]
rjust(width, *args)[source]
rpartition(sep)[source]
rsplit(sep=None, maxsplit=-1)[source]
rstrip(chars=None)[source]
split(sep=None, maxsplit=-1)[source]
splitlines(keepends=0)[source]
startswith(prefix, start=0, end=9223372036854775807)[source]
strip(chars=None)[source]
swapcase()[source]
title()[source]
translate(*args)[source]
upper()[source]
zfill(width)[source]
class bifrost.libbifrost_generated.WindowsLibraryLoader[source]

Bases: bifrost.libbifrost_generated.LibraryLoader

getplatformpaths(libname)[source]
load(path)[source]
load_library(libname)[source]
name_formats = [‘%s.dll’, ‘lib%s.dll’, ‘%slib.dll’]
bifrost.libbifrost_generated.add_library_search_dirs(other_dirs)[source]
class bifrost.libbifrost_generated.c_void[source]

Bases: _ctypes.Structure

dummy

Structure/Union member

bifrost.libbifrost_generated.sockaddr

alias of struct_sockaddr

class bifrost.libbifrost_generated.struct_BFarray_[source]

Bases: _ctypes.Structure

big_endian

Structure/Union member

conjugated

Structure/Union member

data

Structure/Union member

dtype

Structure/Union member

immutable

Structure/Union member

ndim

Structure/Union member

shape

Structure/Union member

space

Structure/Union member

strides

Structure/Union member

class bifrost.libbifrost_generated.struct_BFfdmt_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFfft_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFfir_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFlinalg_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFproclog_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFring_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFrsequence_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFrspan_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFsequence_info_[source]

Bases: _ctypes.Structure

header

Structure/Union member

header_size

Structure/Union member

name

Structure/Union member

nringlet

Structure/Union member

ring

Structure/Union member

time_tag

Structure/Union member

class bifrost.libbifrost_generated.struct_BFsequence_wrapper[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFspan_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFspan_info_[source]

Bases: _ctypes.Structure

data

Structure/Union member

nringlet

Structure/Union member

offset

Structure/Union member

ring

Structure/Union member

size

Structure/Union member

stride

Structure/Union member

class bifrost.libbifrost_generated.struct_BFudpcapture_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFudpsocket_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFudptransmit_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFwsequence_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_BFwspan_impl[source]

Bases: _ctypes.Structure

class bifrost.libbifrost_generated.struct_sockaddr[source]

Bases: _ctypes.Structure

11.20. bifrost.linalg module

class bifrost.linalg.LinAlg[source]

Bases: bifrost.libbifrost.BifrostObject

matmul(alpha, a, b, beta, c)[source]
Computes:
c = alpha*a.b + beta*c
or if b is None:
c = alpha*a.a^H + beta*c
or if a is None:
c = alpha*b^H.b + beta*c

where ‘.’ is matrix product and ‘^H’ is Hermitian transpose. Multi-dimensional semantics are the same as numpy.matmul:

The last two dims represent the matrix, and all other dims are used as batch dims to be matched or broadcast between a and b.

11.21. bifrost.map module

bifrost.map.map(func_string, data, axis_names=None, shape=None, func_name=None, extra_code=None, block_shape=None, block_axes=None)[source]

Apply a function to a set of ndarrays.

Parameters:
  • func_string (str) – The function to apply to the arrays, as a string (see below for examples).
  • data (dict) – Map of string names to ndarrays or scalars.
  • axis_names (list) – List of string names by which each axis is referenced in func_string.
  • shape – The shape of the computation. If None, the broadcast shape of all data arrays is used.
  • func_name (str) – Name of the function, for debugging purposes.
  • extra_code (str) – Additional code to be included at global scope.
  • block_shape – The 2D shape of the thread block (y,x) with which the kernel is launched. This is a performance tuning parameter. If NULL, a heuristic is used to select the block shape. Changes to this parameter do _not_ require re-compilation of the kernel.
  • block_axes – List of axis indices (or names) specifying the 2 computation axes to which the thread block (y,x) is mapped. This is a performance tuning parameter. If NULL, a heuristic is used to select the block axes. Values may be negative for reverse indexing. Changes to this parameter _do_ require re-compilation of the kernel.

Note

Only GPU computation is currently supported.

Examples:

# Add two arrays together
bf.map("c = a + b", {'c': c, 'a': a, 'b': b})

# Compute outer product of two arrays
bf.map("c(i,j) = a(i) * b(j)",
       {'c': c, 'a': a, 'b': b},
       axis_names=('i','j'))

# Split the components of a complex array
bf.map("a = c.real; b = c.imag", {'c': c, 'a': a, 'b': b})

# Raise an array to a scalar power
bf.map("c = pow(a, p)", {'c': c, 'a': a, 'p': 2.0})

# Slice an array with a scalar index
bf.map("c(i) = a(i,k)", {'c': c, 'a': a, 'k': 7}, ['i'], shape=c.shape)

11.22. bifrost.memory module

bifrost.memory.alignment()[source]
bifrost.memory.memcpy(dst, src)[source]
bifrost.memory.memcpy2D(dst, src)[source]
bifrost.memory.memset(dst, val=0)[source]
bifrost.memory.memset2D(dst, val=0)[source]
bifrost.memory.raw_free(ptr, space=’auto’)[source]
bifrost.memory.raw_get_space(ptr)[source]
bifrost.memory.raw_malloc(size, space)[source]
bifrost.memory.space_accessible(space, from_spaces)[source]

11.23. bifrost.ndarray module

A np.ndarray subclass that adds support for different spaces and
bifrost-specific metadata.

TODO: Need backend support for broadcasting arrays TODO: Convert dtype of val in __setitem__ TODO: Some calls result in segfault with space=cuda (e.g., __getitem__

returning scalar).
class bifrost.ndarray.BFArrayInfo(space, dtype, native, conjugated, ownbuffer=None)[source]

Bases: object

bifrost.ndarray.asarray(arr, space=None)[source]
bifrost.ndarray.copy_array(dst, src)[source]
bifrost.ndarray.empty(shape, dtype=’f32’, space=None, **kwargs)[source]
bifrost.ndarray.empty_like(arr, space=None)[source]
bifrost.ndarray.memset_array(dst, value)[source]
class bifrost.ndarray.ndarray[source]

Bases: numpy.ndarray

as_BFarray()[source]
as_GPUArray(*args, **kwargs)[source]
byteswap(inplace=False)[source]
conj()[source]
copy(space=None, order=’C’)[source]
tofile(fid, sep=’‘, format=’%s’)[source]
view(dtype=None, type_=None)[source]
bifrost.ndarray.zeros(shape, dtype=’f32’, space=None, **kwargs)[source]
bifrost.ndarray.zeros_like(arr, space=None)[source]

11.24. bifrost.pipeline module

class bifrost.pipeline.Block(irings, name=None, type_=None, **kwargs)[source]

Bases: bifrost.pipeline.BlockScope

begin_sequences(exit_stack, orings, oheaders, igulp_nframes, istride_nframes)[source]
begin_writing(exit_stack, orings)[source]
commit_spans(ospans, ostrides_actual, ogulp_overlaps)[source]
create_ring(*args, **kwargs)[source]
define_output_nframes(input_nframes)[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

instance_counts = defaultdict(<function <lambda>>, {})
num_outputs()[source]
reserve_spans(exit_stack, oseqs, igulp_nframes=[])[source]
run()[source]
shutdown()[source]
class bifrost.pipeline.BlockScope(name=None, gulp_nframe=None, buffer_nframe=None, buffer_factor=None, core=None, gpu=None, share_temp_storage=False, fuse=False)[source]

Bases: object

cache_scope_hierarchy()[source]
dot_graph(parent_graph=None)[source]
get_temp_storage(space)[source]
instance_count = 0
is_fused_with(other)[source]
class bifrost.pipeline.MultiTransformBlock(irings_, guarantee=True, *args, **kwargs)[source]

Bases: bifrost.pipeline.Block

define_input_overlap_nframe(iseqs)[source]

Return no. input frames that should overlap between successive spans for each input sequence.

define_output_nframes(input_nframes)[source]

Return output nframe for each output, given input_nframes.

main(orings)[source]
on_data(ispans, ospans)[source]

Process data from from ispans to ospans and return the number of frames to commit for each output (or None to commit complete spans).

on_sequence(iseqs)[source]

Return: oheaders (one per output)

on_sequence_end(iseqs)[source]

Do any necessary cleanup

on_skip(islices, ospans)[source]

Handle skipped frames

class bifrost.pipeline.Pipeline(name=None, **kwargs)[source]

Bases: bifrost.pipeline.BlockScope

as_default()[source]
instance_count = 1
run()[source]
shutdown()[source]
shutdown_on_signals(signals=None)[source]
synchronize_block_initializations()[source]
exception bifrost.pipeline.PipelineInitError[source]

Bases: exceptions.Exception

class bifrost.pipeline.SinkBlock(iring, *args, **kwargs)[source]

Bases: bifrost.pipeline.MultiTransformBlock

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)[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.pipeline.SourceBlock(sourcenames, gulp_nframe, space=None, *args, **kwargs)[source]

Bases: bifrost.pipeline.Block

create_reader(sourcename)[source]

Return an object to use for reading source data

define_output_nframes(_)[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

main(orings)[source]
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

class bifrost.pipeline.TransformBlock(iring, *args, **kwargs)[source]

Bases: bifrost.pipeline.MultiTransformBlock

define_input_overlap_nframe(iseq)[source]

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

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

on_sequence_end(iseq)[source]

Do any necessary cleanup

on_skip(islice, ospan)[source]

Handle skipped frames

bifrost.pipeline.block_scope(*args, **kwargs)[source]
bifrost.pipeline.block_view(block, header_transform)[source]

View a block with modified output headers

Use this function to adjust the output headers of a ring on-the-fly, effectively producing a new ‘view’ of the block.

Parameters:
  • block (Block) – Input block.
  • header_transform (function) – A function f(hdr) -> new_hdr.
Returns:

A new block that acts as the old block but modifies its sequence headers on-the-fly.

bifrost.pipeline.get_current_block_scope()[source]
bifrost.pipeline.get_default_pipeline()[source]
bifrost.pipeline.get_ring(block_or_ring)[source]
bifrost.pipeline.izip(*iterables)[source]
bifrost.pipeline.join_all(threads, timeout)[source]
bifrost.pipeline.try_join(thread, timeout=0.0)[source]

11.25. bifrost.portaudio module

11.26. bifrost.proclog module

class bifrost.proclog.ProcLog(name)[source]

Bases: bifrost.libbifrost.BifrostObject

update(contents)[source]

Updates (replaces) the contents of the log contents: string or dict containing data to write to the log

bifrost.proclog.load_by_filename(filename)[source]

Function to read in a ProcLog file and return the contents as a dictionary.

bifrost.proclog.load_by_pid(pid, include_rings=False)[source]

Function to read in and parse all ProcLog files associated with a given process ID. The contents of these files are returned as a collection of dictionaries ordered by:

block name
ProcLog name
entry name

11.27. bifrost.psrdada module

11.28. bifrost.quantize module

bifrost.quantize.quantize(src, dst, scale=1.0)[source]

11.29. bifrost.reduce module

bifrost.reduce.reduce(idata, odata, op=’sum’)[source]

11.30. bifrost.ring module

class bifrost.ring.ReadSequence(ring, which=’specific’, name=’‘, time_tag=None, other_obj=None, guarantee=True)[source]

Bases: bifrost.ring.SequenceBase

acquire(offset, size)[source]
close()[source]
increment()[source]
read(span_size, stride=None, begin=0)[source]
class bifrost.ring.ReadSpan(sequence, offset, size)[source]

Bases: bifrost.ring.SpanBase

release()[source]
class bifrost.ring.Ring(space=’system’, name=None, core=None)[source]

Bases: bifrost.libbifrost.BifrostObject

begin_writing()[source]
core
end_writing()[source]
name
open_earliest_sequence(guarantee=True)[source]
open_latest_sequence(guarantee=True)[source]
open_sequence(name, guarantee=True)[source]
open_sequence_at(time_tag, guarantee=True)[source]
read(whence=’earliest’, guarantee=True)[source]
resize(contiguous_span, total_span=None, nringlet=1, buffer_factor=4)[source]
space
writing_ended()[source]
class bifrost.ring.RingWriter(ring)[source]

Bases: object

begin_sequence(name=’‘, time_tag=-1, header=’‘, nringlet=1)[source]
class bifrost.ring.SequenceBase(ring)[source]

Bases: object

Python object for a ring’s sequence (data unit)

header
header_size
name
nringlet
ring
time_tag
class bifrost.ring.SpanBase(ring, writeable)[source]

Bases: object

data
data_view(dtype=<type ‘numpy.uint8’>, shape=-1)[source]
nringlet
offset
ring
size
stride
class bifrost.ring.WriteSequence(ring, name=’‘, time_tag=-1, header=’‘, nringlet=1)[source]

Bases: bifrost.ring.SequenceBase

end()[source]
reserve(size, nonblocking=False)[source]
class bifrost.ring.WriteSpan(ring, size, nonblocking=False)[source]

Bases: bifrost.ring.SpanBase

close()[source]
commit(size)[source]

11.31. bifrost.ring2 module

class bifrost.ring2.ReadSequence(ring, which=’specific’, name=’‘, time_tag=None, other_obj=None, guarantee=True, header_transform=None)[source]

Bases: bifrost.ring2.SequenceBase

acquire(frame_offset, nframe)[source]
close()[source]
header
increment()[source]
read(nframe, stride=None, begin=0)[source]
resize(gulp_nframe, buf_nframe=None, buffer_factor=None)[source]
class bifrost.ring2.ReadSpan(sequence, frame_offset, nframe)[source]

Bases: bifrost.ring2.SpanBase

nframe_overwritten
release()[source]
class bifrost.ring2.Ring(space=’system’, name=None, owner=None, core=None)[source]

Bases: bifrost.libbifrost.BifrostObject

begin_writing()[source]
core
end_writing()[source]
instance_count = 0
name
open_earliest_sequence(guarantee=True)[source]
open_latest_sequence(guarantee=True)[source]
open_sequence(name, guarantee=True)[source]
open_sequence_at(time_tag, guarantee=True)[source]
read(whence=’earliest’, guarantee=True)[source]
resize(contiguous_bytes, total_bytes=None, nringlet=1)[source]
view()[source]
class bifrost.ring2.RingWriter(ring)[source]

Bases: object

begin_sequence(header, gulp_nframe, buf_nframe)[source]
class bifrost.ring2.SequenceBase(ring)[source]

Bases: object

Python object for a ring’s sequence (data unit)

header
header_size
name
nringlet
ring
tensor
time_tag
class bifrost.ring2.SpanBase(ring, sequence, writeable)[source]

Bases: object

data
dtype
frame_nbyte
frame_offset
nframe
ring
sequence
shape
strides
tensor
class bifrost.ring2.WriteSequence(ring, header, gulp_nframe, buf_nframe)[source]

Bases: bifrost.ring2.SequenceBase

end()[source]
reserve(nframe, nonblocking=False)[source]
class bifrost.ring2.WriteSpan(ring, sequence, nframe, nonblocking=False)[source]

Bases: bifrost.ring2.SpanBase

close()[source]
commit(nframe)[source]
bifrost.ring2.accumulate(vals, op=’+’, init=None, reverse=False)[source]
bifrost.ring2.compose_unary_funcs(f, g)[source]
bifrost.ring2.ring_view(ring, header_transform)[source]
bifrost.ring2.split_shape(shape)[source]

Splits a shape into its ringlet shape and frame shape E.g., (2,3,-1,4,5) -> (2,3), (4,5)

11.32. bifrost.sigproc module

telescope_id: 0 (FAKE) machine_id: 0 (FAKE) data_type: 2 # Time-series data rawdatafile: <delete> source_name: <observer-specified> barycentric: 0 pulsarcentric: <delete> az_start: <delete> or <observer-specified> za_start: <delete> or <observer-specified> src_raj: <observer-specified> or <delete> src_dej: <observer-specified> or <delete> tstart: MJD of first sample tsamp: (secs) E.g., 0.5/(2400*24kHz=57.6MHz)=8.68055556ns nbits: 8 nsamples: No. time samples in file (“rarely used any more”) fch1: 58.776 MHz (center frequency) foff: MHz nchans: 1 nifs: 2 (pols) refdm: 0.0 [pc/cm^3] period: <delete> data: [time][pol][nbit] (General case: [time][if/pol][chan][nbit])

class bifrost.sigproc.SigprocFile[source]

Bases: bifrost.sigproc.SigprocSettings

Reads from or writes to a sigproc filterbank file

append_data(input_data)[source]

append data to local data and file

clear()[source]

Erases file contents

close()[source]

closes file object

get_nframe()[source]

calculate the number of frames from the data

open(filename, mode)[source]

open the filename, and read the header and data from it

read_data(start=None, end=None)[source]

read data from file and store it locally

read_header()[source]

reads in a header from the file and sets local settings

write_to(filename)[source]

writes data and header to a different file

class bifrost.sigproc.SigprocSettings[source]

Bases: object

defines, reads, writes sigproc settings

interpret_header()[source]

redefine variables from header dictionary

bifrost.sigproc.pack(data, nbit)[source]

downgrade data from 8bits to nbits (per value)

bifrost.sigproc.seek_to_data(file_object)[source]

Go the the location in the file where the data begins

bifrost.sigproc.unpack(data, nbit)[source]

upgrade data from nbits to 8bits

11.33. bifrost.sigproc2 module

telescope_id: 0 (FAKE) machine_id: 0 (FAKE) data_type: 2 # Time-series data rawdatafile: <delete> source_name: <observer-specified> barycentric: 0 pulsarcentric: <delete> az_start: <delete> or <observer-specified> za_start: <delete> or <observer-specified> src_raj: <observer-specified> or <delete> src_dej: <observer-specified> or <delete> tstart: MJD of first sample tsamp: (secs) E.g., 0.5/(2400*24kHz=57.6MHz)=8.68055556ns nbits: 8 nsamples: No. time samples in file (“rarely used any more”) fch1: 58.776 MHz (center frequency) foff: MHz nchans: 1 nifs: 2 (pols) refdm: 0.0 [pc/cm^3] period: <delete> data: [time][pol][nbit] (General case: [time][if/pol][chan][nbit])

class bifrost.sigproc2.SigprocFile(filename=None)[source]

Bases: object

bandwidth()[source]
cfreq()[source]
close()[source]
duration()[source]
nframe()[source]
open(filename)[source]
read(nframe_or_start, end=None)[source]
readinto(buf)[source]

Fills buf with raw bytes straight from the file

seek(offset, whence=0)[source]
bifrost.sigproc2.id2machine(id_)[source]
bifrost.sigproc2.id2telescope(id_)[source]
bifrost.sigproc2.machine2id(name)[source]
bifrost.sigproc2.telescope2id(name)[source]
bifrost.sigproc2.unpack(data, nbit)[source]
bifrost.sigproc2.write_header(hdr, f)[source]

11.34. bifrost.temp_storage module

class bifrost.temp_storage.TempStorage(space)[source]

Bases: object

allocate(size)[source]
class bifrost.temp_storage.TempStorageAllocation(parent, size)[source]

Bases: object

release()[source]

11.35. bifrost.transpose module

bifrost.transpose.transpose(dst, src, axes=None)[source]

11.36. bifrost.udp_capture module

class bifrost.udp_capture.UDPCapture(fmt, sock, ring, nsrc, src0, max_payload_size, buffer_ntime, slot_ntime, sequence_callback, core=None)[source]

Bases: bifrost.libbifrost.BifrostObject

end()[source]
flush()[source]
recv()[source]

11.37. bifrost.udp_socket module

class bifrost.udp_socket.UDPSocket[source]

Bases: bifrost.libbifrost.BifrostObject

bind(local_addr)[source]
close()[source]
connect(remote_addr)[source]
fileno()[source]
mtu
shutdown()[source]
timeout

11.38. bifrost.udp_transmit module

class bifrost.udp_transmit.UDPTransmit(sock, core=-1)[source]

Bases: bifrost.libbifrost.BifrostObject

send(packet)[source]
sendmany(packets)[source]

11.39. bifrost.units module

bifrost.units.convert_units(value, old_units, new_units)[source]
bifrost.units.transform_units(units, exponent)[source]

11.40. bifrost.unpack module

bifrost.unpack.unpack(src, dst, align_msb=False)[source]

11.41. bifrost.version module

11.42. Module contents

Bifrost pipeline processing library