Exemple #1
0
 def from_hfile(cls, hfile):
     nwys = hfile["nwys"].value
     nwx = hfile["nwx"].value
     xshifts = hfile["xshifts"].value
     yshifts = hfile["yshifts"].value
     y0 = hfile["y0"].value
     daz = hfile["daz"].value
     scan_speed = hfile["scan_speed"].value
     ncomp = hfile["ncomp"].value
     dtype = np.dtype(hfile["dtype"].value)
     header = astropy.io.fits.Header()
     hwcs = hfile["gwcs"]
     for key in hwcs:
         header[key] = hwcs[key].value
     gwcs = enwcs.WCS(header).sub(2)
     return cls(nwys,
                nwx,
                xshifts,
                yshifts,
                y0,
                daz,
                scan_speed,
                gwcs,
                ncomp=ncomp,
                dtype=dtype)
Exemple #2
0
def build_workspace_wcs(res):
    wcs = enwcs.WCS(naxis=2)
    wcs.wcs.cdelt[:] = res
    wcs.wcs.crpix[:] = 1
    wcs.wcs.crval[:] = 0
    # Should really be plain, but let's pretend it's
    # CAR for ease of plotting.
    wcs.wcs.ctype = ["RA---CAR", "DEC--CAR"]
    return wcs
Exemple #3
0
def build_fullsky_geometry(res):
    nx = int(np.round(360 / res))
    ny = int(np.round(180 / res))
    wcs = enwcs.WCS(naxis=2)
    wcs.wcs.cdelt[:] = [-res, res]
    wcs.wcs.crpix = [1 + nx / 2, 1 + ny / 2]
    wcs.wcs.crval = [0, 0]
    wcs.wcs.ctype = ["RA---CAR", "DEC--CAR"]
    return (ny + 1, nx), wcs
Exemple #4
0
def make_projectable_map_by_pos(pos,
                                lmax,
                                dims=(),
                                oversample=2.0,
                                dtype=float,
                                verbose=False):
    """Make a map suitable as an intermediate step in projecting alms up to
	lmax on to the given positions. Helper function for alm2map."""
    # First find the theta range of the pixels, with a 10% margin
    ra_ref = np.mean(pos[1]) / utils.degree
    decrange = np.array([np.min(pos[0]), np.max(pos[0])])
    decrange = (decrange - np.mean(decrange)) * 1.1 + np.mean(decrange)
    decrange = np.array(
        [max(-np.pi / 2, decrange[0]),
         min(np.pi / 2, decrange[1])])
    decrange /= utils.degree
    wdec = np.abs(decrange[1] - decrange[0])
    # The shortest wavelength in the alm is about 2pi/lmax. We need at least
    # two samples per mode.
    res = 180. / lmax / oversample
    # Set up an intermediate coordinate system for the SHT. We will use
    # CAR coordinates conformal on the equator, with a pixel on each pole.
    # This will give it clenshaw curtis pixelization.
    nx = utils.nint(360 / res)
    nytot = utils.nint(180 / res)
    # First set up the pixelization for the whole sky. Negative cdelt to
    # make sharp extra happy. Not really necessary, but makes some things
    # simpler later.
    wcs = enwcs.WCS(naxis=2)
    wcs.wcs.ctype = ["RA---CAR", "DEC--CAR"]
    wcs.wcs.crval = [ra_ref, 0]
    wcs.wcs.cdelt = [360. / nx, -180. / nytot]
    wcs.wcs.crpix = [nx / 2.0 + 1, nytot / 2.0 + 1]
    # Then find the subset that includes the dec range we want
    y1 = utils.nint(wcs.wcs_world2pix(0, decrange[0], 0)[1])
    y2 = utils.nint(wcs.wcs_world2pix(0, decrange[1], 0)[1])
    y1, y2 = min(y1, y2), max(y1, y2)
    # Offset wcs to start at our target range
    ny = y2 - y1
    wcs.wcs.crpix[1] -= y1
    # Construct the map. +1 to put extra pixel at pole when we are fullsky
    if verbose:
        print "Allocating shape %s dtype %s intermediate map" % (
            dims + (ny + 1, nx), np.dtype(dtype).char)
    tmap = enmap.zeros(dims + (ny + 1, nx), wcs, dtype=dtype)
    return tmap
Exemple #5
0
    def __exit__(self, type, value, traceback):
        sys.stderr.write("%6.2f %6.3f %6.3f %s\n" %
                         (time.time() - self.t1, memory.current() / 1024.**3,
                          memory.max() / 1024.**3, self.desc))


with dprint("spec"):
    ps = powspec.read_spectrum(args.powspec)[:ncomp, :ncomp]

# Construct our output coordinates, a zea system. My standard
# constructor doesn't handle pole crossing, so do it manually.
with dprint("construct omap"):
    R = args.radius * deg2rad
    res = args.res * min2rad
    wo = wcslib.WCS(naxis=2)
    wo.wcs.ctype = ["RA---ZEA", "DEC--ZEA"]
    wo.wcs.crval = [0, 90]
    wo.wcs.cdelt = [res / deg2rad, res / deg2rad]
    wo.wcs.crpix = [1, 1]
    x, y = wo.wcs_world2pix(0, 90 - R / deg2rad, 1)
    y = int(np.ceil(y))
    n = 2 * y - 1
    wo.wcs.crpix = [y, y]
    omap = enmap.zeros((n, n), wo)

# Construct our projection coordinates this is a CAR system in order
# to make interpolation easy.
with dprint("construct imap"):
    ires = np.array([1, 1. / np.sin(R)]) * res / args.supersample
    shape, wi = enmap.geometry(pos=[[np.pi / 2 - R, -np.pi],