Esempio n. 1
0
 def setup(self, **kw):
     self.plotfolder = 'sunmoon_refit'
     self.title = 'SunMoon refit'
     files, pickles = self.load_pickles('sunmoon')
     rdict = dict()
     for f, p in zip(files, pickles):
         name = os.path.split(f)[-1][:9]
         model = p['model'] if 'model' in p else None
         norm = model.parameters[0] if model is not None else np.nan
         norm_unc = np.diag(model.get_cov_matrix()
                            )[0]**0.5 if model is not None else np.nan
         if 'model' not in p: p['model'] = None
         ra, dec = p['ra'], p['dec']
         skydir = SkyDir(ra, dec)
         glat, glon = skydir.b(), skydir.l()
         if glon > 180: glon -= 360.
         rdict[name] = dict(ra=ra,
                            dec=dec,
                            glat=glat,
                            glon=glon,
                            skydir=skydir,
                            norm=norm,
                            norm_unc=norm_unc,
                            delta_likelihood=p['delta_likelihood'])
     self.df = pd.DataFrame(rdict).transpose()
Esempio n. 2
0
 def setup(self, **kw):
     self.plotfolder = 'limb_refit'
     self.source_name = 'limb'
     self.title = 'Limb refit'
     files, pickles = self.load_pickles('limb')
     rdict = dict()
     for f, p in zip(files, pickles):
         name = os.path.split(f)[-1][:9]
         front, back = p['model'].parameters if 'model' in p else (np.nan,
                                                                   np.nan)
         if 'model' not in p: p['model'] = None
         ra, dec = p['ra'], p['dec']
         skydir = SkyDir(ra, dec)
         glat, glon = skydir.b(), skydir.l()
         if glon > 180: glon -= 360.
         rdict[name] = dict(ra=ra,
                            dec=dec,
                            glat=glat,
                            glon=glon,
                            skydir=skydir,
                            front=front,
                            back=back)
     self.df = pd.DataFrame(rdict).transpose()
     self.fpar = self.df.front
     self.bpar = self.df.back
Esempio n. 3
0
 def __getitem__(self, index):
     sdir = self.dirfun(index)
     t = self.skyfun(sdir)
     # problem with C++ code at exactly 180 deg.
     if np.isnan(t):
         sdir = SkyDir(sdir.l() + 1e-3, sdir.b(), SkyDir.GALACTIC)
         t = self.skyfun(sdir)
     assert not np.isnan(t), 'Failed for index %d' % index
     return t
def angle_equatorial_from_galactic(center, angle_galactic):
    """ For a given position in the sky,
        and a given angle defined as a rotation east of galactic
        north, comute the angle defined as a rotation east of
        celestial north. """
    l,b=center.l(),center.b()
    ra,dec=center.ra(),center.dec()

    # define a galacitc projection coordiante system centered on our position in the sky
    wcs = pywcs.WCS(naxis=2)

    # n.b. (l,b) has an image coordiante of (0,0), which is convenient
    wcs.wcs.crpix = [0, 0]
    wcs.wcs.cdelt = np.array([-0.1, 0.1])
    wcs.wcs.crval = [l, b]
    wcs.wcs.ctype = ["GLON-ZEA", "GLAT-ZEA"]

    # compute the axes of increasing 'dec' and 'b'

    gal_axis = wcs.wcs_sky2pix(np.array([[l,b + 0.01]], float),1)[0]
    # find the image vector of increasing galactic latitude
    gal_axis /= np.sqrt(gal_axis.dot(gal_axis))
    
    cel_dir = SkyDir(ra,dec+0.01)
    # find the image vector of increasing equatorial latitude
    cel_axis = wcs.wcs_sky2pix(np.array([[cel_dir.l(),cel_dir.b()]], float),1)[0]
    cel_axis /= np.sqrt(cel_axis.dot(cel_axis))

    # compute the angle between the two axes

    # N.B. use compute angle of each axes using atan2 to get correct coordinate.
    # The difference of these two angles should be the absolute angle
    # with the correct minus sign.
    rotation = np.degrees(
        np.arctan2(gal_axis[1],gal_axis[0]) - np.arctan2(cel_axis[1],cel_axis[0])
    )

    # the new angle is just the old angle + the difference between axes

    # The + sign was determined emperically
    angle_equatorial = angle_galactic +  rotation
    return angle_equatorial 
Esempio n. 5
0
 def draw_ecliptic(self, ax):
     """ draw the ecliptic path onto the axis ax
     """
     ecl_glon = []
     ecl_singlat = []
     zaxis = SkyDir(270, 90 - 23.439281)
     xaxis = SkyDir()
     yaxis = zaxis.cross(xaxis)
     for phi in np.arange(0, 2 * np.pi, 0.05):
         t = np.sin(phi) * xaxis + np.cos(phi) * yaxis
         sd = SkyDir(Hep3Vector(*t))
         tglon = sd.l()
         if tglon > 180: tglon -= 360
         ecl_glon.append(tglon)
         ecl_singlat.append(np.sin(np.radians(sd.b())))
     ia = np.argsort(ecl_glon)
     ax.plot(np.array(ecl_glon)[ia],
             np.array(ecl_singlat)[ia],
             '-',
             color='gray')
Esempio n. 6
0
ltcube = dict2fgl['ltcube']

results = []

for extension_mc in extensions:

    print 'Looping over extension_mc=%g' % extension_mc

    model_mc = PowerLaw(index=index_mc)
    model_mc.set_flux(flux_mc(extension_mc), emin, emax)

    r = dict(
        type = args.type,
        mc = dict(
            extension=extension_mc,
            gal=[ skydir_mc.l(), skydir_mc.b() ],
            cel=[ skydir_mc.ra(), skydir_mc.dec() ],
            model=spectrum_to_dict(model_mc),
            flux=pointlike_model_to_flux(model_mc, emin, emax),
        )
    )

    tempdir = mkdtemp()

    point = 'point'
    ps = PointSource(
        name=point,
        model=model_mc.copy(),
        skydir = skydir_mc
    )