11. Python Reference

11.1. Subpackages

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]
property is_complex
property is_floating_point
property is_integer
property is_real
property is_signed
property itemsize
property 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

property address
property family
property mtu
property 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]

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

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]

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

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]

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

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]

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

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 = {'in_1': 'First input to add. List of floats', 'in_2': 'Second input to add. List of floats', 'out_sum': 'Result of 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 = {'in': 'Input to split. List of floats', 'out_1': 'Gets first share of the ring. List of floats', 'out_2': 'Gets second share of the ring. 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]

Load in settings from input ring header

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)
property blocks
custom(func)[source]
print_header(*args, **kwargs)[source]
property 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

exception bifrost.libbifrost.EndOfDataStop[source]

Bases: RuntimeError

This class is used as a Py3 StopIterator

In Python >3.7, reaching a StopIterator in a generator will raise a RuntimeError (so you can’t do ‘except StopIteration’ to catch it!) See PEP479 https://www.python.org/dev/peps/pep-0479/

11.19. 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.20. bifrost.map module

bifrost.map.clear_map_cache()[source]
bifrost.map.list_map_cache()[source]
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.21. 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.22. 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(base=None, space=None, shape=None, dtype=None, buffer=None, offset=0, strides=None, native=None, conjugated=None)[source]

Bases: numpy.ndarray

as_BFarray()[source]
as_GPUArray(*args, **kwargs)[source]
as_cupy(*args, **kwargs)[source]
byteswap(inplace=False)[source]

Swap the bytes of the array elements

Toggle between low-endian and big-endian data representation by returning a byteswapped array, optionally swapped in-place. Arrays of byte-strings are not swapped. The real and imaginary parts of a complex number are swapped individually.

Parameters

inplace (bool, optional) – If True, swap bytes in-place, default is False.

Returns

out – The byteswapped array. If inplace is True, this is a view to self.

Return type

ndarray

Examples

>>> A = np.array([1, 256, 8755], dtype=np.int16)
>>> list(map(hex, A))
['0x1', '0x100', '0x2233']
>>> A.byteswap(inplace=True)
array([  256,     1, 13090], dtype=int16)
>>> list(map(hex, A))
['0x100', '0x1', '0x3322']

Arrays of byte-strings are not swapped

>>> A = np.array([b'ceg', b'fac'])
>>> A.byteswap()
array([b'ceg', b'fac'], dtype='|S3')
A.newbyteorder().byteswap() produces an array with the same values

but different representation in memory

>>> A = np.array([1, 2, 3])
>>> A.view(np.uint8)
array([1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
       0, 0], dtype=uint8)
>>> A.newbyteorder().byteswap(inplace=True)
array([1, 2, 3])
>>> A.view(np.uint8)
array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0,
       0, 3], dtype=uint8)
conj()[source]

Complex-conjugate all elements.

Refer to numpy.conjugate for full documentation.

See also

numpy.conjugate

equivalent function

copy(order='C')[source]

Return a copy of the array.

Parameters

order ({'C', 'F', 'A', 'K'}, optional) – Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible. (Note that this function and numpy.copy() are very similar but have different default values for their order= arguments, and this function always passes sub-classes through.)

See also

numpy.copy

Similar function with different default behavior

numpy.copyto

Notes

This function is the preferred method for creating an array copy. The function numpy.copy() is similar, but it defaults to using order ‘K’, and will not pass sub-classes through by default.

Examples

>>> x = np.array([[1,2,3],[4,5,6]], order='F')
>>> y = x.copy()
>>> x.fill(0)
>>> x
array([[0, 0, 0],
       [0, 0, 0]])
>>> y
array([[1, 2, 3],
       [4, 5, 6]])
>>> y.flags['C_CONTIGUOUS']
True
tofile(fid, sep='', format='%s')[source]

Write array to a file as text or binary (default).

Data is always written in ‘C’ order, independent of the order of a. The data produced by this method can be recovered using the function fromfile().

Parameters
  • fid (file or str or Path) –

    An open file object, or a string containing a filename.

    Changed in version 1.17.0: pathlib.Path objects are now accepted.

  • sep (str) – Separator between array items for text output. If “” (empty), a binary file is written, equivalent to file.write(a.tobytes()).

  • format (str) – Format string for text file output. Each entry in the array is formatted to text by first converting it to the closest Python type, and then using “format” % item.

Notes

This is a convenience function for quick storage of array data. Information on endianness and precision is lost, so this method is not a good choice for files intended to archive data or transport data between machines with different endianness. Some of these problems can be overcome by outputting the data as text files, at the expense of speed and file size.

