'Reads data from filename.'

def ReadDiskData(self, filename, key=''):

    if self.verbose:
        print ('Reading    from    disk    %s' % filename)
    ext = os.path.splitext(filename)[1]
    if (ext == '.npy'):
        data = np.load(filename)
    elif (ext == '.mat'):
        data = scipy.io.loadmat(filename, struct_as_record=True)[key]
    elif (ext == '.p'):
        data = pickle.load(gzip.GzipFile(filename, 'rb'))
    elif (ext == '.txt'):
        data = np.loadtext(filename)
    elif (ext == '.npz'):
        data = Disk.LoadSparse(filename, verbose=self.verbose)
    elif (ext == '.spec'):
        data = Disk.LoadPickle(filename, key, verbose=self.verbose)
    else:
        raise Exception(('Unknown    file    extension    %s' % ext))
    if (data.dtype == 'float64'):
        data = data.astype('float32')
    if ((len(data.shape) == 1) or ((len(data.shape) == 2) and (data.shape[0] == 1))):
        data = data.reshape((-1), 1)
    return data
