def solve_field( image_files: Union[str, list], base_filename: str = "astrometry", overwrite: bool = True, tweak: bool = True, search_radius: units.Quantity = 1 * units.degree, centre: SkyCoord = None, guess_scale: bool = True, time_limit: units.Quantity = None, verify: bool = True, odds_to_tune_up: float = 1e6, odds_to_solve: float = 1e9, *flags, **params): """ Returns True if successful (by checking whether the corrected file is generated); False if not. :param image_files: :param base_filename: :param overwrite: :param flags: :param params: :return: """ params["o"] = base_filename params["odds-to-tune-up"] = odds_to_tune_up params["odds-to-solve"] = odds_to_solve if time_limit is not None: params["l"] = check_quantity(time_limit, units.second).value if search_radius is not None: params["radius"] = search_radius.to(units.deg).value if centre is not None: params["ra"] = centre.ra.to(units.deg).value params["dec"] = centre.dec.to(units.deg).value debug_print(1, "solve_field(): tweak ==", tweak) flags = list(flags) if overwrite: flags.append("O") if guess_scale: flags.append("g") if not tweak: flags.append("T") if not verify: flags.append("y") system_command("solve-field", image_files, False, True, False, *flags, **params) if isinstance(image_files, list): image_path = image_files[0] else: image_path = image_files check_dir = os.path.split(image_path)[0] check_path = os.path.join(check_dir, f"{base_filename}.new") print(f"Checking for result file at {check_path}...") return os.path.isfile(check_path)
def make_header(table_path: str, output_path: str): """ Executes Montage task mMakeHdr <table_path> <output_path> :param table_path: :param output_path: :return: """ u.sanitise_file_ext(output_path, ".hdr") return u.system_command("mMakeHdr", [table_path, output_path])
def build_astrometry_index(input_fits_catalog: str, unique_id: int, output_index: str = None, scale_number: int = 0, sort_column: str = 'mag', scan_through_catalog: bool = True, *flags, **params): print(input_fits_catalog) params["i"] = input_fits_catalog params["I"] = unique_id if output_index is not None: params["o"] = output_index if scale_number is not None: params["P"] = scale_number if sort_column is not None: params["s"] = sort_column flags = list(flags) if scan_through_catalog: flags.append("E") system_command("build-astrometry-index", None, False, True, *flags, **params)
def image_table(input_directory: str, output_path: str = "images.tbl"): """ Executes the Montage task mImgtbl <input_directory> <output_path> :param input_directory: :param output_path: :return: """ u.sanitise_file_ext(filename=output_path, ext=".tbl") return u.system_command("mImgtbl", [input_directory, output_path])
def psfex(catalog: str, output_name: str = None, output_dir: str = None, **kwargs): old_dir = os.getcwd() if output_dir is None: output_dir = os.getcwd() else: os.chdir(output_dir) if output_name is None: cat_name = os.path.split(catalog)[-1] output_name = cat_name.replace(".fits", ".psf") system_command(command="psfex", arguments=[catalog], force_single_dash=True, **kwargs) os.chdir(old_dir) psfex_path = os.path.join(output_dir, output_name) return psfex_path
def overlaps(table_path: str, difference_table_path: str): """ Executes mOverlaps <table_path> <difference_table_path> :param table_path: :param difference_table_path: :return: """ table_path = u.sanitise_file_ext(filename=table_path, ext=".tbl") difference_table_path = u.sanitise_file_ext(filename=difference_table_path, ext=".tbl") return u.system_command(command="mOverlaps", arguments=[table_path, difference_table_path])
def fit_execute(difference_table_path: str, fit_table_path: str, diff_dir: str): """ Executes mFitExec <difference_table_path> <fit_table_path> <diff_dir> :param difference_table_path: :param fit_table_path: :param diff_dir: :return: """ difference_table_path = u.sanitise_file_ext(filename=difference_table_path, ext=".tbl") fit_table_path = u.sanitise_file_ext(filename=fit_table_path, ext=".tbl") return u.system_command( command="mFitExec", arguments=[difference_table_path, fit_table_path, diff_dir])
def difference_execute(input_directory: str, difference_table_path: str, header_path: str, diff_dir: str): """ Executes mDiffExec <difference_table_path> <header_file> <diff_dir> -p <input_directory> :param input_directory: :return: """ difference_table_path = u.sanitise_file_ext(filename=difference_table_path, ext=".tbl") header_path = u.sanitise_file_ext(filename=header_path, ext=".hdr") return u.system_command( command="mDiffExec", arguments=[difference_table_path, header_path, diff_dir], p=input_directory, )
def background_model(table_path: str, fit_table_path: str, correction_table_path: str): """ Executes mBGModel <table_path> <fit_table_path> <correction_table_path> :param table_path: :param fit_table_path: :param correction_table_path: :return: """ table_path = u.sanitise_file_ext(filename=table_path, ext=".tbl") fit_table_path = u.sanitise_file_ext(filename=fit_table_path, ext=".tbl") correction_table_path = u.sanitise_file_ext(filename=correction_table_path, ext=".tbl") return u.system_command( command="mBgModel", arguments=[table_path, fit_table_path, correction_table_path])
def background_execute(input_directory: str, table_path: str, correction_table_path: str, corr_dir: str): """ Executes mBgExec <table_path> <corrections_table_path> <corr_dir> -p <input_directory> :param input_directory: :param table_path: :param correction_table_path: :param corr_dir: :return: """ table_path = u.sanitise_file_ext(filename=table_path, ext=".tbl") correction_table_path = u.sanitise_file_ext(filename=correction_table_path, ext=".tbl") return u.system_command( command="mBgExec", arguments=[table_path, correction_table_path, corr_dir], p=input_directory)
def project_execute(input_directory: str, table_path: str, header_path: str, proj_dir: str, stats_table_path: str): """ Executes mProjExec <table_path> <header_path> <proj_dir> <stats_table_path> -p <input_directory> :param input_directory: :param table_path: :param header_path: :param proj_dir: :param stats_table_path: :return: """ table_path = u.sanitise_file_ext(filename=table_path, ext=".tbl") header_path = u.sanitise_file_ext(filename=header_path, ext=".hdr") stats_table_path = u.sanitise_file_ext(filename=stats_table_path, ext=".tbl") return u.system_command( command="mProjExec", arguments=[table_path, header_path, proj_dir, stats_table_path], p=input_directory)
def add(input_directory: str, table_path: str, header_path: str, output_path: str = "coadded.fits", coadd_type: str = 'median'): """ Executes mAdd <table_path> <template_path> <output_path> -p <input_directory> -a <coadd_type> :param input_directory: :param table_path: :param header_path: :param output_path: :param coadd_type: :return: """ table_path = u.sanitise_file_ext(filename=table_path, ext=".tbl") header_path = u.sanitise_file_ext(filename=header_path, ext=".hdr") output_path = u.sanitise_file_ext(filename=output_path, ext=".fits") return u.system_command(command="mAdd", arguments=[table_path, header_path, output_path], p=input_directory, a=coadd_type)