def make_flats(cubes, common_cube, conf, temp_token, keep=False): # If the flat files already exist, don't remake them. # "$OBS_ID"."_".$ccd."-".$common.".flat.tab" jitter_cubes = list() n_row = int( common_cube.lines / conf["AutoRegistration"]["ControlNet"]["Control_Lines"] ) for c in cubes: if c == common_cube: continue jitter_cubes.append( hjr.JitterCube( c.next_path, matchccd=common_cube.get_ccd(), config=conf ) ) successful_flats = list() if not all(x.flattab_path.exists() for x in jitter_cubes): confauto = conf["AutoRegistration"] for c in jitter_cubes: params = { "ROWS": n_row, "TOLERANCE": confauto["Algorithm"]["Tolerance"], } min_fraction_good = confauto["AnaylyzeFlat"]["Minimum_Good"] if c.ccdname == "RED": redcolor = "Red" else: redcolor = "Color" params["GROUP"] = "ResolveJitter" params["COLS"] = confauto["ControlNet"]["Control_Cols_" + redcolor] params["PATTERN_SAMPLES"] = confauto["PatternChip" + redcolor][ "Samples" ] params["PATTERN_LINES"] = confauto["PatternChip" + redcolor][ "Lines" ] params["SEARCH_SAMPLES"] = confauto["SearchChip" + redcolor][ "Samples" ] params["SEARCH_LINES"] = confauto["SearchChip" + redcolor]["Lines"] if c.ccdname != "RED": channels = isis.getkey_k( c.path, "Instrument", "StitchedProductIds" ) if len(channels) < 2: logger.info( f"Increasing columns because {c.path} is " "missing a channel." ) params["COLS"] += 1 min_fraction_good *= 0.5 logger.info( "The minimum allowable Fraction Good " f"Matches = {min_fraction_good}" ) step = 0 while step <= confauto["Algorithm"]["Steps"]: logger.info(f"Step {step} begin") hjr.run_HiJitReg( common_cube.next_path, c, params, temp_token, keep=keep ) ret = hjr.Analyze_Flat( c, 0, (min_fraction_good * 2), hijitreg=False ) if ret == 1: successful_flats.append(c.flattab_path) break else: step += 1 c.regdef_path.unlink() c.flattab_path.unlink() c.cnet_path.unlink() params["TOLERANCE"] -= ( confauto["Algorithm"]["Increment"] * step ) else: raise RuntimeError( f"Flat file for {c} is not within tolerances." ) else: successful_flats = list(x.flattab_path for x in jitter_cubes) return successful_flats
def test_run_HiJitReg(self, m_Path, m_hijitreg, m_cnetbin2pvl): hjr.run_HiJitReg(self.r.path, self.j, jitter_params, "foo", keep=True) m_hijitreg.assert_called_once() m_cnetbin2pvl.assert_called_once()