def test_brain_observatory_static_gratings_notebook(boc): data_set = boc.get_ophys_experiment_data(510938357) sg = StaticGratings(data_set) peak_head = sg.peak.head() assert peak_head['cell_specimen_id'][0] == 517399188 assert np.isclose(peak_head['reliability_sg'][0], -0.010099250163301616)
def test_static_gratings(sg, nwb_b, analysis_b_new): sg_new = StaticGratings.from_analysis_file(BODS(nwb_b), analysis_b_new) #assert np.allclose(sg.sweep_response, sg_new.sweep_response) assert np.allclose(sg.mean_sweep_response, sg_new.mean_sweep_response, equal_nan=True) assert np.allclose(sg.response, sg_new.response, equal_nan=True) assert np.allclose(sg.noise_correlation, sg_new.noise_correlation, equal_nan=True) assert np.allclose(sg.signal_correlation, sg_new.signal_correlation, equal_nan=True) assert np.allclose(sg.representational_similarity, sg_new.representational_similarity, equal_nan=True)
def build_type(nwb_file, data_file, configs, output_dir, type_name): data_set = BrainObservatoryNwbDataSet(nwb_file) try: if type_name == "dg": dga = DriftingGratings.from_analysis_file(data_set, data_file) build_drifting_gratings(dga, configs, output_dir) elif type_name == "sg": sga = StaticGratings.from_analysis_file(data_set, data_file) build_static_gratings(sga, configs, output_dir) elif type_name == "nm1": nma = NaturalMovie.from_analysis_file(data_set, data_file, si.NATURAL_MOVIE_ONE) build_natural_movie(nma, configs, output_dir, si.NATURAL_MOVIE_ONE) elif type_name == "nm2": nma = NaturalMovie.from_analysis_file(data_set, data_file, si.NATURAL_MOVIE_TWO) build_natural_movie(nma, configs, output_dir, si.NATURAL_MOVIE_TWO) elif type_name == "nm3": nma = NaturalMovie.from_analysis_file(data_set, data_file, si.NATURAL_MOVIE_THREE) build_natural_movie(nma, configs, output_dir, si.NATURAL_MOVIE_THREE) elif type_name == "ns": nsa = NaturalScenes.from_analysis_file(data_set, data_file) build_natural_scenes(nsa, configs, output_dir) elif type_name == "sp": nma = NaturalMovie.from_analysis_file(data_set, data_file, si.NATURAL_MOVIE_ONE) build_speed_tuning(nma, configs, output_dir) elif type_name == "lsn_on": lsna = lsna_check_hvas(data_set, data_file) build_locally_sparse_noise(lsna, configs, output_dir, True) elif type_name == "lsn_off": lsna = lsna_check_hvas(data_set, data_file) build_locally_sparse_noise(lsna, configs, output_dir, False) elif type_name == "rf": lsna = lsna_check_hvas(data_set, data_file) build_receptive_field(lsna, configs, output_dir) elif type_name == "corr": build_correlation_plots(data_set, data_file, configs, output_dir) elif type_name == "eye": build_eye_tracking_plots(data_set, configs, output_dir) except MissingStimulusException as e: logging.warning("could not load stimulus (%s)", type_name) except Exception as e: traceback.print_exc() logging.critical("error running stimulus (%s)", type_name) raise e
def session_b(self, plot_flag=False, save_flag=True): ns = NaturalScenes(self.nwb) sg = StaticGratings(self.nwb) nm1 = NaturalMovie(self.nwb, 'natural_movie_one', speed_tuning=True) SessionAnalysis._log.info("Session B analyzed") peak = multi_dataframe_merge( [nm1.peak_run, sg.peak, ns.peak, nm1.peak]) self.append_metadata(peak) self.append_metrics_static_grating(self.metrics_b, sg) self.append_metrics_natural_scene(self.metrics_b, ns) self.verify_roi_lists_equal(sg.roi_id, ns.roi_id) self.metrics_b["roi_id"] = sg.roi_id if save_flag: self.save_session_b(sg, nm1, ns, peak) if plot_flag: cp._plot_3sb(sg, nm1, ns, self.save_dir) cp.plot_ns_traces(ns, self.save_dir) cp.plot_sg_traces(sg, self.save_dir)
def sg(nwb_b, analysis_b): return StaticGratings.from_analysis_file(BODS(nwb_b), analysis_b)
def test_harness(dataset, trigger): sg = StaticGratings(dataset) assert sg._stim_table is StimulusAnalysis._PRELOAD assert sg._sweeplength is StimulusAnalysis._PRELOAD assert sg._interlength is StimulusAnalysis._PRELOAD assert sg._extralength is StimulusAnalysis._PRELOAD assert sg._orivals is StimulusAnalysis._PRELOAD assert sg._sfvals is StimulusAnalysis._PRELOAD assert sg._phasevals is StimulusAnalysis._PRELOAD assert sg._number_ori is StimulusAnalysis._PRELOAD assert sg._number_sf is StimulusAnalysis._PRELOAD assert sg._number_phase is StimulusAnalysis._PRELOAD assert sg._sweep_response is StimulusAnalysis._PRELOAD assert sg._mean_sweep_response is StimulusAnalysis._PRELOAD assert sg._pval is StimulusAnalysis._PRELOAD assert sg._response is StimulusAnalysis._PRELOAD assert sg._peak is StimulusAnalysis._PRELOAD if trigger == 1: print(sg._stim_table) print(sg.sweep_response) print(sg.response) print(sg.peak) elif trigger == 2: print(sg.sweeplength) print(sg.mean_sweep_response) print(sg.response) print(sg.peak) elif trigger == 3: print(sg.interlength) print(sg.sweep_response) print(sg.response) print(sg.peak) elif trigger == 4: print(sg.extralength) print(sg.mean_sweep_response) print(sg.response) print(sg.peak) elif trigger == 5: print(sg.orivals) print(sg.sweep_response) print(sg.response) print(sg.peak) elif trigger == 6: print(sg.sfvals) print(sg.sweep_response) print(sg.response) print(sg.peak) elif trigger == 7: print(sg.phasevals) print(sg.mean_sweep_response) print(sg.response) print(sg.peak) elif trigger == 8: print(sg.number_ori) print(sg.mean_sweep_response) print(sg.response) print(sg.peak) elif trigger == 9: print(sg.number_sf) print(sg.sweep_response) print(sg.response) print(sg.peak) elif trigger == 10: print(sg.number_phase) print(sg.sweep_response) print(sg.response) print(sg.peak) assert sg._stim_table is not StimulusAnalysis._PRELOAD assert sg._sweeplength is not StimulusAnalysis._PRELOAD assert sg._interlength is not StimulusAnalysis._PRELOAD assert sg._extralength is not StimulusAnalysis._PRELOAD assert sg._orivals is not StimulusAnalysis._PRELOAD assert sg._sfvals is not StimulusAnalysis._PRELOAD assert sg._phasevals is not StimulusAnalysis._PRELOAD assert sg._number_ori is not StimulusAnalysis._PRELOAD assert sg._number_sf is not StimulusAnalysis._PRELOAD assert sg._number_phase is not StimulusAnalysis._PRELOAD assert sg._sweep_response is not StimulusAnalysis._PRELOAD assert sg._mean_sweep_response is not StimulusAnalysis._PRELOAD assert sg._pval is not StimulusAnalysis._PRELOAD assert sg._response is not StimulusAnalysis._PRELOAD assert sg._peak is not StimulusAnalysis._PRELOAD # check super properties dataset.get_corrected_fluorescence_traces.assert_called_once_with() assert sg._timestamps != StaticGratings._PRELOAD assert sg._celltraces != StaticGratings._PRELOAD assert sg._numbercells != StaticGratings._PRELOAD assert not dataset.get_roi_ids.called assert sg._roi_id is StaticGratings._PRELOAD assert dataset.get_cell_specimen_ids.called assert sg._cell_id is StaticGratings._PRELOAD assert not dataset.get_dff_traces.called assert sg._dfftraces is StaticGratings._PRELOAD assert sg._dxcm is StaticGratings._PRELOAD assert sg._dxtime is StaticGratings._PRELOAD
def build_correlation_plots(data_set, analysis_file, configs, output_dir): sig_corrs = [] noise_corrs = [] avail_stims = si.stimuli_in_session(data_set.get_session_type()) ans = [] labels = [] colors = [] if si.DRIFTING_GRATINGS in avail_stims: dg = DriftingGratings.from_analysis_file(data_set, analysis_file) if hasattr(dg, 'representational_similarity'): ans.append(dg) labels.append(si.DRIFTING_GRATINGS_SHORT) colors.append(si.DRIFTING_GRATINGS_COLOR) setups = [ ( [configs['large']], True ), ( [configs['small']], False )] for cfgs, show_labels in setups: for fn in build_plots("drifting_gratings_representational_similarity", 1.0, cfgs, output_dir): oplots.plot_representational_similarity(dg.representational_similarity, dims=[dg.orivals, dg.tfvals[1:]], dim_labels=["dir", "tf"], dim_order=[1,0], colors=['r','b'], labels=show_labels) if si.STATIC_GRATINGS in avail_stims: sg = StaticGratings.from_analysis_file(data_set, analysis_file) if hasattr(sg, 'representational_similarity'): ans.append(sg) labels.append(si.STATIC_GRATINGS_SHORT) colors.append(si.STATIC_GRATINGS_COLOR) setups = [ ( [configs['large']], True ), ( [configs['small']], False )] for cfgs, show_labels in setups: for fn in build_plots("static_gratings_representational_similarity", 1.0, cfgs, output_dir): oplots.plot_representational_similarity(sg.representational_similarity, dims=[sg.orivals, sg.sfvals[1:], sg.phasevals], dim_labels=["ori", "sf", "ph"], dim_order=[1,0,2], colors=['r','g','b'], labels=show_labels) if si.NATURAL_SCENES in avail_stims: ns = NaturalScenes.from_analysis_file(data_set, analysis_file) if hasattr(ns, 'representational_similarity'): ans.append(ns) labels.append(si.NATURAL_SCENES_SHORT) colors.append(si.NATURAL_SCENES_COLOR) setups = [ ( [configs['large']], True ), ( [configs['small']], False )] for cfgs, show_labels in setups: for fn in build_plots("natural_scenes_representational_similarity", 1.0, cfgs, output_dir): oplots.plot_representational_similarity(ns.representational_similarity, labels=show_labels) if len(ans): for an in ans: sig_corrs.append(an.signal_correlation) extra_dims = range(2,len(an.noise_correlation.shape)) noise_corrs.append(an.noise_correlation.mean(axis=tuple(extra_dims))) for fn in build_plots("correlation", 1.0, [configs['large'], configs['svg']], output_dir): oplots.population_correlation_scatter(sig_corrs, noise_corrs, labels, colors, scale=16.0) oplots.finalize_with_axes() for fn in build_plots("correlation", 1.0, [configs['small']], output_dir): oplots.population_correlation_scatter(sig_corrs, noise_corrs, labels, colors, scale=4.0) oplots.finalize_no_labels() csids = ans[0].data_set.get_cell_specimen_ids() for fn, csid, i in build_cell_plots(csids, "signal_correlation", 1.0, [configs['large']], output_dir): row = ans[0].row_from_cell_id(csid, i) oplots.plot_cell_correlation([ np.delete(sig_corr[row],i) for sig_corr in sig_corrs ], labels, colors) oplots.finalize_with_axes() for fn, csid, i in build_cell_plots(csids, "signal_correlation", 1.0, [configs['small']], output_dir): row = ans[0].row_from_cell_id(csid, i) oplots.plot_cell_correlation([ np.delete(sig_corr[row],i) for sig_corr in sig_corrs ], labels, colors) oplots.finalize_no_labels()