DADAHeader¶
- class baseband.dada.header.DADAHeader(*args, verify=True, mutable=True, **kwargs)[source] [edit on github]¶
Bases:
OrderedDict
DADA baseband file format header.
Defines a number of routines common to all baseband format headers.
- Parameters:
- *argsstr or iterable
If a string, parsed as a DADA header from a file, otherwise as for the OrderedDict baseclass.
- verifybool, optional
Whether to do minimal verification that the header is consistent with the DADA standard. Default:
True
.- mutablebool, optional
Whether to allow the header to be changed after initialisation. Default:
True
.- **kwargs
Any further header keywords to be set. If any value is a 2-item tuple, the second one will be considered a comment.
Notes
Like
OrderedDict
, in order to ensure keywords are kept in the right order, one should pass on values as a tuple, not as a dict. E.g., to copy a header, one should not doDADAHeader(**header)
, but rather:DADAHeader(((key, header[key]) for key in header))
or, to also keep the comments:
DADAHeader(((key, (header[key], header.comments[key])) for key in header))
Attributes Summary
Bits per elementary sample.
Whether the data are complex.
Size of the frame in bytes.
Size of the header in bytes.
Offset from start of observation in units of time.
Size of the payload in bytes.
Number of complete samples per second.
Shape of a sample in the payload (npol, nchan).
Number of complete samples in the frame.
True if upper sideband.
Start time of the observation.
Start time of the part of the observation covered by this header.
Methods Summary
clear
()copy
()Create a mutable and independent copy of the header.
fromfile
(fh[, verify])Reads in DADA header block from a file.
fromkeys
(*args, **kwargs)Initialise a header from keyword values.
fromvalues
(**kwargs)Initialise a header from parsed values.
get
(key[, default])Return the value for key if key is in the dictionary, else default.
items
()keys
()move_to_end
(/, key[, last])Move an existing element to the end (or beginning if last is false).
pop
(/, key[, default])If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem
(/[, last])Remove and return a (key, value) pair from the dictionary.
setdefault
(/, key[, default])Insert key with a value of default if key is not in the dictionary.
tofile
(fh)Write DADA file header to filehandle.
update
(*[, verify])Update the header with new values.
values
()verify
()Basic check of integrity.
Attributes Documentation
- bps¶
Bits per elementary sample.
- complex_data¶
Whether the data are complex.
- frame_nbytes¶
Size of the frame in bytes.
- nbytes¶
Size of the header in bytes.
- offset¶
Offset from start of observation in units of time.
- payload_nbytes¶
Size of the payload in bytes.
- sample_rate¶
Number of complete samples per second.
Can be set with a negative quantity to set
sideband
.
- sample_shape¶
Shape of a sample in the payload (npol, nchan).
- samples_per_frame¶
Number of complete samples in the frame.
- sideband¶
True if upper sideband.
- start_time¶
Start time of the observation.
- time¶
Start time of the part of the observation covered by this header.
Methods Documentation
- clear() None. Remove all items from od. ¶
- copy()[source] [edit on github]¶
Create a mutable and independent copy of the header.
- classmethod fromfile(fh, verify=True)[source] [edit on github]¶
Reads in DADA header block from a file.
The file pointer should be at the start.
- Parameters:
- fhfilehandle
To read data from.
- verify: bool, optional
Whether to do basic checks on whether the header is valid. Default:
True
.
- classmethod fromkeys(*args, **kwargs)[source] [edit on github]¶
Initialise a header from keyword values.
Like fromvalues, but without any interpretation of keywords.
This just calls the class initializer; it is present for compatibility with other header classes only.
- classmethod fromvalues(**kwargs)[source] [edit on github]¶
Initialise a header from parsed values.
Here, the parsed values must be given as keyword arguments, i.e., for any
header
,cls.fromvalues(**header) == header
.However, unlike for the
fromkeys
class method, data can also be set using arguments named after header methods, such astime
.Furthermore, some header defaults are set in
DADAHeader._defaults
.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- move_to_end(/, key, last=True)¶
Move an existing element to the end (or beginning if last is false).
Raise KeyError if the element does not exist.
- pop(/, key, default=<unrepresentable>)¶
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem(/, last=True)¶
Remove and return a (key, value) pair from the dictionary.
Pairs are returned in LIFO order if last is true or FIFO order if false.
- setdefault(/, key, default=None)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- tofile(fh)[source] [edit on github]¶
Write DADA file header to filehandle.
Parts of the header beyond the ascii lines are filled with 0x00. Note that file should in principle be at the start, but we don’t check for that since that would break SequentialFileWriter.
- update(*, verify=True, **kwargs)[source] [edit on github]¶
Update the header with new values.
Here, any keywords matching properties are processed as well, in the order set by the class (in
_properties
), and after all other keywords have been processed.- Parameters:
- verifybool, optional
If
True
(default), verify integrity after updating.- **kwargs
Arguments used to set keywords and properties.
- values() an object providing a view on D's values ¶
- verify()[source] [edit on github]¶
Basic check of integrity.