예제 #1
0
파일: binning.py 프로젝트: pabell/ximpol
 def fit_bin(self, i):
     """Fit the azimuthal distribution for the i-th energy slice.
     """
     hist = (self.phi_y[i], self.phi_binning, None)
     _fit_results = xAzimuthalResponseGenerator.fit_histogram(hist)
     _fit_results.set_polarization(self.modf(self.emean[i]))
     logger.info(_fit_results)
     self.fit_results.append(_fit_results)
     return _fit_results
예제 #2
0
파일: binning.py 프로젝트: pabell/ximpol
 def fit_bin(self, i):
     """Fit the azimuthal distribution for the i-th energy slice.
     """
     hist = (self.phi_y[i], self.phi_binning, None)
     _fit_results = xAzimuthalResponseGenerator.fit_histogram(hist)
     _fit_results.set_polarization(self.modf(self.emean[i]))
     logger.info(_fit_results)
     self.fit_results.append(_fit_results)
     return _fit_results
 def test_constant(self, num_events=1000000, polarization_degree=1.,
                   polarization_angle=numpy.radians(20.)):
     """Test the modulation factor as a random number generator when
     both the polarization angle and degrees are energy- and
     time-independent.
     """
     poldegree = numpy.full(num_events, polarization_degree)
     polangle = numpy.full(num_events, polarization_angle)
     self.modf.generator.plot(show=False)
     save_current_figure('test_modulation_constant_generator.png',
                         show=self.interactive)
     emin = self.modf.xmin()
     emax = self.modf.xmax()
     energy = numpy.random.uniform(emin, emax, num_events)
     phi = self.modf.rvs_phi(energy, poldegree, polangle)
     ebinning = numpy.linspace(emin, emax, 10)
     phi_binning = numpy.linspace(0, 2*numpy.pi, 100)
     fit_results = []
     for i, (_emin, _emax) in enumerate(zip(ebinning[:-1], ebinning[1:])):
         _emean = 0.5*(_emin + _emax)
         _mask = (energy > _emin)*(energy < _emax)
         _phi = phi[_mask]
         _hist = plt.hist(_phi, bins=phi_binning, histtype='step')
         _fr = xAzimuthalResponseGenerator.fit_histogram(_hist)
         _fr.emean = _emean
         fit_results.append(_fr)
         _fr.plot(label='Energy: %.2f--%.2f keV' % (_emin, _emax))
         plt.axis([0., 2*numpy.pi, 0., 1.2*_hist[0].max()])
         overlay_tag()
         save_current_figure('test_modulation_constant_fit_slice%d.png' % i,
                             show=self.interactive)
     _x = [_fr.emean for _fr in fit_results]
     _y = [_fr.phase for _fr in fit_results]
     _dy = [_fr.phase_error for _fr in fit_results]
     plt.errorbar(_x, _y, yerr=_dy, fmt='o')
     plt.plot(_x, numpy.array([polarization_angle]*len(_x)))
     plt.xlabel('Energy [keV]')
     plt.ylabel('Modulation angle [$^\circ$]')
     save_current_figure('test_modulation_constant_angle.png',
                         show=self.interactive)
     _y = [_fr.visibility for _fr in fit_results]
     _dy = [_fr.visibility_error for _fr in fit_results]
     plt.errorbar(_x, _y, yerr=_dy, fmt='o')
     plt.axis([emin, emax, 0, 1])
     self.modf.plot(show=False)
     plt.xlabel('Energy [keV]')
     plt.ylabel('Modulation visibility')
     save_current_figure('test_modulation_constant_visibility.png',
                         show=self.interactive)
예제 #4
0
 def test_constant(self, num_events=1000000, polarization_degree=1.,
                   polarization_angle=numpy.radians(20.)):
     """Test the modulation factor as a random number generator when
     both the polarization angle and degrees are energy- and
     time-independent.
     """
     poldegree = numpy.full(num_events, polarization_degree)
     polangle = numpy.full(num_events, polarization_angle)
     self.modf.generator.plot(show=False)
     save_current_figure('test_modulation_constant_generator.png',
                         show=self.interactive)
     emin = self.modf.xmin()
     emax = self.modf.xmax()
     energy = numpy.random.uniform(emin, emax, num_events)
     phi = self.modf.rvs_phi(energy, poldegree, polangle)
     ebinning = numpy.linspace(emin, emax, 10)
     phi_binning = numpy.linspace(0, 2*numpy.pi, 100)
     fit_results = []
     for i, (_emin, _emax) in enumerate(zip(ebinning[:-1], ebinning[1:])):
         _emean = 0.5*(_emin + _emax)
         _mask = (energy > _emin)*(energy < _emax)
         _phi = phi[_mask]
         _hist = plt.hist(_phi, bins=phi_binning, histtype='step')
         _fr = xAzimuthalResponseGenerator.fit_histogram(_hist)
         _fr.emean = _emean
         fit_results.append(_fr)
         _fr.plot(label='Energy: %.2f--%.2f keV' % (_emin, _emax))
         plt.axis([0., 2*numpy.pi, 0., 1.2*_hist[0].max()])
         overlay_tag()
         save_current_figure('test_modulation_constant_fit_slice%d.png' % i,
                             show=self.interactive)
     _x = [_fr.emean for _fr in fit_results]
     _y = [_fr.phase for _fr in fit_results]
     _dy = [_fr.phase_error for _fr in fit_results]
     plt.errorbar(_x, _y, yerr=_dy, fmt='o')
     plt.plot(_x, numpy.array([polarization_angle]*len(_x)))
     plt.xlabel('Energy [keV]')
     plt.ylabel('Modulation angle [$^\circ$]')
     save_current_figure('test_modulation_constant_angle.png',
                         show=self.interactive)
     _y = [_fr.visibility for _fr in fit_results]
     _dy = [_fr.visibility_error for _fr in fit_results]
     plt.errorbar(_x, _y, yerr=_dy, fmt='o')
     plt.axis([emin, emax, 0, 1])
     self.modf.plot(show=False)
     plt.xlabel('Energy [keV]')
     plt.ylabel('Modulation visibility')
     save_current_figure('test_modulation_constant_visibility.png',
                         show=self.interactive)