def test_clean(global_datadir): fits_file = global_datadir / "test.fits" clean_param = { "isz": 79, "r1": 35, "dr": 2, "apod": True, "window": 65, "f_kernel": 3, "add_bad": [[39, 39]], } cube_clean = amical.select_clean_data(fits_file, clip=True, **clean_param) amical.show_clean_params(fits_file, **clean_param) amical.show_clean_params(fits_file, **clean_param, remove_bad=False) im1 = amical.data_processing._apply_patch_ghost( cube_clean, 40, 40, radius=20, dx=3, dy=3, method="zero" ) im2 = amical.data_processing._apply_patch_ghost( cube_clean, 40, 40, radius=20, dx=3, dy=3, method="bg" ) assert type(cube_clean) == np.ndarray assert im1.shape == cube_clean.shape assert im2.shape == cube_clean.shape
file_c = os.path.join(datadir, 'HD142695_IRD_SCIENCE_DBI_LEFT_CUBE.fits') # ---------------------------------- # Cleaning step # ---------------------------------- clean_param = {'isz': 149, 'r1': 70, 'dr': 2, 'apod': True, 'window': 65, 'f_kernel': 3 } amical.check_data_params(file_t, **clean_param) cube_t = amical.select_clean_data(file_t, clip=True, **clean_param, display=True) cube_c = amical.select_clean_data(file_c, clip=True, **clean_param, display=True) # AMI parameters (refer to the docstrings of `extract_bs` for details) params_ami = {"peakmethod": 'fft', "bs_multi_tri": False, "maskname": "g7", "fw_splodge": 0.7, "filtname": 'K1' } # # Extract raw complex observables for the target and the calibrator: # # It's the core of the pipeline (amical/mf_pipeline/bispect.py)
def perform_clean(args): """Clean the data with AMICAL.""" cprint("---- AMICAL clean process ----", "cyan") clean_param = { "isz": args.isz, "r1": args.r1, "dr": args.dr, "apod": args.apod, "window": args.window, "f_kernel": args.kernel, } if not os.path.exists(args.datadir): print( "%s directory not found, check --datadir. AMICAL look for data only in this specified directory." % args.datadir) return 1 l_file = sorted(glob("%s/*.fits" % args.datadir)) if len(l_file) == 0: print("No fits files found in %s, check --datadir." % args.datadir) return 1 if not args.all: filename, hdr = _select_data_file(args, process="clean") if args.check: amical.show_clean_params(filename, **clean_param) plt.show(block=True) return 0 if not os.path.exists(args.outdir): os.mkdir(args.outdir) clean_param["clip"] = args.clip clean_param["sky"] = args.sky if args.all: # Clean all files in --datadir for f in tqdm(l_file, ncols=100, desc="# files"): hdr = fits.open(f)[0].header hdr["HIERARCH AMICAL step"] = "CLEANED" cube = amical.select_clean_data(f, **clean_param, display=True) f_clean = os.path.join(args.outdir, Path(f).stem + "_cleaned.fits") fits.writeto(f_clean, cube, header=hdr, overwrite=True) else: # Or clean just the specified file (in --datadir) hdr["HIERARCH AMICAL step"] = "CLEANED" now = datetime.now() dt_string = now.strftime("%d/%m/%Y %H:%M:%S") hdr["HIERARCH AMICAL time"] = dt_string for k in clean_param: hdr["HIERARCH AMICAL params %s" % k] = clean_param[k] cube = amical.select_clean_data(filename, **clean_param, display=True) if args.plot: plt.show() f_clean = os.path.join(args.outdir, Path(filename).stem + "_cleaned.fits") fits.writeto(f_clean, cube, header=hdr, overwrite=True) return 0