예제 #1
0
def main():
    args = arg_parser().parse_args()

    util.set_logger(args.verbose, args.logfile, args.log)

    if len(args.img) > 1:
        if not args.output.startswith("."):
            logger.critical(
                "With more than one input IMG file, the --output must start "
                f"with a period, and it does not: {args.output}"
            )
            sys.exit()

        if not args.db.startswith("."):
            logger.critical(
                "With more than one input IMG file, the --db must start with "
                f"a period, and it does not: {args.db}"
            )
            sys.exit()

    gainsinfo = pvl.load(args.gains)

    with util.main_exceptions(args.verbose):
        if len(args.img) == 1:
            # No need to fire up the multiprocessing for just one image.
            db_path = write_json(
                EDR_Stats(
                    args.img[0],
                    util.path_w_suffix(args.output, args.img[0]),
                    gainsinfo,
                    args.histmin,
                    args.histmax,
                    keep=args.keep
                ),
                args.db,
                args.img[0],
            )
            logger.info(f"Wrote {db_path}")
        else:
            with concurrent.futures.ProcessPoolExecutor(
                max_workers=args.max_workers
            ) as executor:
                for img, histats, in zip(args.img, executor.map(
                    EDR_Stats,
                    args.img,
                    map(util.path_w_suffix, repeat(args.output), args.img),
                    repeat(gainsinfo),
                    repeat(args.histmin),
                    repeat(args.histmax),
                    repeat(args.keep),
                )):
                    db_path = write_json(histats, args.db, img)
                    logger.info(f"Wrote {db_path}")
    return
예제 #2
0
def color(obsid, conf_dir: Path, parent: Path, db_list: list, keep=False):
    colors = get_cubes(f"{obsid}_COLOR*.cub", parent)

    # HiColorNorm - only for color
    #   takes *COLOR[4|5].cub
    #   creates *UNFILTERED_COLOR[4|5].cub and *COLOR[4|5].HiColorNorm.cub
    HiColorNorm.HiColorNorm(
        colors,
        "_COLOR.cub",
        pvl.load(conf_dir / "HiColorNorm.conf"),
        db_list=db_list,
        keep=keep,
    )

    # HiBeautify - only for color
    #   takes tmp/*.HiColorNorm.cub
    #   creates *IRB.cub and *RGB.cub
    for x in colors:
        x.with_suffix(".HiColorNorm.cub")
    HiBeautify.HiBeautify(
        [x.with_suffix(".HiColorNorm.cub") for x in colors],
        pvl.load(conf_dir / "HiBeautify.conf"),
    )
    return
예제 #3
0
def main():
    args = arg_parser().parse_args()

    util.set_logger(args.verbose, args.logfile, args.log)

    oid = hirise.get_ObsID_fromfile(args.img[0])
    parent = Path(args.img[0]).parent
    if args.img == 1:
        imgs = parent.glob(f"{oid}*.img") + parent.glob(f"{oid}*.IMG")
    else:
        imgs = args.img

    db_list = None
    with util.main_exceptions(args.verbose):
        try:
            get_cubes(f"{oid}*balance.cub", parent)
        except FileNotFoundError:
            chancubes = edr2stitch(
                imgs,
                args.conf_dir,
                max_workers=args.max_workers,
                keep=args.keep
            )
            db_list = [x.db for x in chancubes]

        if args.color:
            color(oid, args.conf_dir, parent, db_list, keep=args.keep)

        if args.precision or args.jack:
            jack = False
            if args.jack:
                jack = True
            else:
                slithers = list(parent.glob("*.slither.txt"))

                # HiPrecisionInit to determine if you need to HiNoProj or
                # HiJACK takes *slither.txt
                (HiJACK_flags, _, _) = HiPrecisionInit.check(
                    slithers, pvl.load(args.conf_dir / "HiPrecisionInit.conf")
                )

                if any(HiJACK_flags):
                    jack = True

            precision(oid, args.conf_dir, parent, hijack=jack, keep=args.keep)

    return
