Ejemplo n.º 1
0
def read_sdata(ifile):
    # Output thumb for this tod
    with h5py.File(ifile, "r") as hfile:
        sdata = [None for key in hfile]
        for key in hfile:
            ind = int(key)
            g = hfile[key]
            sdat = bunch.Bunch()
            # First parse the wcs
            hwcs = g["wcs"]
            header = astropy.io.fits.Header()
            for key in hwcs:
                header[key] = hwcs[key].value
            wcs = wcsutils.WCS(header).sub(2)
            # Then get the site
            sdat.site = bunch.Bunch(
                **{key: g["site/" + key].value
                   for key in g["site"]})
            # And the rest
            for key in [
                    "map", "div", "srcpos", "sid", "vel", "fknee", "alpha",
                    "id", "ctime", "dur", "el", "az", "off"
            ]:
                sdat[key] = g[key].value
            sdat.map = enmap.ndmap(fixorder(sdat.map), wcs)
            sdat.div = enmap.ndmap(fixorder(sdat.div), wcs)
            sdata[ind] = sdat
    return sdata
Ejemplo n.º 2
0
def build_grid_geometry(bounds, res):
	"""bounds: [[y1,x1],[y2,x2]] in rads
	res: resolution in rads
	Returns shape, wcs"""
	bounds = np.array(bounds)
	ngrid  = np.round((bounds[1]-bounds[0])/res).astype(int)+1
	wcs = wcsutils.WCS(naxis=2)
	wcs.wcs.cdelt[:] = res/utils.degree
	wcs.wcs.crpix[:] = 1
	wcs.wcs.crval = bounds[0,::-1]/utils.degree
	wcs.wcs.ctype = ["RA---CAR","DEC--CAR"]
	return tuple(ngrid), wcs
Ejemplo n.º 3
0
def read_thumb_data(fname):
	res    = bunch.Bunch()
	hdus   = astropy.io.fits.open(fname)
	header = hdus[0].header
	with warnings.catch_warnings():
		wcs = wcsutils.WCS(header).sub(2)
	res.rhs, res.div, res.corr = enmap.fix_endian(enmap.ndmap(hdus[0].data, wcs))
	res.srcinfo = hdus[1].data
	res.detinfo = hdus[2].data
	res.id  = header["id"]
	res.off = np.array([float(header["off_x"]),float(header["off_y"])])*utils.arcmin
	for key in ["bore_az1","bore_az2","bore_el"]:
		res[key] = float(header[key])*utils.degree
	res.ctime = float(header["ctime"])
	return res
Ejemplo n.º 4
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 = wcsutils.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],
Ejemplo n.º 5
0
    with h5py.File(infofile, "r") as hfile:
        rhs = hfile["rhs"].value
        hits = hfile["hits"].value
        srate = hfile["srate"].value
        speed = hfile["speed"].value * utils.degree
        inspec = hfile["inspec"].value
        offsets = hfile["offsets"].value * utils.degree
        site = bunch.Bunch(
            **{k: hfile["site"][k].value
               for k in hfile["site"]})
        pattern = hfile["pattern"].value * utils.degree
        hwcs = hfile["wcs"]
        header = astropy.io.fits.Header()
        for key in hwcs:
            header[key] = hwcs[key].value
        wcs = wcsutils.WCS(header).sub(2)
    # Set up our maps
    rhs = enmap.ndmap(rhs, wcs)
    hits = enmap.ndmap(hits, wcs)
    rhs = prepare(rhs)
    hits = prepare(hits, hitmap=True)

    # Turn offsets into an average array offset and detector offsets relative to that,
    # and use the array offset to set up the Unskew matrix.
    offset_array = np.mean(offsets, 0)
    offset_det = offsets - offset_array
    ndet = len(offsets)
    if args.unskew == "curved":
        U = UnskewCurved(rhs.shape,
                         rhs.wcs,
                         pattern,