Ejemplo n.º 1
0
        run = int(run)

        reader = Reader(datapath,run)

        try:
            print(reader.status())
        except Exception as e:
            print('Status Tree not present.  Returning Error.')
            print('\nError in %s'%inspect.stack()[0][3])
            print(e)
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
            sys.exit(1)
        
        tct = TemplateCompareTool(reader, final_corr_length=final_corr_length, crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, waveform_index_range=(None,None), plot_filters=False,apply_phase_response=False)
        
        filename = createFile(reader) #Creates an analysis file if one does not exist.  Returns filename to load file.
        


        if filename is not None:
            with h5py.File(filename, 'r') as file:
                print(list(file['time_delays'].keys()))
                rf_cut = file['trigger_type'][...] == 2
                peak = file['inband_peak_freq_MHz'][...]
                peak_cut = numpy.logical_and(peak > 76, peak < 81)
                p2p = file['p2p'][...]


                '''
Ejemplo n.º 2
0
        eventids = {}
        eventids['hpol'] = numpy.sort(known_pulser_ids['run%i' % run]['hpol'])
        eventids['vpol'] = numpy.sort(known_pulser_ids['run%i' % run]['vpol'])
        all_eventids = numpy.sort(
            numpy.append(eventids['hpol'], eventids['vpol']))

        hpol_eventids_cut = numpy.isin(all_eventids, eventids['hpol'])
        vpol_eventids_cut = numpy.isin(all_eventids, eventids['vpol'])

        #Set up tempalte compare tool used for making averaged waveforms for first pass alignment.
        reader = Reader(datapath, run)
        tct = TemplateCompareTool(
            reader,
            final_corr_length=final_corr_length,
            crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
            crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
            low_pass_filter_order=low_pass_filter_order,
            high_pass_filter_order=high_pass_filter_order,
            waveform_index_range=waveform_index_range,
            plot_filters=plot_filters,
            apply_phase_response=apply_phase_response)

        #First pass alignment to make templates.
        times, hpol_waveforms = tct.averageAlignedSignalsPerChannel(
            eventids['hpol'],
            align_method=0,
            template_eventid=eventids['hpol'][0],
            plot=False,
            event_type='hpol')
        times, vpol_waveforms = tct.averageAlignedSignalsPerChannel(
            eventids['vpol'],
            align_method=0,
                    try:
                        load_cut = numpy.isin(file['eventids'][...], eventids)
                        calibrated_trigtime = file['calibrated_trigtime'][
                            load_cut]
                        print('\nProcessing Run %i' % run)

                        if numpy.any([
                                plot_averaged_waveforms,
                                get_averaged_waveforms,
                                plot_averaged_waveforms_aligned
                        ]):
                            tct = TemplateCompareTool(
                                reader,
                                final_corr_length=final_corr_length,
                                crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                                crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                                low_pass_filter_order=low_pass_filter_order,
                                high_pass_filter_order=high_pass_filter_order,
                                waveform_index_range=waveform_index_range,
                                plot_filters=False,
                                apply_phase_response=apply_phase_response)

                            #First pass alignment to make templates.
                            times, averaged_waveforms = tct.averageAlignedSignalsPerChannel(
                                eventids,
                                template_eventid=eventids[-1],
                                align_method=0,
                                plot=plot_averaged_waveforms_aligned)

                            if plot_averaged_waveforms:
                                plt.figure()
                                plt.suptitle(
Ejemplo n.º 4
0
        if 'run%i' % run in list(known_pulser_ids.keys()):
            try:
                if 'run%i' % run in list(ignorable_pulser_ids.keys()):
                    eventids = numpy.sort(
                        known_pulser_ids['run%i' % run]
                        [~numpy.isin(known_pulser_ids['run%i' % run],
                                     ignorable_pulser_ids['run%i' % run])])
                else:
                    eventids = numpy.sort(known_pulser_ids['run%i' % run])

                reader = Reader(datapath, run)
                #reader.setEntry(eventids[0])
                tct = TemplateCompareTool(
                    reader,
                    final_corr_length=final_corr_length,
                    crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                    crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                    low_pass_filter_order=low_pass_filter_order,
                    high_pass_filter_order=high_pass_filter_order,
                    initial_template_id=eventids[0])

                if manual_template == True:
                    upsampled_waveforms = tct.loadFilteredWaveformsMultiple(
                        eventids)
                    templates = {}
                    for channel in range(8):
                        template_selected = False
                        template_index = 0
                        while template_selected == False:
                            fig = plt.figure()
                            plt.plot(
                                upsampled_waveforms['ch%i' %
Ejemplo n.º 5
0
    def alignSelectedEvents(self, plot_aligned_wf=False,save_template=False,plot_timedelays=True):
        '''
        My plan is for this to be called when some events are circled in the plot.
        It will take those wf, align them, and plot the averaged waveforms.  No
        filters will be applied. 
        '''
        if plot_timedelays == True:
            runs, counts = numpy.unique(self.id[self.ind][:,0],return_counts=True)
            run = runs[numpy.argmax(counts)]
            print('Only calculating template from run with most points circled: run %i with %i events circled'%(run,max(counts)))
            eventids = self.id[self.ind][:,1][self.id[self.ind][:,0] == run]
            coords = self.xys[self.ind]

            self.plotTimeDelays(self.xys[self.ind][:,0]*60,self.total_hpol_delays[self.ind],self.total_vpol_delays[self.ind])

        _reader = Reader(datapath,run)
        
        crit_freq_low_pass_MHz = None
        low_pass_filter_order = None
        
        crit_freq_high_pass_MHz = None# 45
        high_pass_filter_order = None# 12
        
        waveform_index_range = (None,None)
        
        final_corr_length = 2**18

        tct = TemplateCompareTool(_reader, final_corr_length=final_corr_length, crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, waveform_index_range=waveform_index_range, plot_filters=False,apply_phase_response=True)
        tdc = TimeDelayCalculator(_reader, final_corr_length=final_corr_length, crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, waveform_index_range=waveform_index_range, plot_filters=False,apply_phase_response=True)
        self.cor = Correlator(_reader,  upsample=2**15, n_phi=360, n_theta=360, waveform_index_range=(None,None),crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, plot_filter=False,apply_phase_response=True)
        
        if True:
            print('TRYING TO MAKE CORRELATOR PLOT.')
            print(eventids)
            self.cor.animatedMap(eventids, 'both', '', plane_zenith=None,plane_az=None,hilbert=False, max_method=None,center_dir='E',save=False,dpi=300)

        times, averaged_waveforms = tct.averageAlignedSignalsPerChannel( eventids, align_method=0, template_eventid=eventids[0], plot=plot_aligned_wf,event_type=None)
        
        resampled_averaged_waveforms_original_length = numpy.zeros((8,len(_reader.t())))
        for channel in range(8):
            resampled_averaged_waveforms_original_length[channel] = scipy.interpolate.interp1d(times,averaged_waveforms[channel],kind='cubic',bounds_error=False,fill_value=0)(reader.t())

        if False:
            for channel in range(8):
                plt.figure()
                plt.title(str(channel))
                for eventid in eventids:
                    tct.setEntry(eventid)
                    plt.plot(tct.t(),tct.wf(channel),label=str(eventid),alpha=0.8)
                plt.legend()
                plt.xlabel('t (ns)')
                plt.ylabel('adu')


        if save_template == True:
            filename_index = 0 
            filename = './generated_event_template_%i.csv'%filename_index
            existing_files = numpy.array(glob.glob('./*.csv'))

            while numpy.isin(filename,existing_files):
                filename_index += 1
                filename = './generated_event_template_%i.csv'%filename_index
            numpy.savetxt(filename,resampled_averaged_waveforms_original_length, delimiter=",")
            print('Genreated template saved as:\n%s'%filename)



        tdc.calculateMultipleTimeDelays(eventids, align_method=8,hilbert=False,plot=True, colors=numpy.array(coords)[:,0])

        return resampled_averaged_waveforms_original_length
        run = int(run)

        reader = Reader(datapath,run)

        try:
            print(reader.status())
        except Exception as e:
            print('Status Tree not present.  Returning Error.')
            print('\nError in %s'%inspect.stack()[0][3])
            print(e)
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
            sys.exit(1)
        
        tct = TemplateCompareTool(reader, final_corr_length=final_corr_length, crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, waveform_index_range=waveform_index_range, plot_filters=False,apply_phase_response=True)
        
        filename = createFile(reader) #Creates an analysis file if one does not exist.  Returns filename to load file.
        


        if filename is not None:
            with h5py.File(filename, 'r') as file:
                rf_cut = file['trigger_type'][...] == 2
                peak = file['inband_peak_freq_MHz'][...]
                peak_cut = numpy.logical_and(peak > 76, peak < 81)
                p2p = file['p2p'][...]

                for event_type in [0]:
                    eventids = file['eventids'][...]
                    if event_type == 1:
                                                           run]['hpol'])
            eventids['vpol'] = numpy.sort(known_pulser_ids['run%i' %
                                                           run]['vpol'])
            all_eventids = numpy.sort(
                numpy.append(eventids['hpol'], eventids['vpol']))

            hpol_eventids_cut = numpy.isin(all_eventids, eventids['hpol'])
            vpol_eventids_cut = numpy.isin(all_eventids, eventids['vpol'])

            #Set up tempalte compare tool used for making averaged waveforms for first pass alignment.
            reader = Reader(datapath, run)
            tct = TemplateCompareTool(
                reader,
                final_corr_length=final_corr_length,
                crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                low_pass_filter_order=low_pass_filter_order,
                high_pass_filter_order=high_pass_filter_order,
                waveform_index_range=waveform_index_range,
                plot_filters=site == 1)

            #First pass alignment to make templates.
            times, _hpol_waveforms = tct.averageAlignedSignalsPerChannel(
                eventids['hpol'],
                align_method=0,
                template_eventid=eventids['hpol'][0],
                plot=False,
                event_type='hpol')
            times, _vpol_waveforms = tct.averageAlignedSignalsPerChannel(
                eventids['vpol'],
                align_method=0,