Source code for ipfx.dataset.ephys_data_interface
from typing import Dict, Any, Sequence
import abc
import warnings
from datetime import datetime
from ipfx.stimulus import StimulusOntology
[docs]class EphysDataInterface(abc.ABC):
"""
The interface that any child class providing data to the EphysDataSet must implement
"""
def __init__(self, ontology: StimulusOntology, validate_stim: bool = True):
self.ontology = ontology
self.validate_stim = validate_stim
@abc.abstractproperty
def sweep_numbers(self) -> Sequence[int]:
"""A time-ordered sequence of each sweep's integer identifier
"""
[docs] @abc.abstractmethod
def get_sweep_data(self, sweep_number: int) -> Dict[str, Any]:
"""
Extract sweep data
Parameters
----------
sweep_number
Returns
-------
dict in the format:
{
'stimulus': np.ndarray,
'response': np.ndarray,
'stimulus_unit': string,
'sampling_rate': float
}
"""
raise NotImplementedError
[docs] @abc.abstractmethod
def get_sweep_attrs(self, sweep_number) -> Dict[str, Any]:
"""
Extract sweep attributes
Parameters
----------
sweep_number
Returns
-------
sweep attributes
"""
raise NotImplementedError
[docs] @abc.abstractmethod
def get_stimulus_code(self, sweep_number: int) -> str:
"""Obtain the code of the stimulus presented on a particular sweep.
Parameters
----------
sweep_number : unique identifier for the sweep
Returns
-------
The codified name of the stimulus presented on the
identified sweep
"""
raise NotImplementedError
[docs] @abc.abstractmethod
def get_full_recording_date(self) -> datetime:
"""Obtain the full date and time at which recording began.
Returns
-------
A datetime object, with timezone, reporting the start of recording
"""
[docs] @abc.abstractmethod
def get_stimulus_unit(self, sweep_number: int) -> str:
"""
Extract unit of a stimulus
Parameters
----------
sweep_number
Returns
-------
stimulus unit
"""
raise NotImplementedError
[docs] def get_stimulus_name(self, stim_code):
if not self.ontology:
raise ValueError("Missing stimulus ontology")
try:
stim = self.ontology.find_one(stim_code, tag_type="code")
return stim.tags(tag_type="name")[0][-1]
except KeyError:
if self.validate_stim:
raise
else:
warnings.warn("Stimulus code {} is not in the ontology".format(stim_code))
return
[docs] @abc.abstractmethod
def get_clamp_mode(self, sweep_number) -> str:
"""
Extract clamp mode from the class of Time Series
Parameters
----------
sweep_number
Returns
-------
"""
raise NotImplementedError