Esempio n. 1
0
    def _createStimulusSeries(self, electrodes):
        """
        Return a list of pynwb stimulus series objects created from the ABF file contents.
        """

        series = []
        counter = 0

        for file_index, abf in enumerate(self.abfs):

            stimulus_description = ABFConverter._getProtocolName(abf.protocol)
            scale_factor = self._getScaleFactor(abf, stimulus_description)

            for sweep in range(abf.sweepCount):
                cycle_id = createCycleID([file_index, sweep], total=self.totalSeriesCount)
                for channel in range(abf.channelCount):

                    if not abf._dacSection.nWaveformEnable[channel]:
                        continue

                    abf.setSweep(sweep, channel=channel, absoluteTime=True)
                    name, counter = createSeriesName("index", counter, total=self.totalSeriesCount)
                    data = convertDataset(abf.sweepC * scale_factor, self.compression)
                    conversion, unit = parseUnit(abf.sweepUnitsC)
                    electrode = electrodes[channel]
                    gain = abf._dacSection.fDACScaleFactor[channel]
                    resolution = np.nan
                    starting_time = self._calculateStartingTime(abf)
                    rate = float(abf.dataRate)
                    description = json.dumps({"cycle_id": cycle_id,
                                              "protocol": abf.protocol,
                                              "protocolPath": abf.protocolPath,
                                              "file": os.path.basename(abf.abfFilePath),
                                              "name": abf.dacNames[channel],
                                              "number": abf._dacSection.nDACNum[channel]},
                                             sort_keys=True, indent=4)

                    seriesClass = getStimulusSeriesClass(self._getClampMode(abf, channel))

                    stimulus = seriesClass(name=name,
                                           data=data,
                                           sweep_number=np.uint64(cycle_id),
                                           unit=unit,
                                           electrode=electrode,
                                           gain=gain,
                                           resolution=resolution,
                                           conversion=conversion,
                                           starting_time=starting_time,
                                           rate=rate,
                                           description=description,
                                           stimulus_description=stimulus_description)

                    series.append(stimulus)

        return series
Esempio n. 2
0
    def _createAcquiredSeries(self, electrodes):
        """
        Return a list of pynwb acquisition series objects created from the ABF file contents.
        """

        series = []
        counter = 0

        for file_index, abf in enumerate(self.abfs):

            stimulus_description = ABFConverter._getProtocolName(abf.protocol)
            _, jsonSource = self._findSettingsEntry(abf)
            log.debug(f"Using JSON settings for {jsonSource}.")

            for sweep in range(abf.sweepCount):
                cycle_id = createCycleID([file_index, sweep],
                                         total=self.totalSeriesCount)
                for channel in range(abf.channelCount):
                    adcName = abf.adcNames[channel]

                    if not self.outputFeedbackChannel:
                        if adcName in ABFConverter.adcNamesWithRealData:
                            pass
                        else:
                            # feedback data, skip
                            continue

                    abf.setSweep(sweep, channel=channel, absoluteTime=True)
                    name, counter = createSeriesName(
                        "index", counter, total=self.totalSeriesCount)
                    data = convertDataset(abf.sweepY, self.compression)
                    conversion, unit = parseUnit(abf.sweepUnitsY)
                    electrode = electrodes[channel]
                    gain = abf._adcSection.fADCProgrammableGain[channel]
                    resolution = np.nan
                    starting_time = self._calculateStartingTime(abf)
                    rate = float(abf.dataRate)
                    description = json.dumps(
                        {
                            "cycle_id": cycle_id,
                            "protocol": abf.protocol,
                            "protocolPath": abf.protocolPath,
                            "file": os.path.basename(abf.abfFilePath),
                            "name": adcName,
                            "number": abf._adcSection.nADCNum[channel]
                        },
                        sort_keys=True,
                        indent=4)

                    clampMode = self._getClampMode(abf, channel)
                    settings = self._getAmplifierSettings(
                        abf, clampMode, adcName)
                    seriesClass = getAcquiredSeriesClass(clampMode)

                    if clampMode == V_CLAMP_MODE:
                        acquistion_data = seriesClass(
                            name=name,
                            data=data,
                            sweep_number=np.uint64(cycle_id),
                            unit=unit,
                            electrode=electrode,
                            gain=gain,
                            resolution=resolution,
                            conversion=conversion,
                            starting_time=starting_time,
                            rate=rate,
                            description=description,
                            capacitance_slow=settings["capacitance_slow"],
                            capacitance_fast=settings["capacitance_fast"],
                            resistance_comp_correction=settings[
                                "resistance_comp_correction"],
                            resistance_comp_bandwidth=settings[
                                "resistance_comp_bandwidth"],
                            resistance_comp_prediction=settings[
                                "resistance_comp_prediction"],
                            stimulus_description=stimulus_description,
                            whole_cell_capacitance_comp=settings[
                                "whole_cell_capacitance_comp"],  # noqa: E501
                            whole_cell_series_resistance_comp=settings[
                                "whole_cell_series_resistance_comp"]
                        )  # noqa: E501

                    elif clampMode in (I_CLAMP_MODE, I0_CLAMP_MODE):
                        acquistion_data = seriesClass(
                            name=name,
                            data=data,
                            sweep_number=np.uint64(cycle_id),
                            unit=unit,
                            electrode=electrode,
                            gain=gain,
                            resolution=resolution,
                            conversion=conversion,
                            starting_time=starting_time,
                            rate=rate,
                            description=description,
                            bias_current=settings["bias_current"],
                            bridge_balance=settings["bridge_balance"],
                            stimulus_description=stimulus_description,
                            capacitance_compensation=settings[
                                "capacitance_compensation"])
                    else:
                        raise ValueError(
                            f"Unsupported clamp mode {clampMode}.")

                    series.append(acquistion_data)

        return series
