Example #1
0
def plot(save_plots=False):
    """
    """
    sim_label = 'XIPE %s ks' % (SIM_DURATION/1000.)
    mod_label = 'Input model'
    _phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    _colors = ['blue']*len(_pol_deg)
    plt.figure('Polarization degree')
    _good_fit = _pol_deg > 2*_pol_deg_err
    _bad_fit = numpy.logical_not(_good_fit)
    plt.errorbar(_phase[_good_fit], _pol_deg[_good_fit],
                 xerr=_phase_err[_good_fit], yerr=_pol_deg_err[_good_fit],
                 fmt='o', label=sim_label, color='blue')
    plt.errorbar(_phase[_bad_fit], _pol_deg[_bad_fit],
                 xerr=_phase_err[_bad_fit], yerr=_pol_deg_err[_bad_fit],
                 fmt='o', color='gray')
    pol_degree_spline.plot(show=False, label=mod_label, color='green')
    plt.axis([0., 1., 0., 0.1])
    plt.legend(bbox_to_anchor=(0.37, 0.95))
    plt.figtext(0.6, 0.8, '%.2f--%.2f keV' %\
                (E_BINNING[0], E_BINNING[-1]), size=16)
    if save_plots:
        plt.savefig('gk_per_polarization_degree.png')
    plt.figure('Polarization angle')
    plt.errorbar(_phase[_good_fit], _pol_angle[_good_fit],
                 xerr=_phase_err[_good_fit], yerr=_pol_angle_err[_good_fit],
                 fmt='o', label=sim_label, color='blue')
    plt.errorbar(_phase[_bad_fit], _pol_angle[_bad_fit],
                 xerr=_phase_err[_bad_fit], yerr=_pol_angle_err[_bad_fit],
                 fmt='o', color='gray')
    pol_angle_spline.plot(show=False, label=mod_label, color='green',
                          scale=numpy.radians(1.))
    plt.axis([0., 1., -0.1, 1.5])
    plt.xlabel('Rotational phase')
    plt.ylabel('Polarization angle [rad]')
    plt.legend(bbox_to_anchor=(0.37, 0.95))
    plt.figtext(0.6, 0.8, '%.2f--%.2f keV' %\
                (E_BINNING[0], E_BINNING[-1]), size=16)
    if save_plots:
        plt.savefig('gk_per_polarization_angle.png')
    _ebinning = zip(E_BINNING[:-1], E_BINNING[1:])
    if len(_ebinning) > 1:
        _ebinning.append((E_BINNING[0], E_BINNING[-1]))
    for i, (_emin, _emax) in enumerate(_ebinning):
        plt.figure('Phasogram %d' % i)
        phasogram = xBinnedPhasogram(_phasg_file_path(i))
        _scale = phasogram.counts.sum()/phasogram_spline.norm()/\
                 len(phasogram.counts)
        phasogram_spline.plot(show=False, label=mod_label, scale=_scale,
                              color='green')
        phasogram.plot(show=False, color='blue', label=sim_label )
        plt.legend(bbox_to_anchor=(0.37, 0.95))
        plt.figtext(0.65, 0.8, '%.2f--%.2f keV' % (_emin, _emax), size=16)
        if save_plots:
            plt.savefig('gk_per_phasogram_%d.png' % i)
    plt.show()
 def test_rvs(self):
     """Test the random number generation.
     """
     visibility = numpy.full(1000000, 0.5)
     phi = self.generator.rvs_phi(visibility, 0.25*numpy.pi)
     hist = plt.hist(phi, bins=numpy.linspace(0, 2*numpy.pi, 100),
                     histtype='step', label='Random angles')
     fit_results = self.generator.fit_histogram(hist)
     fit_results.plot()
     plt.xlabel('$\\phi$ [rad]')
     plt.axis([0, 2*numpy.pi, 0, None])
     overlay_tag()
     save_current_figure('test_azimuthal_resp_rvs.png',
                         show=self.interactive)
Example #3
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)
 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)
Example #5
0
 def test_rvs(self):
     """Test the random number generation.
     """
     visibility = numpy.full(1000000, 0.5)
     phi = self.generator.rvs_phi(visibility, 0.25 * numpy.pi)
     hist = plt.hist(phi,
                     bins=numpy.linspace(0, 2 * numpy.pi, 100),
                     histtype='step',
                     label='Random angles')
     fit_results = self.generator.fit_histogram(hist)
     fit_results.plot()
     plt.xlabel('$\\phi$ [rad]')
     plt.axis([0, 2 * numpy.pi, 0, None])
     overlay_tag()
     save_current_figure('test_azimuthal_resp_rvs.png',
                         show=self.interactive)
 def test_cdf(self):
     """Test the one-dimensional azimuthal response underlying pdf.
     """
     phi = numpy.linspace(0., 2*numpy.pi, 100)
     for visibility in numpy.linspace(1, 0, 5):
         cdf = self.generator.cdf(phi, visibility)
         plt.plot(phi, cdf, label='$\\xi = %.2f$' % visibility)
         spline = xInterpolatedUnivariateSplineLinear(phi, cdf)
         self.assertTrue(abs(spline(0.)) < 1e-5, 'cdf(0) = %.3e' % spline(0))
         self.assertTrue(abs(spline(2*numpy.pi) - 1) < 1e-5,
                         'cdf(2pi) = %.3e' % spline(2*numpy.pi))
     plt.axis([0., 2*numpy.pi, None, None])
     plt.xlabel('$\\phi$ [rad]')
     plt.ylabel('cdf($\\phi$)')
     plt.legend(bbox_to_anchor=(0.4, 0.92))
     overlay_tag()
     save_current_figure('test_azimuthal_resp_cdf.png',
                         show=self.interactive)
