Exemplo n.º 1
0
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("icat")
parser.add_argument("ocat")
parser.add_argument("-b", "--beam",    type=str,   default="1.4", help="Beam in arcmin or beam(l)")
parser.add_argument("-s", "--snmin",   type=float, default=5)
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument(      "--bscale",  type=float, default=1)
parser.add_argument(      "--artrad",  type=float, default=20)
parser.add_argument(      "--artnum",  type=float, default=7)
parser.add_argument(      "--artpen",  type=float, default=2)
args = parser.parse_args()
import numpy as np
from enlib import utils, dory

beam      = dory.get_beam(args.beam)
beam_prof = dory.get_beam_profile(beam)
beam_area = dory.calc_beam_profile_area(beam_prof)

# Apply ad-hoc beam scaling
beam_prof[0] *= args.bscale

cat   = dory.read_catalog(args.icat)
nread = len(cat)

# We will remove sources that are weaker than the surroundings' contribution that area, so
# get the total flux at each source's position
flux  = dory.eval_flux_at_srcs(cat, beam_prof, verbose=args.verbose)
# We will also penalize source detection in areas with too many sources. We can
# do this with the same function, if we modify the beam a bit
r_dummy   = np.linspace(0, args.artrad*utils.arcmin, 10000)
Exemplo n.º 2
0
parser.add_argument("--apod-margin",   type=int,   default=10, help="How far away from the apod region a source should be to be valid.")
parser.add_argument("-s", "--nsigma",  type=float, default=3.5, help="The number a sigma a source must be to be included in the catalog when finding sources.")
parser.add_argument("-p", "--pad",     type=int,   default=60, help="The number of pixels to extend each region by in each direciton, to avoid losing sources at region boundaries. Should be larger than apod+apod_margin")
parser.add_argument("-P", "--prior",   type=float, default=1.0, help="The strength of the input prior in fit mode. Actually the inverse of the source variability assumed, so 0 means the source will be assumed to be infinitely variable, and hence the input database amplitudes don't add anything to the new fit. infinity means that the source is completley stable, and the input statistics add in inverse variance to the measurements. The default is 1, which means that the input database contributes only at the 1 sigma level")
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-o", "--output",  type=str,   default="full,reg", help="What types of output to write to the output directory. Comma-separated list. 'full': Output the final, merged quantities. 'reg': Output per-region results. 'debug': Output lots of debug maps. 'maps': Output maps and not just catalogs at each level.")
parser.add_argument(      "--ncomp",   type=int,   default=1, help="The number of stokes components to fit for in fit mode.")
parser.add_argument("--hack",          type=float, default=0)
args = parser.parse_args()
import numpy as np, os
from enlib import dory
from enlib import enmap, utils, bunch, mpi, fft, pointsrcs

comm       = mpi.COMM_WORLD
shape, wcs = enmap.read_map_geometry(args.imap)
beam       = dory.get_beam(args.beam)
regions    = dory.get_regions(args.regions, shape, wcs)

def divdiag(div):
	if   div.ndim == 2: return div.preflat
	elif div.ndim == 3: return div
	elif div.ndim == 4: return enmap.samewcs(np.einsum("aayx->ayx",div),div)
	else: raise ValueError("Invalid div shape: %s" % div.shape)

def get_div(div, ci):
	if len(div) > ci: return div[ci]
	else: return div[0]*2

def get_beam_profile(beam, nsamp=10001, rmax=0, tol=1e-7):
	# First do a low-res run to find rmax
	if not rmax: