def drop_failed_sweeps( dataset: EphysDataSet, stimulus_ontology: Optional[StimulusOntology] = None, qc_criteria: Optional[Dict] = None ) -> List[Dict]: """A convenience which extracts and QCs sweeps in preparation for dataset feature extraction. This function: 1. extracts sweep qc features 2. removes sweeps tagged with failure messages 3. sets sweep states based on qc results Parameters ---------- dataset : dataset from which to draw sweeps Returns ------- sweep_features : a list of dictionaries, each describing a sweep """ if stimulus_ontology is None: stimulus_ontology = StimulusOntology.default() if qc_criteria is None: qc_criteria = qcp.load_default_qc_criteria() sweep_features = sweep_qc_features(dataset) sweep_props.drop_tagged_sweeps(sweep_features) sweep_props.remove_sweep_feature("tags", sweep_features) sweep_states = qcp.qc_sweeps( stimulus_ontology, sweep_features, qc_criteria ) sweep_props.assign_sweep_states(sweep_states, sweep_features) dataset.sweep_info = sweep_features
import pandas as pd from ipfx.dataset.create import create_ephys_data_set from ipfx.qc_feature_extractor import sweep_qc_features import ipfx.sweep_props as sweep_props import ipfx.qc_feature_evaluator as qcp from ipfx.stimulus import StimulusOntology # Download and access the experimental data from DANDI archive per instructions in the documentation # Example below will use an nwb file provided with the package nwb_file = os.path.join(os.path.dirname(os.getcwd()), "data", "nwb2_H17.03.008.11.03.05.nwb") data_set = create_ephys_data_set(nwb_file=nwb_file) # Compute sweep QC features sweep_features = sweep_qc_features(data_set) # Drop sweeps that failed to compute QC criteria sweep_props.drop_tagged_sweeps(sweep_features) sweep_props.remove_sweep_feature("tags", sweep_features) stimulus_ontology = StimulusOntology.default() qc_criteria = qcp.load_default_qc_criteria() sweep_states = qcp.qc_sweeps(stimulus_ontology, sweep_features, qc_criteria) # print a few sweeps and states print(pd.DataFrame(sweep_features).head()) print(sweep_states[0:len(pd.DataFrame(sweep_features).head())])