FileInfo¶
- class baseband.base.base.FileInfo(opener)[source] [edit on github]¶
Bases:
objectFile information collector.
The instance can be used as a function on a file name to get information from that file, by opening it and retrieving
info.- Parameters:
- openercallable
The function to use to open files
Notes
The class is perhaps most easily used via the class method
create.Methods Summary
__call__(name, **kwargs)Collect baseband file information.
check_consistency(info, **kwargs)Check consistency between info and the given arguments.
check_key(key, value, info)Check consistency for a given key and value.
create(ns)Create an info getter for the given namespace.
get_file_info(name, **kwargs)Open a file in binary mode and retrieve info.
get_stream_info(name, file_info, **kwargs)Open a file in stream mode and retrieve info.
is_ok(info)Wether the item returned by _get_info has valid information.
wrapped([module, doc])Wrap as a function named info, replacing docstring and module.
Methods Documentation
- __call__(name, **kwargs)[source] [edit on github]¶
Collect baseband file information.
First try opening as a binary file and check whether the file is of the correct format. If so, and no required information is missing, re-open as a stream, and get information like the start time, sample rate, etc.
- Parameters:
- namestr or filehandle, or sequence of str
File name, filehandle, or sequence of file names.
- **kwargs
Any other arguments the opener needs to open as a stream.
- Returns:
- info
FileReaderInfoorStreamReaderInfo. In addition to the normalinfoattributes, also stored are attributes about what happened to the keyword arguments:used_kwargs,consistent_kwargs,inconsistent_kwargsandirrelevant_kwargs.
- check_consistency(info, **kwargs)[source] [edit on github]¶
Check consistency between info and the given arguments.
The keyword arguments will be sorted into those that were used by the file opener and those that were unused, with the latter split in those that had consistent, inconsistent, or irrelevant information. They are stored on the
infoinstance inused_kwargs,consistent_kwargs,inconsistent_kwargsandirrelevant_kwargsattributes, respectively.- Parameters:
- info
StreamReaderInfo Information gleaned from a file opened in stream reading mode.
- **kwargs
Keyword arguments passed to the opener.
- info
- check_key(key, value, info)[source] [edit on github]¶
Check consistency for a given key and value.
- Parameters:
- keystr
Name of the key.
- valueobject
Corresponding value.
- info
StreamReaderInfo Information collected by opening a file in stream reader mode.
- Returns:
- consistentTrue, False, or None
Whether the information on
infoforkeyis consistent withvalue.Noneif it could not be determined.
- classmethod create(ns)[source] [edit on github]¶
Create an info getter for the given namespace.
This assumes that the namespace contains an
openfunction, which is used to create an instance of the info class that is wrapped in a function with__module__set to the calling module (inferred from the namespace).- Parameters:
- nsdict
Namespace to look in. Generally, pass in
globals()at the call site.
- get_file_info(name, **kwargs)[source] [edit on github]¶
Open a file in binary mode and retrieve info.
Any keyword arguments that were required to open the file will be stored as a
used_kwargsattribute on the returnedinfo.- Parameters:
- namestr or filehandle
Item to be opened for reading in binary mode.
- **kwargs
Any keyword arguments that might be required to open the file successfully (e.g.,
decadefor Mark 4).
- Returns:
- info
FileReaderInfo Information on the file. Will evaluate as
Falseif the file was not in the right format.
- info
- Raises:
- FileNotFoundError
If the file does not exist.
Notes
Getting information for an existing file should never fail. If an
Exceptionis raised or returned, it is a bug in the file reader.
- get_stream_info(name, file_info, **kwargs)[source] [edit on github]¶
Open a file in stream mode and retrieve info.
Any keyword arguments that were required to open the file will be stored as a
used_kwargsattribute on the returnedinfo.- Parameters:
- namestr or filehandle
Item to be opened for reading in stream mode.
- file_info
FileReaderInfo Information gleaned from opening in binary mode.
- **kwargs
Any keyword arguments that might be required to open the file successfully (e.g.,
decadefor Mark 4).
- Returns:
- info
StreamReaderInfo Information on the file. Will evaluate as
Falseif the file was not in the right format. Will returnNoneif no sample rate information was present, or anExceptionif the opening as a stream failed.
- info
- is_ok(info)[source] [edit on github]¶
Wether the item returned by _get_info has valid information.
- wrapped(module=None, doc=None)[source] [edit on github]¶
Wrap as a function named info, replacing docstring and module.