# Base¶

Routines on which the readers and writers for specific baseband formats are based.

## Reference/API¶

### baseband.base Package¶

Base implementations shared between all formats.

Files are considered as composed of multiple frames, each of which have a header and payload, which are encoded in various ways. Base classes implementing the decoding and encoding and exposing a standardized interface are found in the corresponding header, payload and frame modules, with the separate encoding module providing implementations for common encoding formats.

The base module defines base methods for file and stream readers and writers that read or write the frames, including possibly dealing with corrupted data, using the offsets module to keep track of missing pieces. Each file and stream reader has an info property, defined in file_info, that provides standardized information.

Finally, utils contains some general utility routines such as for BCD encoding and decoding, and cyclic redundancy checks.

Base definitions for baseband Headers, in particular for the VLBI types.

Defines a number of helpers to construct a Header class that hold header words corresponding to a frame header, and provides access to the values encoded in those words via a dict-like interface. Definitions for headers are constructed using a HeaderParser class (which is targeted specifically at the VLBI formats).

#### Functions¶

 make_parser(word_index, bit_index, bit_length) Construct a function that converts specific bits from a header. make_setter(word_index, bit_index, bit_length) Construct a function that uses a value to set specific bits in a header. get_default(word_index, bit_index, bit_length) Return the default value from a header keyword.

#### Classes¶

 ParserDict(function) Create a lazily evaluated dictionary of parsers, setters, or defaults. HeaderParserBase Parser & setter for header keywords. HeaderParser Parser & setter for VLBI header keywords. ParsedHeaderBase(words[, verify]) Base class for all baseband headers using parsers. VLBIHeaderBase(words[, verify]) Base class for all VLBI headers.

#### Class Inheritance Diagram¶

Defines a payload class PayloadBase that can be used to hold the words corresponding to a frame payload, providing access to the values encoded in it as a numpy array.

#### Classes¶

 PayloadBase(words, *[, header, …]) Container for decoding and encoding baseband payloads.

### baseband.base.frame Module¶

Base definitions for baseband frames.

Defines a frame class FrameBase that can be used to hold a header and a payload, providing access to the values encoded in both.

#### Classes¶

 FrameBase(header, payload[, valid, verify]) Representation of a baseaband frame, consisting of a header and payload.

### baseband.base.base Module¶

Common classes for accessing baseband data as binary files and streams.

For access as binary files, the main FileBase class provides a base to which simple methods such as read_frame and write_frame can be added. Unlike normal binary file readers, the base can be pickled: it stores the name and re-opens the file if unpickled. The VLBIFileReaderBase adds additional methods useful for streams with small frames, to locate frames and determine the frame rate.

For access as streams, the StreamReaderBase and StreamWriterBase classes allow one to process data in terms of frames, and access them as streams of samples via the read and write methods, providing a number of private methods which can be overridden as needed for specific data formats.

The FileOpener and FileInfo classes are to help create the open and info functions that are expected to exist for each format.

#### Classes¶

 HeaderNotFoundError Error in finding a header in a stream. FileBase(fh_raw) File wrapper, used to add frame methods to a binary data file. VLBIFileReaderBase(fh_raw) VLBI wrapped file reader base class. StreamBase(fh_raw, header0, *[, squeeze]) Baseband file wrapper, allowing access as a stream of data. StreamReaderBase(fh_raw, header0, *[, …]) Base for all stream readers, providing standard reading methods. VLBIStreamReaderBase(fh_raw, header0, **kwargs) Base for VLBI stream readers. StreamWriterBase(fh_raw, header0, *[, squeeze]) Base for all stream writers, providing a standard write method. FileInfo(opener) File information collector. FileOpener(fmt, classes, header_class) File opener for a baseband format.

### baseband.base.offsets Module¶

#### Classes¶

 RawOffsets([frame_nr, offset, frame_nbytes]) File offset tracker.

### baseband.base.file_info Module¶

Provide a base class for “info” properties.

Loosely based on DataInfo.

#### Classes¶

 info_item([attr, needs, default, doc, …]) Like a lazy property, evaluated only once. InfoBase([parent]) Container providing a standardized interface to file information. FileReaderInfo([parent]) Standardized information on file readers. StreamReaderInfo([parent]) Standardized information on stream readers. NoInfo([info]) Info class for cases where no useful information was returned.

### baseband.base.encoding Module¶

Encoders and decoders for generic binary data formats.

#### Functions¶

 encode_1bit_base(values) Generic encoder for data stored using one bit. encode_2bit_base(values) Generic encoder for data stored using two bits. encode_4bit_base(values) Generic encoder for data stored using four bits. decode_8bit(words) Generic decoder for data stored using 8 bits. encode_8bit(values) Encode 8 bit VDIF data.

#### Variables¶

 OPTIMAL_2BIT_HIGH Optimal high value for a 2-bit digitizer for which the low value is 1. TWO_BIT_1_SIGMA Optimal level between low and high for the above OPTIMAL_2BIT_HIGH. FOUR_BIT_1_SIGMA Scaling for four-bit encoding that makes it look like 2 bit. EIGHT_BIT_1_SIGMA Scaling for eight-bit encoding that makes it look like 2 bit. decoder_levels Levels for data encoded with different numbers of bits..

### baseband.base.utils Module¶

#### Functions¶

 lcm(a, b) Calculate the least common multiple of a and b. bcd_decode(value) bcd_encode(value) byte_array(pattern) Convert the pattern to a byte array.

#### Classes¶

 fixedvalue([fget, doc, lazy]) Property that is fixed for all instances of a class. CRC(polynomial) Cyclic Redundancy Check. CRCStack(polynomial) Cyclic Redundancy Check for a bitstream.