FileOpener¶
- class baseband.base.base.FileOpener(fmt, classes, header_class)[source] [edit on github]¶
Bases:
object
File opener for a baseband format.
Each instance can be used as a function to open a baseband stream. It is probably best used inside a wrapper, so that the documentation can reflect the docstring of
__call__
rather than of this class.- Parameters:
- fmtstr
Name of the baseband format
- classesdict
With the file/stream reader/writer classes keyed by names equal to ‘FileReader’, ‘FileWriter’, ‘StreamReader’, ‘StreamWriter’ prefixed by
fmt
. Typically, one will pass inclasses=globals()
.- header_class
VLBIHeaderBase
subclass Used to instantiate a header from keywords as needed.
Attributes Summary
keyword arguments that should never be used to create a header.
Methods Summary
__call__
(name[, mode])Open baseband file(s) for reading or writing.
create
(ns[, doc])Create a standard opener for the given namespace.
get_fh
(name, mode[, kwargs])Ensure name is a filehandle, opening it if necessary.
get_fns
(name, mode, kwargs)Convert a template into a file-name sequencer.
get_header0
(kwargs)Get header0 from kwargs or construct it from kwargs.
get_type
(name)Infer the type of file name is pointing to.
is_fh
(name)Whether name is a filehandle.
is_name
(name)Whether name is a name of a file.
is_sequence
(name)Whether name is an (implied) sequence of files.
is_template
(name)Whether name is a template for a sequence of files.
normalize_mode
(mode)wrapped
([module, doc])Wrap as a function named open, replacing docstring and module.
Attributes Documentation
- non_header_keys = {'file_size', 'fill_value', 'squeeze', 'subset', 'verify'}¶
keyword arguments that should never be used to create a header.
Methods Documentation
- __call__(name, mode='rs', **kwargs)[source] [edit on github]¶
Open baseband file(s) for reading or writing.
Opened as a binary file, one gets a wrapped filehandle that adds methods to read/write a frame. Opened as a stream, the handle is wrapped further, with methods such as reading and writing to the file as if it were a stream of samples.
- Parameters:
- namestr or filehandle, or sequence of str
File name, filehandle, sequence of file names, or template (file name(s) can be
Path
but template has to bestr
).- mode{‘rb’, ‘wb’, ‘rs’, or ‘ws’}, optional
Whether to open for reading or writing, and as a regular binary file or as a stream. Default: ‘rs’, for reading a stream.
- **kwargs
Additional arguments when opening the file as a stream.
- classmethod create(ns, doc=None)[source] [edit on github]¶
Create a standard opener for the given namespace.
This assumes that the namespace contains file and stream readers and writers, as well as a header class, with standard names,
<fmt>FileReader
,<fmt>FileWriter
,<fmt>StreamReader
,<fmt>StreamWriter
, and<fmt>Header
, wherefmt
is the name of the format (which is inferred by looking for a*StreamReader
entry).The opener is instantiated using the format and the above classes, and then a wrapping function is created with
__module__
set to the__name__
of the namespace, and with the documentation of its__call__
method extended withdoc
.- Parameters:
- nsdict
Namespace to look in. Generally, pass in
globals()
at the call site.- docstr, optional
Extra documentation to add to that of the opener’s
__call__
method.
- get_fh(name, mode, kwargs={})[source] [edit on github]¶
Ensure name is a filehandle, opening it if necessary.
- get_fns(name, mode, kwargs)[source] [edit on github]¶
Convert a template into a file-name sequencer.
Any keywords needed to fill the template are popped from kwargs.
- get_header0(kwargs)[source] [edit on github]¶
Get header0 from kwargs or construct it from kwargs.
Possible keyword arguments will be popped from kwargs.
- get_type(name)[source] [edit on github]¶
Infer the type of file name is pointing to.
Options are ‘fh’, ‘name’, ‘sequence’, and ‘template’.
- is_fh(name)[source] [edit on github]¶
Whether name is a filehandle.
- is_name(name)[source] [edit on github]¶
Whether name is a name of a file.
- is_sequence(name)[source] [edit on github]¶
Whether name is an (implied) sequence of files.
- is_template(name)[source] [edit on github]¶
Whether name is a template for a sequence of files.
- normalize_mode(mode)[source] [edit on github]¶
- wrapped(module=None, doc=None)[source] [edit on github]¶
Wrap as a function named open, replacing docstring and module.