width_delay_beam_experiment/DataAnalysis.py
def calculate_envelope(self, neg = False):
        '''
        Calculate_envelope: calculates the positive envelop of the given
        waveform by default (neg = True, for negative envelope) and fits
        the envelop to a model function.

        assumes:
        - the waveform contains clean data -- i.e. waveform.clean(..) has
          been called.

        arguments:
        - neg(bool): a boolean flag which determines if the positive envelope or
                     negative envelope (default False -- positive envelope)
                     is needed.

        returns:
        - nothing: sets the envelope, fitted envelope, and ideal
                   instance attributes.
        '''
        ## This is a hack to get the envelope, since the data is
        ## high frequency -- I keep the lookahead parameter very low
        ## and the delta parameter 0, so that it finds all the positive
        ## peaks of individual pulse signals.
        ##
        ## Then I run the algorithm again, on the result of the first run
        ## the net effect is a smoothing out of the maxima and we end up
        ## with the envelope.
        ##
        ## This sometimes has a bit of noise in the final result -- but
        ## works most of the time.
        tempx, tempy = peak_detect(self.waveform.clean_t, self.waveform.clean_V)
        self.envelope_t, self.envelope_V = peak_detect(tempx, tempy)

        # Exlcude a certain number of points from the beginning
        # of the data
        fitStart = 16

        # Fit the envelope
        mod, params = envelope_fit(self.envelope_t[fitStart:],
                          self.envelope_V[fitStart:],
                          verbose=False)

        # Set the predicted envelope instance attribute
        self.envelope_V_predict = mod.eval(params, t=self.waveform.clean_t)

        # Set the ideal_V instance attribute
        # ideal_V is what the signal should look like if the ground
        # voltage wasn't increasing.
        self.ideal_V = self.waveform.clean_V - self.envelope_V_predict

        # Re-set the predicted envelope data
        # instances to match len(self.envelope_V)
        self.envelope_V_predict = mod.eval(params, t=self.envelope_t)
        self.envelope_t_predict = self.envelope_t
        self.envelope_numturns_predict = self.envelope_t_predict*self.waveform.true_freq

        # Exclude positive values (since the amplifier at KURRI is an
        # inverting amplifier, the ideal signal is purely negative).
        filtered = self.ideal_V <= 0

        # Re-set the ideal values
        self.ideal_V, self.ideal_t, self.ideal_numturns = (
            self.ideal_V[filtered], self.waveform.clean_t[filtered],
            self.waveform.clean_numturns[filtered])
        return

        Calculate_envelope: calculates the positive envelop of the given
        waveform by default (neg = True, for negative envelope) and fits
        the envelop to a model function.

        assumes:
        - the waveform contains clean data -- i.e. waveform.clean(..) has
          been called.

        arguments:
        - neg(bool): a boolean flag which determines if the positive envelope or
                     negative envelope (default False -- positive envelope)
                     is needed.

        returns:
        - nothing: sets the envelope, fitted envelope, and ideal
                   instance attributes.
        
calculates the positive envelop of the given
waveform by default (neg = True, for negative envelope) and fits
the envelop to a model function.

the waveform contains clean data -- i.e.

a boolean flag which determines if the positive envelope or
negative envelope (default False -- positive envelope)
is needed.

sets the envelope, fitted envelope, and ideal
instance attributes.
calculates the positive envelop of the given waveform by default ( neg = True for negative envelope ) and fits the envelop to a model function . the waveform contains clean data -- i . e . a boolean flag which determines if the positive envelope or negative envelope ( default False -- positive envelope ) is needed . sets the envelope fitted envelope and ideal instance attributes .
def calculate_envelope(self, neg = False):
         Then I run the algorithm again, on the result of the first run
         the net effect is a smoothing out of the maxima and we end up
         with the envelope.
         This sometimes has a bit of noise in the final result -- but
         works most of the time.
        tempx, tempy = peak_detect(self.waveform.clean_t, self.waveform.clean_V)
        self.envelope_t, self.envelope_V = peak_detect(tempx, tempy)
        fitStart = 16
        mod, params = envelope_fit(self.envelope_t[fitStart:],
                          self.envelope_V[fitStart:],
                          verbose=False)
        self.envelope_V_predict = mod.eval(params, t=self.waveform.clean_t)
        self.ideal_V = self.waveform.clean_V - self.envelope_V_predict
        self.envelope_V_predict = mod.eval(params, t=self.envelope_t)
        self.envelope_t_predict = self.envelope_t
        self.envelope_numturns_predict = self.envelope_t_predict*self.waveform.true_freq
        filtered = self.ideal_V <= 0
        self.ideal_V, self.ideal_t, self.ideal_numturns = (
            self.ideal_V[filtered], self.waveform.clean_t[filtered],
            self.waveform.clean_numturns[filtered])
        return
def calculate_envelope ( self , neg = False ) : tempx , tempy = peak_detect ( self . waveform . clean_t , self . waveform . clean_V ) self . envelope_t , self . envelope_V = peak_detect ( tempx , tempy ) fitStart = 16 mod , params = envelope_fit ( self . envelope_t [ fitStart : ] , self . envelope_V [ fitStart : ] , verbose = False ) self . envelope_V_predict = mod . eval ( params , t = self . waveform . clean_t ) self . ideal_V = self . waveform . clean_V - self . envelope_V_predict self . envelope_V_predict = mod . eval ( params , t = self . envelope_t ) self . envelope_t_predict = self . envelope_t self . envelope_numturns_predict = self . envelope_t_predict * self . waveform . true_freq filtered = self . ideal_V <= 0 self . ideal_V , self . ideal_t , self . ideal_numturns = ( self . ideal_V [ filtered ] , self . waveform . clean_t [ filtered ] , self . waveform . clean_numturns [ filtered ] ) return
Calculate_envelope: calculates the positive envelop of the given
waveform by default (neg = True, for negative envelope) and fits
the envelop to a model function.
Calculate_envelope : calculates the positive envelop of the given waveform by default ( neg = True for negative envelope ) and fits the envelop to a model function .
'''
        Calculate_envelope: calculates the positive envelop of the given
        waveform by default (neg = True, for negative envelope) and fits
        the envelop to a model function.

        assumes:
        - the waveform contains clean data -- i.e. waveform.clean(..) has
          been called.

        arguments:
        - neg(bool): a boolean flag which determines if the positive envelope or
                     negative envelope (default False -- positive envelope)
                     is needed.

        returns:
        - nothing: sets the envelope, fitted envelope, and ideal
                   instance attributes.
        ''' ## This is a hack to get the envelope, since the data is ## high frequency -- I keep the lookahead parameter very low ## and the delta parameter 0, so that it finds all the positive ## peaks of individual pulse signals. ## ## Then I run the algorithm again, on the result of the first run ## the net effect is a smoothing out of the maxima and we end up ## with the envelope. ## ## This sometimes has a bit of noise in the final result -- but ## works most of the time. # Exlcude a certain number of points from the beginning # of the data # Fit the envelope # Set the predicted envelope instance attribute # Set the ideal_V instance attribute # ideal_V is what the signal should look like if the ground # voltage wasn't increasing. # Re-set the predicted envelope data # instances to match len(self.envelope_V) # Exclude positive values (since the amplifier at KURRI is an # inverting amplifier, the ideal signal is purely negative). # Re-set the ideal values
self
neg