import os
import sys
import time
import glob
import random
import datetime
import numpy as np
from time import time
import SimpleITK as sitk


def load_single_data(data_paths,aux_task=False):
    '''
    Load data denotes by path in data_paths and concatenate them together
    '''
    data = 0
    for path in data_paths:
        temp_data = np.load(path)
        print ('temp_data shape is',temp_data.shape)
        if len(temp_data.shape)==2 and (not aux_task):
            temp_data = temp_data[:,:7]
        elif len(temp_data.shape)==4:
            center = int(temp_data.shape[1]/2)
            margin_size = 32
            temp_data = temp_data[:,center-margin_size:center+margin_size,
                                center-margin_size:center+margin_size,
                                center-margin_size:center+margin_size]
        if type(data) == int:
            data = np.asarray(temp_data)
        else:
            data = np.concatenate([data,temp_data],axis=0)
    return data


def load_data(paths_list,aux_task=False): 
    result_list = [load_single_data(data_paths,aux_task=aux_task) for data_paths in paths_list]

    return result_list