Exemplo n.º 1
0
def handle_args(args=None):
    """
    Parses command line options & arguments using OptionParser.
    Options & default values for the script are defined herein.
    """
    parser = get_argparser()
    options= parser.parse_args()

    # Overwrite 'fixed_coords' with a parsed list of coords
    # collated from both command line and file.
    options.fixed_coords = parse_monitoringlist_positions(
        options, str_name="fixed_posns", list_name="fixed_posns_file"
    )
    # Quick & dirty check that the position list looks plausible
    if options.fixed_coords:
        mlist = numpy.array(options.fixed_coords)
        if not (len(mlist.shape) == 2 and mlist.shape[1] == 2):
            parser.error("Positions for forced-fitting must be [RA,dec] pairs")

    # We have four potential modes, of which we choose only one to run:
    #
    # 1. Blind sourcefinding
    #  1.1 Thresholding, no detection image (no extra cmd line options)
    #  1.2 Thresholding, detection image (--detection-image)
    #  1.3 FDR (--fdr)
    #
    # 2. Fit to fixed points (--fixed-coords and/or --fixed-list)

    if options.fixed_coords:
        if options.fdr:
            parser.error("--fdr not supported with fixed positions")
        elif options.detection_image:
            parser.error("--detection-image not supported with fixed positions")
        options.mode = "fixed" # mode 2 above
    elif options.fdr:
        if options.detection_image:
            parser.error("--detection-image not supported with --fdr")
        options.mode = "fdr" # mode 1.3 above
    elif options.detection_image:
        options.mode = "detimage" # mode 1.2 above
    else:
        options.mode = "threshold" # mode 1.1 above

    return options, options.files
Exemplo n.º 2
0
def handle_args(args=None):
    """
    Parses command line options & arguments using OptionParser.
    Options & default values for the script are defined herein.
    """
    usage = "usage: %prog [options] file1 ... fileN"
    parser = OptionParser(usage)
    parser.add_option("--fdr",
                      action="store_true",
                      dest="fdr",
                      help="Use False Detection Rate algorithm")
    parser.add_option("--alpha", default=1e-2, type="float", help="FDR Alpha")
    parser.add_option("--detection",
                      default=10,
                      type="float",
                      help="Detection threshold")
    parser.add_option("--analysis",
                      default=3,
                      type="float",
                      help="Analysis threshold")
    parser.add_option("--regions",
                      action="store_true",
                      help="Generate DS9 region file(s)")
    parser.add_option("--residuals",
                      action="store_true",
                      help="Generate residual maps")
    parser.add_option("--islands",
                      action="store_true",
                      help="Generate island maps")
    parser.add_option("--deblend-thresholds",
                      default=0,
                      type="int",
                      help="Number of deblending subthresholds; 0 to disable")
    parser.add_option("--bmaj", type="float", help="Major axis of beam (deg)")
    parser.add_option("--bmin", type="float", help="Minor axis of beam (deg)")
    parser.add_option("--bpa", type="float", help="Beam position angle (deg)")
    parser.add_option("--grid",
                      default=64,
                      type="int",
                      help="Background grid segment size")
    parser.add_option("--margin",
                      default=0,
                      type="int",
                      help="Margin applied to each edge of image (in pixels)")
    parser.add_option("--radius",
                      default=0,
                      type="float",
                      help="Radius of usable portion of image (in pixels)")
    parser.add_option("--skymodel",
                      action="store_true",
                      help="Generate sky model")
    parser.add_option(
        "--csv",
        action="store_true",
        help="Generate csv text file for use in programs such as TopCat")
    parser.add_option("--rmsmap", action="store_true", help="Generate RMS map")
    parser.add_option("--sigmap",
                      action="store_true",
                      help="Generate significance map")
    parser.add_option("--force-beam",
                      action="store_true",
                      help="Force fit axis lengths to beam size")
    parser.add_option("--detection-image",
                      type="string",
                      help="Find islands on different image")
    parser.add_option(
        '--fixed-posns',
        help="List of position coordinates to "
        "force-fit (decimal degrees, JSON, e.g [[123.4,56.7],[359.9,89.9]]) "
        "(Will not perform blind extraction in this mode)",
        default=None)
    parser.add_option(
        '--fixed-posns-file',
        help="Path to file containing a list of positions to force-fit "
        "(Will not perform blind extraction in this mode)",
        default=None)
    parser.add_option(
        '--ffbox',
        type='float',
        default=3.,
        help="Forced fitting positional box size as a multiple of beam width.")
    options, files = parser.parse_args(args=args)

    # Overwrite 'fixed_coords' with a parsed list of coords
    # collated from both command line and file.
    options.fixed_coords = parse_monitoringlist_positions(
        options, str_name="fixed_posns", list_name="fixed_posns_file")
    # Quick & dirty check that the position list looks plausible
    if options.fixed_coords:
        mlist = numpy.array(options.fixed_coords)
        if not (len(mlist.shape) == 2 and mlist.shape[1] == 2):
            parser.error("Positions for forced-fitting must be [RA,dec] pairs")

    # We have four potential modes, of which we choose only one to run:
    #
    # 1. Blind sourcefinding
    #  1.1 Thresholding, no detection image (no extra cmd line options)
    #  1.2 Thresholding, detection image (--detection-image)
    #  1.3 FDR (--fdr)
    #
    # 2. Fit to fixed points (--fixed-coords and/or --fixed-list)

    if options.fixed_coords:
        if options.fdr:
            parser.error("--fdr not supported with fixed positions")
        elif options.detection_image:
            parser.error(
                "--detection-image not supported with fixed positions")
        options.mode = "fixed"  # mode 2 above
    elif options.fdr:
        if options.detection_image:
            parser.error("--detection-image not supported with --fdr")
        options.mode = "fdr"  # mode 1.3 above
    elif options.detection_image:
        options.mode = "detimage"  # mode 1.2 above
    else:
        options.mode = "threshold"  # mode 1.1 above

    return options, files
Exemplo n.º 3
0
Arquivo: pyse.py Projeto: hughbg/tkp
def handle_args(args=None):
    """
    Parses command line options & arguments using OptionParser.
    Options & default values for the script are defined herein.
    """
    usage = "usage: %prog [options] file1 ... fileN"
    parser = OptionParser(usage)
    parser.add_option("--fdr", action="store_true", dest="fdr", help="Use False Detection Rate algorithm")
    parser.add_option("--alpha", default=1e-2, type="float", help="FDR Alpha")
    parser.add_option("--detection", default=10, type="float", help="Detection threshold")
    parser.add_option("--analysis", default=3, type="float", help="Analysis threshold")
    parser.add_option("--regions", action="store_true", help="Generate DS9 region file(s)")
    parser.add_option("--residuals", action="store_true", help="Generate residual maps")
    parser.add_option("--islands", action="store_true", help="Generate island maps")
    parser.add_option(
        "--deblend-thresholds", default=0, type="int", help="Number of deblending subthresholds; 0 to disable"
    )
    parser.add_option("--bmaj", type="float", help="Major axis of beam (deg)")
    parser.add_option("--bmin", type="float", help="Minor axis of beam (deg)")
    parser.add_option("--bpa", type="float", help="Beam position angle (deg)")
    parser.add_option("--grid", default=64, type="int", help="Background grid segment size")
    parser.add_option("--margin", default=0, type="int", help="Margin applied to each edge of image (in pixels)")
    parser.add_option("--radius", default=0, type="float", help="Radius of usable portion of image (in pixels)")
    parser.add_option("--skymodel", action="store_true", help="Generate sky model")
    parser.add_option("--csv", action="store_true", help="Generate csv text file for use in programs such as TopCat")
    parser.add_option("--rmsmap", action="store_true", help="Generate RMS map")
    parser.add_option("--sigmap", action="store_true", help="Generate significance map")
    parser.add_option("--force-beam", action="store_true", help="Force fit axis lengths to beam size")
    parser.add_option("--detection-image", type="string", help="Find islands on different image")
    parser.add_option(
        "--fixed-posns",
        help="List of coordinate pairs to " "force-fit (decimal degrees, JSON, e.g [[123.4,56.7],[359.9,89.9]])",
        default=None,
    )
    parser.add_option("--fixed-posn-file", help="Filename containing a list of positions to force-fit", default=None)
    parser.add_option(
        "--ffbox", type="float", default=3.0, help="Forced fitting positional box size as a multiple of beam width."
    )
    options, files = parser.parse_args(args=args)

    # Overwrite 'fixed_coords' with a parsed list of coords
    # collated from both command line and file.
    options.fixed_coords = parse_monitoringlist_positions(options, str_name="fixed", list_name="fixed_list")
    # Quick & dirty check that the position list looks plausible
    if options.fixed_coords:
        mlist = numpy.array(options.fixed_coords)
        if not (len(mlist.shape) == 2 and mlist.shape[1] == 2):
            parser.error("Positions for forced-fitting must be [RA,dec] pairs")

    # We have four potential modes, of which we choose only one to run:
    #
    # 1. Blind sourcefinding
    #  1.1 Thresholding, no detection image (no extra cmd line options)
    #  1.2 Thresholding, detection image (--detection-image)
    #  1.3 FDR (--fdr)
    #
    # 2. Fit to fixed points (--fixed-coords and/or --fixed-list)

    if options.fixed_coords:
        if options.fdr:
            parser.error("--fdr not supported with fixed positions")
        elif options.detection_image:
            parser.error("--detection-image not supported with fixed positions")
        options.mode = "fixed"  # mode 2 above
    elif options.fdr:
        if options.detection_image:
            parser.error("--detection-image not supported with --fdr")
        options.mode = "fdr"  # mode 1.3 above
    elif options.detection_image:
        options.mode = "detimage"  # mode 1.2 above
    else:
        options.mode = "threshold"  # mode 1.1 above

    return options, files