Esempio n. 3
0
    def _createAcquiredSeries(self, electrodes, groups):
        """
        Return a list of pynwb acquisition series objects created from the DAT file contents.

        Parameters
        ----------
        electrodes: list of pynwb.IntracellularElectrode
        groups: list of GroupRecord

        Returns
        -------
        series: list of TimeSeries
        """

        nwbSeries = []
        counter = 0

        for group in groups:
            for series in group:
                for sweep in series:
                    cycle_id = createCycleID([
                        group.GroupCount, series.SeriesCount, sweep.SweepCount
                    ],
                                             total=self.totalSeriesCount)
                    for trace in sweep:
                        name, counter = createSeriesName(
                            "index", counter, total=self.totalSeriesCount)
                        data = convertDataset(self.bundle.data[trace],
                                              self.compression)

                        ampState = DatConverter._getAmplifierState(
                            self.bundle, series, trace)

                        if ampState:
                            gain = ampState.Gain
                        else:
                            gain = np.nan

                        conversion, unit = parseUnit(trace.YUnit)
                        electrodeKey = DatConverter._generateElectrodeKey(
                            trace)
                        electrode = electrodes[
                            self.electrodeDict[electrodeKey]]

                        resolution = np.nan
                        starting_time = self._getStartingTime(sweep)
                        rate = 1.0 / trace.XInterval
                        description = json.dumps(
                            {
                                "cycle_id": cycle_id,
                                "file": os.path.basename(
                                    self.bundle.file_name),
                                "group_label": group.Label,
                                "series_label": series.Label,
                                "sweep_label": sweep.Label
                            },
                            sort_keys=True,
                            indent=4)
                        clampMode = DatConverter._getClampMode(
                            ampState, cycle_id, trace)
                        seriesClass = getAcquiredSeriesClass(clampMode)
                        stimulus_description = series.Label

                        if clampMode == V_CLAMP_MODE:

                            if ampState and ampState.RsOn:
                                resistance_comp_correction = ampState.RsFraction
                                whole_cell_series_resistance_comp = ampState.RsValue
                            else:
                                resistance_comp_correction = np.nan
                                whole_cell_series_resistance_comp = np.nan

                            whole_cell_capacitance_comp = np.nan
                            resistance_comp_bandwidth = np.nan
                            resistance_comp_prediction = np.nan

                            if ampState and (ampState.AutoCFast or
                                             (ampState.CanCCFast
                                              and ampState.CCCFastOn)):
                                # stored in two doubles for enhanced precision
                                capacitance_fast = ampState.CFastAmp1 + ampState.CFastAmp2
                            else:
                                capacitance_fast = np.nan

                            if ampState and (ampState.AutoCSlow or
                                             (ampState.CanCCFast
                                              and not ampState.CCCFastOn)):
                                capacitance_slow = ampState.CSlow
                            else:
                                capacitance_slow = np.nan

                            acquistion_data = seriesClass(
                                name=name,
                                data=data,
                                sweep_number=np.uint64(cycle_id),
                                unit=unit,
                                electrode=electrode,
                                gain=gain,
                                resolution=resolution,
                                conversion=conversion,
                                starting_time=starting_time,
                                rate=rate,
                                description=description,
                                capacitance_slow=capacitance_slow,
                                capacitance_fast=capacitance_fast,
                                resistance_comp_correction=
                                resistance_comp_correction,
                                resistance_comp_bandwidth=
                                resistance_comp_bandwidth,
                                resistance_comp_prediction=
                                resistance_comp_prediction,
                                whole_cell_capacitance_comp=
                                whole_cell_capacitance_comp,
                                stimulus_description=stimulus_description,
                                whole_cell_series_resistance_comp=
                                whole_cell_series_resistance_comp
                            )  # noqa: E501

                        elif clampMode == I_CLAMP_MODE:
                            bias_current = trace.Holding

                            if ampState and (ampState.AutoCFast or
                                             (ampState.CanCCFast
                                              and ampState.CCCFastOn)):
                                # stored in two doubles for enhanced precision
                                capacitance_compensation = ampState.CFastAmp1 + ampState.CFastAmp2
                            elif ampState and (ampState.AutoCSlow or
                                               (ampState.CanCCFast
                                                and not ampState.CCCFastOn)):
                                capacitance_compensation = ampState.CSlow
                            else:
                                capacitance_compensation = np.nan

                            if ampState:
                                bridge_balance = 1.0 / ampState.GSeries
                            else:
                                bridge_balance = np.nan

                            acquistion_data = seriesClass(
                                name=name,
                                data=data,
                                sweep_number=np.uint64(cycle_id),
                                unit=unit,
                                electrode=electrode,
                                gain=gain,
                                resolution=resolution,
                                conversion=conversion,
                                starting_time=starting_time,
                                rate=rate,
                                description=description,
                                bias_current=bias_current,
                                bridge_balance=bridge_balance,
                                stimulus_description=stimulus_description,
                                capacitance_compensation=
                                capacitance_compensation)
                        else:
                            raise ValueError(
                                f"Unsupported clamp mode {clampMode}.")

                        nwbSeries.append(acquistion_data)

        return nwbSeries
