# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01_data.loading.ipynb (unless otherwise specified).


from __future__ import annotations


__all__ = ['load_file', 'load_data']

# Cell
#nbdev_comment from __future__ import annotations
import numpy as np

# Cell
def load_file(name, path='./data', loader=np.load):
    """
    Loads individual data file.

    Args:
        name: the name of the file
        path: the path containing data
        loader: the function used to load. E.g. `np.load` or `pickle.load`

    Returns:
        data as numpy.ndarray or Dict (when pickle is used)
    """
    with open(os.path.join(path, name), 'rb') as f:
        return loader(f)

# Cell
def load_data(path):
    """
    Function loading USDA KSSL dataset focusing here on Exchangeable Potassium (analyte_id=725).

    Args:
        path: the folder path containing data

    Returns:
        A tuple (X, X_names, depth_order, y, tax) with:
            X: spectra (numpy.ndarray)
            X_names: spectra wavenumbers (numpy.ndarray)
            depth_order: depth and order of samples (numpy.ndarray)
            y: exchangeable potassium content (numpy.ndarray)
            tax: look up table order_id -> order_name (Dictionary)
            X_id: unique id of spectra
    """
    X = load_file('spectra-features.npy', path)
    X_names = load_file('spectra-wavenumbers.npy', path)
    depth_order = load_file('depth-order.npy', path)
    y = load_file('target.npy', path)
    tax = load_file('tax-order-lu.pkl', path, loader=pickle.load)
    X_id = load_file('spectra-id.npy', path)
    return X, X_names, depth_order, y, tax, X_id