Exemplo n.º 1
0
 def __init__(self):
     """Initiate all the values."""
     self.constants = MeasurementConstants()
     self.sampleRate = self.constants.patchSealSampRate
     self.frequency = self.constants.patchSealFreq
     self.voltMin = self.constants.patchSealMinVol
     self.voltMax = self.constants.patchSealMaxVol
     self.dutycycle = self.constants.patchSealDuty
     self.readNumber= 500 #Readnumber for the measurementThread (should be a multiple of the wavelength)
     #self.constant = constant
     #wave = self.constant
     wave = blockWave(self.sampleRate, self.frequency, self.voltMin, self.voltMax, self.dutycycle)
     self.measurementThread_hold = ContinuousPatchThread_hold(wave, self.sampleRate, self.readNumber)
    def updateLabels(self, curOut, voltOut):
        """Update the resistance and capacitance labels.
        http://scipy-lectures.org/intro/scipy/auto_examples/plot_curve_fit.html
        https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html"""
        constants = MeasurementConstants()
        sampPerCyc = int(constants.patchSealSampRate / constants.patchSealFreq)

        try:
            curOutCyc = curOut.reshape(int(curOut.size / sampPerCyc),
                                       sampPerCyc)
            curData = np.mean(curOutCyc, axis=0)
        except:
            curData = curOut

        voltData = voltOut
        try:
            #Computing resistance
            tres = np.mean(voltData)
            dV = np.mean(voltData[voltData > tres]) - np.mean(
                voltData[voltData < tres])  #Computing the voltage difference
            dIss = np.mean(
                curData[math.floor(0.15 *
                                   sampPerCyc):math.floor(sampPerCyc / 2) -
                        2]) - np.mean(
                            curData[math.floor(0.65 * sampPerCyc):sampPerCyc -
                                    2])  #Computing the current distance
            membraneResistance = dV / (dIss * 1000000)  #Ohms law (MegaOhm)
            self.resistanceLabel.setText("Resistance:  %.4f M\u03A9" %
                                         membraneResistance)

            self.estimated_size_resistance = 10000 / (
                membraneResistance * 1000000
            )  #The resistance of a typical patch of membrane, RM is 10000 Omega/{cm}^2
        except:
            self.resistanceLabel.setText("Resistance:  %s" % 'NaN')

        try:
            measured_vlotage = np.mean(voltData) * 1000
            self.membraneVoltLabel.setText("Vm:  %.2f mV" % measured_vlotage)
            self.membraneVoltLabel.setStyleSheet('color: red')
        except:
            self.membraneVoltLabel.setText("Vm:  %s" % 'NaN')
        try:
            #Computing capacitance
            points = 10
            maxCur = np.amax(curData)
            maxCurIndex = np.where(curData == maxCur)[0][0]
            curFit = curData[int(maxCurIndex + 1):int(
                maxCurIndex + 1 + points - 1)] - 0.5 * (np.mean(curData[
                    math.floor(0.15 * sampPerCyc):math.floor(sampPerCyc / 2) -
                    2]) + np.mean(
                        curData[math.floor(0.65 * sampPerCyc):sampPerCyc - 2]))
            timepoints = 1000 * np.arange(
                3, points - 1 + 3) / constants.patchSealSampRate
            #Fitting the data to an exponential of the form y=a*exp(-b*x) where b = 1/tau and tau = RC
            #I(t)=I0*e^−t/τ, y=a*exp(-b*x), get log of both sides:log y = -bx + log a
            fit = np.polyfit(
                timepoints, curFit, 1
            )  #Converting the exponential to a linear function and fitting it
            #Extracting data
            current = fit[0]
            resistance = dV * 1000 / current / 2  #Getting the resistance
            tau = -1 / fit[1]
            capacitance = 1000 * tau / resistance
            self.capacitanceLabel.setText("Capacitance:  %.4f" % capacitance)

            self.estimated_size_capacitance = capacitance * (10**-12) * (10**6)

            if self.estimated_size_capacitance > self.estimated_size_resistance:
                self.estimated_ratio = self.estimated_size_capacitance / self.estimated_size_resistance
            else:
                self.estimated_ratio = self.estimated_size_resistance / self.estimated_size_capacitance

            self.ratioLabel.setText(
                "Ratio:  %.4f" % self.estimated_ratio
            )  #http://www.cnbc.cmu.edu/~bard/passive2/node5.html

        except:
            self.capacitanceLabel.setText("Capacitance:  %s" % 'NaN')
            self.ratioLabel.setText("Ratio:  %s" % 'NaN')

        self.patch_parameters = "R_{}_C_{}".format(
            round(membraneResistance, 3), round(capacitance, 3))