예제 #4
0
def precision(obsid, conf_dir: Path, parent: Path, hijack=False, keep=False):

    if hijack:
        bal_cubs = get_cubes(f"{obsid}*balance.cub", parent)
        # HiJACK - starts with balance cubes, needs all the colors
        #   takes all color balance.cubs
        #   creates a whole slow of files in HiJACK/
        HiJACK.HiJACK(
            bal_cubs,
            conf_dir,
            outdir=(parent / "HiJACK"),
            plot=False,
            keep=keep,
        )
    else:
        red_bal_cubs = get_cubes(f"{obsid}_RED*balance.cub", parent)
        # HiNoProj - alternate to HiccdStitch, starts with balance cubes
        #   takes only REDS: *RED*balance.cub
        #   creates PSP_010502_2090_RED.NOPROJ.cub
        HiNoProj.HiNoProj(
            red_bal_cubs, pvl.load(conf_dir / "HiNoProj.conf"), keep=keep
        )

    return
예제 #5
0
def check_lut(img: os.PathLike):
    """Checks whether a stored look up table (LUT) matches a known LUT."""
    # Original author of this function was Robert King, in December 2006.
    # logger.info(check_lut.__doc__)

    img_pvl = pvl.load(str(img))
    lut_type = img_pvl["INSTRUMENT_SETTING_PARAMETERS"][
        "MRO:LOOKUP_TABLE_TYPE"
    ]
    if "STORED" in lut_type:
        lut = dict()
        # dec.28.06 zero-filled LUT (ie, the image was not LUT'ed)
        lut["897256b6709e1a4da9daba92b6bde39ccfccd8c1"] = None

        # dec.19.06 build
        lut["35c8318042da3c30949f3ecb9f3876de524f158f"] = 300
        lut["874f6c26fe21577bc88f8986ec5643ff43747908"] = 301
        lut["02ae8c3834160614a65190cfee95fd62a2227447"] = 302
        lut["919d8f16363d1161b1843783c713564110cef5cc"] = 303
        lut["086adb2152c5f47741ce16e128ad3533fff1fa31"] = 304
        lut["020b40e1aab312ddf9fce61d5eb7cacd33bbeaec"] = 305
        lut["b45de94586e5ab539cc1c0b72d0e0267765e3b69"] = 306
        lut["8e4cd2ba1646d117afb9af658b9f762fcb0bcc48"] = 307
        lut["6227fbb77374afe54ba5de26a5af2cfb954f7783"] = 308
        lut["31d88a70dc4a6c9cf4991eb3f7a07c3b5df624a9"] = 309
        lut["166d23b2c7e71acebfaf07798a697670bff55df9"] = 310
        lut["d0f29aae50c21e443d7d188e7937b249fd8ba447"] = 311
        lut["a44541a295899f7fe55bf038dee9d5c130190c08"] = 312
        lut["58914a9cf58f4abbf7adc60357d8daa0d8104794"] = 313
        lut["bd416e8935556cd22e6caae1e9541ea42fc32fe7"] = 314
        lut["332a862b5963d55716bc00185906ab0195372e03"] = 315
        lut["b7d5169700fa7925adfc9ab4463c4c0c64cb9c31"] = 316
        lut["de35fb5719fabf3da400de015cf2c3155bbfe1ac"] = 317
        lut["55b78c9ca2822a6f87b3c3884d95034d4abbb725"] = 318
        lut["2aaf567e760eb313eca50cff9b3ed74f035af0d5"] = 319
        lut["43a31577737b140eecc327d09f0900c182dddbe3"] = 320
        lut["79d29aa8e13dd1991f810894821ebc518bcf3ff3"] = 321
        lut["dca0da083569fc25b910611f7d43a72738923d59"] = 322
        lut["809c4a81505eced9203e4648d7905a3de9c71f7e"] = 323
        lut["349bf694a6b11ee3e47956189aebeab234be4e9e"] = 324
        lut["063a2d3ed43bb1b47e73a38fbe49091ac4183c3c"] = 325
        lut["9ea3b154b83925f65c36888d0981b84eed35baa6"] = 326
        lut["4ca66adf72eefe25bc53edc801c1c71e99cf4ab9"] = 327

        # may.16.05 build
        lut["23f9889760466065c78b070aa83097229c391ba1"] = 200
        lut["d46c82527435d5b8a3b4a329f4a80ec80ed3a6e5"] = 201
        lut["a814e4a5a679d1ca710c92b745f79c6d2a1c2f43"] = 202
        lut["b67f6fb3adb08c25955878e5f685846c3ede6194"] = 203
        lut["7c03fd37caac821554e6c9ebe593ca60200cee4b"] = 204
        lut["6c21207a2e78517a8e069f99efd8f3c549ace95d"] = 205
        lut["b21a8cb5dfee2be1eaf5e7c8ce2b7b30c7f385ef"] = 206
        lut["801e83161358bf9a4a00a76c8970454521c7aff8"] = 207
        lut["7223df1f14d33a7a57b96d2d9d39b6ae526a1f8b"] = 208
        lut["90b01c7c6055ea580293771601e6f31cc966671c"] = 209
        lut["a23833f7421ae17c066010b1150feb696b7dbb2c"] = 210
        lut["9b20c521c050c37faa959d84e6f1031f4ad42ac6"] = 211
        lut["80b6d126c6ed96d1635bb0755ed701cefb001c72"] = 212
        lut["598df42422e6167304db3d9e2613912a62f80931"] = 213
        lut["d02cda160d162001fbd515a609837320058572c6"] = 214
        lut["876a7779d8418e1a0cb9c9a4312cb65f68fd6d0e"] = 215
        lut["fbc4af8337bd8e68659ffa9bd016ce3d9aa1892b"] = 216
        lut["2948ffacdc179dba578fcf162234a61f3ef5e19c"] = 217
        lut["010344d1afc116b92a3e5a5c3884a5c3d4f1997d"] = 218
        lut["7904b0a9c14194b6209f02161be15fe6d1416926"] = 219
        lut["a57657074cb1059b4529854e2b64db750b78ec93"] = 220
        lut["e55530adfd7b4f7bb9715bff81870f32c528c559"] = 221
        lut["e8ed81aa0c81a4d54b43d8a94fcd75133585a32c"] = 222
        lut["901e6113448d3de51fff452c67d4b9f93f700a9c"] = 223
        lut["258f9f498804b3bcfb4fea679df5aa528b71021b"] = 224
        lut["71305d279ae2f2b2915fe33ceff59bd1038f6df5"] = 225
        lut["53d91396bee5b7f8c4026343e4145b1b54269a47"] = 226
        lut["07c0e1a8453a53232ccdb09d183612dd33e28ecd"] = 227

        # sep.04.04 build
        lut["3b2797fbf2588e6815f5cef7fa33ee4d3d9ef7db"] = 100
        lut["37e4bf9213d992ce974caa936211099fbf63befc"] = 101
        lut["da37672307cb95fe51b381fad59c68c537f7dff4"] = 102
        lut["23f795926899e5bf1f32f0126418be4e91ac0f94"] = 103
        lut["3f1835f9a832cd5c31ed4eb8276a964dcbf7ce12"] = 104
        lut["95f2043d5eb69c2c5d987bccf8ffd6714cbfc333"] = 105
        lut["2cd93e0418b89329ddf94daf44bfe605884d2e7f"] = 106
        lut["51817ef40212588e80155d03e19fcdc586ef7781"] = 107
        lut["8d2ec79837e6cb684a54068218f225262cc392e3"] = 108
        lut["9a9802f68a3828a0003a302b553364fd46cc1797"] = 109
        lut["f2a728884a478c0826a8c52700a6fdc53cf645e7"] = 110
        lut["247b510cfc32ec50c2029fef7a9e2dc1e906f807"] = 111
        lut["9d37b56fec19fecc73e90c183c74a17de7e29bd1"] = 112
        lut["99e4a80b7acc14d0c903f45a379cd43d14ab471e"] = 113
        lut["c9cc0c2dce9f053a1fb00fac37540c27bbe287c3"] = 114
        lut["d1f7ec6a8a8ba2a249c04b8a05571bc352fbefd9"] = 115
        lut["9544bb6b8c664413b76d8045f0291caf74d30654"] = 116
        lut["d81ed931335a16a84c5b5335d533ea54018bcc75"] = 117
        lut["e5dc08252003d7e9b4efa7ee6491387b4e0912c0"] = 118
        lut["c4bfc2c546e588e3036333d485ede76d3619d407"] = 119
        lut["ac3e23a5bd22d6300e46e7d30671bac3593858d5"] = 120
        lut["687d908ad9821d90a5efb6a9661bce6620a21630"] = 121
        lut["16df8d98efe62be7e18a1a83e29e15dcd70390d9"] = 122
        lut["802b52209dda8c0d20a0889cb8dd4d1432bc08f2"] = 123
        lut["b054f3a6bd8ddf33c7361b73aef1357fbf0dc894"] = 124
        lut["bfdb8f8a90e3f7e1d8495a878a42cfb790bb7e88"] = 125
        lut["49584c404d0eb35f96d947b7498d90f8deb9138c"] = 126
        lut["386ef62256956ef1d42ab53fe5c08abdb6faadd2"] = 127

        with open(img, mode="rb") as f:
            f.seek(32768 + 800)
            buf = f.read(16384)

        return lut[hashlib.sha1(buf).hexdigest()]

    return None
