def plot_signal_map(self, *args, **kwargs):
     if self.define_signal_window is True and \
     self.signal_span_selector.range is not None:
         ileft = self.SI.energy2index(self.signal_span_selector.range[0])
         iright = self.SI.energy2index(self.signal_span_selector.range[1])
         signal_sp = self.SI.data_cube[ileft:iright,...].squeeze().copy()
         if self.define_background_window is True:
             pars = utils.two_area_powerlaw_estimation(
             self.SI, *self.bg_span_selector.range, only_current_spectrum = False)
             x = self.SI.energy_axis[ileft:iright, np.newaxis, np.newaxis]
             A = pars['A'][np.newaxis,...]
             r = pars['r'][np.newaxis,...]
             self.bg_sp = (A*x**(-r)).squeeze()
             signal_sp -= self.bg_sp
         self.signal_map = signal_sp.sum(0)
         if self.map_ax is None:
             f = plt.figure()
             self.map_ax = f.add_subplot(111)
             if len(self.signal_map.squeeze().shape) == 2:
                 self.map = self.map_ax.imshow(self.signal_map.T, 
                                               interpolation = 'nearest')
             else:
                 self.map, = self.map_ax.plot(self.signal_map.squeeze())
         if len(self.signal_map.squeeze().shape) == 2:
                 self.map.set_data(self.signal_map.T)
                 self.map.autoscale()
                 
         else:
             self.map.set_ydata(self.signal_map.squeeze())
         self.map_ax.figure.canvas.draw()
 def store_current_spectrum_bg_parameters(self, *args, **kwards):
     if self.define_background_window is False or \
     self.bg_span_selector.range is None: return
     pars = utils.two_area_powerlaw_estimation(
     self.SI, *self.bg_span_selector.range,only_current_spectrum = True)
     self.pl.r.value = pars['r']
     self.pl.A.value = pars['A']
                  
     if self.define_signal_window is True and \
     self.signal_span_selector.range is not None:
         self.plot_signal_map()
def energy_window_dependency(s, left, right, min_width = 10):
    ins = s.energy2index(left)
    ine = s.energy2index(right)
    energies = s.energy_axis[ins:ine - min_width]
    rs = []
    As = []
    for E in energies:
        di = utils.two_area_powerlaw_estimation(s, E, ine)
        rs.append(di['r'].mean())
        As.append(di['A'].mean())
    f = plt.figure()
    ax1  = f.add_subplot(211)
    ax1.plot(s.energy_axis[ins:ine - min_width], rs)
    ax1.set_title('Rs')
    ax1.set_xlabel('Energy')
    ax2  = f.add_subplot(212, sharex = ax1)
    ax2.plot(s.energy_axis[ins:ine - min_width], As)
    ax2.set_title('As')
    ax2.set_xlabel('Energy')
    return rs, As
Esempio n. 4
0
    def two_area_background_estimation(self, E1=None, E2=None):
        """
        Estimates the parameters of a power law background with the two
        area method.
        """
        ea = self.axis.axis[self.channel_switches]
        if E1 is None or E1 < ea[0]:
            E1 = ea[0]
        else:
            E1 = E1
        if E2 is None:
            if self.edges:
                i = 0
                while self.edges[i].edge_position() < E1 or \
                self.edges[i].active is False:
                    i += 1
                E2 = self.edges[i].edge_position() - \
                defaults.preedge_safe_window_width
            else:
                E2 = ea[-1]
        else:
            E2 = E2
        print \
        "Estimating the parameters of the background by the two area method"
        print "E1 = %s\t E2 = %s" % (E1, E2)

        try:
            estimation = utils.two_area_powerlaw_estimation(
                self.spectrum, E1, E2)
            bg = self._background_components[0]
            bg.A.map['is_set'][:] = True
            bg.r.map['is_set'][:] = True
            bg.r.map['values'] = estimation['r']
            bg.A.map['values'] = estimation['A']
            self.charge()
        except ValueError:
            messages.warning(
                "The power law background parameters could not be estimated\n"
                "Try choosing a different energy range for the estimation")
Esempio n. 5
0
    def two_area_background_estimation(self, E1 = None, E2 = None):
        """
        Estimates the parameters of a power law background with the two
        area method.
        """
        ea = self.axis.axis[self.channel_switches]
        if E1 is None or E1 < ea[0]:
            E1 = ea[0]
        else:
            E1 = E1
        if E2 is None:
            if self.edges:
                i = 0
                while self.edges[i].edge_position() < E1 or \
                self.edges[i].active is False:
                    i += 1
                E2 = self.edges[i].edge_position() - \
                defaults.preedge_safe_window_width
            else:
                E2 = ea[-1]
        else:
            E2 = E2           
        print \
        "Estimating the parameters of the background by the two area method"
        print "E1 = %s\t E2 = %s" % (E1, E2)

        try:
            estimation = utils.two_area_powerlaw_estimation(self.spectrum,E1,E2)
            bg = self._background_components[0]
            bg.A.map['is_set'][:] = True
            bg.r.map['is_set'][:] = True
            bg.r.map['values'] = estimation['r']
            bg.A.map['values'] = estimation['A']
            self.charge()
        except ValueError:
            messages.warning(
            "The power law background parameters could not be estimated\n"
            "Try choosing a different energy range for the estimation")