def test_natural_movie_one_a(nm1a, nwb_a, analysis_a_new):
    nm1a_new = NaturalMovie.from_analysis_file(BODS(nwb_a), analysis_a_new, si.NATURAL_MOVIE_ONE)
    #assert np.allclose(nm1a.sweep_response, nm1a_new.sweep_response)
    assert np.allclose(nm1a.binned_cells_sp, nm1a_new.binned_cells_sp, equal_nan=True)
    assert np.allclose(nm1a.binned_cells_vis, nm1a_new.binned_cells_vis, equal_nan=True)
    assert np.allclose(nm1a.binned_dx_sp, nm1a_new.binned_dx_sp, equal_nan=True)
    assert np.allclose(nm1a.binned_dx_vis, nm1a_new.binned_dx_vis, equal_nan=True)
예제 #2
0
    def session_c(self, plot_flag=False, save_flag=True):
        lsn = LocallySparseNoise(self.nwb)
        nm2 = NaturalMovie(self.nwb, 'natural_movie_two')
        nm1 = NaturalMovie(self.nwb, 'natural_movie_one', speed_tuning=True)
        SessionAnalysis._log.info("Session C analyzed")
        peak = multi_dataframe_merge([nm1.peak_run, nm1.peak, nm2.peak])
        self.append_metadata(peak)

        self.metrics_c["roi_id"] = nm1.roi_id

        if save_flag:
            self.save_session_c(lsn, nm1, nm2, peak)

        if plot_flag:
            cp._plot_3sc(lsn, nm1, nm2, self.save_dir)
            cp.plot_lsn_traces(lsn, self.save_dir)
예제 #3
0
def test_natural_movie_one_a(nm1a, nwb_a, analysis_a_new):
    nm1a_new = NaturalMovie.from_analysis_file(BODS(nwb_a), analysis_a_new, si.NATURAL_MOVIE_ONE)
    #assert np.allclose(nm1a.sweep_response, nm1a_new.sweep_response)
    assert np.allclose(nm1a.binned_cells_sp, nm1a_new.binned_cells_sp, equal_nan=True)
    assert np.allclose(nm1a.binned_cells_vis, nm1a_new.binned_cells_vis, equal_nan=True)
    assert np.allclose(nm1a.binned_dx_sp, nm1a_new.binned_dx_sp, equal_nan=True)
    assert np.allclose(nm1a.binned_dx_vis, nm1a_new.binned_dx_vis, equal_nan=True)
예제 #4
0
def test_harness(dataset, trigger):
    movie_name = "Mock Movie Name"
    nm = NaturalMovie(dataset, movie_name)

    assert nm._stim_table is StimulusAnalysis._PRELOAD
    assert nm._sweeplength is StimulusAnalysis._PRELOAD
    assert nm._sweep_response is StimulusAnalysis._PRELOAD
    assert nm._peak is StimulusAnalysis._PRELOAD

    for attr in trigger:
        print(getattr(nm, attr))

    assert nm._stim_table is not StimulusAnalysis._PRELOAD
    assert nm._sweeplength is not StimulusAnalysis._PRELOAD
    assert nm._sweep_response is not StimulusAnalysis._PRELOAD
    assert nm._peak is not StimulusAnalysis._PRELOAD

    # check super properties weren't preloaded
    dataset.get_corrected_fluorescence_traces.assert_called_once_with()
    assert nm._timestamps is not NaturalMovie._PRELOAD
    assert nm._celltraces is not NaturalMovie._PRELOAD
    assert nm._numbercells is not NaturalMovie._PRELOAD

    assert not dataset.get_roi_ids.called
    assert nm._roi_id is NaturalMovie._PRELOAD

    assert dataset.get_cell_specimen_ids.called
    assert nm._cell_id is NaturalMovie._PRELOAD

    assert not dataset.get_dff_traces.called
    assert nm._dfftraces is NaturalMovie._PRELOAD

    assert nm._dxcm is NaturalMovie._PRELOAD
    assert nm._dxtime is NaturalMovie._PRELOAD
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
예제 #6
0
    def session_a(self, plot_flag=False, save_flag=True):
        nm1 = NaturalMovie(self.nwb, 'natural_movie_one', speed_tuning=True)
        nm3 = NaturalMovie(self.nwb, 'natural_movie_three')
        dg = DriftingGratings(self.nwb)

        SessionAnalysis._log.info("Session A analyzed")
        peak = multi_dataframe_merge(
            [nm1.peak_run, dg.peak, nm1.peak, nm3.peak])

        self.append_metrics_drifting_grating(self.metrics_a, dg)
        self.metrics_a["roi_id"] = dg.roi_id

        self.append_metadata(peak)

        if save_flag:
            self.save_session_a(dg, nm1, nm3, peak)

        if plot_flag:
            cp._plot_3sa(dg, nm1, nm3, self.save_dir)
            cp.plot_drifting_grating_traces(dg, self.save_dir)
