예제 #1
0
    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
 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)
예제 #3
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