def anova_all(self): blank = self.blank.meantrace if self.blank else [] flicker = self.flicker.meantrace if self.flicker else [] all_oris = [[ont.array.mean() for ont in ori.ontimes] for sf, resp in self.sorted_responses for ori in resp.orientations.responses] print 'anova all: number of alll oris: {}'.format(len(all_oris)) if self.flicker and self.blank: print 'anova all: condition has both flicker and blank' f_reps = [ont.array.mean() for ont in self.flicker.ontimes] b_reps = [ont.array.mean() for ont in self.blank.ontimes] matrix = np.array([f_reps, b_reps] + all_oris).T f, p = stats.f_oneway(f_reps, b_reps, *all_oris) return util.nan_for_json(dict(f=f, p=p, matrix=matrix)) elif self.flicker: print 'anova all: condition has only flicker' f_reps = [ont.array.mean() for ont in self.flicker.ontimes] matrix = np.array([f_reps] + all_oris).T f, p = stats.f_oneway(f_reps, *all_oris) return util.nan_for_json(dict(f=f, p=p, matrix=matrix)) elif self.blank: print 'anova all: condition has only blank' b_reps = [ont.array.mean() for ont in self.blank.ontimes] matrix = np.array([b_reps] + all_oris).T f, p = stats.f_oneway(b_reps, *all_oris) return util.nan_for_json(dict(f=f, p=p, matrix=matrix)) else: matrix = [[]] return util.nan_for_json(dict(matrix=matrix))
def toDict(self): dog_x_ext, dog_y_ext = self.dog_xy_ext pref = self.preferred_sfreq.x peak = self.peak_sfreq.x ratio = self.bandwidth_ratio dog_x = self.dog_x dog_y = self.dog_y blank = self.blank flicker = self.flicker sfx = self.xfreq sfy = self.ymeas param = self.dog_param plot = self.plot_io() return util.nan_for_json( dict(pref=pref, peak=peak, ratio=ratio, dog_x=dog_x, dog_y=dog_y, dog_x_ext=dog_x_ext.tolist(), dog_y_ext=dog_y_ext.tolist(), blank=blank, flicker=flicker, sfx=sfx, sfy=sfy, param=param, plot=plot, rc10=self._rel_cutoff10, rc20=self._rel_cutoff20, c15=self._cutoff15, c20=self._cutoff20))
def toDict(self): return util.nan_for_json( dict(traces=self.traces, mean=self.mean, name=self.orientation.value, tau=self.tau, x=self.x, y_fit=self.y_fit))
def main(workspace, condition, roi, datatag, dff0s=None): n_panes = condition.info.get('focal_pane_args', {}).get('n', 1) pane_offset = workspace.cur_pane or 0 if not dff0s: dff0s = roi.dttrialdff0s bls = dff0s.filter_by(trial_blank=True) fls = dff0s.filter_by(trial_flicker=True) flicker = [ np.nanmean(np.array(f.value['on'][pane_offset::n_panes])) for f in fls ] blank = [ np.nanmean(np.array(b.value['on'][pane_offset::n_panes])) for b in bls ] if datatag.trial_tf: all_trials = dff0s.filter_by(trial_contrast=datatag.trial_contrast, trial_tf=datatag.trial_tf, trial_flicker=False, trial_blank=False) else: all_trials = dff0s.filter_by(trial_contrast=datatag.trial_contrast, trial_flicker=False, trial_blank=False) trials = ori_by_sf(all_trials, condition.sfrequencies, condition.orientations) # all_oris = [ # [np.nanmean(np.array(rep.value['on'][pane_offset::n_panes])) for rep in reps] # for sf, oris in roi.dt_ori_by_sf(datatag.trial_contrast).items() # for ori, reps in oris.items() # ] all_oris = [[ np.nanmean(np.array(rep.value['on'][pane_offset::n_panes])) for rep in reps ] for sf, oris in trials.items() for ori, reps in oris.items()] matrix = np.array([blank, flicker] + all_oris).T flicker_non_nans = list(filter(np.isfinite, flicker)) blank_non_nans = list(filter(np.isfinite, blank)) all_oris_non_nans = [ list(filter(np.isfinite, trial)) for trial in all_oris ] f, p = stats.f_oneway(flicker_non_nans, blank_non_nans, *all_oris_non_nans) return util.nan_for_json(dict(f=f, p=p, matrix=matrix.tolist()))
def stats(self): if not self.normalfit: return {} g = self.normalfit.gaussian return util.nan_for_json( dict( tau=self.decay.tau, # bootstrap = self.bootstrap, osi=g.osi, dsi=g.dsi, sigma=g.sigma, o_pref=g.o_pref, r_max=g.r_max, residual=g.residual, anova=self.anova, ttest=self.ttest, cv=self.cv))
def toDict(self): dog_x_ext, dog_y_ext = self.dog_xy_ext pref = self.preferred_sfreq.x peak = self.peak_sfreq.x ratio = self.bandwidth_ratio dog_x = self.dog_x.tolist() dog_y = self.dog_y.tolist() blank = self.blank flicker = self.flicker sfx = util.nan_for_list(self.xfreq.tolist()) sfy = util.nan_for_list(self.ymeas.tolist()) param = self.dog_param._asdict() plot = self.plot_io() # rc10 = self._rel_cutoff10 # rc20 = self._rel_cutoff20 rc33 = self._rel_cutoff33 # c15 = self._cutoff15 # c20 = self._cutoff20 return util.nan_for_json( dict( pref=pref, peak=peak, ratio=ratio, dog_x=dog_x, dog_y=dog_y, dog_x_ext=dog_x_ext.tolist(), dog_y_ext=dog_y_ext.tolist(), blank=blank, flicker=flicker, sfx=sfx, sfy=sfy, param=param, plot=plot, # rc10 = rc10, # rc20 = rc20, rc33=rc33, # c15 = c15, # c20 = c20 ))
def main(workspace, condition, roi, datatag, dff0s=None, bestprefs=None): if not dff0s: dff0s = roi.dttrialdff0s n_panes = condition.info.get('focal_pane_args', {}).get('n', 1) pane_offset = workspace.cur_pane or 0 if datatag.trial_tf: trials = dff0s.filter_by( trial_sf=datatag.trial_sf, trial_contrast=datatag.trial_contrast, trial_tf=datatag.trial_tf, # added by JZ trial_blank=False, trial_flicker=False, ) else: trials = dff0s.filter_by( trial_sf=datatag.trial_sf, trial_contrast=datatag.trial_contrast, trial_blank=False, trial_flicker=False, ) if not bestprefs: bestprefs = roi.dtorientationbestprefs best_pref = bestprefs.filter_by( trial_contrast=datatag.trial_contrast).first best_pref_ori = best_pref.value oris = [] # this is where response for given orientation and sf is made for ori in condition.orientations: reps_by_ori = trials.filter_by(trial_ori=ori) arr = np.array( [rep.value['on'][pane_offset::n_panes] for rep in reps_by_ori]) meantrace_for_ori = np.nanmean(arr, axis=0) oris.append(meantrace_for_ori) mat = np.nanmean(np.array(oris), axis=1) params = datatag.sog_params or sog_default # Patched to use auto-selection of max amplitudes based off the max of the average response across orientations. (JZ) if not params['override']: params['a1_max'] = max(mat) if max(mat) > 0 else 0 params['a2_max'] = max(mat) if max(mat) > 0 else 0 params['sigma_min'] = 180 / len(condition.orientations) if params['use_seed']: peak_sf_index = best_pref.peak_sf_index if not peak_sf_index: print 'Peak Spatial Frequency information not found. Try refresh...' best_pref.refresh() peak_sf_index = best_pref.peak_sf_index seed = mat[peak_sf_index] print 'Fitting SoG using a seed value...' print 'Peak SF Index is {}, Value is {}'.format(peak_sf_index, seed) params['a1_max'] = seed params['a2_max'] = seed # p = roi.sog_initial_guess or workspace.sog_initial_guess # a1m, a1M, a2m, a2M, sm, sM, om, oM = [p[attr] for attr in PATTRS] fit = SumOfGaussianFit(condition.orientations, mat, best_pref_ori, ((params['a1_min'], params['a1_max']), (params['a2_min'], params['a2_max']), (params['sigma_min'], params['sigma_max']), (params['offset_min'], params['offset_max']))) return util.nan_for_json( dict( orientations=condition.orientations, osi=fit.osi, dsi=fit.dsi, cv=fit.cv, dcv=fit.dcv, # added by (JZ) sigma=fit.sigma, o_pref=fit.o_pref, r_max=fit.r_max, residual=fit.residual, x=fit.stretched.x.tolist(), y_meas=fit.stretched.y.tolist(), y_fit=fit.y_fit.tolist()))
def toDict(self): return util.nan_for_json(dict( mean=self.mean, std=self.std ))