コード例 #1
0
ファイル: combined.py プロジェクト: mahmoud-lsw/PhD-python
    def plot(
            self,
            filename=None,
            axes=None,
            fignum=None,
            figsize=(5.5, 4.5),
            spectral_kwargs=dict(color='red', zorder=1.9),
            cutoff_kwargs=dict(color='blue', zorder=1.9),
    ):

        if axes is None:
            fig = P.figure(fignum, figsize)
            axes = SpectralAxes(fig=fig,
                                rect=(0.22, 0.15, 0.75, 0.8),
                                flux_units=self.flux_units,
                                energy_units=self.energy_units)
            fig.add_axes(axes)

            axes.set_xlim_units(100 * units.MeV, 10**5.5 * units.MeV)

        # plot sed
        sed = SED(self.sed_4bpd)
        sed.plot_points(axes=axes)

        if self.hypothesis == 'at_pulsar':
            # plot power-law limits
            ul = UpperLimit(self.powerlaw_limit)
            ul.plot(axes=axes, color='orange', zorder=1.9)

        axes.autoscale(False)

        # plot spectral model
        sp = SpectrumPlotter(axes=axes)
        sp.plot(self.spectral_model, **spectral_kwargs)
        sp.plot_error(self.spectral_model, alpha=0.25, **spectral_kwargs)

        if self.hypothesis != 'extended':
            # plot cutoff model
            sp.plot(self.cutoff_model, **cutoff_kwargs)
            sp.plot_error(self.cutoff_model, alpha=0.25, **cutoff_kwargs)

        if self.hypothesis == 'at_pulsar':
            ul = UpperLimit(self.cutoff_limit)
            ul.plot(axes=axes, color='purple', zorder=1.9)

        #if self.code == 'gtlike':
        #    bf = BandFitter(self.bandfits)
        #    bf.plot(axes=axes,
        #            spectral_kwargs=dict(color='green',zorder=1.9),
        #            spectral_error_kwargs=dict(color='green', alpha=0.25))

        if filename is not None:
            P.savefig(expandvars(filename))
        return axes
コード例 #2
0
ファイル: cutoff.py プロジェクト: jimmyliao13536/PhD-python
    def plot(self, filename=None, axes=None, title=None, 
             sed_results=None,
             fignum=None, figsize=(4,4),
             model_0_kwargs=dict(color='red', zorder=0),
             model_1_kwargs=dict(color='blue', zorder=0),
             sed_kwargs=dict(),
             plot_kwargs=dict(),):
        """ Plots the cutoff test performed of a spectrum using the function
            gtlike_test_cutoff.

            Input:
                cutoff_dict: created by gtlike_test_cutoff
                sed_dict: created by GtlikeSED.todict(). Can also be a yaml
                  file created by GtlikeSED.save().

                model_0_kwargs: kwargs for model_0's plot 
                model_1_kwargs: kwargs for model_0's plot 
                sed_kwargs: kwargs to pass into SED
                  E.G. flux_units, flux_units, figsize, ...
        """
        if axes is None:
            fig = P.figure(fignum,figsize)
            axes = SpectralAxes(fig=fig, rect=(0.22,0.15,0.75,0.8),
                         flux_units=self.flux_units,
                         energy_units=self.energy_units)
            fig.add_axes(axes)
            energy = self.results['energy']
            axes.set_xlim_units(energy['emin']*units.fromstring(energy['energy_units']), 
                                energy['emax']*units.fromstring(energy['energy_units']))

        if sed_results is not None:
            sed = SED(sed_results)
            sed.plot_points(axes=axes, **sed_kwargs)

        sp = SpectrumPlotter(axes=axes)
        sp.plot(self.results['hypothesis_0']['spectrum'], 
                autoscale=False, **model_0_kwargs)
        sp.plot_error(self.results['hypothesis_0']['spectrum'], 
                      self.results['hypothesis_0']['spectrum']['covariance_matrix'],
                      alpha=0.5,
                      autoscale=False, **model_0_kwargs)

        sp.plot(self.results['hypothesis_1']['spectrum'], 
                autoscale=False, **model_1_kwargs)
        sp.plot_error(self.results['hypothesis_1']['spectrum'], 
                      self.results['hypothesis_1']['spectrum']['covariance_matrix'], 
                      alpha=0.5,
                      autoscale=False, **model_1_kwargs)

        if title is not None: axes.set_title(title)
        if filename is not None: 
            P.savefig(expandvars(filename))
        return axes
