Exemplo n.º 1
0
			if args.mask:
				mshape, mwcs = enmap.read_map_geometry(args.mask)
				mbox  = enmap.pixbox_of(mwcs, imap.shape, imap.wcs)
				mask  = enmap.read_map(args.mask, pixbox=mbox).preflat[0] > 0
				idiv *= 1-mask
				# Inpaint masked area, in case it contains fourier-unfriendly values
				imap = enmap.inpaint(imap, mask)
				del mask
			if "debug" in args.output: dump_prefix = args.odir + "/region_%02d_" % ri
			else:                      dump_prefix = None
			imap[~np.isfinite(imap)] = 0
			idiv[~np.isfinite(idiv)] = 0
			idiv[idiv<0] = 0
			# Get our flux conversion factor
			#print "fit barea: %8.3f" % (barea*1e9)
			fluxconv = utils.flux_factor(barea, args.freq*1e9)/1e6
			reg_cat = None
			local_amps = None
			for ci in range(len(imap)):
				# Build an amplitude prior from our input catalog fluxes
				prior    = dory.build_prior(icat.flux[:,ci]/fluxconv, icat.dflux[:,ci]/fluxconv, 1/args.prior)
				src_pos  = np.array([icat.dec,icat.ra]).T
				fit_inds, amp, icov, lamps = dory.fit_src_amps(imap[ci], get_div(idiv,ci), src_pos, beam, prior=prior,
						apod=args.apod, apod_margin=args.apod_margin, verbose=args.verbose, dump=dump_prefix, hack=args.hack,
						region=ri)
				if reg_cat is None:
					reg_cat = icat[fit_inds].copy()
					reg_cat.amp = reg_cat.damp = reg_cat.flux = reg_cat.dflux = 0
				if ci == 0: local_amps = lamps
				reg_cat.amp[:,ci]  = amp
				reg_cat.damp[:,ci] = np.diag(icov)**-0.5
Exemplo n.º 2
0
		data.tod  = data.tod.astype(dtype)
		# Set up our likelihood
		L = Likelihood(data, srcpos[:,sids], amps[sids], filter=highpass)
		# Find out which sources are reliable, so we don't waste time on bad ones
		if prune_unreliable_srcs:
			_, aicov = L.fit_amp()
			good = amps[sids]**2*aicov[:,0,0,0,0] > args.minsn**2
			sids = [sid for sid,g in zip(sids,good) if g]
			nsrc = len(sids)
			print("Restricted to %d srcs: %s" % (nsrc,", ".join(["%d (%.1f)" % (i,a) for i,a in zip(sids,amps[sids])])))
		if nsrc == 0: continue
		L    = Likelihood(data, srcpos[:,sids], amps[sids], perdet=perdet, thumbs=True, N=L.N, method=args.method, filter=highpass)
		beam_area = get_beam_area(data.beam)
		_, uids   = actdata.split_detname(data.dets) # Argh, stupid detnames
		freq      = data.array_info.info.nom_freq[uids[0]]
		fluxconv  = utils.flux_factor(beam_area, freq*1e9)
		group_data.append(bunch.Bunch(data=data, sids=sids, lik=L, id=id, oid=oid, ind=ind, beam_area=beam_area, freq=freq, fluxconv=fluxconv))

	if len(group_data) == 0:
		print("No usable tods in group %s. Skipping" % ",".join([ids[i] for i in group]))
		continue

	# Set up the full likelihood
	progress_thumbs = args.minimaps and verbose >= 3
	chisq_wrappers  = [data.lik.chisq_wrapper(thumb_path=args.odir + "/" + data.oid + "_thumb%03d.fits", thumb_interval=progress_thumbs) for data in group_data]
	def likfun(off): return sum([chisq_wrapper(off) for chisq_wrapper in chisq_wrappers])
	# Representaive individual lik for stuff that's common to them. This is a bit hacky.
	# A single joint lik class would have been cleaner.
	L = group_data[0].lik

	if not args.nogrid:
