Skip to content

Commit

Permalink
Merge pull request #98 from desihub/tilepath
Browse files Browse the repository at this point in the history
Check if input tile files exist before looking in data folder.
  • Loading branch information
sbailey committed Feb 11, 2019
2 parents 236bd07 + d3d67d6 commit b3178e7
Showing 1 changed file with 29 additions and 6 deletions.
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

0 comments on commit b3178e7

Please sign in to comment.