コード例 #1
0
ファイル: roi_image.py プロジェクト: tburnett/pointlike
    def __init__(self,roi,**kwargs):
        super(ResidualImage,self).__init__(roi,**kwargs)

        self.model=ModelImage(self.roi,**keyword_options.defaults_to_kwargs(self,ModelImage))
        self.counts=CountsImage(self.roi,**keyword_options.defaults_to_kwargs(self,CountsImage))

        self.image = self.counts.image - self.model.image
        SmoothedImage.add_to_skyimage(self.skyimage,self.image)
コード例 #2
0
    def __init__(self, *args, **kwargs):

        super(SmoothedImage, self).__init__(*args, **kwargs)

        self.kernel = self.get_kernel(self.kerneltype, self.kernel_rad,
                                      self.pixelsize)

        self.kernelsize = self.kernel.shape[0]

        # Make an image, bigger then the desired one, by twice
        # the smooth radius in each direction.
        self.pass_dict = keyword_options.defaults_to_kwargs(self, self.object)
        self.pass_dict['size'] = self.size + self.kernelsize * self.pixelsize
        self.smoothed = self.object(self.roi, **self.pass_dict)

        self.smoothed.skyimage = SmoothedImage.convolve_skyimage(
            self.smoothed.skyimage, self.kernel)
        self.smoothed.image = ROIImage.skyimage2numpy(self.smoothed.skyimage)

        # now, shrink down smoothed image and replace the current skyimage with it

        self.image = self.smoothed.image[self.kernelsize / 2:-self.kernelsize /
                                         2, self.kernelsize /
                                         2:-self.kernelsize / 2]

        if self.per_solid_angle:
            # convert from counts to counts per square degree
            self.image = self.image / self.pixelsize**2

        SmoothedImage.add_to_skyimage(self.skyimage, self.image)
コード例 #3
0
ファイル: gtlike.py プロジェクト: jimmyliao13536/PhD-python
    def __init__(self, like, name, *args, **kwargs):
        keyword_options.process(self, kwargs)

        self.like = like
        self.name = name

        if self.ul_algorithm not in BaseGtlikeSED.ul_choices:
            raise Exception("Upper Limit Algorithm %s not in %s" % (self.ul_algorithm,str(BaseGtlikeSED.ul_choices)))

        if self.bin_edges is not None:
            if not BaseGtlikeSED.good_binning(like, self.bin_edges):
                raise Exception("bin_edges is not commensurate with the underlying energy binning of pyLikelihood.")
            
            self.bin_edges = np.asarray(self.bin_edges)
            energy = np.sqrt(self.bin_edges[1:]*self.bin_edges[:-1])
        else:
            # These energies are always in MeV
            self.bin_edges = like.energies
            energy = like.e_vals

        self.lower=self.bin_edges[:-1]
        self.upper=self.bin_edges[1:]

        source=self.like.logLike.getSource(name) 
        self.init_spectrum=source.spectrum()
        self.init_model=build_pointlike_model(self.init_spectrum)

        self.results = dict(
            Name=name,
            spectrum=name_to_spectral_dict(like,name, errors=True, covariance_matrix=True),
        )
        self._calculate(like)

        super(GtlikeSED,self).__init__(self.results, **keyword_options.defaults_to_kwargs(self, SED))
コード例 #4
0
ファイル: roi_state.py プロジェクト: tburnett/pointlike
    def __init__(self, roi):
        self.roi = roi
        self.point_sources = self._copy_ps(roi.psm.point_sources)
        self.bgmodels = self._copy_bg(roi.dsm.bgmodels)

        from uw.like.roi_analysis import ROIAnalysis
        self.roi_kwargs = defaults_to_kwargs(roi, ROIAnalysis)
コード例 #5
0
    def __init__(self, roi, **kwargs):

        if kwargs.has_key('show_colorbar') or \
           kwargs.has_key('overlay_psf'):
            raise Exception("This feature doesn't work, for now...")

        keyword_options.process(self, kwargs)

        self.roi = roi

        sources_kwargs = keyword_options.defaults_to_kwargs(
            self, ROISmoothedSources)
        sources_kwargs['show_colorbar'] = False
        self.smoothed_sources = ROISmoothedSources(roi, **sources_kwargs)

        source_kwargs = keyword_options.defaults_to_kwargs(
            self, ROISmoothedSources)
        source_kwargs['overlay_psf'] = False
        self.smoothed_source = ROISmoothedSource(roi, **source_kwargs)
コード例 #6
0
ファイル: roi_analysis.py プロジェクト: tburnett/pointlike
 def change_binning(self, fit_emin, fit_emax):
     """ This function recreates the ROI using a new energy binning.  
         Kind of inefficient, but easy. """
     kwargs = keyword_options.defaults_to_kwargs(self, ROIAnalysis)
     kwargs['fit_emin'] = fit_emin
     kwargs['fit_emax'] = fit_emax
     self.__init__(roi_dir=self.roi_dir,
                   ps_manager=self.psm,
                   ds_manager=self.dsm,
                   spectral_analysis=self.sa,
                   **kwargs)
コード例 #7
0
    def __init__(self, roi, name, **kwargs):
        keyword_options.process(self, kwargs)
        self.roi = roi
        self.name = name
        
        bf = BandFlux(self.roi, which=self.name, merge=self.merge, scale_factor=1)
        results = PointlikeSED.pointlike_sed_to_dict(bf, flux_units=self.flux_units, energy_units=self.energy_units)

        results['spectrum'] = name_to_spectral_dict(roi, name, errors=True, covariance_matrix=True)

        super(PointlikeSED,self).__init__(results, **keyword_options.defaults_to_kwargs(self, SED))
コード例 #8
0
    def __init__(self, roi, **kwargs):
        keyword_options.process(self, kwargs)

        self.roi = roi

        self.cmap = colormaps.b

        # Fit many pixels inside of the summing radius
        self.pixelsize = self.kernel_rad / 5.0

        # Background subtracted counts
        counts_kwargs = keyword_options.defaults_to_kwargs(
            self, ROISmoothedSources)
        counts_kwargs['show_colorbar'] = False
        counts_kwargs['overlay_psf'] = False
        self.counts = ROISmoothedSources(roi, **counts_kwargs)

        # Model counts for non-background sources.
        model_kwargs = keyword_options.defaults_to_kwargs(
            self, ROISmoothedSources)
        model_kwargs['overlay_psf'] = False
        self.model = ROISmoothedModel(roi, **model_kwargs)
コード例 #9
0
ファイル: gtlike.py プロジェクト: jimmyliao13536/PhD-python
    def __init__(self, like, name, *args, **kwargs):
        keyword_options.process(self, kwargs)

        self.like = like
        self.name = name

        if self.ul_algorithm not in BaseGtlikeSED.ul_choices:
            raise Exception("Upper Limit Algorithm %s not in %s" %
                            (self.ul_algorithm, str(BaseGtlikeSED.ul_choices)))

        if self.bin_edges is not None:
            if not BaseGtlikeSED.good_binning(like, self.bin_edges):
                raise Exception(
                    "bin_edges is not commensurate with the underlying energy binning of pyLikelihood."
                )

            self.bin_edges = np.asarray(self.bin_edges)
            energy = np.sqrt(self.bin_edges[1:] * self.bin_edges[:-1])
        else:
            # These energies are always in MeV
            self.bin_edges = like.energies
            energy = like.e_vals

        self.lower = self.bin_edges[:-1]
        self.upper = self.bin_edges[1:]

        source = self.like.logLike.getSource(name)
        self.init_spectrum = source.spectrum()
        self.init_model = build_pointlike_model(self.init_spectrum)

        self.results = dict(
            Name=name,
            spectrum=name_to_spectral_dict(like,
                                           name,
                                           errors=True,
                                           covariance_matrix=True),
        )
        self._calculate(like)

        super(GtlikeSED,
              self).__init__(self.results,
                             **keyword_options.defaults_to_kwargs(self, SED))
コード例 #10
0
    def __init__(self, roi, name, **kwargs):
        keyword_options.process(self, kwargs)
        self.roi = roi
        self.name = name

        bf = BandFlux(self.roi,
                      which=self.name,
                      merge=self.merge,
                      scale_factor=1)
        results = PointlikeSED.pointlike_sed_to_dict(
            bf, flux_units=self.flux_units, energy_units=self.energy_units)

        results['spectrum'] = name_to_spectral_dict(roi,
                                                    name,
                                                    errors=True,
                                                    covariance_matrix=True)

        super(PointlikeSED,
              self).__init__(results,
                             **keyword_options.defaults_to_kwargs(self, SED))
コード例 #11
0
    def fill(self):

        tscalc = TSCalc(self.roi,
                        **keyword_options.defaults_to_kwargs(self, TSCalc))
        temp = TSCalcPySkyFunction(tscalc)
        self.skyimage.fill(temp.get_pyskyfun())