Example #7
0
def plot(save=False):
    """Plot the stuff in the analysis file.
    """
    sim_label = 'XIPE %s ks' % (SIM_DURATION/1000.)
    sim_label = 'OBS: %s ks' % (SIM_DURATION/1000.)
    mod_label = 'Input model'
    lc_label = 'Light curve'
    _phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err, _index, _index_err, _norm,\
        _norm_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    plt.figure('Polarization degree')
    pl_normalization_spline.plot(scale=0.12, show=False, color='lightgray',
                                 label=lc_label)

    _pol_deg_err_p=numpy.where((_pol_deg+_pol_deg_err)<1.0,_pol_deg_err,1.0-_pol_deg)
    _pol_deg_err_m=numpy.where((_pol_deg-_pol_deg_err)>0.0,_pol_deg_err,_pol_deg)
    #if (_pol_deg+_pol_deg_err)>1.0: _pol_deg_err=1.0-yerr_p
    
    plt.errorbar(_phase, _pol_deg, xerr=_phase_err, yerr=[_pol_deg_err_m,_pol_deg_err_p], fmt='o',
                 label=sim_label)
    pol_degree_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 0., 0.5])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_polarization_degree', OUTPUT_FOLDER, False)
    plt.figure('Polarization angle')
    pl_normalization_spline.plot(scale=0.4, offset=1.25, show=False,
                                 color='lightgray', label=lc_label)
    plt.errorbar(_phase, _pol_angle, xerr=_phase_err, yerr=_pol_angle_err,
                 fmt='o', label=sim_label)
    pol_angle_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 1.25, 3.])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_polarization_angle', OUTPUT_FOLDER, False)
    plt.figure('PL normalization')
    plt.errorbar(_phase, _norm, xerr=_phase_err, yerr=_norm_err, fmt='o',
                 label=sim_label)
    pl_normalization_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., None, None])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_pl_norm', OUTPUT_FOLDER, False)
    plt.figure('PL index')
    pl_normalization_spline.plot(scale=0.18, offset=1.3, show=False,
                                 color='lightgray', label=lc_label)
    plt.errorbar(_phase, _index, xerr=_phase_err, yerr=_index_err, fmt='o',
                 label=sim_label)
    pl_index_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 1.3, 2.1])
    plt.legend(bbox_to_anchor=(0.45, 0.95))
    if save:
        save_current_figure('crab_pl_index', OUTPUT_FOLDER, False)
    plt.show()
Example #8
0
 def plot_bin(self, i, show=True, fit=True):
     """Plot the azimuthal distribution for the i-th energy slice.
     """
     _emin = self.emin[i]
     _emax = self.emax[i]
     _emean = self.emean[i]
     label = '%.2f-%.2f $<$%.2f$>$ keV' % (_emin, _emax, _emean)
     plt.errorbar(self.phi_x, self.phi_y[i], yerr=numpy.sqrt(self.phi_y[i]),
                  fmt='o')
     if fit:
         fit_results = self.fit_bin(i)
         fit_results.plot(label=label)
    
     plt.axis([0., 2*numpy.pi, 0.0, 1.2*self.phi_y[i].max()])
     plt.xlabel('Azimuthal angle [rad]')
     plt.ylabel('Counts/bin')
     plt.text(0.02, 0.92, label, transform=plt.gca().transAxes,
              fontsize=15)
     if show:
         plt.show()
Example #9
0
 def test_cdf(self):
     """Test the one-dimensional azimuthal response underlying pdf.
     """
     phi = numpy.linspace(0., 2 * numpy.pi, 100)
     for visibility in numpy.linspace(1, 0, 5):
         cdf = self.generator.cdf(phi, visibility)
         plt.plot(phi, cdf, label='$\\xi = %.2f$' % visibility)
         spline = xInterpolatedUnivariateSplineLinear(phi, cdf)
         self.assertTrue(
             abs(spline(0.)) < 1e-5, 'cdf(0) = %.3e' % spline(0))
         self.assertTrue(
             abs(spline(2 * numpy.pi) - 1) < 1e-5,
             'cdf(2pi) = %.3e' % spline(2 * numpy.pi))
     plt.axis([0., 2 * numpy.pi, None, None])
     plt.xlabel('$\\phi$ [rad]')
     plt.ylabel('cdf($\\phi$)')
     plt.legend(bbox_to_anchor=(0.4, 0.92))
     overlay_tag()
     save_current_figure('test_azimuthal_resp_cdf.png',
                         show=self.interactive)
 def test_pdf(self):
     """Test the one-dimensional azimuthal response underlying pdf.
     """
     self.generator.plot(show=self.interactive)
     overlay_tag(color='white')
     save_current_figure('test_azimuthal_resp_generator.png',
                         show=self.interactive)
     phi = numpy.linspace(0., 2*numpy.pi, 100)
     for visibility in numpy.linspace(1, 0, 5):
         pdf = self.generator.pdf(phi, visibility)
         plt.plot(phi, pdf, label='$\\xi = %.2f$' % visibility)
         spline = xInterpolatedUnivariateSplineLinear(phi, pdf)
         norm = spline.norm()
         self.assertTrue(abs(norm - 1.) < 1e-5,
                         'Normalization is %.3e' % norm)
     plt.axis([0., 2*numpy.pi, None, None])
     plt.xlabel('$\\phi$ [rad]')
     plt.ylabel('pdf($\\phi$) [1/rad]')
     plt.legend(bbox_to_anchor=(0.88, 0.92))
     overlay_tag()
     save_current_figure('test_azimuthal_resp_pdf.png',
                         show=self.interactive)