コード例 #3
0
ファイル: combined.py プロジェクト: jimmyliao13536/PhD-python
    def plot(self, filename=None, axes=None,
            fignum=None, figsize=(5.5,4.5),
            spectral_kwargs=dict(color='red', zorder=1.9),
            cutoff_kwargs=dict(color='blue', zorder=1.9),
            ):

        if axes is None:
            fig = P.figure(fignum,figsize)
            axes = SpectralAxes(fig=fig,
                                rect=(0.22,0.15,0.75,0.8),
                                flux_units=self.flux_units,
                                energy_units=self.energy_units)
            fig.add_axes(axes)

            axes.set_xlim_units(100*units.MeV, 10**5.5*units.MeV)
    
        # plot sed
        sed = SED(self.sed_4bpd)
        sed.plot_points(axes=axes)

        if self.hypothesis == 'at_pulsar':
            # plot power-law limits
            ul=UpperLimit(self.powerlaw_limit)
            ul.plot(axes=axes, color='orange', zorder=1.9)

        axes.autoscale(False)

        # plot spectral model
        sp=SpectrumPlotter(axes=axes)
        sp.plot(self.spectral_model, **spectral_kwargs)
        sp.plot_error(self.spectral_model, alpha=0.25, **spectral_kwargs)

        if self.hypothesis != 'extended':
            # plot cutoff model
            sp.plot(self.cutoff_model, **cutoff_kwargs)
            sp.plot_error(self.cutoff_model, alpha=0.25, **cutoff_kwargs)

        if self.hypothesis == 'at_pulsar':
            ul=UpperLimit(self.cutoff_limit)
            ul.plot(axes=axes, color='purple', zorder=1.9)

        #if self.code == 'gtlike':
        #    bf = BandFitter(self.bandfits)
        #    bf.plot(axes=axes, 
        #            spectral_kwargs=dict(color='green',zorder=1.9), 
        #            spectral_error_kwargs=dict(color='green', alpha=0.25))

        if filename is not None:
            P.savefig(expandvars(filename))
        return axes
コード例 #4
0
 def plot(self, filename):
     sed = SED(self.sed_points)
     # Plot SED points
     axes = sed.plot()
     # Plot model0, model1
     sed.plot_spectrum(self.model0, axes=axes, label='model0')
     sed.plot_spectrum(self.comprehensive_model, axes=axes, label='model1')
     sed.plot_spectrum(self.comprehensive_model_start,
                       axes=axes,
                       label='model1 (start)')
     axes.legend()
     P.savefig(filename)
コード例 #5
0
ファイル: comptest.py プロジェクト: jimmyliao13536/PhD-python
 def plot(self, filename):
     sed = SED(self.sed_points)
     # Plot SED points
     axes=sed.plot()
     # Plot model0, model1
     sed.plot_spectrum(self.model0, axes=axes, label='model0')
     sed.plot_spectrum(self.comprehensive_model, axes=axes, label='model1')
     sed.plot_spectrum(self.comprehensive_model_start, axes=axes, label='model1 (start)')
     axes.legend()
     P.savefig(filename)
コード例 #6
0
            axes_pad=0.0,
            axes_class=(SpectralAxes, dict(energy_units='GeV')),
           )


for i,pwn in enumerate(cutoff_candidates):
    print i,pwn

    axes=grid[i]


    r = classifier.get_results(pwn)
    spectrum = r['spectrum']
    sed = r['sed_4bpd']

    s = SED(sed)
    s.plot_points(axes=axes, zorder=2.1)

    sp = SpectrumPlotter(axes=axes)
    sp.plot(spectrum, autoscale=False, color='red' if not bw else 'grey', zorder=1.9)

label_axes(grid)

grid[0].set_ylabel('')
grid[4].set_ylabel('')


for i in range(nrows*ncols):
    axes=grid[i]
    #axes.set_xlim_units(10**2*units.MeV,10**5.5*units.MeV)
    axes.set_xlim(0.1,10**2.5)
コード例 #7
0
    def plot(
            self,
            filename=None,
            axes=None,
            title=None,
            sed_results=None,
            fignum=None,
            figsize=(4, 4),
            model_0_kwargs=dict(color='red', zorder=0),
            model_1_kwargs=dict(color='blue', zorder=0),
            sed_kwargs=dict(),
            plot_kwargs=dict(),
    ):
        """ Plots the cutoff test performed of a spectrum using the function
            gtlike_test_cutoff.

            Input:
                cutoff_dict: created by gtlike_test_cutoff
                sed_dict: created by GtlikeSED.todict(). Can also be a yaml
                  file created by GtlikeSED.save().

                model_0_kwargs: kwargs for model_0's plot 
                model_1_kwargs: kwargs for model_0's plot 
                sed_kwargs: kwargs to pass into SED
                  E.G. flux_units, flux_units, figsize, ...
        """
        if axes is None:
            fig = P.figure(fignum, figsize)
            axes = SpectralAxes(fig=fig,
                                rect=(0.22, 0.15, 0.75, 0.8),
                                flux_units=self.flux_units,
                                energy_units=self.energy_units)
            fig.add_axes(axes)
            energy = self.results['energy']
            axes.set_xlim_units(
                energy['emin'] * units.fromstring(energy['energy_units']),
                energy['emax'] * units.fromstring(energy['energy_units']))

        if sed_results is not None:
            sed = SED(sed_results)
            sed.plot_points(axes=axes, **sed_kwargs)

        sp = SpectrumPlotter(axes=axes)
        sp.plot(self.results['hypothesis_0']['spectrum'],
                autoscale=False,
                **model_0_kwargs)
        sp.plot_error(
            self.results['hypothesis_0']['spectrum'],
            self.results['hypothesis_0']['spectrum']['covariance_matrix'],
            alpha=0.5,
            autoscale=False,
            **model_0_kwargs)

        sp.plot(self.results['hypothesis_1']['spectrum'],
                autoscale=False,
                **model_1_kwargs)
        sp.plot_error(
            self.results['hypothesis_1']['spectrum'],
            self.results['hypothesis_1']['spectrum']['covariance_matrix'],
            alpha=0.5,
            autoscale=False,
            **model_1_kwargs)

        if title is not None: axes.set_title(title)
        if filename is not None:
            P.savefig(expandvars(filename))
        return axes