diff --git a/pypeit/core/wavecal/autoid.py b/pypeit/core/wavecal/autoid.py index 334c3223fe..f36d9d4e6b 100644 --- a/pypeit/core/wavecal/autoid.py +++ b/pypeit/core/wavecal/autoid.py @@ -1053,6 +1053,10 @@ def full_template(spec, lamps, par, ok_mask, det, binspectral, nsnippet=2, slit_ # Load template if template_dict is None: + # Error checking + if par['reid_arxiv'] is None: + msgs.error('WavelengthSolutionPar parameter `reid_arxiv` not ' + 'specified for "full_template" method.') temp_wv, temp_spec, temp_bin = waveio.load_template( par['reid_arxiv'], det, wvrng=par['wvrng_arxiv']) else: diff --git a/pypeit/core/wavecal/waveio.py b/pypeit/core/wavecal/waveio.py index e765ebe90a..5760d72907 100644 --- a/pypeit/core/wavecal/waveio.py +++ b/pypeit/core/wavecal/waveio.py @@ -50,7 +50,7 @@ def load_wavelength_calibration(filename: pathlib.Path) -> dict: return wv_calib -def load_template(arxiv_file, det, wvrng=None): +def load_template(arxiv_file:str, det:int, wvrng:list=None)->tuple[np.ndarray,np.ndarray,int]: """ Load a full template file from disk @@ -73,13 +73,8 @@ def load_template(arxiv_file, det, wvrng=None): binning of the template arc spectrum """ - # 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..cba62b0153 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, arxiv_file.split('.')[-1].lower() def get_skisim_filepath(skisim_file: str) -> pathlib.Path: