Esempio n. 1
0
    def execute(self):
        self._pr = PixelReader(season = '2017', array=self.get_context().get_array())
        print '[INFO] Getting timeseries...'
        tod_data = self.get_store().get(self._tod_key)  # retrieve tod_data                                                                                                     

    
        def timeseries(pixel_id, s_time, e_time, buffer=10):
            
            start_time = s_time - buffer
            end_time = e_time + buffer
                
            a1, a2 = self._pr.get_f1(pixel_id)
            b1, b2 = self._pr.get_f2(pixel_id)
            d1, d2 = tod_data.data[a1], tod_data.data[a2]
            d3, d4 = tod_data.data[b1], tod_data.data[b2]
            
            # try to remove the mean from start_time to end_time                                                                                                                
            d1 -= np.mean(d1[start_time:end_time])
            d2 -= np.mean(d2[start_time:end_time])
            d3 -= np.mean(d3[start_time:end_time])
            d4 -= np.mean(d4[start_time:end_time])
                
            time = tod_data.ctime - tod_data.ctime[0]
            time = time[start_time:end_time]
                
            d_1 = d1[start_time:end_time]
            d_2 = d2[start_time:end_time]
            d_3 = d3[start_time:end_time]
            d_4 = d4[start_time:end_time]
                
            
            return time, d_1, d_2, d_3, d_4

        self.get_store().set(self._output_key,timeseries)
Esempio n. 2
0
    def execute(self, store):
        print '[INFO] Plotting all glitches affecting detector ...'
        taus = store.get(self._time_constants)
        for tc in taus:
            if tc['det_uid'] == self._detuid:
                tau = tc['tau']

        tod_data = store.get(self._tod_key)  # retrieve tod_data
        cuts = store.get(self._cosig_key)  # retrieve tod_data
        array_name = self.get_array()
        peaks = cuts['peaks']
        self._pr = PixelReader()

        def cs_cuts():
            cuts = store.get(self._cosig_key)
            return cuts['coincident_signals']

        timeseries = store.get(self._timeseries_key)

        def plotter(pid, tau, start_time, end_time):

            x = timeseries(pid, start_time, end_time)[0]
            y1 = timeseries(pid, start_time, end_time)[1]
            y2 = timeseries(pid, start_time, end_time)[2]
            y3 = timeseries(pid, start_time, end_time)[3]
            y4 = timeseries(pid, start_time, end_time)[4]

            plt.title('Pixel affected from ' + str(start_time) + '-' +
                      str(end_time) + ', Pixel ' + str(pid))
            plt.xlabel('TOD track:' + str(self._tag) + ' Tau:' + str(tau))
            plt.plot(x, y1, '.-', label='90 GHz')
            plt.plot(x, y2, '.-', label='90 GHz')
            plt.plot(x, y3, '.-', label='150 GHz')
            plt.plot(x, y4, '.-', label='150 GHz')

            plt.legend()
            plt.show()

        cs = cuts['coincident_signals']

        for peak in peaks:

            stime = peak[0]
            etime = peak[1]
            pixels = pixels_affected_in_event(cs, peak)
            for pixel in pixels:
                if pixel == self._detuid:
                    plotter(pixel, tau, stime, etime)
Esempio n. 3
0
    def execute(self, store):
        # get pixel reader
        pr = PixelReader(season='2017', array=self.get_array())

        # retrieve events data from data store
        events_data = store.get(self._event_key)
        events = events_data['events']
        nsamps = events_data['nsamps']

        # retrieve tod data
        tod_data = store.get(self._tod_key)

        # loop through the given event id and see if it is in the
        # retrieved events list.
        for event in events:
            # check if the event is of interests
            if event['id'] in self._list_of_events:
                self.logger.info('Found event: %s' % event['id'])
                # retrieve event information
                # pick only one pixel for plotting
                pixels = event['pixels_affected']
                start_time = event['start']
                end_time = event['end']

                # loop over pixels
                for pid in pixels:
                    # get time series
                    ctime, d1, d2, d3, d4 = timeseries(tod_data, pid,
                                                       start_time,
                                                       end_time, pr,
                                                       buffer=20)

                    for d in [d1, d2, d3, d4]:
                        # rescale them
                        d = (d - np.min(d)) / (np.max(d) - np.min(d))

                        # find maximum index
                        d_i = np.argmax(d)

                        # only start from maximum
                        d_y = d[d_i:]
                        d_x = np.arange(0, len(d_y))

                        # make a smooth curve
                        # f = interp1d(d_x, d_y, kind='cubic')
                        f = interp1d(d_x, d_y)
                        d_x_new = np.linspace(0, len(d_y)-1, 100)
                        self._ax.plot(d_x_new, f(d_x_new), 'r-', alpha=0.1)