예제 #7
0
    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)
예제 #8
0
def nm2(nwb_c, analysis_c):
    return NaturalMovie.from_analysis_file(BODS(nwb_c), analysis_c, si.NATURAL_MOVIE_TWO)
예제 #9
0
def nm1b(nwb_b, analysis_b):
    return NaturalMovie.from_analysis_file(BODS(nwb_b), analysis_b, si.NATURAL_MOVIE_ONE)
예제 #10
0
def nm3(nwb_a, analysis_a):
    return NaturalMovie.from_analysis_file(BODS(nwb_a), analysis_a, si.NATURAL_MOVIE_THREE)
예제 #11
0
print ' Part III'
print '##############\n'

#	 goal: Figure out how to get the cell specimen data specifically for nm3 session A stimuli associated
#         with ophy_experiment_id: 570305847, experiment_container_id: 566759225

##	 Remember: you have downloaded the NWB data for an experiment. You need to get the fluorecent traces
##   of the cells from this data

# 1: begin analysis using the
# 	 natural_movie class. nm3 will be a NaturalMovie object.
##   It will be important to ensure whether or not passing in the moview_name arguement
##   is necessary for data analysis of information 'I know' is recorded from the
##   natural movie three stimulus. I believe the 'movie_name' param is neccessary
##   because of the whole tuning analysis to a specific movie which is a big part of this class
nm3_object = NaturalMovie(session_A_data, stim_info.NATURAL_MOVIE_THREE)

#  2: grab the sweep response from the nm3_object and convert it to a pandas dataframe
sweep_response = nm3_object.get_sweep_response()
sweep_response = pd.DataFrame.from_records(sweep_response)

# print len(sweep_response.iloc[0][0])
# print sweep_response.iloc[1][0]
# __________________________________________________________________________________
print '\n##############'
print ' Part IV'
print '##############\n'

# 	 goal: using the sweep responce information, create traces of a cell for all 10 trials

# 	 remember: the sweep_response dataframe is a trial(i) X cell matrix(j), 0 = i < 10, and 0 = j < 181.
예제 #12
0
p.pprint(cell_experiment)

data_set = boc.get_ophys_experiment_data(cell_experiment['id'])
print '\nhere is the metadata set for the cell experiment above:'
p.pprint(data_set.get_metadata())

# print '\nhere is the stimuli available for this file:'
# print(data_set.list_stimuli())
# ___________________________________________________________________________________________________
# PART III: Mess around with the Natural Movie class
print '\n******************'
print '     PART III     '
print '******************\n'

# access the NaturalMovie class
nm = NaturalMovie(data_set, stim_info.NATURAL_MOVIE_THREE)
# print 'Natural Movie class has the following characteristics'
# print nm.movie_name
# print nm._sweeplength
# print nm._sweep_response
# print str(nm.__dict__)
# print '----------------------------'
sweep_response = pd.DataFrame.from_records(
    nm.get_sweep_response())  #turned the numpy array into a pandas dataframe
# print sweep_response #the sweep response numpy array contains the dF/F response for each cell
# print 'sweep length is: ' + str(nm.sweeplength)
# print ' lets try this peak thing again \n' + str(pd.DataFrame.from_records(nm.get_peak()))

# with sweep response, we can export that to a csv file to get a good look at it
sweep_response.to_csv('Sweep_Response_Data.csv', index=True, header=True)
def nm1c(nwb_c, analysis_c):
    return NaturalMovie.from_analysis_file(BODS(nwb_c), analysis_c, si.NATURAL_MOVIE_ONE)
def nm1b(nwb_b, analysis_b):
    return NaturalMovie.from_analysis_file(BODS(nwb_b), analysis_b, si.NATURAL_MOVIE_ONE)
def nm3(nwb_a, analysis_a):
    return NaturalMovie.from_analysis_file(BODS(nwb_a), analysis_a, si.NATURAL_MOVIE_THREE)