FileInfo

class baseband.base.base.FileInfo(opener)[source] [edit on github]

Bases: object

File 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

FileReaderInfo or StreamReaderInfo. In addition to the normal info attributes, also stored are attributes about what happened to the keyword arguments: used_kwargs, consistent_kwargs, inconsistent_kwargs and irrelevant_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 info instance in used_kwargs, consistent_kwargs, inconsistent_kwargs and irrelevant_kwargs attributes, respectively.

Parameters:
infoStreamReaderInfo

Information gleaned from a file opened in stream reading mode.

**kwargs

Keyword arguments passed to the opener.

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.

infoStreamReaderInfo

Information collected by opening a file in stream reader mode.

Returns:
consistentTrue, False, or None

Whether the information on info for key is consistent with value. None if 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 open function, 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_kwargs attribute on the returned info.

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., decade for Mark 4).

Returns:
infoFileReaderInfo

Information on the file. Will evaluate as False if the file was not in the right format.

Raises:
FileNotFoundError

If the file does not exist.

Notes

Getting information for an existing file should never fail. If an Exception is 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_kwargs attribute on the returned info.

Parameters:
namestr or filehandle

Item to be opened for reading in stream mode.

file_infoFileReaderInfo

Information gleaned from opening in binary mode.

**kwargs

Any keyword arguments that might be required to open the file successfully (e.g., decade for Mark 4).

Returns:
infoStreamReaderInfo

Information on the file. Will evaluate as False if the file was not in the right format. Will return None if no sample rate information was present, or an Exception if the opening as a stream failed.

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.