Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if input tile files exist before looking in data folder. #98

Merged
merged 5 commits into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions py/desimodel/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
I/O utility functions for files in desimodel.
"""
import os
import sys
from astropy.io import fits
import yaml
import numpy as np
Expand Down Expand Up @@ -164,12 +165,34 @@ def load_tiles(onlydesi=True, extra=False, tilesfile=None, cache=True):
global _tiles

if tilesfile is None:
tilesfile = 'desi-tiles.fits'

#- Check if tilesfile includes a path (absolute or relative)
tilespath, filename = os.path.split(tilesfile)
if tilespath == '':
tilesfile = os.path.join(os.environ['DESIMODEL'],'data','footprint',filename)
# Use the default
tilesfile = os.path.join(
os.environ['DESIMODEL'], 'data', 'footprint', 'desi-tiles.fits')
else:
# Check if the file name exists locally
have_local = False
if os.path.isfile(tilesfile):
have_local = True
# Check if the file name exists in the package data directory
have_dmdata = False
check = os.path.join(os.environ['DESIMODEL'], 'data', 'footprint',
tilesfile)
if os.path.isfile(check):
have_dmdata = True
# Choose the file
if have_dmdata:
if have_local:
msg = 'File "{}" in $DESIMODEL/data is shadowed by a local'\
' file. Choosing $DESIMODEL file.'.format(tilesfile)
warnings.warn(msg)
tilesfile = check
elif not have_local:
msg = 'File "{}" does not exist locally or in $DESIMODEL/data'\
.format(tilesfile)
if sys.version_info.major == 2:
raise IOError(msg)
else:
raise FileNotFoundError(msg)

#- standarize path location
tilesfile = os.path.abspath(tilesfile.format(**os.environ))
Expand Down