Skip to content

Commit

Permalink
Merge pull request #1716 from pypeit/reidarxiv_err_msg
Browse files Browse the repository at this point in the history
Hotfix: Improve error message when `reid_arxiv` file missing
  • Loading branch information
kbwestfall authored Nov 2, 2023
2 parents f0ec8e0 + 75c14bc commit 6733b52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 4 additions & 0 deletions pypeit/core/wavecal/autoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 3 additions & 8 deletions pypeit/core/wavecal/waveio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
22 changes: 17 additions & 5 deletions pypeit/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 6733b52

Please sign in to comment.