Exemplo n.º 1
0
    def bigger_wsdl(self, band, compare=None):
        """ Want to sample on a grid that is comparable in size (or
            smaller than) 10% of the psf to ensure we get a reasonable
            sampling of the grid. """
        if compare is None:
            r10 = band.psf.inverse_integral_on_axis(0.10)
            compare = r10

        self.factor = int(np.ceil(self.pixelsize / compare))

        if self.factor == 1:
            return self.wsdl
        else:
            # hold onto this thing since it is needed by downsample_model
            if not hasattr(self.size, '__iter__'):
                self.fine_skyimage = SkyImage(
                    self.center, '',
                    float(self.pixelsize) / self.factor, self.size, 1,
                    self.proj, self.galactic, False)
            else:
                self.fine_skyimage = SkyImage(
                    self.center, '',
                    float(self.pixelsize) / self.factor, float(self.size[0]),
                    1, self.proj, self.galactic, False, float(self.size[1]))

            wsdl = self.fine_skyimage.get_wsdl()
            return wsdl
Exemplo n.º 2
0
def load_skyspect(fn = r'T:\data\galprop\ring_21month_P6v11.fits', 
# r'D:\fermi\data\galprop\gll_iem_v02.fit', 
        nside=192, 
        show_kw = dict(fun=np.log10, cmap='hot'),
        ):
    """
    load a galactic diffuse distribution.
    Save the HEALpix respresentation at an energy (1 GeV default)
    
    fn : string
        filename for the FITS representaion of a  SKySpectrum  
    nside: int
        HEALpix nside to use for represenation -- note that 192 is 12*16, about 0.25 deg
    show_kw : dict
        fun: weighting function, cmap, vmin, vmax
    """
    t = SkyImage(fn)
    galname = os.path.split(fn)[-1]
    print '%s: nx, ny, layers: %d %d %d' %(galname, t.naxis1(), t.naxis2(), t.layers())
    hpdir = Band(nside).dir
    dmap = map(lambda i:t(hpdir(i)), xrange(12*nside**2))
    tdm=DisplayMap(dmap)
    tdm.fill_ait(fignum=12, source_kw=dict(edgecolor='w',), show_kw=show_kw )
    plt.title(galname+' (1 GeV)')
    sfn = galname.split('.')[0]+'.png'
    plt.savefig(galname.split('.')[0]+'.png', bbox_inches='tight', pad_inches=0)
    print 'saved figure to %s' % sfn
    return tdm
Exemplo n.º 3
0
 def __init__(
     self,
     name,
     filename,
     nside=512,
 ):
     self.skyimage = SkyImage(filename)
     super(HPfitscube, self).__init__(name, self.skyimage, nside)
Exemplo n.º 4
0
    def __init__(self, roi, **kwargs):
        """ Note, unlike ZEA, can support non-square images. To specify a nonsquare
            image, set the size parameter to a lenght two tuple:
                
                size=(10,5) # dx=10 degrees, dy=5 degrees. 
        """
        keyword_options.process(self, kwargs)

        if self.size < self.pixelsize:
            raise Exception("Can only create images with >=1 pixel in them.")

        self.roi = roi

        self.selected_bands = tuple(self.roi.bands if self.conv_type < 0 else \
            [ band for band in self.roi.bands if band.ct == self.conv_type ])

        # by default, use get energy range and image center from roi.
        if self.center is None: self.center = self.roi.roi_dir

        # set up, then create a SkyImage object to perform the projection
        # to a grid and manage an image
        if not isinstance(self.size, collections.Iterable):

            # make sure size and pixelsize are commensurate (helpful for
            # various downsampling code later).
            self.size = int(self.size / self.pixelsize + 0.01) * self.pixelsize
            self.skyimage = SkyImage(self.center, '', self.pixelsize,
                                     self.size, 1, self.proj, self.galactic,
                                     False)
        else:
            self.skyimage = SkyImage(self.center, '', self.pixelsize,
                                     float(self.size[0]), 1, self.proj,
                                     self.galactic, False, float(self.size[1]))

        self.fill()

        self.nx, self.ny = self.skyimage.naxis1(), self.skyimage.naxis2()
        self.image = ROIImage.skyimage2numpy(self.skyimage)
Exemplo n.º 5
0
    def __init__(self, filename):
        t = os.path.split(os.path.splitext(filename)[0])[-1].split('_')
        self.sourcename = ' '.join(t[:-1]).replace('p', '+')

        self.df = df = SkyImage(filename)
        wcs = df.projector()
        self.tsmap = np.array(df.image())
        nx, ny = df.naxis1(), df.naxis2()
        assert nx == ny, 'Array not square?'

        vals = np.exp(-0.5 * self.tsmap**2)  # convert to likelihood from TS
        norm = 1. / sum(vals)
        self.peak_fract = norm * vals.max()
        center, variance = self.moments_analysis(vals)
        ra, dec = wcs.pix2sph(center[1], center[0])
        self.peak = SkyDir(ra, dec)
        self.scale = wcs.pix2sph(center[0], center[1] + 1)[1] - dec
        self.size = nx * self.scale
        self.variance = self.scale**2 * variance
        rac, decc = wcs.pix2sph(nx / 2, ny / 2)
        self.offset = np.degrees(self.peak.difference(SkyDir(rac, decc)))