Esempio n. 4
0
    def _createStimulusSeries(self, electrodes, groups):
        """
        Return a list of pynwb stimulus series objects created from the DAT file contents.

        Parameters
        ----------
        electrodes: list of pynwb.IntracellularElectrode
        groups: list of GroupRecord

        Returns
        -------
        series: list of TimeSeries
        """

        generator = StimSetGenerator(self.bundle)
        nwbSeries = []
        counter = 0

        for group in groups:
            for series in group:
                for sweep in series:
                    cycle_id = createCycleID([
                        group.GroupCount, series.SeriesCount, sweep.SweepCount
                    ],
                                             total=self.totalSeriesCount)
                    stimRec = self.bundle.pgf[getStimulusRecordIndex(sweep)]
                    for trace in sweep:
                        stimset = generator.fetch(sweep, trace)

                        if not len(stimset):
                            print(
                                f"Can not yet recreate stimset {series.Label}")
                            continue

                        name, counter = createSeriesName(
                            "index", counter, total=self.totalSeriesCount)

                        sweepIndex = sweep.SweepCount - 1
                        data = convertDataset(stimset[sweepIndex],
                                              self.compression)

                        electrodeKey = DatConverter._generateElectrodeKey(
                            trace)
                        electrode = electrodes[
                            self.electrodeDict[electrodeKey]]
                        gain = 1.0
                        resolution = np.nan
                        stimulus_description = series.Label
                        starting_time = self._getStartingTime(sweep)
                        rate = 1.0 / stimRec.SampleInterval
                        description = json.dumps(
                            {
                                "cycle_id": cycle_id,
                                "file": os.path.basename(
                                    self.bundle.file_name),
                                "group_label": group.Label,
                                "series_label": series.Label,
                                "sweep_label": sweep.Label
                            },
                            sort_keys=True,
                            indent=4)

                        ampState = DatConverter._getAmplifierState(
                            self.bundle, series, trace)
                        clampMode = DatConverter._getClampMode(
                            ampState, cycle_id, trace)

                        if clampMode == V_CLAMP_MODE:
                            conversion, unit = 1e-3, "V"
                        elif clampMode == I_CLAMP_MODE:
                            conversion, unit = 1e-12, "A"

                        seriesClass = getStimulusSeriesClass(clampMode)

                        timeSeries = seriesClass(
                            name=name,
                            data=data,
                            sweep_number=np.uint64(cycle_id),
                            unit=unit,
                            electrode=electrode,
                            gain=gain,
                            resolution=resolution,
                            rate=rate,
                            stimulus_description=stimulus_description,
                            starting_time=starting_time,
                            conversion=conversion,
                            description=description)

                        nwbSeries.append(timeSeries)

        return nwbSeries