Exemplo n.º 3
0
    def update_resistance_capacitance(self, curOut, voltOut):
        """ Update the resistance and capacitance labels.
        http://scipy-lectures.org/intro/scipy/auto_examples/plot_curve_fit.html
        https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
        This function was taken from lhuismans and modified by TvdrBurgt.
        """
        constants = MeasurementConstants()
        sampPerCyc = int(constants.patchSealSampRate / constants.patchSealFreq)

        try:
            curOutCyc = curOut.reshape(int(curOut.size / sampPerCyc),
                                       sampPerCyc)
            curData = np.mean(curOutCyc, axis=0)
        except:
            curData = curOut

        voltData = voltOut
        try:
            # Computing resistance
            tres = np.mean(voltData)
            dV = np.mean(voltData[voltData > tres]) - np.mean(
                voltData[voltData < tres])  # Computing the voltage difference
            dIss = np.mean(
                curData[int(np.floor(0.15 * sampPerCyc)
                            ):int(np.floor(sampPerCyc / 2)) - 2]) - np.mean(
                                curData[int(np.floor(0.65 *
                                                     sampPerCyc)):sampPerCyc -
                                        2])  # Computing the current distance
            membraneResistance = dV / (dIss * 1000000)  # Ohms law (MegaOhm)
            self.resistance_value_label.setText(
                "{:.2f}".format(membraneResistance))
            R_to_append = membraneResistance * 1e6

            estimated_size_resistance = 10000 / (
                membraneResistance * 1000000
            )  # The resistance of a typical patch of membrane, RM is 10000 Omega/{cm}^2
        except:
            self.resistance_value_label.setText("NaN")
            R_to_append = np.nan

        try:
            measured_vlotage = np.mean(voltData) * 1000
            self.membranevoltage_value_label.setText(
                "{:.1f}".format(measured_vlotage))
        except:
            self.membranevoltage_value_label.setText("NaN")
        try:
            # Computing capacitance
            points = 10
            maxCur = np.amax(curData)
            maxCurIndex = np.where(curData == maxCur)[0][0]
            curFit = curData[int(maxCurIndex+1) : int(maxCurIndex+1+points-1)] - \
                0.5*(np.mean(curData[int(np.floor(0.15*sampPerCyc)) : int(np.floor(sampPerCyc/2)) - 2]) + \
                     np.mean(curData[int(np.floor(0.65*sampPerCyc)) : sampPerCyc-2]))
            timepoints = 1000 * np.arange(
                3, points - 1 + 3) / constants.patchSealSampRate

            # Fitting the data to an exponential of the form y=a*exp(-b*x) where b = 1/tau and tau = RC
            # I(t)=I0*e^−t/τ, y=a*exp(-b*x), get log of both sides:log y = -bx + log a
            fit = np.polyfit(
                timepoints, curFit, 1
            )  # Converting the exponential to a linear function and fitting it

            # Extracting data
            current = fit[0]
            resistance = dV * 1000 / current / 2  # Getting the resistance
            tau = -1 / fit[1]
            capacitance = 1000 * tau / resistance
            self.capacitance_value_label.setText("{:.1f}".format(capacitance))
            C_to_append = capacitance

            estimated_size_capacitance = capacitance * (10**-12) * (10**6)

            if estimated_size_capacitance > estimated_size_resistance:
                estimated_ratio = (estimated_size_capacitance /
                                   estimated_size_resistance)
            else:
                estimated_ratio = (estimated_size_resistance /
                                   estimated_size_capacitance)

            self.ratio_value_label.setText(
                "{:.1f}".format(estimated_ratio)
            )  # http://www.cnbc.cmu.edu/~bard/passive2/node5.html

        except:
            self.capacitance_value_label.setText("NaN")
            C_to_append = np.nan
            self.ratio_value_label.setText("NaN")

        # store resistance and capacitance values in backend
        self.backend._resistance_append_(R_to_append)
        self.backend._capacitance_append_(C_to_append)