Exemple #1
0
def test_locally_sparse_noise(lsn, nwb_c, analysis_c_new):
    ds = BODS(nwb_c)
    session_type = ds.get_metadata()['session_type']
    logging.debug(session_type)

    if session_type == si.THREE_SESSION_C:
        lsn_new = LocallySparseNoise.from_analysis_file(ds, analysis_c_new, si.LOCALLY_SPARSE_NOISE)
    elif session_type == si.THREE_SESSION_C2:
        lsn_new = LocallySparseNoise.from_analysis_file(ds, analysis_c_new, si.LOCALLY_SPARSE_NOISE_4DEG)
        
    #assert np.allclose(lsn.sweep_response, lsn_new.sweep_response)
    assert np.allclose(lsn.mean_sweep_response, lsn_new.mean_sweep_response, equal_nan=True)
def test_locally_sparse_noise(lsn, nwb_c, analysis_c_new):
    ds = BODS(nwb_c)
    session_type = ds.get_metadata()['session_type']
    logging.debug(session_type)

    if session_type == si.THREE_SESSION_C:
        lsn_new = LocallySparseNoise.from_analysis_file(ds, analysis_c_new, si.LOCALLY_SPARSE_NOISE)
    elif session_type == si.THREE_SESSION_C2:
        lsn_new = LocallySparseNoise.from_analysis_file(ds, analysis_c_new, si.LOCALLY_SPARSE_NOISE_4DEG)
        
    #assert np.allclose(lsn.sweep_response, lsn_new.sweep_response)
    assert np.allclose(lsn.mean_sweep_response, lsn_new.mean_sweep_response, equal_nan=True)
Exemple #3
0
def lsn(nwb_c, analysis_c):
    # in order to work around 2/3 unicode compatibility, separate files are specified for python 2 and 3
    # we need to look up a different key depending on python version
    key = si.LOCALLY_SPARSE_NOISE_4DEG if sys.version_info < (
        3, ) else si.LOCALLY_SPARSE_NOISE

    return LocallySparseNoise.from_analysis_file(BODS(nwb_c), analysis_c, key)
def write_rfs(dataset, write_dir):
    '''
    https://allensdk.readthedocs.io/en/latest/_static/examples/nb/brain_observatory_analysis.html
    '''

    cell_ids = dataset.get_cell_specimen_ids()
    session_type = dataset.get_session_type()

    if 'locally_sparse_noise' in dataset.list_stimuli():
        logging.info('WRITING RECEPTIVE FIELDS FOR EXPERIMENT {}'.format(
            dataset.get_metadata()['ophys_experiment_id']))

        on_dir = os.path.join(write_dir, 'ReceptiveFields', 'on', session_type)
        off_dir = os.path.join(write_dir, 'ReceptiveFields', 'off',
                               session_type)
        os.makedirs(on_dir, exist_ok=True)
        os.makedirs(off_dir, exist_ok=True)

        lsn = LocallySparseNoise(dataset)
        rfs = lsn.receptive_field
        rfs[np.isnan(rfs)] = 0

        for ind, cell_id in enumerate(cell_ids):
            rf = rfs[:, :, ind, :]
            rf = max_min_scale(rf) * 255
            on, off = rf.transpose([2, 0, 1])
            fname = str(cell_id) + '.png'

            cv2.imwrite(os.path.join(on_dir, fname), on)
            cv2.imwrite(os.path.join(off_dir, fname), off)
def lsna_check_hvas(data_set, data_file):
    avail_stims = si.stimuli_in_session(data_set.get_session_type())    
    targeted_structure = data_set.get_metadata()['targeted_structure']

    stim = None

    if targeted_structure == "VISp":
        if si.LOCALLY_SPARSE_NOISE_4DEG in avail_stims:
            stim = si.LOCALLY_SPARSE_NOISE_4DEG
        elif si.LOCALLY_SPARSE_NOISE in avail_stims:
            stim = si.LOCALLY_SPARSE_NOISE
    else:
        if si.LOCALLY_SPARSE_NOISE_8DEG in avail_stims:
            stim = si.LOCALLY_SPARSE_NOISE_8DEG
        elif si.LOCALLY_SPARSE_NOISE in avail_stims:
            stim = si.LOCALLY_SPARSE_NOISE

    if stim is None:
        raise MissingStimulusException("Could not find appropriate LSN stimulus for session %s", 
                                       data_set.get_session_type())
    else:
        logging.debug("in structure %s, using %s stimulus for plots", targeted_structure, stim)
            
    
    return LocallySparseNoise.from_analysis_file(data_set, data_file, stim)
