Exemple #1
0
def resp_map(norm_stack, n_baseline=30, n_stim=30):
    """
    Compute a smooth response image

    Parameters
    ----------
    norm_stack: 3D np array
    n_baseline: int
    n_stim: int

    Returns
    -------
    im_resp: numpy array
        Response map
    df: numpy array
        Signal of all responding pixels
    """
    # r = norm_stack[..., n_baseline:n_baseline+n_stim].mean(2)
    r = find_resp(norm_stack)
    # Keep only the top 5% pixels
    z = r > np.percentile(r, 95)

    im_resp = np.zeros(r.shape)
    im_resp[z] = r[z]

    mask = np.ones(r.shape)
    # mask[100:-100,100:-100] = 1
    im_resp = im_resp * mask
    im_resp = gauss_filt(im_resp, 2)
    ##### Warning
    im_resp = clean_response(im_resp)
    df = norm_stack[im_resp > 0, :]

    return im_resp, df
Exemple #2
0
def overlay(ref, avg_stack=None, resp=None, cm=YlOrRd):
    brain = np.float32(ref)
    brain = img_to_uint8(brain)
    brain = grey2rgb(brain)
    if resp is None and avg_stack is not None:
        resp = find_resp(avg_stack)
    elif resp is None and avg_stack is None:
        raise ValueError('No suitable data provided')
    fresp = gauss_filt(resp, 2)
    rgb_resp = cm(fresp)[..., :3]
    rgb_resp = gauss_filt(rgb_resp, 2)
    rgb_resp = img_to_uint8(rgb_resp)
    rgb_resp[resp <= 0, :] = 0
    overlaid = np.uint8(.6 * brain + .4 * rgb_resp)

    return overlaid
Exemple #3
0
    def _make_frame(self, t):
        full_time = np.linspace(0, self._duration, self._movie_stack.shape[2])
        ix = np.intp(np.argmin(np.abs(full_time - t)))
        c_frame = self._movie_stack[..., ix]
        c_frame = gauss_filt(c_frame, 5)

        return viridis(c_frame, alpha=None, bytes=True)[..., :3]
Exemple #4
0
 def norm_pic(self, pic):
     b_pic = pic.copy()
     b_pic = np.clip(b_pic, None, self.max_slider.value()/1000)
     b_pic = gauss_filt(b_pic, 3)
     divider = (b_pic.max() - b_pic.min())
     if divider == 0:
         divider = 1
     b_pic = 255 * (b_pic - b_pic.min()) / divider
     b_pic = np.uint8(b_pic)
     return b_pic
Exemple #5
0
 def export_response(self):
     # resp = np.mean(self.norm_stack[..., self.n_baseline:(self.n_baseline+30)], 2)
     if 'resp_map' not in self.file['df']:
         self.resp_mapping()
     resp = self.file['df']['resp_map'][()]
     # resp = np.clip(resp, 0, 2/100)
     # resp = exposure.equalize_hist(resp)
     resp = viridis(gauss_filt(resp, 3))[..., :3]
     resp[self.max_project <= 0, :] = 0
     # resp = 255 * (resp - resp.min()) / (resp.max() - resp.min())
     resp = img_to_uint8(resp)
     # resp = np.uint8(resp)
     imsave(self.path.parent / f'response_{self.path.name}.png', resp)
Exemple #6
0
def normalize_stack(stack, n_baseline=30):
    start = 10
    # Global average
    y = np.nanmean(stack, (0, 1))[start:n_baseline]
    y_min, y_max = y.min(), y.max()
    # Exponential fit during baseline
    t = np.arange(start, n_baseline)
    z = 1 + (y - y_min) / (y_max - y_min)
    p = np.polyfit(t, np.log(z), 1)
    # Modeled decay
    full_t = np.arange(stack.shape[2])
    decay = np.exp(p[1]) * np.exp(full_t * p[0])
    # Renormalized
    decay = (decay - 1) * (y_max - y_min) + y_min
    norm_stack = stack - decay
    norm_stack = gauss_filt(norm_stack, 3, multichannel=False)
    return norm_stack
Exemple #7
0
 def resp(self):
     return gauss_filt(self.file['df']['max_project'][()], 3)