コード例 #1
0
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)
コード例 #2
0
    def filter_ophys_experiments(self, experiments,
                                 ids=None,
                                 experiment_container_ids=None,
                                 targeted_structures=None,
                                 imaging_depths=None,
                                 transgenic_lines=None,
                                 stimuli=None,
                                 session_types=None):

        # re-using the code from above
        experiments = self.filter_experiment_containers(experiments,
                                                        ids=ids,
                                                        targeted_structures=targeted_structures,
                                                        imaging_depths=imaging_depths,
                                                        transgenic_lines=transgenic_lines)

        if experiment_container_ids is not None:
            experiments = [e for e in experiments if e[
                'experiment_container_id'] in experiment_container_ids]

        if session_types is not None:
            experiments = [e for e in experiments if e[
                'stimulus_name'] in session_types]

        if stimuli is not None:
            experiments = [e for e in experiments
                           if len(set(stimuli) & set(stimulus_info.stimuli_in_session(e['stimulus_name']))) > 0]

        return experiments
コード例 #3
0
    def get_ophys_experiment_stimuli(self, experiment_id):
        """ For a single experiment, return the list of stimuli present in that experiment. """
        exps = self.get_ophys_experiments(ids=[experiment_id])

        if len(exps) == 0:
            return None

        return stim_info.stimuli_in_session(exps[0]['session_type'])
コード例 #4
0
    def get_ophys_experiment_stimuli(self, experiment_id):
        """ For a single experiment, return the list of stimuli present in that experiment. """
        exps = self.get_ophys_experiments(ids=[experiment_id])

        if len(exps) == 0:
            return None

        return stim_info.stimuli_in_session(exps[0]['session_type'])
コード例 #5
0
    def filter_ophys_experiments(self,
                                 experiments,
                                 ids=None,
                                 experiment_container_ids=None,
                                 targeted_structures=None,
                                 imaging_depths=None,
                                 cre_lines=None,
                                 reporter_lines=None,
                                 transgenic_lines=None,
                                 stimuli=None,
                                 session_types=None,
                                 include_failed=False,
                                 require_eye_tracking=False,
                                 simple=False):

        experiments = self.filter_experiments_and_containers(
            experiments,
            ids=ids,
            targeted_structures=targeted_structures,
            imaging_depths=imaging_depths,
            cre_lines=cre_lines,
            reporter_lines=reporter_lines,
            transgenic_lines=transgenic_lines)

        if require_eye_tracking:
            experiments = [
                e for e in experiments
                if e.get('fail_eye_tracking', None) is False
            ]
        if not include_failed:
            experiments = [
                e for e in experiments
                if not e.get('experiment_container', {}).get('failed', False)
            ]

        if experiment_container_ids is not None:
            experiments = [
                e for e in experiments
                if e['experiment_container_id'] in experiment_container_ids
            ]

        if session_types is not None:
            experiments = [
                e for e in experiments if e['stimulus_name'] in session_types
            ]

        if stimuli is not None:
            experiments = [
                e for e in experiments if len(
                    set(stimuli)
                    & set(stimulus_info.stimuli_in_session(e['stimulus_name']))
                ) > 0
            ]

        if simple:
            experiments = self.simplify_ophys_experiments(experiments)

        return experiments
コード例 #6
0
    def filter_ophys_experiments(self, experiments,
                                 ids=None,
                                 experiment_container_ids=None,
                                 targeted_structures=None,
                                 imaging_depths=None,
                                 cre_lines=None,
                                 reporter_lines=None,
                                 transgenic_lines=None,
                                 stimuli=None,
                                 session_types=None,
                                 include_failed=False,
                                 require_eye_tracking=False,
                                 simple=False):

        experiments = self.filter_experiments_and_containers(experiments,
                                                             ids=ids,
                                                             targeted_structures=targeted_structures,
                                                             imaging_depths=imaging_depths,
                                                             cre_lines=cre_lines,
                                                             reporter_lines=reporter_lines,
                                                             transgenic_lines=transgenic_lines)

        if require_eye_tracking:
            experiments = [e for e in experiments
                           if e.get('fail_eye_tracking', None) is False]
        if not include_failed:
            experiments = [e for e in experiments 
                           if not e.get('experiment_container',{}).get('failed', False)]

        if experiment_container_ids is not None:
            experiments = [e for e in experiments if e[
                'experiment_container_id'] in experiment_container_ids]

        if session_types is not None:
            experiments = [e for e in experiments if e[
                'stimulus_name'] in session_types]

        if stimuli is not None:
            experiments = [e for e in experiments
                           if len(set(stimuli) & set(stimulus_info.stimuli_in_session(e['stimulus_name']))) > 0]

        if simple:
            experiments = self.simplify_ophys_experiments(experiments)

        return experiments
コード例 #7
0
def _add_stim_epochs(trace,ax,data_set):

    stim_colors_dict = {'locally_sparse_noise':'green','drifting_gratings':'yellow','natural_movie_one':'magenta','natural_movie_two':'magenta','natural_movie_three':'red','natural_scenes':'orange','spontaneous':'grey','static_gratings':'blue'}

    from allensdk.brain_observatory.stimulus_info import stimuli_in_session

    stim_types = stimuli_in_session(data_set.get_metadata()['session_type'])


    for stim in stim_types:
        #print(stim)
        stim_table = data_set.get_stimulus_table(stim)
        window_list = _get_epoch_windows(stim_table)
        for w in window_list:
            #ax.fill_betweenx(np.arange(trace.shape[0]),w[0],w[1],facecolor=stim_colors_dict[stim],alpha=0.2)
            #ax.axvspan(w[0],w[1],np.min(trace),np.max(trace),facecolor=stim_colors_dict[stim],alpha=0.2)
            ax.axvspan(w[0],w[1],facecolor=stim_colors_dict[stim],alpha=0.2)
            ax.set_ylim([np.min(trace),np.max(trace)])
コード例 #8
0
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()