When fid is a file object, array contents are directly written to the file, bypassing the file object’s write method. As a result, tofile cannot be used with files objects supporting compression (e.g., GzipFile) or file-like objects that do not support fileno() (e.g., BytesIO).

view([dtype][, type])[source]

New view of array with the same data.

Note

Passing None for dtype is different from omitting the parameter, since the former invokes dtype(None) which is an alias for dtype('float_').

Parameters
  • dtype (data-type or ndarray sub-class, optional) – Data-type descriptor of the returned view, e.g., float32 or int16. Omitting it results in the view having the same data-type as a. This argument can also be specified as an ndarray sub-class, which then specifies the type of the returned object (this is equivalent to setting the type parameter).

  • type (Python type, optional) – Type of the returned view, e.g., ndarray or matrix. Again, omission of the parameter results in type preservation.

Notes

a.view() is used two different ways:

a.view(some_dtype) or a.view(dtype=some_dtype) constructs a view of the array’s memory with a different data-type. This can cause a reinterpretation of the bytes of memory.

a.view(ndarray_subclass) or a.view(type=ndarray_subclass) just returns an instance of ndarray_subclass that looks at the same array (same shape, dtype, etc.) This does not cause a reinterpretation of the memory.

For a.view(some_dtype), if some_dtype has a different number of bytes per entry than the previous dtype (for example, converting a regular array to a structured array), then the behavior of the view cannot be predicted just from the superficial appearance of a (shown by print(a)). It also depends on exactly how a is stored in memory. Therefore if a is C-ordered versus fortran-ordered, versus defined as a slice or transpose, etc., the view may give different results.

Examples

>>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)])

Viewing array data using a different type and dtype:

>>> y = x.view(dtype=np.int16, type=np.matrix)
>>> y
matrix([[513]], dtype=int16)
>>> print(type(y))
<class 'numpy.matrix'>

Creating a view on a structured array so it can be used in calculations

>>> x = np.array([(1, 2),(3,4)], dtype=[('a', np.int8), ('b', np.int8)])
>>> xv = x.view(dtype=np.int8).reshape(-1,2)
>>> xv
array([[1, 2],
       [3, 4]], dtype=int8)
>>> xv.mean(0)
array([2.,  3.])

Making changes to the view changes the underlying array

>>> xv[0,1] = 20
>>> x
array([(1, 20), (3,  4)], dtype=[('a', 'i1'), ('b', 'i1')])

Using a view to convert an array to a recarray:

>>> z = x.view(np.recarray)
>>> z.a
array([1, 3], dtype=int8)

Views share data:

>>> x[0] = (9, 10)
>>> z[0]
(9, 10)

Views that change the dtype size (bytes per entry) should normally be avoided on arrays defined by slices, transposes, fortran-ordering, etc.:

>>> x = np.array([[1,2,3],[4,5,6]], dtype=np.int16)
>>> y = x[:, 0:2]
>>> y
array([[1, 2],
       [4, 5]], dtype=int16)
>>> y.view(dtype=[('width', np.int16), ('length', np.int16)])
Traceback (most recent call last):
    ...
ValueError: To change to a dtype of a different size, the array must be C-contiguous
>>> z = y.copy()
>>> z.view(dtype=[('width', np.int16), ('length', np.int16)])
array([[(1, 2)],
       [(4, 5)]], dtype=[('width', '<i2'), ('length', '<i2')])
bifrost.ndarray.zeros(shape, dtype='f32', space=None, **kwargs)[source]
bifrost.ndarray.zeros_like(arr, space=None)[source]

11.23. 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 = {}
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: 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.24. bifrost.portaudio module

11.25. 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.26. bifrost.psrdada module

11.27. bifrost.quantize module

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

11.28. bifrost.reduce module

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

11.29. 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]
property core
end_writing()[source]
property 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]
property 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)

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

Bases: object

property data
data_view(dtype=<class 'numpy.uint8'>, shape=-1)[source]
property nringlet
property offset
property ring
property size
property 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.30. 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]
property 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

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

Bases: bifrost.libbifrost.BifrostObject

begin_writing()[source]
property core
end_writing()[source]
instance_count = 0
property 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)

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

Bases: object

property data
property dtype
property frame_nbyte
property frame_offset
property nframe
property ring
property sequence
property shape
property strides
property 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.31. bifrost.romein module

class bifrost.romein.Romein[source]

Bases: bifrost.libbifrost.BifrostObject

execute(idata, odata)[source]
init(positions, kernels, ngrid, polmajor=True)[source]
set_kernels(kernels)[source]
set_positions(positions)[source]

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]
property mtu
shutdown()[source]
property 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. Module contents

Bifrost pipeline processing library