Exemplo n.º 3
0
                                       pixbox=pixbox,
                                       bbox=mybbox,
                                       comm=comm).astype(dtype)
            refmap = signal.prepare(refmap)

        # Get the frequency and beam for this chunk. We assume that
        # this is the same for every member of the chunk, so we only need
        # to do this for one scan
        scan = actscan.ACTScan(filedb.data[chunk_ids[inds[0]]])
        _, dets = actdata.split_detname(scan.dets)
        beam = scan.beam
        freq = scan.array_info.info.nom_freq[dets[0]]
        barea = planet9.calc_beam_area(scan.beam)
        # Get the conversion from ref-freq flux to observed amplitude. This includes
        # dilution by the beam area
        flux2amp = 1 / utils.flux_factor(barea, args.fref * 1e9, utils.T_cmb)
        fref2freq = utils.planck(freq * 1e9, args.Tref) / utils.planck(
            args.fref * 1e9, args.Tref)
        rfact = flux2amp * fref2freq * 1e3  # 1e3 for flux in mJy and amp in uK

        # only work will be 3,ny,nx. The rest are scalar. Will copy in-out as necessary
        work = signal.work()
        rhs = area[0]
        div = rhs.copy()
        wrhs = signal.prepare(rhs)
        wdiv = signal.prepare(div)
        kvals = np.zeros(len(corr_pos), dtype)
        freqs, bareas = np.zeros(ntod), np.zeros(ntod)

        bleh = True and args.inject
        if bleh:
Exemplo n.º 4
0
			# We support polarization here, but treat each component independently
			imap   = enmap.read_map(args.imap, pixbox=reg_pad).preflat[:args.ncomp]
			idiv   = divdiag(enmap.read_map(args.idiv, pixbox=reg_pad))[:args.ncomp]
			if args.mask:
				mshape, mwcs = enmap.read_map_geometry(args.mask)
				mbox  = enmap.pixbox_of(mwcs, imap.shape, imap.wcs)
				idiv *= (1-enmap.read_map(args.mask, pixbox=mbox).preflat[0])
			if "debug" in args.output: dump_prefix = args.odir + "/region_%02d_" % ri
			else:                      dump_prefix = None
			imap[~np.isfinite(imap)] = 0
			idiv[~np.isfinite(idiv)] = 0
			idiv[idiv<0] = 0
			# Get our flux conversion factor
			beam2d = dory.calc_2d_beam(beam, imap.shape, imap.wcs)
			barea  = dory.calc_beam_transform_area(beam2d)
			fluxconv = utils.flux_factor(barea, args.freq*1e9)/1e6
			reg_cat = None
			for ci in range(len(imap)):
				# Build an amplitude prior from our input catalog fluxes
				prior    = dory.build_prior(icat.flux[:,ci]/fluxconv, icat.dflux[:,ci]/fluxconv, 1/args.prior)
				src_pos  = np.array([icat.dec,icat.ra]).T
				print imap.shape, idiv.shape, ci
				fit_inds, amp, icov = dory.fit_src_amps(imap[ci], get_div(idiv,ci), src_pos, beam, prior=prior, apod=args.apod,
						apod_margin=args.apod_margin, verbose=args.verbose, dump=dump_prefix, hack=args.hack, region=ri)
				if reg_cat is None:
					reg_cat = icat[fit_inds].copy()
					reg_cat.amp = reg_cat.damp = reg_cat.flux = reg_cat.dflux = 0
				reg_cat.amp[:,ci]  = amp
				reg_cat.damp[:,ci] = np.diag(icov)**-0.5
			reg_cat.flux  = reg_cat.amp*fluxconv
			reg_cat.dflux = reg_cat.damp*fluxconv
Exemplo n.º 5
0
    srcs= np.array([[srcpos[0], srcpos[1], 1, 0, 0, 70.6, 6.13, D]]).T  # use close-enough value
    # srcs= np.array([[srcpos[0], srcpos[1]]])
    with bench.show("create pointing matrix"):
        P = lib.PmatTotVar(scan, srcs, perdet=False, sys=sys)
        # P = lib.PmatTot(scan, srcs[:,0], perdet=False, sys=sys)

    # I should be able to use the same pointing matrix to do a search
    # of pulsars by treating different period and phases as different
    # sources, and estimating their amplitudes together. Let me give
    # that a try below

    # a factor to convert uK to mJy
    beam_area = lib.get_beam_area(scan.beam)
    _, uids   = actdata.split_detname(scan.dets) # Argh, stupid detnames
    freq      = scan.array_info.info.nom_freq[uids[0]]
    fluxconv  = u.flux_factor(beam_area, freq*1e9)/1e3
    print("fluxconv = ", fluxconv)

    # prepare pointing matrix and noise model for searching
    # for signal-only test I won't apply any noise model
    # N = NmatTot(scan, model="uncorr", window=2.0, filter=highpass)
    # srcs

    # rhs (= P'N"d)
    # N.apply(tod)
    with bench.show("project TOD to src space"):
        rhs = P.backward(tod, ncomp=1)

    # div (= P'N"P)
    tod[:] = 0
    P.forward(tod, rhs*0+1)