예제 #1
0
 def test_set_outpath(self):
     d = Path("dummy-directory")
     output = Path("foo")
     chid = hirise.CCDID("PSP_010502_2090_RED5_0")
     self.assertEqual(output, hs.set_outpath(output, chid, d))
     suffix = ".foo"
     with_suffix = d / Path("PSP_010502_2090_RED5.foo")
     self.assertEqual(with_suffix, hs.set_outpath(suffix, chid, d))
예제 #2
0
    def test_HiStitch(
        self,
        mock_histitch,
        mock_copyfile,
        mock_handmos,
        mock_algebra,
        mock_highpass,
        mock_lowpass,
        mock_mask,
        mock_fx,
        mock_rename,
        mock_cid_fromfile
    ):
        cubes = ("dummy1.in", "dummy2.in")
        out_c = Path("dummy.out")

        def getkey(cube, group, key):
            values = {
                "TruthChannel": 0,  # need to look at actual output
                "BalanceRatio": 3,
                "Summing": 2,
                "Lines": 1024,
                "Samples": 1024,
                "PRODUCT_ID": "PSP_010502_2090_RED4_0"
            }
            if key == "ChannelNumber":
                return cube.stem[-1]
            else:
                return values[key]

        db0 = self.my_db0
        db0["PRODUCT_ID"] = "PSP_010502_2090_RED4_0"
        db1 = self.my_db1
        db1["PRODUCT_ID"] = "PSP_010502_2090_RED4_1"

        with patch("hiproc.HiStitch.isis.getkey_k", side_effect=getkey):
            self.assertEqual(
                (0, 3),
                hs.HiStitch(
                    Path("dummy0.in"),
                    Path("dummy1.in"),
                    db0,
                    db1,
                    out_c,
                    {"HiStitch": self.my_c},
                    keep=True
                ),
            )

        with patch("hiproc.HiStitch.isis.getkey_k", side_effect=getkey):
            self.assertEqual(
                (None, None),
                hs.HiStitch(
                    [cubes, ], out_c, self.my_c, self.my_dbs, 5, keep=True
                ),
            )
예제 #3
0
 def test_get_chids(self):
     cid_list = (
         "PSP_010502_2090_RED4_0",
         "PSP_010502_2090_RED4_1",
         "PSP_010502_2090_RED5_0",
     )
     cube_list = list()
     for p in cid_list:
         cube_list.append(p + ".EDR_Stats.HiCal.cub")
     self.assertEqual(
         cid_list[0:2], tuple(map(str, hs.get_chids(cube_list[0:2])))
     )
     self.assertEqual(cid_list[-1], str(hs.get_chids((cube_list[-1],))[0]))
     self.assertRaises(ValueError, hs.get_chids, cube_list[1:3])
     with contextlib.suppress(FileNotFoundError):
         Path("print.prt").unlink()
예제 #4
0
 def test_set_flags(self):
     b = 1, 2, 4, 8, 16
     self.assertEqual(
         (True, True, False),
         hs.set_flags(self.my_c, self.my_dbs, 5, b.index(2), 6491.35),
     )
     self.my_c["HiStitch_Equalize"] = True
     self.assertEqual(
         (True, False, True),
         hs.set_flags(self.my_c, self.my_dbs, 5, b.index(2), 6491.35),
     )
     self.my_dbs[0]["zapped"] = True
     self.assertEqual(
         (False, False, True),
         hs.set_flags(self.my_c, self.my_dbs, 5, b.index(2), 6491.35),
     )
예제 #5
0
    def test_sort_input_cubes(self):
        cub0 = "PSP_010502_2090_RED4_0"
        cub1 = "PSP_010502_2090_RED4_1"
        with patch(
            "hiproc.HiStitch.isis.getkey_k", side_effect=[cub0[-1], cub1[-1]]
        ):
            self.assertEqual((cub0, cub1), hs.sort_input_cubes(cub0, cub1))

        with patch(
            "hiproc.HiStitch.isis.getkey_k", side_effect=[cub1[-1], cub0[-1]]
        ):
            self.assertEqual((cub0, cub1), hs.sort_input_cubes(cub1, cub0))

        with patch("hiproc.HiStitch.isis.getkey_k", return_value=0):
            self.assertRaises(RuntimeError, hs.sort_input_cubes, cub0, cub0)

        with patch("hiproc.HiStitch.isis.getkey_k", side_effect=[0, 2]):
            self.assertRaises(RuntimeError, hs.sort_input_cubes, cub0, cub1)
예제 #6
0
 def test_sort_databases(self):
     chids = (
         hirise.ChannelID("PSP_010502_2090_RED4_0"),
         hirise.ChannelID("PSP_010502_2090_RED4_1"),
     )
     dbs = ({"PRODUCT_ID": str(chids[0])}, {"PRODUCT_ID": str(chids[1])})
     _ = "dummy_path"
     with patch("hiproc.HiStitch.open", mock_open(read_data="dummy")):
         with patch("hiproc.HiStitch.json.load", side_effect=dbs):
             self.assertRaises(
                 IndexError, hs.sort_databases, (_, _, _), chids
             )
         # with patch('hiproc.HiStitch.json.load', side_effect=dbs):
         self.assertRaises(
             LookupError, hs.sort_databases, dbs, (chids[0], chids[0])
         )
         # with patch('hiproc.HiStitch.json.load', side_effect=dbs):
         self.assertEqual(dbs, hs.sort_databases(dbs, chids))
         # with patch('hiproc.HiStitch.json.load', side_effect=reversed(dbs)):
         self.assertEqual(
             dbs, hs.sort_databases(list(reversed(dbs)), chids)
         )
