xdas.io.Engine#
- class xdas.io.Engine(vtype=None, ctype=None)[source]#
Base class for file format handlers in xdas.
The Engine class provides a plugin architecture for reading and writing various file formats. Each Engine subclass corresponds to a specific file format (e.g., “xdas”, “asn”, “miniseed”) and implements methods to open and save DataArray or DataCollection objects.
Engines are registered in a class-level registry using the __init_subclass__ hook, allowing them to be accessed by name using the Engine[name] syntax. Aliases can also be defined for backwards compatibility or convenience.
- Parameters:
vtype (str, optional) – The virtualization type to use. If vtype is None, the first supported type is used.
ctype (str or dict, optional) – The coordinate type(s) to use. Can be: - None: uses the first supported ctype for each component - str: uses the same ctype for all components - dict: maps component names to their specific ctypes If None or incomplete, missing ctypes default to the first supported option.
Notes
Subclasses should define class attributes: - _supported_vtypes (list): List of supported virtualization types - _supported_ctypes (dict): Maps component names to lists of supported coordinate types
Examples
Subclass registration (automatic via __init_subclass__):
>>> class NetCDFEngine(Engine, name="netcdf", aliases=["nc"]): ... _supported_vtypes = ["hdf5"] ... _supported_ctypes = { ... "time": ["sampled", "dense"], "distance": ["sampled", "dense"] ... } ... def open_dataarray(self, fname, **kwargs): ... ...
Access registered engines:
>>> engine = Engine["netcdf"](vtype="hdf5") >>> engine = Engine["nc"](ctype="dense") # Using alias
Methods
__init__([vtype, ctype])open_dataarray(fname, **kwargs)Open fname and return a
DataArray(abstract).open_datacollection(fname, **kwargs)Open fname and return a
DataCollection(abstract).save_dataarray(da, fname, **kwargs)Write da to fname (abstract).
save_datacollection(dc, fname, **kwargs)Write dc to fname (abstract).