Esempio n. 4
0
    def execute(self, store):
        array= self.get_array()
        pr = PixelReader(season='2017', array= array)
        self.logger.info('Plotting glitches ...')

        # retrieve tod_data
        tod_data = store.get(self._tod_key)  

        # retrieve events
        events_data = store.get(self._event_key)  
        events = events_data['events']
        nsamps = events_data['nsamps']
        
        # plot functions
        # plot all pixels affected given an array of pixel ids
        # and a starting time and ending time
        plt.figure(figsize=(8,8))

        def plotter(ax, pixels, start_time, end_time):
            for pid in pixels:
                ctime, d1, d2, d3, d4 = timeseries(tod_data, pid, start_time, end_time, pr)
                ax.set_title('Pixels affected from ' +str(start_time)+ '-' + str(end_time)+ ' at 90 GHz')
                ax.set_xlabel('TOD_ID: %d    TOD_NAME: %s' % (self.get_id(), self.get_name()))  # CHANGE TOD TRACK NAME
                ax.plot(d1,'.-')
                ax.plot(d2,'.-')
                ax.plot(d3,'.-')
                ax.plot(d4,'.-')

        # trim the beginning and ending glitches, these are usually related to
        # re-biasing and not interesting
        TRIM = 100
        events_trim = [e for e in events if (e['start'] > TRIM and e['end'] < nsamps-TRIM)]
        self.logger.info('nsamps: %d' % nsamps)

        # plot all pixels affected in a event one by one for all events
        for event in events_trim:
            self.logger.info(event)
            pixels_affected = event['pixels_affected']
            start_time = event['start']
            end_time = event['end']
            fig, ax = plt.subplots()
            plotter(ax, pixels_affected, start_time, end_time)
            fig.savefig("outputs/nSig_10/plots/%s.png" % event['id'])
            plt.close('all')
