Beispiel #1
0
def read_features(filename_fet, nchannels, fetdim, freq):
    """Read a .fet file and return the normalize features array,
    as well as the spiketimes."""
    
    features = load_text(filename_fet, np.int32, skiprows=1)
    features = np.array(features, dtype=np.float32)
    
    # HACK: There are either 1 or 5 dimensions more than fetdim*nchannels
    # we can't be sure so we first try 1, if it does not work we try 5.
    for nextradim in [1, 5]:
        try:
            features = features.reshape((-1,
                                         fetdim * nchannels + nextradim))
            # if the features array could be reshape, directly break the loop
            break
        except ValueError:
            features = None
    if features is None:
        raise ValueError("""The number of columns in the feature matrix
        is not fetdim (%d) x nchannels (%d) + 1 or 5.""" % 
            (fetdim, nchannels))
    
    # get the spiketimes
    spiketimes = features[:,-1].copy()
    spiketimes *= (1. / freq)
    
    # count the number of extra features
    nextrafet = features.shape[1] - nchannels * fetdim
    
    # normalize normal features while keeping symmetry
    features[:,:-nextrafet] = normalize(features[:,:-nextrafet],
                                        symmetric=True)
    # normalize extra features without keeping symmetry
    features[:,-nextrafet:] = normalize(features[:,-nextrafet:],
                                        symmetric=False)
    
    return features, spiketimes
Beispiel #2
0
def read_masks(filename_mask, fetdim):
    full_masks = load_text(filename_mask, np.float32, skiprows=1)
    masks = full_masks[:,:-1:fetdim]
    return masks, full_masks
Beispiel #3
0
def read_clusters(filename_clu):
    clusters = load_text(filename_clu, np.int32)
    clusters = clusters[1:]
    return clusters