예제 #7
0
    def test_HiStitchStep(self):
        cubes = ("dummy1.in", "dummy2.in")
        out_c = "dummy.out"

        with patch("hiproc.HiStitch.isis.histitch") as mock:
            hs.HiStitchStep(cubes, out_c, 2, 5, self.my_c, False, False)
            mock.assert_called_with(
                from1=cubes[0], from2=cubes[1], to=out_c, balance=False
            )

            hs.HiStitchStep([cubes[0], ], out_c, 2, 5, self.my_c, False, False)
            mock.assert_called_with(from1=cubes[0], to=out_c, balance=False)

            hs.HiStitchStep(cubes, out_c, 2, 5, self.my_c, True, False)
            mock.assert_called_with(
                from1=cubes[0],
                from2=cubes[1],
                to=out_c,
                balance="TRUE",
                channel=0,
                seamsize=7,
                skip=7,
            )

            hs.HiStitchStep(cubes, out_c, 4, 0, self.my_c, False, True)
            mock.assert_called_with(
                from1=cubes[0],
                from2=cubes[1],
                to=out_c,
                balance="EQUALIZE",
                channel=1,
                seamsize=5,
                skip=7,
                operator="MULTIPLY",
                width=1501,
            )
예제 #8
0
 def test_conf_check(self):
     self.assertIsNone(hs.conf_check(conf))
예제 #9
0
    def test_HiFurrow_Fix(
        self,
        mock_copyfile,
        mock_handmos,
        mock_algebra,
        mock_highpass,
        mock_lowpass,
        mock_mask,
        mock_fx,
    ):
        with patch("hiproc.HiStitch.isis.getkey_k", return_value=1):
            self.assertRaises(
                ValueError, hs.HiFurrow_Fix, "dum_in", "dum_out", 0
            )
        with patch("hiproc.HiStitch.isis.getkey_k", side_effect=[2, 1, 1]):
            self.assertRaises(
                ValueError, hs.HiFurrow_Fix, "dum_in", "dum_out", 0
            )
        with patch(
            "hiproc.HiStitch.isis.getkey_k", side_effect=["2", "1024", "1024"]
        ):
            in_cube = "dummy_in.cub"
            out_cube = "dummy_out.cub"
            hs.HiFurrow_Fix(in_cube, out_cube, 1000, keep=True)

            mock_fx.assert_called_once()
            eqn = r"\(1*(sample<512)+ 1*(sample>513) + 0)"
            fx_path = mock_fx.call_args[1]["to"]
            mock_fx.assert_called_once_with(
                equation=eqn,
                lines=1024,
                mode="OUTPUTONLY",
                samples=1024,
                to=fx_path,
            )

            mask1_path = mock_mask.call_args_list[0][1]["to"]
            mask2_path = mock_mask.call_args_list[1][1]["to"]
            mock_calls = [
                call(
                    Path(in_cube),
                    mask=fx_path,
                    max_=1,
                    min_=1,
                    preserve="INSIDE",
                    spixels="NULL",
                    to=mask1_path,
                ),
                call(
                    Path(in_cube),
                    mask=fx_path,
                    max_=0,
                    min_=0,
                    preserve="INSIDE",
                    spixels="NULL",
                    to=mask2_path,
                ),
            ]
            self.assertEqual(mock_calls, mock_mask.call_args_list)

            lpf_path = mock_lowpass.call_args[1]["to"]
            mock_lowpass.assert_called_once_with(
                mask1_path,
                his=False,
                hrs=False,
                line=41,
                lis=False,
                null=True,
                sample=5,
                to=lpf_path,
            )

            hpf_path = mock_highpass.call_args[1]["to"]
            mock_highpass.assert_called_once_with(
                mask2_path, line=41, sample=1, to=hpf_path
            )

            alg_path = mock_algebra.call_args[1]["to"]
            mock_algebra.assert_called_once_with(
                A=1.0,
                B=1.0,
                from2=hpf_path,
                from_=lpf_path,
                operator="ADD",
                to=alg_path,
            )

            mock_handmos.assert_called_once_with(
                alg_path,
                create="NO",
                inband=1,
                inline=1,
                insample=1,
                mosaic=out_cube,
                outband=1,
                outline=1,
                outsample=1,
            )
예제 #10
0
def edr2stitch(images, conf_dir, bitflipwidth=0, lis_tolerance=1, keep=False):
    chids = list()
    for i in images:
        out_edr = util.path_w_suffix(".EDR_Stats.cub", i)

        # EDR_Stats
        db = EDR_Stats.EDR_Stats(i,
                                 out_edr,
                                 pvl.load(conf_dir /
                                          "EDR_Stats_gains_config.pvl"),
                                 keep=keep)

        # HiCal
        out_hical = util.path_w_suffix(".HiCal.cub", out_edr)

        db = HiCal.HiCal(
            out_edr,
            out_hical,
            db,
            HiCal.conf_setup(pvl.load(conf_dir / "HiCal.conf"),
                             pvl.load(conf_dir / "NoiseFilter.conf")),
            conf_dir / "HiCal.conf",
            None,
            None,
            bitflipwidth,
            lis_tolerance,
            keep=keep,
        )

        chids.append(ChannelCube(out_hical, db))

    # HiStitch
    # get Channel pairs
    cids = list()
    for chid1, chid2 in get_CCDpairs(chids):
        (db, o_path) = HiStitch.HiStitch(
            chid1.nextpath,
            chid2.nextpath,
            chid1.db,
            chid2.db,
            ".HiStitch.cub",
            pvl.load(conf_dir / "HiStitch.conf"),
            keep=keep,
        )
        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 SliterStats on the *slither.txt
    HiSlither.HiSlither(for_jitreg)

    return chids