Source code for neuroconv.datainterfaces.ecephys.axon.axondatainterface
from datetime import datetime, timedelta
from pathlib import Path
from warnings import warn
from pydantic import FilePath
from pynwb.ecephys import ElectricalSeries
from ..baserecordingextractorinterface import BaseRecordingExtractorInterface
from ....utils import DeepDict, get_schema_from_hdmf_class
[docs]
class AxonRecordingInterface(BaseRecordingExtractorInterface):
"""
Data interface class for converting extracellular data recorded in Axon Binary Format (ABF) data.
Uses the :py:func:`~spikeinterface.extractors.read_axon` reader from SpikeInterface.
"""
display_name = "Axon Recording"
keywords = BaseRecordingExtractorInterface.keywords + ("axon", "abf")
associated_suffixes = (".abf",)
info = "Interface for extracellular data recorded in Axon Binary Format (ABF) recordings."
[docs]
@classmethod
def get_source_schema(cls) -> dict:
source_schema = super().get_source_schema()
source_schema["properties"]["file_path"]["description"] = "Path to an Axon Binary Format (.abf) file"
return source_schema
def __init__(
self,
file_path: FilePath,
verbose: bool = False,
es_key: str = "ElectricalSeries",
):
"""
Load and prepare raw data and corresponding metadata from the Axon Binary Format (.abf files).
Parameters
----------
file_path : FilePath
Path to an Axon Binary Format (.abf) file
verbose : bool, default: False
Verbose
es_key : str, default: "ElectricalSeries"
The key for the ElectricalSeries in the metadata
"""
self.file_path = Path(file_path)
super().__init__(file_path=file_path, verbose=verbose, es_key=es_key)
def _get_start_datetime(self, neo_reader):
"""
Get start datetime for ABF file.
Parameters
----------
neo_reader : neo.io.AxonIO
The Neo reader object for the ABF file.
Returns
-------
datetime
The start date and time of the recording.
"""
if all(k in neo_reader._axon_info for k in ["uFileStartDate", "uFileStartTimeMS"]):
startDate = str(neo_reader._axon_info["uFileStartDate"])
startTime = round(neo_reader._axon_info["uFileStartTimeMS"] / 1000)
startDate = datetime.strptime(startDate, "%Y%m%d")
startTime = timedelta(seconds=startTime)
return startDate + startTime
else:
warn(
f"uFileStartDate or uFileStartTimeMS not found in {neo_reader.filename.split('/')[-1]}, datetime for "
"recordings might be wrongly stored."
)
return neo_reader._axon_info["rec_datetime"]