The data_io sub-package#
The data_io subpackage includes functionality to load and save data in various formats.
- class pydidas.data_io.IoMaster(clsname: str, bases: list[type], attrs: dict)#
Metaclass to manage imports and exporters for different file types.
- classmethod clear_registry()#
Clear the registry and remove all items.
- classmethod export_to_file(filename: Path | str, data: ndarray, **kwargs: dict)#
Export the data to file using the exporter based on the extension.
- Parameters:
filename (str) – The full filename and path.
data (np.ndarray) – The data to be exported.
**kwargs (dict) – Any kwargs which should be passed to the underlying exporter.
- classmethod get_registered_formats(mode: Literal['import', 'export'] = 'import')#
Get the names and file extensins of all registered formats.
- Parameters:
mode (Literal["import", "export"]) – The mode to use: Choose between import and export. The default is import.
- Returns:
A dictionary with <format name> : <extensions> entries.
- Return type:
dict
- classmethod get_string_of_formats(mode: Literal['import', 'export'] = 'import')#
Get a list of strings with the different formats and extensions.
This class method is designed to have an easy way of creating the required lists for QFileDialog windows.
- Parameters:
mode (Literal["import", "export"]) – The mode to use: Choose between import and export. The default is import.
- Returns:
The string entries for each format and one entry for all formats, each separated by a “;;”.
- Return type:
str
- classmethod import_from_file(filename: Path | str, **kwargs: dict) Dataset #
Import data from a file, using the importer based on the extension.
- Parameters:
filename (Union[Path, str]) – The full filename and path.
**kwargs (dict) – Keyword arguments for the concrete importer implementation call.
- Returns:
The imported Dataset.
- Return type:
- classmethod is_extension_registered(extension: str, mode: Literal['import', 'export'] = 'import')#
Check if the extension of filename corresponds to a registered class.
The extension is stored without the leading dot. If the given extension includes a leading dot, it is stripped before checking the extension. This behaviour allows to use pathlib.Path instances’ suffix property to be used directly.
- Parameters:
extension (str) – The extension to be checked. If the extension includes a leading dot, it is stripped.
mode (Literal["import", "export"]) – The mode to use: Choose between import and export. The default is import.
- Returns:
Flag whether the extension is registered or not.
- Return type:
bool
- classmethod register_class(new_class: type, update_registry: bool = False)#
Register a class as object for its native extensions.
- Parameters:
new_class (type) – The class to be registered.
update_registry (bool, optional) – Keyword to allow updating / overwriting of registered extensions. The default is False.
- Raises:
KeyError – If an extension associated with new_class has already been registered and update_registry is False.
- classmethod verify_extension_is_registered(ext: str, mode: Literal['import', 'export'] = 'import', filename: str | None = None)#
Verify the extension is registered with the MetaClass.
- Parameters:
ext (str) – The file extension
mode (str[import, export], optional) – The mode to use: Choose between import and export. The default is import.
filename (Union[None, str]) – The filename of the file to be checked.
- Raises:
UserConfigError – If the extension is not registered.
- pydidas.data_io.export_data(filename: str | Path, data: ndarray, **kwargs: dict)#
Export data to a file using the pydidas.data_io.IoMaster metaclass.
- Parameters:
filename (Union[str, pathlib.Path]) – The filename to be used for the exported data.
data (Union[np.ndarray, pydidas.core.Dataset]) – The data to be exported.
**kwargs (dict) – Any keyword arguments. These will be passed to the implemented exporter and the supported keywords vary depending on the selected file extension.
- pydidas.data_io.import_data(filename: str | Path, **kwargs: dict) Dataset #
Import data from a file using the pydidas.data_io.IoMaster metaclass.
- Parameters:
filename (Union[str, pathlib.Path]) – The filename to be used for the exported data.
**kwargs (dict) – Any keyword arguments. These will be passed to the implemented importer and the supported keywords vary depending on the selected file extension.