Skip to content

Commit

Permalink
PR Comments
Browse files Browse the repository at this point in the history
	modified:   pypeit/core/wavecal/waveio.py
	modified:   pypeit/data/utils.py
  • Loading branch information
tbowers7 committed Nov 1, 2023
1 parent b083fc5 commit 5e92575
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
12 changes: 2 additions & 10 deletions pypeit/core/wavecal/waveio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
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, reid_path.suffix.replace('.','').lower()


def get_skisim_filepath(skisim_file: str) -> pathlib.Path:
Expand Down

0 comments on commit 5e92575

Please sign in to comment.