Esempio n. 5
0
    def execute(self):
        # retrieve all cuts
        self._pr = PixelReader(season=self._season,
                               array=self.get_context().get_array())
        cuts_data = self.get_store().get(self._input_key)  # get saved cut data
        cuts = cuts_data['cuts']
        nsamps = cuts_data['nsamps']

        # get all pixels
        pixels = self._pr.get_pixels()

        # initialize dictionary to store coincident signals
        cosig = {}

        # loop through pixels and find cosig for each pixel
        for p in pixels:
            dets_f1 = self._pr.get_f1(p)
            dets_f2 = self._pr.get_f2(p)

            if self._strict:  # strict mode, 4 TES have to be present
                if len(dets_f1) == 2 and len(dets_f2) == 2:
                    cuts_f1_A = cuts.cuts[
                        dets_f1[0]]  # low freq, polarization A
                    cuts_f1_B = cuts.cuts[
                        dets_f1[1]]  # low freq, polarization B

                    cuts_f2_A = cuts.cuts[
                        dets_f2[0]]  # high freq, polarization A
                    cuts_f2_B = cuts.cuts[
                        dets_f2[1]]  # high freq, polarization B

                    if self._polarized:  # if looking for polarized, glitch may occur in either polarization
                        cuts_f1 = merge_cuts(
                            cuts_f1_A, cuts_f1_B
                        )  # polarized spikes may appear at either pol
                        cuts_f2 = merge_cuts(cuts_f2_A, cuts_f2_B)

                    else:  # if looking for unpolarized, glitch must occur in both polarizations
                        cuts_f1 = common_cuts(
                            cuts_f1_A, cuts_f1_B
                        )  # unpolarized spikes appear in both pols
                        cuts_f2 = common_cuts(cuts_f2_A, cuts_f2_B)

                    cosig[str(p)] = common_cuts(
                        cuts_f1,
                        cuts_f2)  # store coincident signals by pixel id

            else:  # loose mode, at least one TES has to be present each freq
                if len(dets_f1) == 2 and len(dets_f2) == 2:
                    cuts_f1_A = cuts.cuts[
                        dets_f1[0]]  # low freq, polarization A
                    cuts_f1_B = cuts.cuts[
                        dets_f1[1]]  # low freq, polarization B

                    cuts_f2_A = cuts.cuts[
                        dets_f2[0]]  # high freq, polarization A
                    cuts_f2_B = cuts.cuts[
                        dets_f2[1]]  # high freq, polarization B

                    if self._polarized:  # if looking for polarized, glitch may occur in either polarization
                        cuts_f1 = merge_cuts(
                            cuts_f1_A, cuts_f1_B
                        )  # polarized spikes may appear at either pol
                        cuts_f2 = merge_cuts(cuts_f2_A, cuts_f2_B)

                    else:  # if looking for unpolarized, glitch must occur in both polarizations
                        cuts_f1 = common_cuts(
                            cuts_f1_A, cuts_f1_B
                        )  # unpolarized spikes appear in both pols
                        cuts_f2 = common_cuts(cuts_f2_A, cuts_f2_B)

                    cosig[str(p)] = common_cuts(
                        cuts_f1,
                        cuts_f2)  # store coincident signals by pixel id

                elif len(dets_f1) == 1 and len(dets_f2) == 2:
                    cuts_f1 = cuts.cuts[dets_f1[0]]  # low freq, polarization A

                    cuts_f2_A = cuts.cuts[
                        dets_f2[0]]  # high freq, polarization A
                    cuts_f2_B = cuts.cuts[
                        dets_f2[1]]  # high freq, polarization B

                    if self._polarized:  # if looking for polarized, glitch may occur in either polarization
                        cuts_f2 = merge_cuts(cuts_f2_A, cuts_f2_B)

                    else:  # if looking for unpolarized, glitch must occur in both polarizations
                        cuts_f2 = common_cuts(cuts_f2_A, cuts_f2_B)

                    cosig[str(p)] = common_cuts(
                        cuts_f1,
                        cuts_f2)  # store coincident signals by pixel id

                elif len(dets_f1) == 2 and len(dets_f2) == 1:
                    cuts_f1_A = cuts.cuts[
                        dets_f1[0]]  # low freq, polarization A
                    cuts_f1_B = cuts.cuts[
                        dets_f1[1]]  # low freq, polarization B

                    cuts_f2 = cuts.cuts[
                        dets_f2[0]]  # high freq, polarization A

                    if self._polarized:  # if looking for polarized, glitch may occur in either polarization
                        cuts_f1 = merge_cuts(cuts_f1_A, cuts_f1_B)

                    else:  # if looking for unpolarized, glitch must occur in both polarizations
                        cuts_f1 = common_cuts(cuts_f1_A, cuts_f1_B)

                    cosig[str(p)] = common_cuts(
                        cuts_f1,
                        cuts_f2)  # store coincident signals by pixel id

                elif len(dets_f1) == 1 and len(dets_f2) == 1:
                    cuts_f1 = cuts.cuts[dets_f1[0]]  # low freq, polarization A
                    cuts_f2 = cuts.cuts[
                        dets_f2[0]]  # high freq, polarization A

                    cosig[str(p)] = common_cuts(
                        cuts_f1,
                        cuts_f2)  # store coincident signals by pixel id

        # cosig may contain empty cut vectors because we didn't enforce it, filter them out now
        cosig_filtered = {}
        for pixel in cosig:
            cuts = cosig[pixel]
            if len(cuts) != 0:
                cosig_filtered[pixel] = cuts

        # save cosig for further processing
        self.get_store().set(
            self._output_key,
            cosig_filtered)  # save the coincident signals under the output_key
        self.get_store().set(
            "nsamps",
            nsamps)  # save the number of sampling points, not graceful
