UnifiedIORegistry#
- class gwpy.io.registry.UnifiedIORegistry[source]#
Bases:
UnifiedIORegistryUnifiedIORegistry that can handle reading files in parallel.
Methods Summary
identify_format(origin, data_class_required, ...)Loop through identifiers to see which formats match.
register_identifier(data_format, data_class, ...)Associate an identifier function with a specific data type.
Methods Documentation
- identify_format(
- origin: Literal['read', 'write'],
- data_class_required: type,
- path: FileSystemPath | None,
- fileobj: FileLike | None,
- args: tuple,
- kwargs: dict,
Loop through identifiers to see which formats match.
- Parameters:
- origin
str A string
"reador"write"identifying whether the file is to be opened for reading or writing.- data_class_required
object The specified class for the result of
reador the class that is to be written.- path
stror path-like orNone The path to the file or None.
- fileobjfile-like or None.
An open file object to read the file’s contents, or
Noneif the file could not be opened.- argssequence
Positional arguments for the
readorwritefunction. Note that these must be provided as sequence.- kwargsdict-like
Keyword arguments for the
readorwritefunction. Note that this parameter must bedict-like.
- origin
- Returns:
- valid_formats
list List of matching formats.
- valid_formats
- register_identifier( ) None[source]#
Associate an identifier function with a specific data type.
- Parameters:
- data_format
str The data format identifier. This is the string that is used to specify the data type when reading/writing.
- data_class
class The class of the object that can be written.
- identifier
function A function that checks the argument specified to
readorwriteto determine whether the input can be interpreted as a table of typedata_format. This function should take the following arguments:origin: A string"read"or"write"identifying whether the file is to be opened for reading or writing.path: The path to the file.fileobj: An open file object to read the file’s contents, orNoneif the file could not be opened.*args: Positional arguments for thereadorwritefunction.**kwargs: Keyword arguments for thereadorwritefunction.
One or both of
pathorfileobjmay beNone. If they are bothNone, the identifier will need to work fromargs[0].The function should return True if the input can be identified as being of format
data_format, and False otherwise.- forcebool, optional
Whether to override any existing function if already present. Default is
False.
- data_format
Examples
To set the identifier based on extensions, for formats that take a filename as a first argument, you can do for example
from astropy.io.registry import register_identifier from astropy.table import Table def my_identifier(*args, **kwargs): return isinstance(args[0], str) and args[0].endswith('.tbl') register_identifier('ipac', Table, my_identifier) unregister_identifier('ipac', Table)