Skip to content

i_data_access_layer

Module for IDataAccessLayer interface

!!! interfaces IDataAccessLayer

IDataAccessLayer (ABC)

Interface for the data layer

Source code in api/i_data_access_layer.py
class IDataAccessLayer(ABC):
    """Interface for the data layer"""

    @abstractmethod
    def retrieve_file_names(self, path: Path) -> dict:
        """
        Find all files according to the pattern in the path string

        Args:
            path (str): path to input file (with * for generic part)

        Returns:
            List: List of strings with all files in folder according to pattern

        """

    @abstractmethod
    def read_input_file(self, path: Path) -> IModelData:
        """Reads input file from provided path

        Args:
            path (str): path to input file

        Returns:
            IModelData: Data regarding model
        """

    @abstractmethod
    def read_input_dataset(self, dataset_data: IDatasetData) -> _xr.Dataset:
        """Uses the provided dataset_data to create/read a xarray Dataset

        Args:
            dataset_data (IDatasetData): dataset data for creating an
                                         xarray dataset

        Returns:
            _xr.Dataset: Dataset based on provided dataset_data
        """

    @abstractmethod
    def write_output_file(
        self, dataset: _xr.Dataset, path: Path, settings: OutputFileSettings
    ) -> None:
        """Write output files to provided path

        Args:
            dataset (XArray dataset): dataset to write
            path (str): path to output file
            settings (OutputFileSettings): settings to use for saving output

        Returns:
            None

        Raises:
            FileExistsError: if output file location does not exist
            OSError: if output file cannot be written
        """

read_input_dataset(self, dataset_data)

Uses the provided dataset_data to create/read a xarray Dataset

Parameters:

Name Type Description Default
dataset_data IDatasetData

dataset data for creating an xarray dataset

required

Returns:

Type Description
_xr.Dataset

Dataset based on provided dataset_data

Source code in api/i_data_access_layer.py
@abstractmethod
def read_input_dataset(self, dataset_data: IDatasetData) -> _xr.Dataset:
    """Uses the provided dataset_data to create/read a xarray Dataset

    Args:
        dataset_data (IDatasetData): dataset data for creating an
                                     xarray dataset

    Returns:
        _xr.Dataset: Dataset based on provided dataset_data
    """

read_input_file(self, path)

Reads input file from provided path

Parameters:

Name Type Description Default
path str

path to input file

required

Returns:

Type Description
IModelData

Data regarding model

Source code in api/i_data_access_layer.py
@abstractmethod
def read_input_file(self, path: Path) -> IModelData:
    """Reads input file from provided path

    Args:
        path (str): path to input file

    Returns:
        IModelData: Data regarding model
    """

retrieve_file_names(self, path)

Find all files according to the pattern in the path string

Parameters:

Name Type Description Default
path str

path to input file (with * for generic part)

required

Returns:

Type Description
List

List of strings with all files in folder according to pattern

Source code in api/i_data_access_layer.py
@abstractmethod
def retrieve_file_names(self, path: Path) -> dict:
    """
    Find all files according to the pattern in the path string

    Args:
        path (str): path to input file (with * for generic part)

    Returns:
        List: List of strings with all files in folder according to pattern

    """

write_output_file(self, dataset, path, settings)

Write output files to provided path

Parameters:

Name Type Description Default
dataset XArray dataset

dataset to write

required
path str

path to output file

required
settings OutputFileSettings

settings to use for saving output

required

Returns:

Type Description
None

None

Exceptions:

Type Description
FileExistsError

if output file location does not exist

OSError

if output file cannot be written

Source code in api/i_data_access_layer.py
@abstractmethod
def write_output_file(
    self, dataset: _xr.Dataset, path: Path, settings: OutputFileSettings
) -> None:
    """Write output files to provided path

    Args:
        dataset (XArray dataset): dataset to write
        path (str): path to output file
        settings (OutputFileSettings): settings to use for saving output

    Returns:
        None

    Raises:
        FileExistsError: if output file location does not exist
        OSError: if output file cannot be written
    """