# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_sens.ipynb.

# %% auto 0
__all__ = ['int2sens', 'senspath', 'fmatpath', 'sensdirs', 'getsens', 'getfmat']

# %% ../nbs/02_sens.ipynb 6
from pathlib import Path

# %% ../nbs/02_sens.ipynb 8
from typing import List

# %% ../nbs/02_sens.ipynb 10
#| export


# %% ../nbs/02_sens.ipynb 12
#| export

# %% ../nbs/02_sens.ipynb 14
from psrc import dirdirs
from nchr import DOT
from nlit import (SENSITIVITY, FILTERED_MATRIX)

# %% ../nbs/02_sens.ipynb 16
def int2sens(s: int) -> str: 
    '''Convert the sensitivity integer to a string'''
    return f'{SENSITIVITY}_{s}'

def senspath(path: Path, sens: int = None) -> Path:
    '''Return the path with the sensitivity directory if `sens` is provided'''
    return Path(path) / (int2sens(sens) if sens else Path(DOT))

def fmatpath(path: Path):
    '''Ensure that the path ends with the filtered_matrix directory'''
    return path / FILTERED_MATRIX if (path := Path(path)).name != FILTERED_MATRIX else path

def sensdirs(path: Path) -> List[Path]:
    '''Get all the sensitivity directories in the path. 
    
    Notes
    -----
    - `sensdirs` automatically calls `fmatpath` to ensure that the given path ends with the `filtered_matrix` directory
    - The use of `dirdirs` will return the full path, unlike `os.listdir` which only returns the directory name.
    '''
    return sorted([d for d in dirdirs(fmatpath(path)) if d.name.startswith(SENSITIVITY)])

def getsens(path: Path, sens: int = 1) -> Path:   
    '''Get the path to the sensitivity directory of the given sensitivity''' 
    return [d for d in sensdirs(path) if d.name.endswith(int2sens(sens))][0]

def getfmat(path: Path) -> Path:
    '''Ensures the path points to the filtered matrix directory'''
    path = fmatpath(path).expanduser().absolute().resolve()
    if not (path.name == FILTERED_MATRIX and path.is_dir()): 
        raise ValueError(f'Path {path} does not end with filtered_matrix')
    return path
