import numpy as np
import os
import pickle
import pandas as pd
from scipy.io import loadmat
from pylearn2.format.target_format import OneHotFormatter
from scipy.signal import butter, filtfilt
from sklearn import preprocessing
from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix, DefaultViewConverter

class CHBMIT(DenseDesignMatrix):

    # These are representative channel MATLAB index (it needs to be subtracted by 1 before using in python)
    rep_channel_matlab_idx = {
        1: np.asarray([7,8,11,13,14,21,22]),
        3: np.asarray([3,4,6,16,19]),
        5: np.asarray([4,5,7,8,11,12,17,18]),
        8: np.asarray([6,7,8,10,11,17,18]),
        10: np.asarray([2,3,19,20,21]),
        20: np.asarray([1,2,3,19,20,21,24,25,26,27,28])
    }

    def __init__(self, patient_id, which_set, preprocessor_path, data_dir, transform, window_size, batch_size,
                 specified_files=None, leave_one_out_file=None, axes=('b', 0, 1, 'c'), default_seed=0):
        """
        The CHBMIT dataset customized for leave-one-file-out cross validation.

        Parameters
        ----------
        patient_id : int
            Patient ID.
        which_set : string