Example #11
0
 def test_pdf(self):
     """Test the one-dimensional azimuthal response underlying pdf.
     """
     self.generator.plot(show=self.interactive)
     overlay_tag(color='white')
     save_current_figure('test_azimuthal_resp_generator.png',
                         show=self.interactive)
     phi = numpy.linspace(0., 2 * numpy.pi, 100)
     for visibility in numpy.linspace(1, 0, 5):
         pdf = self.generator.pdf(phi, visibility)
         plt.plot(phi, pdf, label='$\\xi = %.2f$' % visibility)
         spline = xInterpolatedUnivariateSplineLinear(phi, pdf)
         norm = spline.norm()
         self.assertTrue(
             abs(norm - 1.) < 1e-5, 'Normalization is %.3e' % norm)
     plt.axis([0., 2 * numpy.pi, None, None])
     plt.xlabel('$\\phi$ [rad]')
     plt.ylabel('pdf($\\phi$) [1/rad]')
     plt.legend(bbox_to_anchor=(0.88, 0.92))
     overlay_tag()
     save_current_figure('test_azimuthal_resp_pdf.png',
                         show=self.interactive)
Example #12
0
 def plot_bin(self, i, show=True, fit=True):
     """Plot the azimuthal distribution for the i-th energy slice.
     """
     _emin = self.emin[i]
     _emax = self.emax[i]
     _emean = self.emean[i]
     label = '%.2f-%.2f $<$%.2f$>$ keV' % (_emin, _emax, _emean)
     plt.errorbar(self.phi_x,
                  self.phi_y[i],
                  yerr=numpy.sqrt(self.phi_y[i]),
                  fmt='o')
     if fit:
         fit_results = self.fit_bin(i)
         fit_results.plot(label=label)
     view_range = 1.5 * (self.phi_y[i].max() - self.phi_y[i].min())
     view_ymin = self.phi_y[i].min() - view_range
     view_ymax = self.phi_y[i].max() + view_range
     plt.axis([0., 2 * numpy.pi, view_ymin, view_ymax])
     plt.xlabel('Azimuthal angle [rad]')
     plt.ylabel('Counts/bin')
     plt.text(0.02, 0.92, label, transform=plt.gca().transAxes, fontsize=15)
     if show:
         plt.show()
def plot(save=False):
    """Plot the stuff in the analysis file.
    """
    for j in range(len(E_BINNING)):
        if (j==len(E_BINNING)-1):
            analysis_file = ANALYSIS_FILE_PATH
            emin=E_BINNING[0]
            emax=E_BINNING[-1]
        else:
            analysis_file = '%s_%d' % (ANALYSIS_FILE_PATH,j)
            emin=E_BINNING[j]
            emax=E_BINNING[j+1]
            
        sim_label = 'XIPE %s ks' % (SIM_DURATION/1000.)
        mod_label = 'Input model'
        lc_label = 'Light curve'
        _phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,\
            _pol_angle_err, _index, _index_err, _norm,\
            _norm_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
        plt.figure('Polarization degree (%g-%g keV)' % (emin,emax))
        plt.title('Her X-1 (%g-%g keV)' % (emin,emax))
        pl_normalization_spline.plot(scale=20, show=False, color='lightgray',
                                     label=lc_label)
        plt.errorbar(_phase, _pol_deg, xerr=_phase_err, yerr=_pol_deg_err, fmt='o',
                     label=sim_label)
        pol_degree_spline.plot(show=False, label=mod_label)
#        pol_degree_spline_noqed.plot(show=False, label='No QED')
        plt.axis([0., 1., 0., 1.1])
        plt.legend(bbox_to_anchor=(0.4, 0.5))
        if save:
            save_current_figure('herx1_polarization_degree_%d' % j, OUTPUT_FOLDER, False)
        plt.figure('Polarization angle (%g-%g keV)' % (emin,emax))
        plt.title('Her X-1 (%g-%g keV)' % (emin,emax))
        pl_normalization_spline.plot(scale=60, offset=0, show=False,
                                     color='lightgray', label=lc_label)
        plt.errorbar(_phase, _pol_angle, xerr=_phase_err, yerr=_pol_angle_err,
            fmt='o', label=sim_label)
        pol_angle_spline.plot(show=False, label=mod_label)
        plt.axis([0., 1., 0, 3.15])
        plt.legend(bbox_to_anchor=(0.4, 0.3))
        if save:
            save_current_figure('herx1_polarization_angle_%d' %j, OUTPUT_FOLDER, False)
        plt.figure('Flux (%g-%g keV)' % (emin,emax))
        plt.title('Her X-1 (%g-%g keV)' % (emin,emax))
        plt.errorbar(_phase,
                     0.21*_norm/(2-_index)*(10.**(2.0-_index)-2.**(2.-_index)), xerr=_phase_err,
                     yerr=0.21*_norm_err/(2-_index)*(10.**(2-_index)-2.**(2.-_index)), fmt='o',
                     label=sim_label)
        pl_normalization_spline.plot(scale=1,show=False, label=mod_label)
        plt.axis([0., 1., None, None])
        plt.legend(bbox_to_anchor=(0.75, 0.95))
        if save:
            save_current_figure('herx1_flux_%d' % j, OUTPUT_FOLDER, False)
        plt.show()
Example #14
0
def plot(save=False):
    """Plot the stuff in the analysis file.
    """
    sim_label = 'XIPE %s ks' % (SIM_DURATION/1000.)
    mod_label = 'Input model'
    lc_label = 'Light curve'
    _phase, _phase_err, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err, _index, _index_err, _norm,\
        _norm_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    plt.figure('Polarization degree')
    pl_normalization_spline.plot(scale=20, show=False, color='lightgray',
                                 label=lc_label)
    plt.errorbar(_phase, _pol_deg, xerr=_phase_err, yerr=_pol_deg_err, fmt='o',
                 label=sim_label)
    pol_degree_spline.plot(show=False, label='QED-On')
    pol_degree_spline_noqed.plot(show=False, offset=0.03, scale=1.06,
                                 label='QED-Off')
    plt.axis([0., 1., 0., 1.1])
    plt.legend(bbox_to_anchor=(0.4, 0.6))
    if save:
        save_current_figure('4u_polarization_degree', OUTPUT_FOLDER, False)
    plt.figure('Polarization angle')
    pl_normalization_spline.plot(scale=60, offset=0, show=False,
                                 color='lightgray', label=lc_label)
    plt.errorbar(_phase, _pol_angle, xerr=_phase_err, yerr=_pol_angle_err,
                 fmt='o', label=sim_label)
    pol_angle_spline.plot(show=False, label=mod_label)
    plt.axis([0., 1., 0, 3.15])
    plt.legend(bbox_to_anchor=(0.4, 0.3))
    if save:
        save_current_figure('4u_polarization_angle', OUTPUT_FOLDER, False)
    plt.figure('Flux (2-10 keV)')
    plt.errorbar(_phase, 0.21*_norm/(2-_index)*(10.**(2.0-_index)-2.**(2.-_index)), xerr=_phase_err, yerr=0.21*_norm_err/(2-_index)*(10.**(2-_index)-2.**(2.-_index)), fmt='o',
                 label=sim_label)
    pl_normalization_spline.plot(scale=1,show=False, label=mod_label)
    plt.axis([0., 1., None, None])
    plt.legend(bbox_to_anchor=(0.75, 0.95))
    if save:
        save_current_figure('4u_flux', OUTPUT_FOLDER, False)
    plt.show()
Example #15
0
def plot(save=False):
    """Plot the stuff in the analysis file.
    """

    def draw_time_grid(color='blue'):
        """
        """
        times = [3600., 3600.*24., 3600.*24.*7.]
        labels = ['1 hour', '1 day', '1 week']
        for t, l in zip(times, labels):
            plt.axvline(t, linestyle='dashed', color=color)
            ymin, ymax = plt.gca().get_ylim()
            y = ymin + 1.05*(ymax - ymin)
            plt.text(t, y, l, ha='center', color=color)

    sim_label = 'XIPE'
    mod_label = 'Input model'
    lc_label = 'Light curve'
    _time, _time_errp, _time_errm, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err, _index, _index_err, _norm,\
        _norm_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    logger.info(_time)
    logger.info((_time_errp + _time_errm)/3600.)
    _pol_angle = numpy.degrees(_pol_angle)
    _pol_angle_err = numpy.degrees(_pol_angle_err)
    plt.figure('Polarization degree')
    pol_degree_spline.plot(show=False, label=mod_label, logx=True)
    plt.errorbar(_time, _pol_deg, xerr=[_time_errm, _time_errp],
                 yerr=_pol_deg_err, fmt='o', label=sim_label)
    plt.axis([100., 1e6, 0., 0.6])
    plt.legend(bbox_to_anchor=(0.4, 0.95))
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_polarization_degree',
                            OUTPUT_FOLDER, False)
    plt.figure('Polarization angle')
    _x = pol_degree_spline.x
    _y = numpy.full(len(_x), polarization_angle(_x, None, None, None))
    _y = numpy.degrees(_y)
    fmt = dict(xname='Time', xunits='s', yname='Polarization angle',
               yunits=r'$^\circ$')
    _s = xInterpolatedUnivariateSpline(_x, _y, **fmt)
    _s.plot(logx=True, show=False, label=mod_label)
    plt.errorbar(_time, _pol_angle, xerr=[_time_errm, _time_errp],
                 yerr=_pol_angle_err, fmt='o', label=sim_label)
    plt.axis([100., 1e6, None, None])
    plt.legend(bbox_to_anchor=(0.4, 0.95))
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_polarization_angle',
                            OUTPUT_FOLDER, False)
    plt.figure('PL index')
    _y = numpy.full(len(_x), PL_INDEX)
    fmt = dict(xname='Time', xunits='s', yname='PL index')
    _s = xInterpolatedUnivariateSpline(_x, _y, **fmt)
    _s.plot(logx=True, show=False, label=mod_label)
    plt.errorbar(_time, _index, xerr=[_time_errm, _time_errp], yerr=_index_err,
                 fmt='o', label=sim_label)
    plt.axis([100., 1e6, None, None])
    plt.legend(bbox_to_anchor=(0.4, 0.95))
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_pl_index', OUTPUT_FOLDER, False)
    #plt.figure('PL normalization')
    #plt.errorbar(_time, _norm, xerr=[_time_errm, _time_errp], yerr=_norm_err,
    #             fmt='o', label=sim_label)
    #pl_normalization_spline.plot(show=False, label=mod_label)
    #plt.axis([100., 1e6, None, None])
    #plt.legend(bbox_to_anchor=(0.4, 0.95))
    #draw_time_grid()
    #if save:
    #    save_current_figure('grb130427_swift_pl_norm', OUTPUT_FOLDER, False)
    plt.figure('Light curve')
    lc = xBinnedLightCurve(_lc_file_path())
    lc.plot(show=False)
    # This should be implemented in the binned LC class.
    plt.xscale('log')
    plt.yscale('log')
    plt.axis([100., 1e6, None, None])
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_lc', OUTPUT_FOLDER, False)
    plt.show()
Example #16
0
plt.xlabel("Integral energy flux %.0f-%.0f keV [erg cm$^{-2}$ s$^{-1}$]" % (E_MIN, E_MAX))
plt.ylabel("MDP 99% CL [%]")

for j, blazar in enumerate(blazar_list):
    _x_max = blazar["flux_max"]
    _x_min = blazar["flux_min"]
    _y_max = blazar["p_opt_max"]
    _y_min = blazar["p_opt_min"]
    plt.plot([_x_min, _x_max, _x_max], [_y_max, _y_max, _y_min], color=_color[:, j], lw=1.5)
    _x_text = numpy.sqrt((_x_max) * (_x_min))
    if j in mirror_list:
        _y_text = 0.88 * _y_max
    else:
        _y_text = 1.02 * _y_max
    plt.text(_x_text, _y_text, blazar["name"], color=_color[:, j], horizontalalignment="center", size="large")
plt.axis([1e-13, 1e-8, 0.5, 50])
plt.savefig("blazar_mdp_average.png")


"""
plt.figure('Average polarization degree', (14, 10))
_x = numpy.logspace(-13, -7, 100)
for obs_time in [1.e3, 10.e3, 100.e3, 1.e6]:
    _y = 100.* mdp_ref * numpy.sqrt(OBS_TIME_REF/obs_time * FLUX_REF/_x)
    plt.plot(_x, _y, color=GRID_COLOR, ls='dashed', lw=0.5)
    _i = 51
    #plt.text(_x[_i], _y[_i], '$T_{obs} =$ %d ks' % (obs_time/1000.),
    #         color=GRID_COLOR, rotation=-42., size=12)
    if obs_time is 1.e3:
        _x_text = _x[_i]
        _y_text = _y[_i]
Example #17
0
aeff, psf, modf, edisp = load_irfs(IRF_NAME)

plt.figure('On axis effective area')
xInterpolatedUnivariateSplineLinear.plot(aeff, show=False)
save_current_figure('aeff_on_axis.png', OUTPUT_FOLDER, clear=False)

plt.figure('Vignetting')
aeff.vignetting.plot(show=False)
save_current_figure('aeff_vignetting.png', OUTPUT_FOLDER, clear=False)

plt.figure('Edisp matrix')
edisp.matrix.plot(show=False)
save_current_figure('edisp_matrix.png', OUTPUT_FOLDER, clear=False)

plt.figure('Edisp slice')
_e = 6.
edisp.matrix.vslice(_e).plot(show=False, label='E = %.2f keV' % _e)
plt.axis([0, 256, None, None])
plt.legend(bbox_to_anchor=(0.45, 0.75))
save_current_figure('edisp_slice.png', OUTPUT_FOLDER, clear=False)

plt.figure('PSF')
psf.plot(show=False)
save_current_figure('psf.png', OUTPUT_FOLDER, clear=False)

plt.figure('Modulation factor')
modf.plot(show=False)
save_current_figure('modf.png', OUTPUT_FOLDER, clear=False)

plt.show()
Example #18
0
_x = numpy.logspace(-13, -7, 100)
for obs_time in [1.e3, 10.e3, 100.e3, 1.e6]:
    _y = 100.* mdp_ref * numpy.sqrt(OBS_TIME_REF/obs_time * FLUX_REF/_x)
    plt.plot(_x, _y, color=GRID_COLOR, ls='dashed', lw=0.5)
    _i = 53
    plt.text(_x[_i], _y[_i], '$T_{obs} =$ %d ks' % (obs_time/1000.),
             color=GRID_COLOR, rotation=-45.)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('Integral energy flux %.0f-%.0f keV [erg cm$^{-2}$ s$^{-1}$]' %\
           (E_MIN, E_MAX))
plt.ylabel('MDP 99% CL [%]')

for j, source in enumerate(obs_plan_list):
    _x = source['flux']
    _y = source['mdp']*_disp[j]
    plt.plot(_x, _y, 'o', color=_color[:,j])
    _text = source['name']
    if source['notes'] is not '':
        _text += '\n' + source['notes']
    if j in mirror_list:
        _y *= 0.8
    else:
        _y *= 1.05
    plt.text(_x, _y, _text, color=_color[:,j],
             horizontalalignment='center', size='large')
plt.axis([1e-12, 1e-7, 0.4, 30])
#plt.savefig('obs_plan.png')

plt.show()
Example #19
0
def plot(save=False):
    """Plot the stuff in the analysis file.
    """
    def draw_time_grid(color='blue'):
        """
        """
        times = [3600., 3600. * 24., 3600. * 24. * 7.]
        labels = ['1 hour', '1 day', '1 week']
        for t, l in zip(times, labels):
            plt.axvline(t, linestyle='dashed', color=color)
            ymin, ymax = plt.gca().get_ylim()
            y = ymin + 1.05 * (ymax - ymin)
            plt.text(t, y, l, ha='center', color=color)

    sim_label = 'XIPE'
    mod_label = 'Input model'
    lc_label = 'Light curve'
    _time, _time_errp, _time_errm, _pol_deg, _pol_deg_err, _pol_angle,\
        _pol_angle_err, _index, _index_err, _norm,\
        _norm_err = numpy.loadtxt(ANALYSIS_FILE_PATH, unpack=True)
    logger.info(_time)
    logger.info((_time_errp + _time_errm) / 3600.)
    _pol_angle = numpy.degrees(_pol_angle)
    _pol_angle_err = numpy.degrees(_pol_angle_err)
    plt.figure('Polarization degree')
    pol_degree_spline.plot(show=False, label=mod_label, logx=True)
    plt.errorbar(_time,
                 _pol_deg,
                 xerr=[_time_errm, _time_errp],
                 yerr=_pol_deg_err,
                 fmt='o',
                 label=sim_label)
    plt.axis([100., 1e6, 0., 0.6])
    plt.legend(bbox_to_anchor=(0.4, 0.95))
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_polarization_degree',
                            OUTPUT_FOLDER, False)
    plt.figure('Polarization angle')
    _x = pol_degree_spline.x
    _y = numpy.full(len(_x), polarization_angle(_x, None, None, None))
    _y = numpy.degrees(_y)
    fmt = dict(xname='Time',
               xunits='s',
               yname='Polarization angle',
               yunits=r'$^\circ$')
    _s = xInterpolatedUnivariateSpline(_x, _y, **fmt)
    _s.plot(logx=True, show=False, label=mod_label)
    plt.errorbar(_time,
                 _pol_angle,
                 xerr=[_time_errm, _time_errp],
                 yerr=_pol_angle_err,
                 fmt='o',
                 label=sim_label)
    plt.axis([100., 1e6, None, None])
    plt.legend(bbox_to_anchor=(0.4, 0.95))
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_polarization_angle',
                            OUTPUT_FOLDER, False)
    plt.figure('PL index')
    _y = numpy.full(len(_x), PL_INDEX)
    fmt = dict(xname='Time', xunits='s', yname='PL index')
    _s = xInterpolatedUnivariateSpline(_x, _y, **fmt)
    _s.plot(logx=True, show=False, label=mod_label)
    plt.errorbar(_time,
                 _index,
                 xerr=[_time_errm, _time_errp],
                 yerr=_index_err,
                 fmt='o',
                 label=sim_label)
    plt.axis([100., 1e6, None, None])
    plt.legend(bbox_to_anchor=(0.4, 0.95))
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_pl_index', OUTPUT_FOLDER, False)
    #plt.figure('PL normalization')
    #plt.errorbar(_time, _norm, xerr=[_time_errm, _time_errp], yerr=_norm_err,
    #             fmt='o', label=sim_label)
    #pl_normalization_spline.plot(show=False, label=mod_label)
    #plt.axis([100., 1e6, None, None])
    #plt.legend(bbox_to_anchor=(0.4, 0.95))
    #draw_time_grid()
    #if save:
    #    save_current_figure('grb130427_swift_pl_norm', OUTPUT_FOLDER, False)
    plt.figure('Light curve')
    lc = xBinnedLightCurve(_lc_file_path())
    lc.plot(show=False)
    # This should be implemented in the binned LC class.
    plt.xscale('log')
    plt.yscale('log')
    plt.axis([100., 1e6, None, None])
    draw_time_grid()
    if save:
        save_current_figure('grb130427_swift_lc', OUTPUT_FOLDER, False)
    plt.show()
Example #20
0
plt.figure('Source spectrum')
_t = numpy.linspace(T_MIN, T_MAX, 100)
_e = aeff.x
fmt = dict(xname='Time', xunits='s', yname='Energy', yunits='keV',
           zname='dN/dE', zunits='cm$^{-2}$ s$^{-1}$ keV$^{-1}$')
spectrum_spline = xInterpolatedBivariateSplineLinear(_t, _e, spectrum, **fmt)
spectrum_spline.plot(show=False, logz=True)
save_current_figure('source_spectrum.png', OUTPUT_FOLDER, clear=False)

plt.figure('Source spectrum slices')
for t in [T_MIN, 0.5*(T_MIN + T_MAX), T_MAX]:
    spectrum_spline.vslice(t).plot(show=False, logx=True, logy=True,
                                   label='t = %d s' % t)
plt.legend(bbox_to_anchor=(0.75, 0.95))
plt.axis([1, 10, None, None])
save_current_figure('source_spectrum_slices.png', OUTPUT_FOLDER, clear=False)

plt.figure('Count spectrum')
count_spectrum = xCountSpectrum(spectrum, aeff, _t)
count_spectrum.plot(show=False, logz=True)
save_current_figure('count_spectrum.png', OUTPUT_FOLDER, clear=False)

plt.figure('Count spectrum slices')
for t in [T_MIN, 0.5*(T_MIN + T_MAX), T_MAX]:
    count_spectrum.vslice(t).plot(show=False, logx=True, logy=True,
                                  label='t = %d s' % t)
plt.legend(bbox_to_anchor=(0.9, 0.95))
plt.axis([1, 10, None, None])
save_current_figure('count_spectrum_slices.png', OUTPUT_FOLDER, clear=False)
Example #21
0
"""
ROI_MODEL = xROIModel(GK_PER_RA, GK_PER_DEC)
gk_per = xPeriodicPointSource(
    "GK Per",
    GK_PER_RA,
    GK_PER_DEC,
    energy_spectrum,
    polarization_degree,
    polarization_angle,
    ephem,
    column_density=0.0,
    redshift=0.0,
)
ROI_MODEL.add_source(gk_per)


