From 5e925752dd56536f0afcfda1757d4b0d86a89c25 Mon Sep 17 00:00:00 2001 From: "Timothy P. Ellsworth Bowers" Date: Wed, 1 Nov 2023 10:01:29 -0700 Subject: [PATCH] PR Comments modified: pypeit/core/wavecal/waveio.py modified: pypeit/data/utils.py --- pypeit/core/wavecal/waveio.py | 12 ++---------- pypeit/data/utils.py | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pypeit/core/wavecal/waveio.py b/pypeit/core/wavecal/waveio.py index 3b437e4c60..5760d72907 100644 --- a/pypeit/core/wavecal/waveio.py +++ b/pypeit/core/wavecal/waveio.py @@ -73,16 +73,8 @@ def load_template(arxiv_file:str, det:int, wvrng:list=None)->tuple[np.ndarray,np binning of the template arc spectrum """ - if not isinstance(arxiv_file, (str, pathlib.Path)) or arxiv_file is None or arxiv_file == "": - msgs.error(f"Incorrect or nonexistant arxiv file specified: {arxiv_file}") - - # Path already included? - if pathlib.Path(arxiv_file).name == arxiv_file: - calibfile, _ = data.get_reid_arxiv_filepath(arxiv_file) - else: - calibfile = pathlib.Path(arxiv_file) - # Read me - tbl = astropy.table.Table.read(calibfile, format='fits') + calibfile, fmt = data.get_reid_arxiv_filepath(arxiv_file) + tbl = astropy.table.Table.read(calibfile, format=fmt) # Parse on detector? if 'det' in tbl.keys(): idx = np.where(tbl['det'].data & 2**det)[0] diff --git a/pypeit/data/utils.py b/pypeit/data/utils.py index 263eb52872..41c32c7c53 100644 --- a/pypeit/data/utils.py +++ b/pypeit/data/utils.py @@ -211,18 +211,30 @@ def get_reid_arxiv_filepath(arxiv_file: str) -> tuple[pathlib.Path, str]: version of PypeIt). Args: - arxiv_file (str): + arxiv_file (:obj:`str`): The base filename of the ``reid_arxiv`` file to be located Returns: tuple: The full path and whether the path is in the cache: - * reid_path (:obj:`pathlib.Path`): The full path to the ``reid_arxiv`` file + * reid_path (:obj:`~pathlib.Path`): The full path to the ``reid_arxiv`` file * arxiv_fmt (:obj:`str`): The extension of the ``reid_arxiv`` file (format) """ - # Full path within the package data structure: + # First check that what is passed in works + if not isinstance(arxiv_file, (str, pathlib.Path)): + msgs.error(f"Incorrect or non-existent arxiv file specified: {arxiv_file}") + if isinstance(arxiv_file, pathlib.Path): + arxiv_file = str(arxiv_file) + + # Check if the `arxiv_file` already comes with a full path + if (reid_path := pathlib.Path(arxiv_file)).name != arxiv_file: + # Check existence, return it with format + if not reid_path.is_file(): + msgs.error(f"Incorrect or non-existent arxiv file specified: {reid_path}") + return reid_path, reid_path.suffix.replace('.','').lower() + + # Else, full path within the package data structure: reid_path = Paths.reid_arxiv / arxiv_file - arxiv_fmt = arxiv_file.split(".")[-1].lower() # Check if the file does NOT exist in the package directory # NOTE: This should be the case for all but from-source installations @@ -235,7 +247,7 @@ def get_reid_arxiv_filepath(arxiv_file: str) -> tuple[pathlib.Path, str]: reid_path = fetch_remote_file(arxiv_file, "arc_lines/reid_arxiv") # Return the path to the `reid_arxiv` file, and the file format - return reid_path, arxiv_fmt + return reid_path, reid_path.suffix.replace('.','').lower() def get_skisim_filepath(skisim_file: str) -> pathlib.Path: