Пример #1
0
    def __getitem__(self, name):
        """ returns an HParray object corresponding to the name
        """
        if name == 'galactic':
            return hpm.HParray(name, self.df['final'] - self.df['src'])
        if name == 'isotropic':
            return hpm.HParray(name, self.df['egb'])
        if name == 'sources':
            return hpm.HParray(name, self.df['src'] + self.df['UN'])

        return hpm.HParray(name, self.df[name])
Пример #2
0
def check_bubble_maps(cubefile):
    if not os.path.exists(cubefile):

        bubble = [
            diffuse.HealpixCube(f) for f in [
                '../uw8600/bubbles.fits', '../uw8604/bubbles_v2.fits',
                '../uw8605/bubbles_v3.fits', '../uw8606/bubbles_v4.fits'
            ]
        ]
        for b in bubble:
            b.load()

        # multiply them all together
        energies = bubble[0].energies
        pr = np.array([b.vec for b in bubble[0]])

        for bb in bubble[1:]:
            pr *= np.array([b.vec for b in bb])

        t = [
            healpix_map.HParray('{:.0f} MeV'.format(energy), v)
            for energy, v in zip(energies, pr)
        ]
        bcube = healpix_map.HEALPixFITS(t, energies=energies)
        healpix_map.multi_ait(t,
                              vmin=0.8,
                              vmax=2.0,
                              cmap=plt.get_cmap('jet'),
                              grid_color='grey',
                              cblabel='ratio to diffuse',
                              title='bubbles correction to diffuse')

        bcube.write(cubefile)
    else:
        print 'Using existing file {}'.format(cubefile)
Пример #3
0
    def __init__(self,
                 modelname,
                 energy=131,
                 root='/nfs/farm/g/glast/g/catalog/pointlike/fermi/gardian/',
                 reload=False):
        from astropy.table import Table

        cfile = '{}{}_{:d}.fits'.format(root, modelname, energy)
        if not os.path.exists(cfile) or reload:
            print 'Will create file {}'.format(cfile)
            GarDian(modelname=mname, energy=energy).write(cfile)

        assert os.path.exists(cfile), 'File "{}" not found'.format(cfile)
        self.df = Table.read(cfile, hdu=1).to_pandas()
        self.modelname, self.energy = modelname, energy
        self.nside = nside = int(np.sqrt(len(self.df) / 12))
        print 'read file {}'.format(cfile)

        # add locations to the DataFrame
        glon, glat = healpy.pix2ang(nside, range(12 * nside**2), lonlat=True)
        glon[glon > 180] -= 360
        self.df['glon'] = glon
        self.df['glat'] = glat

        # a column with combined sources
        self.df['sources'] = self.df['src'] + self.df['UN']

        data, model = np.array(self.df['counts']), np.array(self.df['final'])
        resid = (data - model) / np.sqrt(model)
        #print resid.mean(), resid.std()

        self.pulls = hpm.HParray('f{} pulls'.format(energy),
                                 (data - model) / np.sqrt(model))
        self.df['pull'] = self.pulls.vec
        self.label = '{} @ {:.0f} MeV'.format(self.modelname, self.energy)
Пример #4
0
 def setEnergy(self, energy):
     self.load()
     if energy == self.energy: return
     self.eindex = -1
     for i, e in enumerate(self.energies):
         if abs(e - energy) < 0.01 * e:
             self.eindex = i
             self.energy = energy
             break
     assert self.eindex >= 0, 'Energy %.0f not found' % energy
     cname = self.col_names[self.eindex]
     self.hpm = healpix_map.HParray(cname, self.columns.field(cname))
Пример #5
0
    def ait_plot(self,
                 vmin=0,
                 vmax=None,
                 log=False,
                 ax=None,
                 cmap=plt.get_cmap('coolwarm'),
                 **kwargs):

        y = hpm.HParray('', self.map)
        y.plot(title='{} @ {:.2f} GeV'.format(self.cname, self.energy / 1e3),
               ait_kw=dict(),
               log=log,
               vmin=vmin,
               vmax=vmax,
               cmap=cmap,
               **kwargs).grid()
Пример #6
0
 def modify_by_patch(self, patch, newfile=None):
     modlayer = []
     for i, layer in enumerate((self)):
         name = layer.name
         a = layer.vec
         if i < len(patch):
             p = patch[i]
         else:
             p = patch[-1]
         b = p.vec
         print layer.name, ',',
         modlayer.append(
             healpix_map.HParray(layer.name, healpix_map.multiply(a, b)))
     print
     outmap = healpix_map.HEALPixFITS(modlayer, energies=self.energies)
     if newfile is not None: outmap.write(newfile)
     return outmap
Пример #7
0
    def __init__(self, cubefile, sigsfile, start=0, stop=8, deg=2):
        
        check_bubble_maps(cubefile)
        m = diffuse.HealpixCube(cubefile); m.load()
        msig = diffuse.HealpixCube(sigsfile); msig.load()
        meas = np.array([m[i].vec for i in range(8)])
        sig  = np.array([msig[i].vec for i in range(8)])

        self.planes = np.array(range(start,stop)) # plane numbers
        self.values = meas[start:,:]
        weights = 100./sig[start:,:] #from percent
        self.wtmean = weights.mean(axis=1)

        self.fit, self.residuals, self.rank, self.svals, self.rcond =\
            np.polyfit(self.planes,self.values, deg=deg, full=True, w=self.wtmean)
            
        labels= 'intercept slope curvature'.split()   
        self.hpfit=[healpix_map.HParray(labels[deg-i], self.fit[i,:]) for i in range(deg,-1,-1)]
Пример #8
0
 def ait_plot(self, comp, fraction=False, **kwargs):
     fig, ax = plt.subplots(figsize=(16, 8))
     if not fraction:
         defaults = dict(
             log=True,
             vmin=1,
             vmax=1000.,
             title=kwargs.get('title', comp),
         )
         defaults.update(**kwargs)
         t = self[comp].plot(axes=ax, **defaults)
     else:
         defaults = dict(vmin=0, vmax=100.)
         defaults.update(**kwargs)
         a = self[comp].vec
         b = self['final'].vec - self['src'].vec
         title = '{} / total (%)'.format(comp)
         t = hpm.HParray(title, a / b * 100.).plot(axes=ax,
                                                   title=title,
                                                   cbtext='%',
                                                   **defaults)
     t.grid(color='lightgrey')
Пример #9
0
 def __getitem__(self, index):
     """return a plane as a HParray object"""
     energy = self.energies[index]
     col = self.column(energy)
     return healpix_map.HParray('{:.0f} MeV'.format(energy), col)
Пример #10
0
 def write(self, filename):
     """generate a FITS file with all the (combined) maps for this energy
     """
     hh = [hpm.HParray(name, value.map) for name, value in self.iteritems()]
     t = hpm.HEALPixFITS(hh)
     t.write(filename)