Esempio n. 6
0
    def execute(self):
        print '[INFO] Loading Glitch Data ...'
        tod_data = self.get_store().get(self._tod_key)  # retrieve tod_data                                                    
        array_name = self.get_array()
        events = self.get_store().get(self._input_key)
        peaks = [event['peak'] for event in events]

        for i in range(len(peaks)):
            print ('[INFO] Filtered peak: ', i,peaks[i])
        self._pr = PixelReader(season= '2017', array=self.get_context().get_array())

      
        plot = raw_input("Do you want to plot an event? Enter y/n: ")
        if plot == "y":
            tod_data = self.get_store().get(self._tod_key)  # retrieve tod_data     
            events = self.get_store().get(self._input_key)  # retrieve tod_data
            peaks = [event['peak'] for event in events]
            timeseries = self.get_store().get(self._timeseries_key)
            

            """
            PLOTTING FUNCTION
            Plot all pixels affected given an array of pixel ids
            and a starting time and ending time
            
            """
            def plotter(pixels,start_time,end_time):
                        
                for pid in pixels:
               
                    x = timeseries(pid,start_time,end_time)[0]
                    y1 = timeseries(pid,start_time,end_time)[1]
                    y2 = timeseries(pid,start_time,end_time)[2]
                    y3 = timeseries(pid,start_time,end_time)[3]
                    y4 = timeseries(pid,start_time,end_time)[4]
                    
                    
                    plt.title('Pixel affected from ' +str(start_time)+ '-' + str(end_time)+ ', Pixel ' + str(pid))
                    plt.xlabel('TOD track:' + str(self._tag)) 
                    plt.plot(x,y1,'.-',label='90 GHz')
                    plt.plot(x,y2,'.-',label='90 GHz')
                    plt.plot(x,y3,'.-',label='150 GHz')
                    plt.plot(x,y4,'.-',label='150 GHz')
                    
                    plt.legend()
                    plt.show()


                
            """
            SPECIFIC EVENT
            To plot specific event, this interface will ask you to supply the event list, make sure you 
            manually convert the last string to a float or integer
            """

            e = raw_input('Please copy the event index to plot 4 freq channels:')

            event = events[int(e)]
            stime = event['start']
            etime = event['end']
            pixels = event['pixels_affected']
            plotter(pixels, stime, etime)
            
            self._pr.plot(pixels)
            plt.show()
                
            y_n = ' '
                
            while y_n != 'n':
                y_n = raw_input ("Would you like to plot another event? Enter y/n...")
                if y_n == 'y':
                    e= raw_input('Please copy the event index  to plot 4 freq channels:')
                    event = events[int(e)]
                    stime = event['start']
                    etime = event['end']
                    pixels = event['pixels_affected']
                    print '[INFO] Plotting Glitch...'
                    plotter(pixels, stime, etime)
                    self._pr.plot(pixels)
                    plt.show()
                        
        else:
            print 'No plot will be displayed!'      
Esempio n. 7
0
    def execute(self):
        print '[INFO] Checking for correlation ...'
        self._pr = PixelReader(season = '2017', array=self.get_context().get_array())
        tod_data = self.get_store().get(self._tod_key)  # retrieve tod_data
        events = self.get_store().get(self._input_key)
        peaks = [event['peak'] for event in events]
        timeseries = self.get_store().get(self._timeseries_key)

        def avg_signal(pixels, start_time, end_time):

            for pid in pixels:
                x, y1, y2, y3, y4 = timeseries(pid,start_time,end_time)
                avg_y1, avg_y2, avg_y3, avg_y4  = np.zeros(len(y1)),np.zeros(len(y2)),np.zeros(len(y3)),np.zeros(len(y4))
                avg_x = x
                avg_y1 += y1
                avg_y2 += y2
                avg_y3 += y3
                avg_y4 += y4

            x = avg_x
            y1 = avg_y1/len(avg_y1)
            y2 = avg_y2/len(avg_y2)
            y3 = avg_y3/len(avg_y3)
            y4 = avg_y4/len(avg_y4)
            return x, y1,y2,y3,y4



        def correlation(x1,x2,y1,y2):

            ts1 = y1
            ts2 = y2 
            l1 = len(ts1)
            l2 = len(ts2)
            if l1 < l2:
                n = l1
                return max([np.corrcoef(ts1, ts2[i:n+i])[0][1] for i in range(0, l2-l1)])
            elif l2 < l1:
                n = l2
                return max([np.corrcoef(ts1[i:n+i], ts2)[0][1] for i in range(0, l1-l2)])
            else: 
                return np.corrcoef(ts1, ts2)[0][1]


        avg_x1, avg_y1 = self._template[0], self._template[1]

        possible_events = []
        highlylikely_events = []
        lower_threshold = 0.6
        upper_threshold = self._coeff
        
        for event in events:
            all_pixels = event['pixels_affected']
            avg_x2, avg_y2_1,avg_y2_2,avg_y2_3,avg_y2_4 = avg_signal(all_pixels, event['start'], event['end'])
            coeff1 = correlation(avg_x1, avg_x2, avg_y1, avg_y2_1)
            coeff2 = correlation(avg_x1, avg_x2, avg_y1, avg_y2_2)
            coeff3 = correlation(avg_x1, avg_x2, avg_y1, avg_y2_3)
            coeff4 = correlation(avg_x1, avg_x2, avg_y1, avg_y2_4)

            if (lower_threshold <= coeff1)  & (lower_threshold <=  coeff2 ) & (lower_threshold <= coeff3)  & (lower_threshold <= coeff4) & (coeff1 < upper_threshold) & (coeff2 < upper_threshold) & (coeff3 < upper_threshold) & (coeff4 < upper_threshold):
                possible_events.append(event)
        
            elif (coeff1 >= upper_threshold) & (coeff2 >= upper_threshold) & (coeff3 >= upper_threshold) & (coeff4 >= upper_threshold):
                highlylikely_events.append(event)
                
        #print highlylikely_events
        print '[INFO] Correlation events passed: %d / %d' % (len(highlylikely_events), len(peaks))
        
        self.get_store().set(self._output_key,highlylikely_events)
 def initialize(self):
     self._pr = PixelReader()