def test_brain_observatory_locally_sparse_noise_notebook(boc):
    specimen_id = 517410165
    cell = boc.get_cell_specimens(ids=[specimen_id])[0]
    
    exp = boc.get_ophys_experiments(experiment_container_ids=[cell['experiment_container_id']],
                                    stimuli=[stim_info.LOCALLY_SPARSE_NOISE])[0]
                                             
    data_set = boc.get_ophys_experiment_data(exp['id'])
    lsn = LocallySparseNoise(data_set)
    specimen_ids = data_set.get_cell_specimen_ids()
    cell_loc = np.argwhere(specimen_ids==specimen_id)[0][0]
    receptive_field = lsn.receptive_field[:,:,cell_loc,0]

    assert True
Exemple #7
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)
Exemple #8
0
def test_harness(dataset, stimulus, trigger):
    with patch(
            'allensdk.brain_observatory.stimulus_analysis.StimulusAnalysis.get_speed_tuning',
            mock_speed_tuning()) as get_speed_tuning:
        lsn = LocallySparseNoise(dataset, stimulus)

        assert lsn._stim_table is StimulusAnalysis._PRELOAD
        assert lsn._LSN is StimulusAnalysis._PRELOAD
        assert lsn._LSN_mask is StimulusAnalysis._PRELOAD
        assert lsn._sweeplength is StimulusAnalysis._PRELOAD
        assert lsn._interlength is StimulusAnalysis._PRELOAD
        assert lsn._extralength is StimulusAnalysis._PRELOAD
        assert lsn._sweep_response is StimulusAnalysis._PRELOAD
        assert lsn._mean_sweep_response is StimulusAnalysis._PRELOAD
        assert lsn._pval is StimulusAnalysis._PRELOAD
        assert lsn._receptive_field is StimulusAnalysis._PRELOAD

        if trigger == 1:
            print(lsn.stim_table)
            print(lsn.sweep_response)
            print(lsn.receptive_field)
        elif trigger == 2:
            print(lsn.LSN)
            print(lsn.mean_sweep_response)
            print(lsn.receptive_field)
        elif trigger == 3:
            print(lsn.LSN_mask)
            print(lsn.pval)
            print(lsn.receptive_field)
        elif trigger == 4:
            print(lsn.sweeplength)
            print(lsn.sweep_response)
            print(lsn.receptive_field)
        elif trigger == 5:
            print(lsn.interlength)
            print(lsn.mean_sweep_response)
            print(lsn.receptive_field)
        elif trigger == 6:
            print(lsn.extralength)
            print(lsn.pval)
            print(lsn.receptive_field)

        assert lsn._stim_table is not StimulusAnalysis._PRELOAD
        assert lsn._LSN is not StimulusAnalysis._PRELOAD
        assert lsn._LSN_mask is not StimulusAnalysis._PRELOAD
        assert lsn._sweeplength is not StimulusAnalysis._PRELOAD
        assert lsn._interlength is not StimulusAnalysis._PRELOAD
        assert lsn._extralength is not StimulusAnalysis._PRELOAD
        assert lsn._sweep_response is not StimulusAnalysis._PRELOAD
        assert lsn._mean_sweep_response is not StimulusAnalysis._PRELOAD
        assert lsn._pval is not StimulusAnalysis._PRELOAD
        assert lsn._receptive_field is not StimulusAnalysis._PRELOAD

        # verify super class members weren't preloaded
        assert not dataset.get_corrected_fluorescence_traces.called
        assert lsn._timestamps is StimulusAnalysis._PRELOAD
        assert lsn._celltraces is StimulusAnalysis._PRELOAD
        assert lsn._numbercells is StimulusAnalysis._PRELOAD

        assert not dataset.get_roi_ids.called
        assert lsn._roi_id is StimulusAnalysis._PRELOAD

        assert not dataset.get_cell_specimen_ids.called
        assert lsn._cell_id is StimulusAnalysis._PRELOAD

        assert not dataset.get_dff_traces.called
        assert lsn._dfftraces is StimulusAnalysis._PRELOAD

        assert lsn._dxcm is StimulusAnalysis._PRELOAD
        assert lsn._dxtime is StimulusAnalysis._PRELOAD
def lsn(nwb_c, analysis_c):
    return LocallySparseNoise.from_analysis_file(BODS(nwb_c), analysis_c,
                                                 si.LOCALLY_SPARSE_NOISE_8DEG)
def lsn(nwb_c, analysis_c):
    # in order to work around 2/3 unicode compatibility, separate files are specified for python 2 and 3
    # we need to look up a different key depending on python version
    key =  si.LOCALLY_SPARSE_NOISE_4DEG if sys.version_info < (3,) else si.LOCALLY_SPARSE_NOISE

    return LocallySparseNoise.from_analysis_file(BODS(nwb_c), analysis_c, key)