def test_simple(tempfiles): n = 2 files = tempfiles[:n] for i in range(n): data = np.full((100, 100), 5, dtype=float) fits.writeto(files[i], data) flat, fhead = combine_flat(files, "common", "", extension=0) assert isinstance(flat, np.ndarray) assert flat.shape[0] == 100 assert flat.shape[1] == 100 assert np.all(flat == 5 * n) n = 6 files = tempfiles[:n] for i in range(n): data = np.full((200, 100), 5, dtype=float) fits.writeto(files[i], data, overwrite=True) flat, fhead = combine_flat(files, "common", "", extension=0, window=50) assert isinstance(flat, np.ndarray) assert flat.shape[0] == 200 assert flat.shape[1] == 100 assert np.all(flat == 5 * n)
def test_flat(instrument, mode, files, mask): if len(files["flat"]) == 0: pytest.skip(f"No flat files for instrument {instrument}") flat, fhead = combine_flat(files["flat"], instrument, mode, window=50, mask=mask) assert isinstance(flat, np.ma.masked_array) assert isinstance(fhead, fits.Header) assert flat.ndim == 2 assert flat.shape[0] > 1 assert flat.shape[1] > 1
def flat(instrument, mode, files, extension, mask, bias, output_dir): """Load or if necessary create the flat field calibration data Parameters ---------- instrument : str instrument name mode : str observing mode files : dict(str:str) calibration file names extension : int fits data extension mask : array(bool) Bad pixel mask bias : array(float) bias calibration data output_dir : str output directory Returns ------- flat : array(float) flat field calibration data fhead : fits.header flat information """ flatfile = os.path.join(output_dir, "test_flat.fits") try: flat = fits.open(flatfile) fhead, flat = flat[0].header, flat[0].data flat = np.ma.masked_array(flat, mask=mask) except FileNotFoundError: bias, _ = bias flat, fhead = combine_flat( files["flat"], instrument, mode, extension=extension, bias=bias, window=50, mask=mask, ) fits.writeto(flatfile, data=flat.data, header=fhead, overwrite=True) return flat, fhead
def test_flat(instrument, mode, files, extension, mask): flat, fhead = combine_flat( files["flat"], instrument, mode, extension=extension, bias=0, window=50, mask=mask, ) assert isinstance(flat, np.ma.masked_array) assert isinstance(fhead, fits.Header) assert flat.ndim == fhead["NAXIS"] assert flat.shape[0] == fhead["NAXIS1"] - 100 # remove window from both sides assert flat.shape[1] == fhead["NAXIS2"]
base_dir=base_dir, input_dir=input_dir, output_dir=output_dir, configuration=config, # order_range=(0, 25), ) files = data[0]["files"] mask = data[0]["mask"] bias, bhead = data[0]["bias"] orders, column_range = data[0]["orders"] wave, coef, linelist = data[0]["wavecal"] xwd = config["wavecal"]["extraction_width"] nrow, ncol = bias.shape nord = len(orders) xwd, column_range, orders = fix_parameters(xwd, column_range, orders, nrow, ncol, nord) orig, _ = combine_flat( files["wavecal_master"], instrument, mode, extension, mask=mask, bias=bias, bhead=bhead, ) ref = make_reference_spectrum(linelist, nrow, ncol, nord) plot_comparison(orig, orders, ref, None, xwd, column_range)