예제 #6
0
def edr2stitch(
    images,
    conf_dir,
    bitflipwidth=0,
    lis_tolerance=1.0,
    max_workers=None,
    keep=False,
):
    chids = list()
    edr_conf = pvl.load(conf_dir / "EDR_Stats_gains_config.pvl")
    hical_conf = HiCal.conf_setup(
        pvl.load(conf_dir / "HiCal.conf"),
        pvl.load(conf_dir / "NoiseFilter.conf"),
    )
    with concurrent.futures.ProcessPoolExecutor(
                max_workers=max_workers
    ) as executor:
        future_dbs = dict()
        for i in images:
            out_edr = util.path_w_suffix(".EDR_Stats.cub", i)
            out_hical = util.path_w_suffix(".HiCal.cub", out_edr)

            f = executor.submit(
                edr_cal,
                i,
                out_edr,
                out_hical,
                edr_conf,
                hical_conf,
                conf_dir / "HiCal.conf",
                bitflipwidth=bitflipwidth,
                lis_tolerance=lis_tolerance,
                keep=False,
            )
            future_dbs[f] = out_hical

        for future in concurrent.futures.as_completed(future_dbs):
            out_hical = future_dbs[future]
            chids.append(ChannelCube(out_hical, future.result()))

    # HiStitch
    # get Channel pairs
    cids = list()
    stitch_conf = pvl.load(conf_dir / "HiStitch.conf")
    with concurrent.futures.ProcessPoolExecutor(
        max_workers=max_workers
    ) as executor:
        future_tuples = list()
        for chid1, chid2 in get_CCDpairs(chids):
            f = executor.submit(
                # (db, o_path) = HiStitch.HiStitch(
                HiStitch.HiStitch,
                chid1.nextpath,
                chid2.nextpath,
                chid1.db,
                chid2.db,
                ".HiStitch.cub",
                stitch_conf,
                keep=keep,
            )
            future_tuples.append(f)

        for future in concurrent.futures.as_completed(future_tuples):
            (db, o_path) = future.result()
            cid = HiccdStitch.HiccdStitchCube(o_path)
            cid.gather_from_db(db)
            cids.append(cid)

    # HiccdStitch, makes balance cubes
    # need to separate by color:
    color_groups = get_color_groups(cids)
    for color_group in color_groups.values():
        db, out_stitch = HiccdStitch.HiccdStitch(
            color_group,
            ".HiccdStitch.cub",
            pvl.load(conf_dir / "HiccdStitch.conf"),
            sline=None,
            eline=None,
            keep=keep,
        )
    # HiColorInit
    #   takes *balance.cub
    #   creates *[IR|BG]*.balance.precolor.cub
    #   Can then run JitPlot on these *.balance.precolor.cub
    HiColorInit.HiColorInit(
        [c.nextpath for c in cids], ".precolor.cub", keep=keep
    )

    # HiJitReg
    #   takes tmp/*balance.cub tmp/*balance.precolor.cub
    #   creates *regdef.pvl and *flat.tab files
    for_jitreg = list()
    for color, balcubes in color_groups.items():
        if color == "RED":
            for c in balcubes:
                for_jitreg.append(c.nextpath)
        else:
            for c in balcubes:
                for_jitreg.append(c.nextpath.with_suffix(".precolor.cub"))

    HiJitReg.HiJitReg(
        for_jitreg, pvl.load(conf_dir / "HiJitReg.conf"), keep=keep
    )

    # HiSlither
    #   takes same as HiJitReg (and assumes its products are available.
    #   creates *slither.txt, *slither.cub, and *COLOR[4|5].cub
    #   Can then run SlitherStats on the *slither.txt
    HiSlither.HiSlither(for_jitreg)

    return chids