if __name__ == "__main__":
    print(ROI_MODEL)
    from ximpol.utils.matplotlib_ import pyplot as plt

    plt.figure()
    spectrum_spline.plot(show=False, logx=True, logy=True)
    plt.axis([0.75, 11, 1e-10, 1e-2])
    plt.figure()
    phasogram_spline.plot(show=False)
    plt.figure()
    pol_degree_spline.plot(show=False)
    plt.figure()
    pol_angle_spline.plot(show=False)
    plt.show()
Example #22
0
plt.xlabel('Energy [keV]')
plt.ylabel('Polarization degree')
bad = pol_deg < 3*pol_deg_err
good = numpy.invert(bad)
bad[len(E_BINNING)-1] = False
good[len(E_BINNING)-1] = False
_dx = numpy.array([mod_cube.emean - mod_cube.emin, mod_cube.emax - mod_cube.emean])
if bad.sum() > 0:
    plt.errorbar(mod_cube.emean[bad], pol_deg[bad], pol_deg_err[bad],
                            _dx.T[bad].T, fmt='o', label='Data', color='gray')
if good.sum() > 0:
    plt.errorbar(mod_cube.emean[good], pol_deg[good], pol_deg_err[good],
                            _dx.T[good].T, fmt='o', label='Data', color='blue')
pol_degree.plot(show=False, label='Model', linestyle='dashed', color='green')
plt.legend(bbox_to_anchor=(0.30, 0.95))
plt.axis([1, 10, 0, 0.1])
#plt.savefig('/home/nicco/%s_0_0_10x%dMs_polarization_degree.png' %\
#                                                (NAME_LIST[0:3], TIME/100000))

fig = plt.figure('Polarization angle')
plt.xlabel('Energy [keV]')
plt.ylabel('Polarization angle [$^\circ$]')
if bad.sum() > 0:
    plt.errorbar(mod_cube.emean[bad], pol_ang[bad], pol_ang_err[bad],
                            _dx.T[bad].T, fmt='o', label='Data', color='gray')
if good.sum() > 0:
    plt.errorbar(mod_cube.emean[good], pol_ang[good], pol_ang_err[good],
                            _dx.T[good].T, fmt='o', label='Data', color='blue')
pol_angle.plot(show=False, label='Model', linestyle='dashed', color='green')
plt.legend(bbox_to_anchor=(0.95, 0.95))
plt.axis([1, 10, 0, 180])
    def test_power_law_stationary(self):
        """Test a time-independent power law.

        This creates a count spectrum with no time dependence, i.e., with
        only two (identical) interpolating time points on the auxiliary
        (time) axis. The power-law parameters (C and gamma) are constant

        >>> tmin = 0.
        >>> tmax = 100.
        >>> C = 1.
        >>> Gamma = 2.
        >>>
        >>> def powerlaw(E, t):
        >>>     return C*numpy.power(E, -Gamma)
        >>>
        >>> _t = numpy.linspace(tmin, tmax, 2)
        >>> count_spectrum = xCountSpectrum(powerlaw, self.aeff, _t)

        and the underlying xUnivariateAuxGenerator looks like.

        .. image:: ../figures/test_power_law_stationary_2d.png

        Then a vertical slice (i.e., an interpolated linear spline) is taken
        in the middle of the auxiliary axis

        >>> tref = 0.5*(tmin + tmax)
        >>> ref_slice = count_spectrum.slice(tref)

        and the y-values of the spline are compared with the direct product of
        the effective area and the input spectrum:

        >>> _x = self.aeff.x
        >>> _y = C*numpy.power(_x, -Gamma)*self.aeff.y

        (Note that in general the two are technically not the same thing, as
        going from the count spectrum to the slice we do interpolate in time,
        although in this particular case the interpolation is trivial).
        If everything goes well, they should be on top of each other.
        The figure below is also showing the original power-law spectrum
        multiplied by the peak effective area.

        .. image:: ../figures/test_power_law_stationary_slice.png

        """
        tmin = 0.
        tmax = 100.
        tref = 0.5*(tmin + tmax)
        C = 1.
        Gamma = 2.

        def powerlaw(E, t):
            """Function defining a time-dependent energy spectrum.
            """
            return C*numpy.power(E, -Gamma)

        _t = numpy.linspace(tmin, tmax, 2)
        count_spectrum = xCountSpectrum(powerlaw, self.aeff, _t)
        count_spectrum.plot(show=False)
        overlay_tag(color='white')
        save_current_figure('test_power_law_stationary_2d.png',
                            show=self.interactive)

        ref_slice = count_spectrum.slice(tref)
        _x = self.aeff.x
        _y = C*numpy.power(_x, -Gamma)*self.aeff.y.max()
        plt.plot(_x, _y, '-', label='Original power-law spectrum')
        _y = C*numpy.power(_x, -Gamma)*self.aeff.y
        _mask = _y > 0.
        _x = _x[_mask]
        _y = _y[_mask]
        delta = abs((_y - ref_slice(_x))/_y).max()
        self.assertTrue(delta < 1e-3, 'max deviation %.9f' % delta)
        plt.plot(_x, _y, 'o', label='Direct convolution with aeff')
        ref_slice.plot(logx=True, logy=True, show=False,
                       label='xCountSpectrum output')
        overlay_tag()
        plt.text(0.1, 0.1, 'Max. difference = %.3e' % delta,
                 transform=plt.gca().transAxes)
        plt.legend(bbox_to_anchor=(0.75, 0.5))
        plt.axis([0.6, 10, None, None])
        save_current_figure('test_power_law_stationary_slice.png',
                            show=self.interactive)
    def test_power_law_variable(self):
        """Test a time-dependent power law.

        This creates a time-dependent count spectrum, where the two parameters
        of the underlying power law (C and Gamma) vary linearly with time, in
        opposite direction, between 1 and 2.

        >>> def C(t):
        >>>     return 1. + (t - tmin)/(tmax - tmin)
        >>>
        >>> def Gamma(t):
        >>>    return 2. - (t - tmin)/(tmax - tmin)
        >>>
        >>> def powerlaw(E, t):
        >>>    return C(t)*numpy.power(E, -Gamma(t))

        (Beware: this does not mean that you can interpolate linearly between
        the two time extremes, as both parameters vary at the same time and
        the spectral shape does not evolve linearly with time---we're sampling
        the time axis with 100 points).
        The underlying xUnivariateAuxGenerator looks like.

        .. image:: ../figures/test_power_law_variable_2d.png

        Then a vertical slice (i.e., an interpolated linear spline) is taken
        in the middle of the auxiliary axis and the y-values of the spline
        are compared with the direct product of the effective area and the
        count spectrum (evaluated at the same time). If everything goes well,
        they should be on top of each other. The figure below is also showing
        the orignal power-law spectrum multiplied by the peak effective area.

        .. image:: ../figures/test_power_law_variable_slice.png

        Finally, we do test the light-curve building by comparing it with the
        values from a direct intergration of the vertical slices on a
        fixed-spacing grid. Note that, since the normalization increases with
        time and the spectral index becomes harder, the light-curve increases
        more than linearly.

        .. image:: ../figures/test_power_law_variable_lc.png

        """
        tmin = 0.
        tmax = 100.
        tref = 0.5*(tmin + tmax)

        def C(t):
            """Time-dependent C---equals to 1 @ tmin and 2 @ tmax.
            """
            return 1. + (t - tmin)/(tmax - tmin)

        def Gamma(t):
            """Time-dependent C---equals to 2 @ tmin and 1 @ tmax.
            """
            return 2. - (t - tmin)/(tmax - tmin)

        def powerlaw(E, t):
            """Function defining a time-dependent energy spectrum.
            """
            return C(t)*numpy.power(E, -Gamma(t))

        _t = numpy.linspace(tmin, tmax, 100)
        count_spectrum = xCountSpectrum(powerlaw, self.aeff, _t)
        count_spectrum.plot(show=False)
        overlay_tag(color='white')
        save_current_figure('test_power_law_variable_2d.png',
                            show=self.interactive)

        ref_slice = count_spectrum.slice(tref)
        _x = self.aeff.x
        _y = self.aeff.y.max()*C(tref)*numpy.power(_x, -Gamma(tref))
        plt.plot(_x, _y, '-', label='Original power-law spectrum')
        _y = C(tref)*numpy.power(_x, -Gamma(tref))*self.aeff.y
        _mask = _y > 0.
        _x = _x[_mask]
        _y = _y[_mask]
        delta = abs((_y - ref_slice(_x))/_y).max()
        self.assertTrue(delta < 1e-3, 'max deviation %.9f' % delta)
        plt.plot(_x, _y, 'o', label='Direct convolution with aeff')
        ref_slice.plot(logx=True, logy=True, show=False,
                       label='xCountSpectrum output')
        overlay_tag()
        plt.text(0.1, 0.1, 'Max. difference = %.3e' % delta,
                 transform=plt.gca().transAxes)
        plt.legend(bbox_to_anchor=(0.75, 0.5))
        plt.axis([0.6, 10, None, None])
        save_current_figure('test_power_law_variable_slice.png',
                            show=self.interactive)

        _x = numpy.linspace(tmin, tmax, 33)
        _y = []
        for _xp in _x:
            _y.append(count_spectrum.slice(_xp).norm())
        _y = numpy.array(_y)
        plt.plot(_x, _y, 'o', label='Direct integral flux values')
        delta = abs((_y - count_spectrum.light_curve(_x))/_y).max()
        self.assertTrue(delta < 1e-3, 'max deviation %.9f' % delta)
        count_spectrum.light_curve.plot(show=False,
                                        label='xCountSpectrum light-curve')
        overlay_tag()
        plt.legend(bbox_to_anchor=(0.65, 0.75))
        plt.text(0.5, 0.1, 'Max. difference = %.3e' % delta,
                 transform=plt.gca().transAxes)
        save_current_figure('test_power_law_variable_lc.png',
                            show=self.interactive)
Example #25
0
sgrb1 = xUniformDisk('Sgr B1', 266.75833, -28.5325, angular_radius(6.),
                     energy_spectrum_b1, polarization_degree_b1,
                     polarization_angle_b1)

spectrum_spline_b2 = parse_spectral_model('spec_model_SgrB2.txt')

def energy_spectrum_b2(E, t):
    """
    """
    return spectrum_spline_b2(E)

polarization_degree_b2 = constant(0.455)
polarization_angle_b2 = constant(numpy.radians(84.4))
sgrb2 = xUniformDisk('Sgr B2', 266.835, -28.38528, angular_radius(5.),
                     energy_spectrum_b2, polarization_degree_b2,
                     polarization_angle_b2)

ROI_MODEL.add_sources(sgrb1, sgrb2)


if __name__ == '__main__':
    print(ROI_MODEL)
    from ximpol.utils.matplotlib_ import pyplot as plt
    plt.figure('Sgr complex')
    spectrum_spline_b1.plot(show=False, label='Sgr B1')
    spectrum_spline_b2.plot(show=False, label='Sgr B2')
    plt.yscale('log')
    plt.axis([1, 10, 1e-7, 1e-3])
    plt.legend(bbox_to_anchor=(0.35, 0.85))
    plt.show()