Beispiel #1
0
def point_in_polygon_safe(points, polygons):
    points = np.asarray(points)
    polygons = np.array(polygons)
    # Put the polygon on the same side of the sky as the points
    polygons[0] = utils.rewind(polygons[0], points[0], 360)
    # But don't allow sky wraps inside polygons
    polygons[0] = utils.rewind(polygons[0], polygons[0, 0], 360)
    return utils.point_in_polygon(points.T, polygons.T)
Beispiel #2
0
def poly_dist(points, polygons):
    points = np.asarray(points) * utils.degree
    polygons = np.array(polygons) * utils.degree
    # Put the polygon on the same side of the sky as the points
    polygons[0] = utils.rewind(polygons[0], points[0])
    # But don't allow sky wraps inside polygons
    polygons[0] = utils.rewind(polygons[0], polygons[0, 0])
    inside = utils.point_in_polygon(points.T, polygons.T)
    dists = utils.poly_edge_dist(points.T, polygons.T)
    dists = np.where(inside, 0, dists)
    return dists
Beispiel #3
0
def get_sids_in_tod(id, src_pos, bounds, ind, isids=None, src_sys="cel"):
	if isids is None: isids = list(range(src_pos.shape[-1]))
	if bounds is not None:
		poly      = bounds[:,:,ind]*utils.degree
		poly[0]   = utils.rewind(poly[0],poly[0,0])
		# bounds are defined in celestial coordinates. Must convert srcpos for comparison
		mjd       = utils.ctime2mjd(float(id.split(".")[0]))
		srccel    = coordinates.transform(src_sys, "cel", src_pos, time=mjd)
		srccel[0] = utils.rewind(srccel[0], poly[0,0])
		poly      = pad_polygon(poly.T, poly_pad).T
		accepted  = np.where(utils.point_in_polygon(srccel.T, poly.T))[0]
		sids      = [isids[i] for i in accepted]
	else:
		sids = isids
	return sids
Beispiel #4
0
tod_srcs = {}
for sid, src in enumerate(srcs):
    if args.src is not None and sid != args.src: continue
    if src.type == "planet":
        # This is a bit hacky, but sometimes the "t" member is unavailable
        # in the database. This also ignores the planet movement during the
        # TOD. We will take that into account in the final step in the mapping, though.
        t = np.char.partition(db.ids, ".")[:, 0].astype(float) + 300
        ra, dec = ephemeris.ephem_pos(src.name, utils.ctime2mjd(t), dt=0)[:2]
    else:
        ra, dec = src.ra, src.dec
    points = np.array([ra, dec])
    polys = db.data["bounds"] * utils.degree
    polys[0] = utils.rewind(polys[0], points[0])
    polys[0] = utils.rewind(polys[0], polys[0, 0])
    inside = utils.point_in_polygon(points.T, polys.T)
    dists = utils.poly_edge_dist(points.T, polys.T)
    dists = np.where(inside, 0, dists)
    hit = np.where(dists < args.hit_tol * utils.degree)[0]
    for id in db.ids[hit]:
        if not id in tod_srcs: tod_srcs[id] = []
        tod_srcs[id].append(sid)

