def test_combine_frames(files): img = np.full((100, 100), 10) ovscx = 5 for f in files: data = img + np.random.randint(0, 20, size=img.shape) head = fits.Header( cards={ "ESO DET OUT1 PRSCX": 0, "ESO DET OUT1 OVSCX": ovscx, "ESO DET OUT1 CONAD": 1, "ESO DET OUT1 RON": 0, "EXPTIME": 10, "RA": 100, "DEC": 51, "MJD-OBS": 12030, } ) fits.writeto(f, data=data, header=head) combine, chead = combine_frames.combine_frames(files, "UVES", "middle", 0, window=5) assert combine.shape[0] == img.shape[0] - ovscx assert combine.shape[1] == img.shape[1] assert chead["exptime"] == 10 * len(files)
def original(files, instrument, mode, mask): if len(files["curvature"]) == 0: return None, None files = files["curvature"] original, chead = combine_frames(files, instrument, mode, mask=mask) return original, chead
def test_bad_window_size(tempfiles): for f in tempfiles: create_file(f, 100, 100, 5) combine, chead = combine_frames.combine_frames(tempfiles, "UVES", "middle", 0, window=80) assert combine.shape[0] == 100 - 5 assert combine.shape[1] == 100 assert chead["exptime"] == len(tempfiles)
def test_normal_orientation(tempfiles): for f in tempfiles: create_file(f, 100, 100, 0) combine, chead = combine_frames.combine_frames(tempfiles, "CRIRES_PLUS", "J_2_3_OPEN", 0, window=10) assert combine.shape[0] == 100 assert combine.shape[1] == 100 assert chead["exptime"] == len(tempfiles)
def test_normal_orientation(tempfiles): for f in tempfiles: create_file(f, 100, 100, 0) combine, chead = combine_frames.combine_frames(tempfiles, "CRIRES_PLUS", "J1228_OPEN_det1", 0, window=10) assert combine.shape[ 0] == 100 - 10 # there is a 5 pixel cutoff on each side assert combine.shape[ 1] == 100 - 10 # there is a 5 pixel cutoff on each side assert chead["exptime"] == len(tempfiles)
def test_twofiles(tempfiles): tempfiles = tempfiles[:2] for f in tempfiles: create_file(f, 100, 100, 5) combine, chead = combine_frames.combine_frames(tempfiles, "UVES", "middle", 0, window=5) assert combine.shape[0] == 100 - 5 assert combine.shape[1] == 100 assert chead["exptime"] == len(tempfiles)
def test_onefile(tempfiles): tempfiles = tempfiles[:1] nx, ny = 110, 100 compare, head = create_file(tempfiles[0], nx, ny, 5) compare = np.rot90(compare, -1)[:-5] combine, chead = combine_frames.combine_frames(tempfiles, "UVES", "middle", 0, window=5) assert combine.shape[0] == nx - 5 assert combine.shape[1] == ny assert np.allclose(combine, compare) for key, value in head.items(): assert chead[key] == value
def test_orders(instr, instrument, mode, files, settings, mask): if len(files["orders"]) == 0: pytest.skip( f"No order definition files found for instrument {instrument}") order_img, _ = combine_frames(files["orders"], instrument, mode, mask=mask) settings = settings["orders"] orders, column_range = mark_orders( order_img, min_cluster=settings["min_cluster"], min_width=settings["min_width"], filter_size=settings["filter_size"], noise=settings["noise"], opower=settings["degree"], degree_before_merge=settings["degree_before_merge"], regularization=settings["regularization"], closing_shape=settings["closing_shape"], border_width=settings["border_width"], manual=False, auto_merge_threshold=settings["auto_merge_threshold"], merge_min_threshold=settings["merge_min_threshold"], sigma=settings["split_sigma"], plot=False, ) assert isinstance(orders, np.ndarray) assert np.issubdtype(orders.dtype, np.floating) assert orders.shape[1] == settings["degree"] + 1 assert isinstance(column_range, np.ndarray) assert np.issubdtype(column_range.dtype, np.integer) assert column_range.shape[1] == 2 assert np.all(column_range >= 0) assert np.all(column_range <= order_img.shape[1]) assert orders.shape[0] == column_range.shape[0]
def test_nofiles(): files = [] with pytest.raises(ValueError): combine_frames.combine_frames(files, "UVES", "middle", 0, window=5)