def fors_photometry(aligned_phot: List[str], master_sky_flat_img: str, output_dir: str, output_filename: str = None, chip_num: int = 1, sof_name: str = "photometry.sof"): sof_name = u.sanitise_file_ext(sof_name, ".sof") old_dir = os.getcwd() os.chdir(output_dir) sof_path = os.path.join(output_dir, sof_name) phot_table = select_phot_table(chip_num) sof( { "MASTER_SKY_FLAT_IMG": [master_sky_flat_img], "ALIGNED_PHOT": aligned_phot, "PHOT_TABLE": [os.path.join(fors2_calib_path, phot_table)], }, sof_path) u.system_command_verbose( f"{eso_bin_path} fors_photometry --fite=one {sof_path}") master_path = os.path.join(output_dir, "phot_coeff_table.fits") if output_filename is not None: final_path = os.path.join(output_dir, output_filename) shutil.move(master_path, final_path) else: final_path = master_path os.chdir(old_dir) return final_path
def disco( redux_dir: str, tags: list = None, expression: str = None, output: str = None, file_glob: str = "*_skySubtracted.fits", refcat: str = None, refcat_format: str = None, #"ascii.csv", refcat_ra: str = None, refcat_dec: str = None, ignore_objcat: bool = False): # Switch working directory to reduction directory. pwd = os.getcwd() os.chdir(redux_dir) ds_str = build_data_select_str(tags=tags, expression=expression, file_glob=file_glob) sys_str = f"disco `{ds_str}`" if output is not None: if os.path.isfile(output): os.remove(output) sys_str += f" -o {output}" if refcat is not None: if refcat_ra is not None or refcat_dec is not None: filename = os.path.split(refcat)[-1] refcat_tbl = Table.read(refcat, format=refcat_format) if refcat_ra is not None: refcat_tbl["RA"] = refcat_tbl[refcat_ra] refcat_tbl.remove_column(refcat_ra) if refcat_dec is not None: refcat_tbl["DEC"] = refcat_tbl[refcat_dec] refcat_tbl.remove_column(refcat_dec) refcat_tbl.write(os.path.join(redux_dir, filename), overwrite=True) refcat = filename sys_str += f" --refcat_columns RA,DEC" sys_str += f" --refcat {refcat}" if refcat_format is not None: sys_str += f" --refcat_format {refcat_format}" if ignore_objcat: sys_str += " --ignore_objcat" u.system_command_verbose(sys_str) os.chdir(pwd)
def source_extractor( image_path: str, output_dir: str = None, configuration_file: str = None, parameters_file: str = None, catalog_name: str = None, copy_params: bool = True, template_image_path: str = None, **configs): """ :param configs: Any source-extractor (sextractor) parameter, normally read via the config file but that can be overridden by passing to the shell command, can be given here. """ if "gain" in configs: configs["gain"] = u.check_quantity(number=configs["gain"], unit=gain_unit).to(gain_unit).value old_dir = os.getcwd() if output_dir is None: output_dir = os.getcwd() else: u.mkdir_check(output_dir) os.chdir(output_dir) if copy_params: os.system(f"cp {os.path.join(p.path_to_config_psfex(), '*')} .") sys_str = "source-extractor " if template_image_path is not None: sys_str += f"{template_image_path}," sys_str += image_path + " " if configuration_file is not None: sys_str += f" -c {configuration_file}" if catalog_name is None: image_name = os.path.split(image_path)[-1] catalog_name = f"{image_name}.cat" sys_str += f" -CATALOG_NAME {catalog_name}" if parameters_file is not None: sys_str += f" -PARAMETERS_NAME {parameters_file}" for param in configs: sys_str += f" -{param.upper()} {configs[param]}" u.system_command_verbose(sys_str, error_on_exit_code=True) catalog_path = os.path.join(output_dir, catalog_name) os.chdir(old_dir) return catalog_path
def fors_bias(bias_frames: List[str], output_dir: str, output_filename: str = None, sof_name: str = "bias.sof"): sof_name = u.sanitise_file_ext(sof_name, ".sof") old_dir = os.getcwd() os.chdir(output_dir) sof_path = os.path.join(output_dir, sof_name) sof({"BIAS": bias_frames}, sof_path) u.system_command_verbose(f"{eso_bin_path} fors_bias {sof_path}") master_path = os.path.join(output_dir, "master_bias.fits") if output_filename is not None: final_path = os.path.join(output_dir, output_filename) shutil.move(master_path, final_path) else: final_path = master_path os.chdir(old_dir) return final_path
def fors_zeropoint( standard_img: str, master_bias: str, master_sky_flat_img: str, output_dir: str, output_filename: str = None, chip_num: int = 1, sof_name: str = "zeropoint.sof", flux_std_imgs: List[str] = fors_flux_std_imgs, ): sof_name = u.sanitise_file_ext(sof_name, ".sof") old_dir = os.getcwd() os.chdir(output_dir) sof_path = os.path.join(output_dir, sof_name) phot_table = select_phot_table(chip_num) sof( { "STANDARD_IMG": [standard_img], "MASTER_BIAS": [master_bias], "MASTER_SKY_FLAT_IMG": [master_sky_flat_img], "FLX_STD_IMG": list( map(lambda f: os.path.join(fors2_calib_path, f), flux_std_imgs)), "PHOT_TABLE": [os.path.join(fors2_calib_path, phot_table)], }, sof_path) u.system_command_verbose(f"{eso_bin_path} fors_zeropoint {sof_path}") master_path = os.path.join(output_dir, "aligned_phot.fits") std_path = os.path.join(output_dir, "standard_reduced_img.fits") if output_filename is not None: final_path = os.path.join(output_dir, output_filename) shutil.move(master_path, final_path) else: final_path = master_path os.chdir(old_dir) return final_path, std_path
def fors_img_sky_flat(flat_frames: List[str], master_bias: str, output_dir: str, output_filename: str = None, sof_name: str = "flat.sof"): sof_name = u.sanitise_file_ext(sof_name, ".sof") old_dir = os.getcwd() os.chdir(output_dir) sof_path = os.path.join(output_dir, sof_name) sof({ "SKY_FLAT_IMG": flat_frames, "MASTER_BIAS": [master_bias], }, sof_path) u.system_command_verbose(f"{eso_bin_path} fors_img_sky_flat {sof_path}") master_path = os.path.join(output_dir, "master_sky_flat_img.fits") if output_filename is not None: final_path = os.path.join(output_dir, output_filename) shutil.move(master_path, final_path) else: final_path = master_path os.chdir(old_dir) return final_path
def data_select(redux_dir: str, directory: str, file_glob: str = "*.fits", tags: list = None, expression: str = None, output: str = None): # Switch working directory to reduction directory. pwd = os.getcwd() os.chdir(redux_dir) sys_str = build_data_select_str(directory=directory, file_glob=file_glob, tags=tags, expression=expression, output=output) u.system_command_verbose(sys_str) data_list = None if output is not None: with open(output) as data_file: data_list = data_file.read() os.chdir(pwd) return data_list