# Prune those those that are done
if args.cont:
    good = []
    for id in tod_srcs:
        bid = id.replace(":", "_")
        ndone = 0
        for sid in tod_srcs[id]:
            if os.path.exists("%s%s_src%03d_map.fits" %
Beispiel #5
0
	if args.cont:
		if os.path.exists(oname):
			print "%5d/%d %s is done: skipping" % (ind+1, len(ids), id)
			continue
		if os.path.exists(ename):
			print "%5d/%d %s already failed: skipping" % (ind+1, len(ids), id)
			continue

	# Check if we hit any of the sources. We first make sure
	# there's no angle wraps in the bounds, and then move the sources
	# to the same side of the sky.
	poly      = bounds[:,:,ind]*utils.degree
	poly[0]   = utils.rewind(poly[0],poly[0,0])
	srcpos    = srcpos.copy()
	srcpos[0] = utils.rewind(srcpos[0], poly[0,0])
	sids      = np.where(utils.point_in_polygon(srcpos.T, poly.T))[0]
	sids      = np.array(sorted(list(set(sids)&allowed)))
	if len(sids) == 0:
		print "%5d/%d %s has 0 srcs: skipping" % (ind+1, len(ids), id)
		continue
	nsrc = len(sids)
	print "%5d/%d %s has %d srcs: %s" % (ind+1, len(ids), id,nsrc,", ".join(["%d (%.1f)" % (i,a) for i,a in zip(sids,amps[sids])]))

	def skip(msg):
		print "%s skipped: %s" % (id, msg)
		with open(ename, "w")  as f:
			f.write(msg + "\n")

	entry = filedb.data[id]
	try:
		with bench.show("read"):
Beispiel #6
0
db = filedb.scans.select(filedb.scans[args.sel])
tod_srcs = {}
for sid, src in enumerate(srcs):
	if args.src is not None and sid != args.src: continue
	if src.type == "planet":
		# This is a bit hacky, but sometimes the "t" member is unavailable
		# in the database. This also ignores the planet movement during the
		# TOD. We will take that into account in the final step in the mapping, though.
		t = np.char.partition(db.ids,".")[:,0].astype(float)+300
		ra, dec = ephemeris.ephem_pos(src.name, utils.ctime2mjd(t), dt=0)[:2]
	else: ra, dec = src.ra, src.dec
	points = np.array([ra, dec])
	polys  = db.data["bounds"]*utils.degree
	polys[0] = utils.rewind(polys[0], points[0])
	polys[0] = utils.rewind(polys[0], polys[0,0])
	inside   = utils.point_in_polygon(points.T, polys.T)
	dists    = utils.poly_edge_dist(points.T, polys.T)
	dists    = np.where(inside, 0, dists)
	hit      = np.where(dists < args.hit_tol*utils.degree)[0]
	for id in db.ids[hit]:
		if not id in tod_srcs: tod_srcs[id] = []
		tod_srcs[id].append(sid)

# Prune those those that are done
if args.cont:
	good = []
	for id in tod_srcs:
		bid = id.replace(":","_")
		ndone = 0
		for sid in tod_srcs[id]:
			if os.path.exists("%s%s_src%03d_map.fits" % (prefix, bid, sid)) or os.path.exists("%s%s_empty.txt" % (prefix, bid)):
Beispiel #7
0
for ind in range(comm.rank, len(ids), comm.size):
    id = ids[ind]
    oid = id.replace(":", "_")
    oname = "%s/%s.hdf" % (args.odir, oid)
    if args.cont and os.path.exists(oname):
        print "%s is done: skipping" % id
        continue

    # Check if we hit any of the sources. We first make sure
    # there's no angle wraps in the bounds, and then move the sources
    # to the same side of the sky.
    poly = bounds[:, :, ind] * utils.degree
    poly[0] = utils.rewind(poly[0], poly[0, 0])
    srcpos = srcpos.copy()
    srcpos[0] = utils.rewind(srcpos[0], poly[0, 0])
    sids = np.where(utils.point_in_polygon(srcpos.T, poly.T))[0]
    sids = sorted(list(set(sids) & allowed))
    if len(sids) == 0:
        print "%s has 0 srcs: skipping" % id
        continue
    nsrc = len(sids)
    print "%s has %d srcs: %s" % (id, nsrc, ", ".join(
        ["%d (%.1f)" % (i, a) for i, a in zip(sids, amps[sids])]))

    entry = filedb.data[id]
    try:
        with bench.mark("read"):
            d = actdata.read(entry)
        with bench.mark("calib"):
            d = actdata.calibrate(d, exclude=["autocut"])
        if d.ndet < 2 or d.nsamp < 1: