Example #1
0
    def process_accumulated_data(self,
                                 accumulated_data,
                                 save=True,
                                 rawfile=False):

        if rawfile:
            for idx, raw_npz_file in enumerate(os.listdir(self.save_folder)):
                d = np.load(os.path.join(self.save_folder, raw_npz_file))
                rawdata = d['data']
                accumulated_data = hht4.filter_raw_antibunch_data(
                    rawdata, 0, 700)
                dts = hht4.get_dts(accumulated_data, start_ch=0, stop_ch=1)

                if save:
                    np.savez(os.path.join(self.save_folder,
                                          'Dts_%.3d.npz' % idx),
                             dts=dts,
                             data=accumulated_data)

        else:
            dts = hht4.get_dts(accumulated_data, start_ch=0, stop_ch=1)

            if save:
                np.savez(os.path.join(self.save_folder, 'Dts.npz'),
                         dts=dts,
                         data=accumulated_data)

        return dts
    def process_accumulated_data(self, accumulated_data, save = True, rawfile = False):
        
        if rawfile:
            for idx, raw_npz_file in enumerate(os.listdir(self.save_folder)):
                d = np.load(os.path.join(self.save_folder, raw_npz_file))
                rawdata = d['data']
                accumulated_data = hht4.filter_raw_antibunch_data(rawdata, 0, 700)
                dts = hht4.get_dts(accumulated_data, start_ch = 0, stop_ch = 1)

                if save:
                    np.savez(os.path.join(self.save_folder, 'Dts_%.3d.npz'%idx), 
                            dts = dts, data = accumulated_data)

        else:
            dts = hht4.get_dts(accumulated_data, start_ch = 0, stop_ch = 1)

            if save:
                np.savez(os.path.join(self.save_folder, 'Dts.npz'), 
                        dts = dts, data = accumulated_data)

        return dts
