def main(): manifestfile = "manifest.yaml" parser = argparse.ArgumentParser( description="Update %s with generated products" % manifestfile) parser.add_argument("-c", "--create", dest="create", action="store_true", help="create '%s' under current " % manifestfile + "working directory if not exists") parser.add_argument("-D", "--add-directory", dest="add_directory", action="store_true", help="add an 'directory' item to the manifest " + "storing the directory where the manifest locates") parser.add_argument("-r", "--repro", dest="reprodir", default=None, help="path to the repro directory; add the " + "reprocessed products to manifest if specified") args = parser.parse_args() if (not os.path.exists(manifestfile)) and args.create: logger.info("Create %s" % manifestfile) open(manifestfile, "a").close() manifest = get_manifest() if args.reprodir: add_repro(reprodir=args.reprodir, manifest=manifest)
def main(): parser = argparse.ArgumentParser( description="Make spectral-weighted exposure map") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") parser.add_argument("-M", "--update-manifest", dest="update_manifest", action="store_true", help="update manifest with newly created images") parser.add_argument("-i", "--infile", dest="infile", required=True, help="input image file to apply exposure correction") parser.add_argument("-e", "--expmap", dest="expmap", help="exposure map (default: 'expmap' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", help="filename of output exposure-corrected image " + "(default: append '_expcorr' to the base filename)") args = parser.parse_args() setup_pfiles(["dmimgcalc", "dmimgthresh"]) manifest = get_manifest() if args.expmap: expmap = args.expmap else: expmap = manifest.getpath("expmap", relative=True) if args.outfile: img_expcorr = args.outfile else: img_expcorr = os.path.splitext(args.infile)[0] + "_expcorr.fits" img_thresh = os.path.splitext(args.infile)[0] + "_thresh.fits" logger.info("infile: %s" % args.infile) logger.info("expmap: %s" % expmap) logger.info("output exposure-corrected image: %s" % img_expcorr) logger.info("output threshold-cut counts image: %s" % img_thresh) xygrid_infile = get_xygrid(args.infile) xygrid_expmap = get_xygrid(expmap) logger.info("%s:xygrid: %s" % (args.infile, xygrid_infile)) logger.info("%s:xygrid: %s" % (expmap, xygrid_expmap)) if xygrid_infile != xygrid_expmap: raise ValueError("xygrid: input image and exposure map do not match") threshold_image(infile=args.infile, outfile=img_thresh, expmap=expmap, clobber=args.clobber) correct_exposure(infile=img_thresh, outfile=img_expcorr, expmap=expmap, clobber=args.clobber) if args.update_manifest: logger.info("Add newly created images to manifest ...") key = "img_expcorr" manifest.setpath(key, img_expcorr) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) key = "img_thresh" manifest.setpath(key, img_thresh) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Extract surface brightness profile (SBP)") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") parser.add_argument("-r", "--region", dest="region", help="region file specifying the SBP " + "(default: 'sbp_reg' from manifest)") parser.add_argument("-i", "--infile", dest="infile", required=True, help="input binned image ") parser.add_argument("-e", "--expmap", dest="expmap", help="exposure map (default: 'expmap' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", help="output SBP filename (default: same " + "basename as the input region file)") args = parser.parse_args() setup_pfiles(["dmextract", "dmtcalc"]) manifest = get_manifest() if args.region: region = args.region else: region = manifest.getpath("sbp_reg", relative=True) if args.expmap: expmap = args.expmap else: expmap = manifest.getpath("expmap", relative=True) if args.outfile: outfile = args.outfile else: outfile = os.path.splitext(region)[0] + ".fits" sbp_data = os.path.splitext(outfile)[0] + ".txt" sbp_qdp = os.path.splitext(outfile)[0] + ".qdp" extract_sbp(outfile=outfile, infile=args.infile, expmap=expmap, region=region, clobber=args.clobber) make_sbp_txt(outfile=sbp_data, sbp=outfile, clobber=args.clobber) make_sbp_qdp(outfile=sbp_qdp, sbp_data=sbp_data, clobber=args.clobber) logger.info("Add SBP files to manifest ...") key = "sbp" manifest.setpath(key, outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) key = "sbp_reg" manifest.setpath(key, region) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) key = "sbp_data" manifest.setpath(key, sbp_data) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) key = "sbp_qdp" manifest.setpath(key, sbp_qdp) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Make a cleaned evt2 for scientific analysis") parser.add_argument("-i", "--infile", dest="infile", help="input evt2 produced by 'chandra_repro' " + "(default: request from manifest)") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") args = parser.parse_args() setup_pfiles(["dmkeypar", "dmcopy", "celldetect", "dmextract"]) manifest = get_manifest() if args.infile: infile = args.infile else: infile = manifest.getpath("evt2", relative=True) chips = ACIS.get_chips_str(infile, sep="-") chips_all = ACIS.get_chips_str(infile) logger.info("infile: %s" % infile) logger.info("chips: %s" % chips) evt2_chips = "evt2_c{chips}_orig.fits".format(chips=chips) evt2_rmsrc = "evt2_c{chips}_rmsrc.fits".format(chips=chips) evt2_clean = "evt2_c{chips}_clean.fits".format(chips=chips) srcfile = "sources_celld.reg" lcfile = "ex_bkg.lc" gtifile = os.path.splitext(lcfile)[0] + ".gti" filter_chips(infile, evt2_chips, chips, clobber=args.clobber) write_keyword(evt2_chips, keyword="DETNAM", value="ACIS-{0}".format(chips_all)) detect_sources(evt2_chips, srcfile, clobber=args.clobber) remove_sources(evt2_chips, evt2_rmsrc, srcfile, clobber=args.clobber) extract_lightcurve(evt2_rmsrc, lcfile, clobber=args.clobber) make_gti(lcfile, gtifile, clobber=args.clobber) filter_gti(evt2_rmsrc, evt2_clean, gtifile, clobber=args.clobber) # Add cleaned evt2 and other products to manifest key = "evt2_clean" manifest.setpath(key, evt2_clean) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) key = "reg_sources" manifest.setpath(key, srcfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) key = "gti" manifest.setpath(key, gtifile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) # Remove useless intermediate files os.remove(evt2_chips) os.remove(evt2_rmsrc)
def main(): parser = argparse.ArgumentParser( description="Make image by binning the event file") parser.add_argument("-L", "--elow", dest="elow", type=int, default=700, help="lower energy limit [eV] of the output image " + "(default: 700 [eV])") parser.add_argument("-H", "--ehigh", dest="ehigh", type=int, default=7000, help="upper energy limit [eV] of the output image " + "(default: 7000 [eV])") parser.add_argument("-i", "--infile", dest="infile", help="event file from which to create the image " + "(default: 'evt2_clean' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", help="output image filename (default: " + "build in format 'img_c<chip>_e<elow>-<ehigh>.fits')") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") args = parser.parse_args() setup_pfiles(["dmkeypar", "dmcopy"]) manifest = get_manifest() fov = manifest.getpath("fov", relative=True) if args.infile: infile = args.infile else: infile = manifest.getpath("evt2_clean", relative=True) chips = ACIS.get_chips_str(infile, sep="-") erange = "{elow}-{ehigh}".format(elow=args.elow, ehigh=args.ehigh) if args.elow >= args.ehigh: raise ValueError("invalid energy range: %s" % erange) if args.outfile: outfile = args.outfile else: outfile = "img_c{chips}_e{erange}.fits".format( chips=chips, erange=erange) logger.info("infile: %s" % infile) logger.info("outfile: %s" % outfile) logger.info("fov: %s" % fov) logger.info("chips: %s" % chips) logger.info("erange: %s" % erange) make_image(infile, outfile, chips, erange, fov, args.clobber) chips_all = ACIS.get_chips_str(infile) write_keyword(outfile, keyword="DETNAM", value="ACIS-{0}".format(chips_all)) # Add created image to manifest key = "img_e{erange}".format(erange=erange) manifest.setpath(key, outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def build_manifest(reprodir="repro", manifestfile="manifest.yaml"): """ Build the ``manifest.yaml`` with reprocessed products. """ logger.info("Build manifest with reprocessed products ...") if os.path.exists(manifestfile): logger.info("Use existing manifest file: %s" % manifestfile) else: logger.info("Create a new manifest file: %s" % manifestfile) open(manifestfile, "w").close() manifest = get_manifest(manifestfile) update_manifest.add_directory(manifest) update_manifest.add_repro(reprodir=reprodir, manifest=manifest)
def main(): parser = argparse.ArgumentParser( description="Make blanksky background") parser.add_argument("-i", "--infile", dest="infile", help="input evt2 file " + "(default: 'evt2_clean' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", help="output blanksky background file " + "(default: 'blanksky_c{chips}.fits')") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") args = parser.parse_args() setup_pfiles(["acis_bkgrnd_lookup", "dmcopy", "dmmerge", "dmkeypar", "dmhedit", "reproject_events", "acis_process_events"]) manifest = get_manifest() if args.infile: infile = args.infile else: infile = manifest.getpath("evt2_clean", relative=True) chips = ACIS.get_chips_str(infile, sep="-") if args.outfile: outfile = args.outfile else: outfile = "blanksky_c{chips}.fits".format(chips=chips) asol = manifest.getpath("asol", relative=True, sep=",") logger.info("infile: %s" % infile) logger.info("outfile: %s" % outfile) logger.info("chips: %s" % chips) logger.info("asol: %s" % asol) bkgfiles = find_blanksky(infile, copy=True, clobber=args.clobber) bkg_orig = os.path.splitext(outfile)[0] + "_orig.fits" merge_blanksky(bkgfiles, bkg_orig, clobber=args.clobber) bkg_clean = os.path.splitext(outfile)[0] + "_clean.fits" clean_vfaint(bkg_orig, bkg_clean, clobber=args.clobber) bkg_gained = os.path.splitext(outfile)[0] + "_gained.fits" apply_gainfile(bkg_clean, bkg_gained, evt2=infile, clobber=args.clobber) # Add the PNT header keywords copy_keyword(infile, bkg_gained, keyword=["RA_PNT", "DEC_PNT", "ROLL_PNT"]) reproject_blanksky(bkg_gained, outfile, evt2=infile, asol=asol, clobber=args.clobber) # Add blanksky background to manifest key = "bkg_blank" manifest.setpath(key, outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Make the SBP regions") parser.add_argument("-L", "--elow", dest="elow", type=int, default=700, help="lower energy limit to calculate the photon " + "counts [eV] (default: 700 eV)") parser.add_argument("-H", "--ehigh", dest="ehigh", type=int, default=7000, help="upper energy limit to calculate the photon " + "counts [eV] (default: 7000 eV)") parser.add_argument("-p", "--elow-pb", dest="elow_pb", type=int, default=9500, help="lower energy limit of the particle " + "background [eV] (default: 9500 eV)") parser.add_argument("-P", "--ehigh-pb", dest="ehigh_pb", type=int, default=12000, help="upper energy limit of the particle " + "background [eV] (default: 12000 eV)") parser.add_argument("-m", "--min-counts", dest="min_counts", type=int, default=50, help="minimum photon counts of echo SBP " + "region (default: 50)") parser.add_argument("-M", "--min-width", dest="min_width", type=int, default=5, help="minimum annulus/pie width of the inner-type " + "regions (default: 5 [pix])") parser.add_argument("-N", "--n-inner", dest="n_inner", type=int, default=10, help="number of the inner-type regions (default: 10)") parser.add_argument("-R", "--ratio-radius", dest="ratio_radius", type=float, default=1.2, help="ratio of outer radius w.r.t. inner radius " + "(default: 1.2)") parser.add_argument("-S", "--snr-thresh", dest="snr_thresh", type=float, default=1.5, help="lower threshold of the SNR (default: 1.5)") parser.add_argument("-V", "--view", dest="view", action="store_true", help="open DS9 to view output centroid") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing files") parser.add_argument("-b", "--bkg", dest="bkg", help="background file for SNR calculation; " + "may be blanksky or corrected background spectrum") parser.add_argument("-c", "--center", dest="center", help="Region file specifying the center " + "(default: 'reg_centroid' from manifest)") parser.add_argument("-i", "--infile", dest="infile", help="input event file " + "(default: 'evt2_clean' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", default="sbprofile.reg", help="output SBP region filename " + "(default: sbprofile.reg)") args = parser.parse_args() if os.path.exists(args.outfile): if args.clobber: os.remove(args.outfile) else: raise OSError("File already exists: %s" % args.outfile) setup_pfiles(["dmlist", "dmstat", "dmextract"]) manifest = get_manifest() if args.infile: infile = args.infile else: infile = manifest.getpath("evt2_clean", relative=True) if args.center: center_reg = args.center else: center_reg = manifest.getpath("reg_centroid", relative=True) region = Regions(center_reg).regions[0] center = (region.xc, region.yc) regions = gen_regions(center=center, evt=infile, bkg=args.bkg, n_inner=args.n_inner, min_counts=args.min_counts, min_width=args.min_width, ratio_radius=args.ratio_radius, snr_thresh=args.snr_thresh, elow=args.elow, ehigh=args.ehigh, elow_pb=args.elow_pb, ehigh_pb=args.ehigh_pb) open(args.outfile, "w").write("\n".join(regions) + "\n") if args.view: ds9_view(infile, regfile=args.outfile) # Add generated SBP region file to manifest key = "sbp_reg" manifest.setpath(key, args.outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Make spectral-weighted exposure map") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") parser.add_argument("-w", "--weights", dest="weights", help="spectral weights file (default: " + "'spec_weights' from manifest)") parser.add_argument("-e", "--evtfile", dest="evtfile", help="event file for aspect histogram creation " + "(default: 'evt2_clean' from manifest)") parser.add_argument("-i", "--infile", dest="infile", required=True, help="input image file") parser.add_argument("-o", "--outfile", dest="outfile", required=True, help="filename of output exposure map") args = parser.parse_args() setup_pfiles([ "get_sky_limits", "asphist", "mkinstmap", "mkexpmap", "ardlib", "acis_set_ardlib", "dmimgcalc", "dmimgthresh" ]) manifest = get_manifest() if args.weights: weights = args.weights else: weights = manifest.getpath("spec_weights", relative=True) if args.evtfile: evtfile = args.evtfile else: evtfile = manifest.getpath("evt2_clean", relative=True) asol = manifest.getpath("asol", relative=True, sep=",") bpix = manifest.getpath("bpix", relative=True) msk = manifest.getpath("msk", relative=True) chips = ACIS.get_chips_str(args.infile) logger.info("infile: %s" % args.infile) logger.info("output expmap: %s" % args.outfile) logger.info("weights: %s" % weights) logger.info("evtfile: %s" % evtfile) logger.info("chips: %s" % chips) logger.info("bpix: %s" % bpix) logger.info("asol: %s" % asol) logger.info("msk: %s" % msk) xygrid = get_xygrid(args.infile) logger.info("%s:xygrid: %s" % (args.infile, xygrid)) expmaps = [] for c in chips: logger.info("Processing chip %s ..." % c) asphist = "asphist_c{chip}.fits".format(chip=c) instmap = "instmap_c{chip}.fits".format(chip=c) expmap = "expmap_c{chip}.fits".format(chip=c) make_aspect_histogram(outfile=asphist, asol=asol, evtfile=evtfile, chip=c, clobber=args.clobber) make_instrument_map(outfile=instmap, spectrumfile=weights, chip=c, obsfile=args.infile, maskfile=msk, badpixfile=bpix, clobber=args.clobber) make_exposure_map(outfile=expmap, asphistfile=asphist, instmapfile=instmap, xygrid=xygrid, clobber=args.clobber) expmaps.append(expmap) # Remove intermediate files os.remove(asphist) os.remove(instmap) combine_expmaps(outfile=args.outfile, expmaps=expmaps, clobber=args.clobber) detnam = "ACIS-{0}".format(chips) logger.info("Update keyword 'DETNAM' to %s" % detnam) write_keyword(args.outfile, keyword="DETNAM", value=detnam) threshold_expmap(args.outfile, clobber=args.clobber) logger.info("Add created exposure map to manifest ...") key = "expmap" manifest.setpath(key, args.outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Calculate the emission centroid within the image") parser.add_argument("-i", "--infile", dest="infile", required=True, help="input image file (e.g., 0.7-2.0 keV)") parser.add_argument("-o", "--outfile", dest="outfile", default="centroid.reg", help="output centroid region file " + "(default: centroid.reg") parser.add_argument("-R", "--radius1", dest="radius1", type=float, default=100, help="circle radius [pixel] for first phase " + "centroid calculation (default: 100 pixel)") parser.add_argument("-r", "--radius2", dest="radius2", type=float, default=50, help="circle radius [pixel] for second phase " + "calculation to tune centroid (default: 50 pixel)") parser.add_argument("-n", "--niter", dest="niter", type=int, default=10, help="iterations for each phase (default: 10)") parser.add_argument("-s", "--start", dest="start", help="a region file containing a circle/point " + "that specifies the starting point " + "(default: using the peak of the image)") parser.add_argument("-V", "--view", dest="view", action="store_true", help="open DS9 to view output centroid") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing files") args = parser.parse_args() setup_pfiles(["aconvolve", "dmstat"]) print("Smooth input image using 'aconvolve' ...", file=sys.stderr) img_smoothed = smooth_image(args.infile, clobber=args.clobber) if args.start: print("Get starting point from region file: %s" % args.start, file=sys.stderr) region = Regions(args.start).regions[0] center = (region.xc, region.yc) else: print("Use peak as the starting point ...", file=sys.stderr) center = get_peak(img_smoothed) print("Starting point: (%f, %f)" % center, file=sys.stderr) centroid = center for phase, radius in enumerate([args.radius1, args.radius2]): print("Calculate centroid phase %d (circle radius: %.1f)" % (phase + 1, radius), file=sys.stderr) for i in range(args.niter): print("%d..." % (i + 1), end="", flush=True, file=sys.stderr) centroid = get_centroid(img_smoothed, center=centroid, radius=radius) print("Done!", file=sys.stderr) with open(args.outfile, "w") as f: f.write("point(%f,%f)\n" % centroid) print("Saved centroid to file:", args.outfile, file=sys.stderr) if args.view: ds9_view(img_smoothed, regfile=args.outfile) # Add calculated centroid region to manifest manifest = get_manifest() key = "reg_centroid" manifest.setpath(key, args.outfile) print("Added item '%s' to manifest: %s" % (key, manifest.get(key)), file=sys.stderr)
def main(): parser = argparse.ArgumentParser( description="Calculate the spectral weights for exposure map creation") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") parser.add_argument("-L", "--elow", dest="elow", type=int, default=700, help="lower energy limit [eV] (default: 700 [eV])") parser.add_argument("-H", "--ehigh", dest="ehigh", type=int, default=7000, help="upper energy limit [eV] (default: 7000 [eV])") parser.add_argument("-n", "--nh", dest="nh", type=float, required=True, help="HI column density (unit: 1e22) for " + "spectral weights creation") parser.add_argument("-z", "--redshift", dest="redshift", type=float, required=True, help="source redshift for spectral weights creation") parser.add_argument("-T", "--temperature", dest="temperature", type=float, required=True, help="source average temperature (unit: keV) " + "for spectral weights creation") parser.add_argument("-Z", "--abundance", dest="abundance", type=float, required=True, help="source average abundance (unit: solar/grsa) " + "for spectral weights creation") parser.add_argument("-o", "--outfile", dest="outfile", default="spectral_weights.txt", help="output spectral weights filename " + "(default: spectral_weights.txt)") args = parser.parse_args() setup_pfiles(["make_instmap_weights"]) manifest = get_manifest() logger.info("outfile: %s" % args.outfile) logger.info("nh: %s (1e22 cm^-2)" % args.nh) logger.info("redshift: %s" % args.redshift) logger.info("temperature: %s (keV)" % args.temperature) logger.info("abundance: %s (solar/grsa)" % args.abundance) calc_spectral_weights(outfile=args.outfile, nh=args.nh, redshift=args.redshift, temperature=args.temperature, abundance=args.abundance, elow=args.elow, ehigh=args.ehigh, clobber=args.clobber) # Add created weights file to manifest key = "spec_weights" manifest.setpath(key, args.outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser(description="Make the SBP regions") parser.add_argument("-L", "--elow", dest="elow", type=int, default=700, help="lower energy limit to calculate the photon " + "counts [eV] (default: 700 eV)") parser.add_argument("-H", "--ehigh", dest="ehigh", type=int, default=7000, help="upper energy limit to calculate the photon " + "counts [eV] (default: 7000 eV)") parser.add_argument("-p", "--elow-pb", dest="elow_pb", type=int, default=9500, help="lower energy limit of the particle " + "background [eV] (default: 9500 eV)") parser.add_argument("-P", "--ehigh-pb", dest="ehigh_pb", type=int, default=12000, help="upper energy limit of the particle " + "background [eV] (default: 12000 eV)") parser.add_argument("-m", "--min-counts", dest="min_counts", type=int, default=50, help="minimum photon counts of echo SBP " + "region (default: 50)") parser.add_argument("-M", "--min-width", dest="min_width", type=int, default=5, help="minimum annulus/pie width of the inner-type " + "regions (default: 5 [pix])") parser.add_argument("-N", "--n-inner", dest="n_inner", type=int, default=10, help="number of the inner-type regions (default: 10)") parser.add_argument("-R", "--ratio-radius", dest="ratio_radius", type=float, default=1.2, help="ratio of outer radius w.r.t. inner radius " + "(default: 1.2)") parser.add_argument("-S", "--snr-thresh", dest="snr_thresh", type=float, default=1.5, help="lower threshold of the SNR (default: 1.5)") parser.add_argument("-V", "--view", dest="view", action="store_true", help="open DS9 to view output centroid") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing files") parser.add_argument("-b", "--bkg", dest="bkg", help="background file for SNR calculation; " + "may be blanksky or corrected background spectrum") parser.add_argument("-c", "--center", dest="center", help="Region file specifying the center " + "(default: 'reg_centroid' from manifest)") parser.add_argument("-i", "--infile", dest="infile", help="input event file " + "(default: 'evt2_clean' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", default="sbprofile.reg", help="output SBP region filename " + "(default: sbprofile.reg)") args = parser.parse_args() if os.path.exists(args.outfile): if args.clobber: os.remove(args.outfile) else: raise OSError("File already exists: %s" % args.outfile) setup_pfiles(["dmlist", "dmstat", "dmextract"]) manifest = get_manifest() if args.infile: infile = args.infile else: infile = manifest.getpath("evt2_clean", relative=True) if args.center: center_reg = args.center else: center_reg = manifest.getpath("reg_centroid", relative=True) region = Regions(center_reg).regions[0] center = (region.xc, region.yc) regions = gen_regions(center=center, evt=infile, bkg=args.bkg, n_inner=args.n_inner, min_counts=args.min_counts, min_width=args.min_width, ratio_radius=args.ratio_radius, snr_thresh=args.snr_thresh, elow=args.elow, ehigh=args.ehigh, elow_pb=args.elow_pb, ehigh_pb=args.ehigh_pb) open(args.outfile, "w").write("\n".join(regions) + "\n") if args.view: ds9_view(infile, regfile=args.outfile) # Add generated SBP region file to manifest key = "sbp_reg" manifest.setpath(key, args.outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Make image by binning the event file") parser.add_argument("-L", "--elow", dest="elow", type=int, default=700, help="lower energy limit [eV] of the output image " + "(default: 700 [eV])") parser.add_argument("-H", "--ehigh", dest="ehigh", type=int, default=7000, help="upper energy limit [eV] of the output image " + "(default: 7000 [eV])") parser.add_argument("-i", "--infile", dest="infile", help="event file from which to create the image " + "(default: 'evt2_clean' from manifest)") parser.add_argument("-o", "--outfile", dest="outfile", help="output image filename (default: " + "build in format 'img_c<chip>_e<elow>-<ehigh>.fits')") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing file") args = parser.parse_args() setup_pfiles(["dmkeypar", "dmcopy"]) manifest = get_manifest() fov = manifest.getpath("fov", relative=True) if args.infile: infile = args.infile else: infile = manifest.getpath("evt2_clean", relative=True) chips = ACIS.get_chips_str(infile, sep="-") erange = "{elow}-{ehigh}".format(elow=args.elow, ehigh=args.ehigh) if args.elow >= args.ehigh: raise ValueError("invalid energy range: %s" % erange) if args.outfile: outfile = args.outfile else: outfile = "img_c{chips}_e{erange}.fits".format(chips=chips, erange=erange) logger.info("infile: %s" % infile) logger.info("outfile: %s" % outfile) logger.info("fov: %s" % fov) logger.info("chips: %s" % chips) logger.info("erange: %s" % erange) make_image(infile, outfile, chips, erange, fov, args.clobber) chips_all = ACIS.get_chips_str(infile) write_keyword(outfile, keyword="DETNAM", value="ACIS-{0}".format(chips_all)) # Add created image to manifest key = "img_e{erange}".format(erange=erange) manifest.setpath(key, outfile) logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key)))
def main(): parser = argparse.ArgumentParser( description="Calculate the emission centroid within the image") parser.add_argument("-i", "--infile", dest="infile", required=True, help="input image file (e.g., 0.7-2.0 keV)") parser.add_argument("-o", "--outfile", dest="outfile", default="centroid.reg", help="output centroid region file " + "(default: centroid.reg") parser.add_argument("-R", "--radius1", dest="radius1", type=float, default=100, help="circle radius [pixel] for first phase " + "centroid calculation (default: 100 pixel)") parser.add_argument("-r", "--radius2", dest="radius2", type=float, default=50, help="circle radius [pixel] for second phase " + "calculation to tune centroid (default: 50 pixel)") parser.add_argument("-n", "--niter", dest="niter", type=int, default=10, help="iterations for each phase (default: 10)") parser.add_argument("-s", "--start", dest="start", help="a region file containing a circle/point " + "that specifies the starting point " + "(default: using the peak of the image)") parser.add_argument("-V", "--view", dest="view", action="store_true", help="open DS9 to view output centroid") parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", help="overwrite existing files") args = parser.parse_args() setup_pfiles(["aconvolve", "dmstat"]) print("Smooth input image using 'aconvolve' ...", file=sys.stderr) img_smoothed = smooth_image(args.infile, clobber=args.clobber) if args.start: print("Get starting point from region file: %s" % args.start, file=sys.stderr) region = Regions(args.start).regions[0] center = (region.xc, region.yc) else: print("Use peak as the starting point ...", file=sys.stderr) center = get_peak(img_smoothed) print("Starting point: (%f, %f)" % center, file=sys.stderr) centroid = center for phase, radius in enumerate([args.radius1, args.radius2]): print("Calculate centroid phase %d (circle radius: %.1f)" % (phase+1, radius), file=sys.stderr) for i in range(args.niter): print("%d..." % (i+1), end="", flush=True, file=sys.stderr) centroid = get_centroid(img_smoothed, center=centroid, radius=radius) print("Done!", file=sys.stderr) with open(args.outfile, "w") as f: f.write("point(%f,%f)\n" % centroid) print("Saved centroid to file:", args.outfile, file=sys.stderr) if args.view: ds9_view(img_smoothed, regfile=args.outfile) # Add calculated centroid region to manifest manifest = get_manifest() key = "reg_centroid" manifest.setpath(key, args.outfile) print("Added item '%s' to manifest: %s" % (key, manifest.get(key)), file=sys.stderr)