Ejemplo n.º 1
0
 def __init__(self,
              files,
              random_state=42,
              batch_size=32,
              train=True,
              var_name_hdf5='mov',
              subindices=None):
     """ 
     Create a Sequence object for Ca datasets. Not used at the moment
     """
     if isinstance(files, str):
         files = [files]
     self.files = files
     dims, T = get_file_size(files, var_name_hdf5=var_name_hdf5)
     if subindices is not None:
         T = len(range(T)[subindices])
     if isinstance(T, int):
         T = [T]
     self.num_examples_per_npy = T[0]
     self.random_state = random_state
     self.n_channels = 1
     self.dim = dims
     self.T = T
     self.batch_size = batch_size
     self.train = train
     self.on_epoch_end()
     self.var_name_hdf5 = var_name_hdf5
Ejemplo n.º 2
0
def mean_image(file_name,
                 Tot_frames=None,
                 fr: float = 10.,
                 window: int = 100,
                 dview=None):
    """
    Efficient (parallel) computation of mean image in chunks

    Args:
        Y:  str
            path to movie file

        Tot_frames: int
            Number of total frames considered

        fr: int (100)
            Frame rate (optional)

        window: int (100)
            Window length in frames

        dview: map object
            Use it for parallel computation
    
    Returns:
        mm: cm.movie (2D).
            mean image

    """
    if Tot_frames is None:
        _, Tot_frames = get_file_size(file_name)

    params: List = [[file_name, range(j * window, (j + 1) * window)]
                    for j in range(int(Tot_frames / window))]

    remain_frames = Tot_frames - int(Tot_frames / window) * window
    if remain_frames > 0:
        params.append([file_name, range(int(Tot_frames / window) * window, Tot_frames)])

    if dview is None:
        parallel_result = list(map(mean_image_parallel, params))
    else:
        if 'multiprocessing' in str(type(dview)):
            parallel_result = dview.map_async(mean_image_parallel, params).get(4294967)
        else:
            parallel_result = dview.map_sync(mean_image_parallel, params)
            dview.results.clear()

    mm = cm.movie(np.concatenate(parallel_result, axis=0), fr=fr/len(parallel_result))
    if remain_frames > 0:
        mean_image = (mm[:-1].sum(axis=0) + (remain_frames / window) * mm[-1]) / (len(mm) - 1 + remain_frames / window)  
    else:
        mean_image = mm.mean(axis=0)
    return mean_image
Ejemplo n.º 3
0
def local_correlations_movie_offline(file_name,
                                     Tot_frames=None,
                                     fr: float = 10.,
                                     window: int = 100,
                                     stride: int = 100,
                                     swap_dim: bool = False,
                                     eight_neighbours: bool = True,
                                     order_mean: int = 1,
                                     ismulticolor: bool = False,
                                     dview=None,
                                     remove_baseline: bool = False,
                                     winSize_baseline: int = 50,
                                     quantil_min_baseline: float = 8,
                                     gaussian_blur: bool=False):
    """
    Efficient (parallel) computation of correlation image in shifting windows 
    with option for prior baseline removal

    Args:
        Y:  str
            path to movie file

        Tot_frames: int
            Number of total frames considered

        fr: int (100)
            Frame rate (optional)

        window: int (100)
            Window length in frames

        stride: int (30)
            Stride length in frames

        swap_dim: bool (False)
            True indicates that time is listed in the last axis of Y (matlab format)
            and moves it in the front (default: False)

        eight_neighbours: Boolean
            Use 8 neighbors if true, and 4 if false for 3D data
            Use 18 neighbors if true, and 6 if false for 4D data

        dview: map object
            Use it for parallel computation

        remove_baseline: bool (False)
            Flag for removing baseline prior to computation of CI

        winSize_baseline: int (50)
            Running window length for computing baseline

        quantile_min_baseline: float (8)
            Percentile used for baseline computations
            
        gaussian_blur: bool (False)
            Gaussian smooth the signal

    Returns:
        mm: cm.movie (3D or 4D).
            local correlation movie

    """
    if Tot_frames is None:
        _, Tot_frames = get_file_size(file_name)

    params: List = [[file_name, range(j, j + window), eight_neighbours, swap_dim,
                     order_mean, ismulticolor, remove_baseline, winSize_baseline,
                     quantil_min_baseline, gaussian_blur]
                    for j in range(0, Tot_frames - window, stride)]

    params.append([file_name, range(Tot_frames - window, Tot_frames), eight_neighbours, swap_dim,
                   order_mean, ismulticolor, remove_baseline, winSize_baseline,
                   quantil_min_baseline, gaussian_blur])

    if dview is None:
        parallel_result = list(map(local_correlations_movie_parallel, params))
    else:
        if 'multiprocessing' in str(type(dview)):
            parallel_result = dview.map_async(local_correlations_movie_parallel, params).get(4294967)
        else:
            parallel_result = dview.map_sync(local_correlations_movie_parallel, params)
            dview.results.clear()

    mm = cm.movie(np.concatenate(parallel_result, axis=0), fr=fr/len(parallel_result))
    return mm