Esempio n. 9
0
    def execute(self, store):
        print '[INFO] Loading Glitch Data ...'
        tod_data = store.get(self._tod_key)  # retrieve tod_data
        cuts = store.get(self._cosig_key)  # retrieve tod_data
        array_name = self.get_array()
        peaks = cuts['peaks']
        #print('[INFO] All glitches, unfiltered...')
        #print('[INFO] peaks: ', peaks)
        #self._pr = PixelReader(season= '2017', array=self.get_context().get_array()) #for covered
        self._pr = PixelReader()  #for uncovered
        #self._pr = PixelReader(season='2017',array = str(array_name))
        #self._pr = PixelReader(season='2017', array=self.get_context().get_array())

        plot = raw_input("Do you want to plot an event? Enter y/n: ")
        if plot == "y":
            tod_data = store.get(self._tod_key)  # retrieve tod_data
            cuts = store.get(self._cosig_key)  # retrieve tod_data
            peaks = cuts['peaks']

            def cs_cuts():
                cuts = store.get(self._cosig_key)
                return cuts['coincident_signals']

            timeseries = store.get(self._timeseries_key)
            """
            PLOTTING FUNCTION
            Plot all pixels affected given an array of pixel ids
            and a starting time and ending time
            
            """

            def plotter(pixels, start_time, end_time):

                for pid in pixels:

                    x = timeseries(pid, start_time, end_time)[0]
                    y1 = timeseries(pid, start_time, end_time)[1]
                    y2 = timeseries(pid, start_time, end_time)[2]
                    y3 = timeseries(pid, start_time, end_time)[3]
                    y4 = timeseries(pid, start_time, end_time)[4]

                    plt.title('Pixel affected from ' + str(start_time) + '-' +
                              str(end_time) + ', Pixel ' + str(pid))
                    plt.xlabel('TOD track:' + str(self._tag))
                    plt.plot(x, y1, '.-', label='90 GHz')
                    plt.plot(x, y2, '.-', label='90 GHz')
                    plt.plot(x, y3, '.-', label='150 GHz')
                    plt.plot(x, y4, '.-', label='150 GHz')

                    plt.legend()
                    plt.show()

            """
            SPECIFIC EVENT
            To plot specific event, this interface will ask you to supply the event list, make sure you 
            manually convert the last string to a float or integer
            """
            cs = cuts['coincident_signals']
            e = raw_input(
                'Please copy the event list to plot 4 freq channels:')
            event = json.loads(e)
            stime = event[0]
            etime = event[1]
            pixels = pixels_affected_in_event(cs, event)
            plotter(pixels, stime, etime)

            self._pr.plot(pixels)
            plt.show()

            y_n = ' '

            while y_n != 'n':
                y_n = raw_input(
                    "Would you like to plot another event? Enter y/n...")
                if y_n == 'y':
                    e = raw_input(
                        'Please copy the event list to plot 4 freq channels:')
                    event = json.loads(e)
                    stime = event[0]
                    etime = event[1]
                    pixels = pixels_affected_in_event(cs, event)
                    print '[INFO] Plotting Glitch...'
                    plotter(pixels, stime, etime)
                    self._pr.plot(pixels)
                    plt.show()

        else:
            print 'No plot will be displayed!'
Esempio n. 10
0
 def initialize(self):
     self._pr = PixelReader()
     self._hist = Hist1D(0, 5, 100)  #change max
Esempio n. 11
0
 def initialize(self):
     self._pr = PixelReader(season=self._season, array=self._array)