def test_natural_scenes(ns, nwb_b, analysis_b_new): ns_new = NaturalScenes.from_analysis_file(BODS(nwb_b), analysis_b_new) #assert np.allclose(ns.sweep_response, ns_new.sweep_response) assert np.allclose(ns.mean_sweep_response, ns_new.mean_sweep_response, equal_nan=True) assert np.allclose(ns.noise_correlation, ns_new.noise_correlation, equal_nan=True) assert np.allclose(ns.signal_correlation, ns_new.signal_correlation, equal_nan=True) assert np.allclose(ns.representational_similarity, ns_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 ns(nwb_b, analysis_b): return NaturalScenes.from_analysis_file(BODS(nwb_b), analysis_b)
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()