# Path: brainiak/image.py
# class SingleConditionSpec(ConditionSpec):
#     """ConditionSpec with a single condition applicable to an epoch."""
# 
#     def extract_labels(self) -> np.ndarray:
#         """Extract condition labels.
# 
#         Returns
#         -------
#         np.ndarray
#             The condition label of each epoch.
#         """
#         condition_idxs, epoch_idxs, _ = np.where(self)
#         _, unique_epoch_idxs = np.unique(epoch_idxs, return_index=True)
#         return condition_idxs[unique_epoch_idxs]


from pathlib import Path
from typing import Callable, Iterable, List, Union
from nibabel.nifti1 import Nifti1Pair
from nibabel.spatialimages import SpatialImage
from .image import SingleConditionSpec
import logging
import nibabel as nib
import numpy as np

    Returns
    -------
    np.ndarray
        Boolean array corresponding to mask.
    """
    if not isinstance(path, str):
        path = str(path)
    data = nib.load(path).get_data()
    if predicate is not None:
        mask = predicate(data)
    else:
        mask = data.astype(np.bool)
    return mask


def load_labels(path: Union[str, Path]) -> List[SingleConditionSpec]:
    """Load labels files.

    Parameters
    ----------
    path
        Path of labels file.

    Returns
    -------
    List[SingleConditionSpec]
        List of SingleConditionSpec stored in labels file.
    """
    condition_specs = np.load(str(path))

# Path: brainiak/image.py
# class SingleConditionSpec(ConditionSpec):
#     """ConditionSpec with a single condition applicable to an epoch."""
# 
#     def extract_labels(self) -> np.ndarray:
#         """Extract condition labels.
# 
#         Returns
#         -------
#         np.ndarray
#             The condition label of each epoch.
#         """
#         condition_idxs, epoch_idxs, _ = np.where(self)
#         _, unique_epoch_idxs = np.unique(epoch_idxs, return_index=True)
#         return condition_idxs[unique_epoch_idxs]


# Path: brainiak/io.py
from pathlib import Path
from typing import Callable, Iterable, List, Union
from nibabel.nifti1 import Nifti1Pair
from nibabel.spatialimages import SpatialImage
from .image import SingleConditionSpec
import logging
import nibabel as nib
import numpy as np


    Returns
    -------
    np.ndarray
        Boolean array corresponding to mask.
    """
    if not isinstance(path, str):
        path = str(path)
    data = nib.load(path).get_data()
    if predicate is not None:
        mask = predicate(data)
    else:
        mask = data.astype(np.bool)
    return mask


def load_labels(path: Union[str, Path]) -> List[SingleConditionSpec]:
    """Load labels files.

    Parameters
    ----------
    path
        Path of labels file.

    Returns
    -------
    List[SingleConditionSpec]
        List of SingleConditionSpec stored in labels file.
    """
    condition_specs = np.load(str(path))

    return [c.view(SingleConditionSpec) for c in condition_specs]