Example #3
0
    def get_T3_pulsed_events(self,
                             sync_period,
                             start_ch0=0,
                             start_ch1=0,
                             save_raw=True,
                             raw_max_len=1E6,
                             sleep_time=10E-3):
        """
        Get ch0 and ch1 events in T3 mode.
        Author: Wolfgang, July 1, 2012.
        Adapted by Gerwin, June 20, 2013

        Filtering options:
        start_ch0, start_ch1:
            minimum event time (in bins) after the sync
        max_pulses:
            how many syncs after a marker on channel 1 are taken into
            account
        
        returns:
            (ch0, ch1, markers)
            ch0: array with two columns: col1 = absolute sync no, col2 = time
            ch1: ditto
            markers: array with three columns:
                col1 = sync no, col2 = time, col3 = marker channel
        """

        if .001 * hharp.get_ResolutionPS() * 2**15 < sync_period:
            print('Warning: resolution is too high to cover entire sync \
                    period in T3 mode, events might get lost.')

        #prepare for saving the data; create directory etc...
        if save_raw:
            rawdir = self.save_folder
            if not os.path.isdir(rawdir):
                os.makedirs(rawdir)
            rawidx = 0
            lengths = np.array([])
            times = np.array([])
            accumulated_data = np.empty((0, 4), dtype=np.uintc)
        else:
            #initialize the overflow offset number to 0. This will be updated in
            #the loop everytime the function is called later on. In this way the
            #sync number increases linearly with time and doesn't fall back
            #everytime the function is called.
            syncnr_offset = 0
            accumulated_data = np.empty((0, 4), dtype=np.uintc)
            rawidx = 0

        #here comes the actual data acquisition
        while hharp.get_MeasRunning() == True:
            length, data = hharp.get_TTTR_Data()

            #if we don't want to process the data at all use this
            if save_raw:
                accumulated_data = np.append(accumulated_data, data[:length])
                lengths = np.append(lengths, length)
                times = np.append(times, int(time.strftime('%M%S')))

                if len(accumulated_data) > raw_max_len:
                    np.savez(os.path.join(rawdir, 'LDE_rawdata-%.3d' % rawidx),
                             length=len(accumulated_data),
                             data=accumulated_data)

                    accumulated_data = np.array([])
                    rawidx += 1

            #if we first want to filter the data before saving use this
            else:
                print "I registered... %d events" % length
                #analyze the entire array or just the new data?
                prefiltered, syncnr_offset = hht4.filter_raw_antibunch_data(
                    data[:length], syncnr_offset,
                    int(self.sync_rep_rate / 0.256),
                    int(self.sync_rep_rate / 0.256))

                accumulated_data = np.append(accumulated_data,
                                             prefiltered,
                                             axis=0)

                #if the accumulated_data is large enough, save it to a file
                if len(accumulated_data) > raw_max_len:
                    print "Saving accumulated data..."
                    np.savez(os.path.join(rawdir,
                                          'LDE_prefiltered-%.3d' % rawidx),
                             length=len(accumulated_data),
                             data=accumulated_data)

                    rawidx += 1
                    accumulated_data = np.array((0, 4), dtype=np.uintc)

            #Sleeping might give a bit more stable data acquisition
            #But be careful not to make it too big
            qt.msleep(sleep_time, exact=True)

            if (msvcrt.kbhit() and msvcrt.getch() == 'x'):
                print 'x pressed, quitting current run'
                hharp.StopMeas()

        return accumulated_data
    def get_T3_pulsed_events(self, sync_period, 
            start_ch0=0, start_ch1=0, save_raw=True, raw_max_len=1E6, 
            sleep_time = 10E-3):
        """
        Get ch0 and ch1 events in T3 mode.
        Author: Wolfgang, July 1, 2012.
        Adapted by Gerwin, June 20, 2013

        Filtering options:
        start_ch0, start_ch1:
            minimum event time (in bins) after the sync
        max_pulses:
            how many syncs after a marker on channel 1 are taken into
            account
        
        returns:
            (ch0, ch1, markers)
            ch0: array with two columns: col1 = absolute sync no, col2 = time
            ch1: ditto
            markers: array with three columns:
                col1 = sync no, col2 = time, col3 = marker channel
        """

        if .001*hharp.get_ResolutionPS() * 2**15 < sync_period:
            print('Warning: resolution is too high to cover entire sync \
                    period in T3 mode, events might get lost.')

        #prepare for saving the data; create directory etc...
        if save_raw:
            rawdir = self.save_folder
            if not os.path.isdir(rawdir):
                os.makedirs(rawdir)
            rawidx = 0
            lengths = np.array([])
            times = np.array([])
            accumulated_data = np.empty((0,4), dtype = np.uintc)
        else:        
            #initialize the overflow offset number to 0. This will be updated in
            #the loop everytime the function is called later on. In this way the
            #sync number increases linearly with time and doesn't fall back 
            #everytime the function is called.
            syncnr_offset = 0
            accumulated_data = np.empty((0,4), dtype = np.uintc)
            rawidx = 0

        #here comes the actual data acquisition    
        while hharp.get_MeasRunning() == True:
            length, data = hharp.get_TTTR_Data()

            #if we don't want to process the data at all use this
            if save_raw:
                accumulated_data = np.append(accumulated_data, data[:length])
                lengths = np.append(lengths, length)
                times = np.append(times, int(time.strftime('%M%S')))
                
                if len(accumulated_data) > raw_max_len:
                    np.savez(os.path.join(rawdir, 'LDE_rawdata-%.3d'%rawidx), 
                        length=len(accumulated_data), data=accumulated_data)
                    
                    accumulated_data = np.array([])
                    rawidx += 1
            
            #if we first want to filter the data before saving use this
            else:
                print "I registered... %d events"%length
                #analyze the entire array or just the new data?
                prefiltered, syncnr_offset = hht4.filter_raw_antibunch_data(
                        data[:length], syncnr_offset, int(self.sync_rep_rate/0.256),
                        int(self.sync_rep_rate/0.256))
               
                accumulated_data = np.append(accumulated_data, prefiltered, axis = 0)
                
                #if the accumulated_data is large enough, save it to a file
                if len(accumulated_data) > raw_max_len:
                    print "Saving accumulated data..."
                    np.savez(os.path.join(rawdir, 'LDE_prefiltered-%.3d'%rawidx), 
                        length=len(accumulated_data), data=accumulated_data)
                    
                    rawidx += 1
                    accumulated_data = np.array((0,4), dtype = np.uintc)
            
            #Sleeping might give a bit more stable data acquisition
            #But be careful not to make it too big
            qt.msleep(sleep_time, exact = True)
            
            if(msvcrt.kbhit() and msvcrt.getch()=='x'):
                print 'x pressed, quitting current run'
                hharp.StopMeas()

        return accumulated_data