Skip to content

Commit 741222b

Browse files
duplicate changes into jwst locate
1 parent 9dbc077 commit 741222b

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

crds/jwst/locate.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# =======================================================================
1717

18+
from crds import api
1819
from crds.core import rmap, config, utils, timestamp, log, exceptions
1920
from crds.certify import generic_tpn
2021
from crds import data_file
@@ -467,12 +468,35 @@ def locate_file(refname, mode=None, parameters=None):
467468
parameters = dict()
468469
if mode is None:
469470
mode = config.get_crds_ref_subdir_mode(observatory="jwst")
471+
470472
if mode == "instrument":
471-
try:
472-
instrument = utils.header_to_instrument(parameters)
473-
except KeyError:
474-
instrument = utils.file_to_instrument(refname)
475-
rootdir = locate_dir(instrument, mode)
473+
474+
# Check if the file is already in the local cache
475+
for instrument in INSTRUMENTS:
476+
if instrument != 'all':
477+
rootdir = locate_dir(instrument, mode)
478+
if os.path.exists(os.path.join(rootdir, os.path.basename(refname))):
479+
break
480+
else:
481+
rootdir = None
482+
483+
# Not in local cache. Try various other methods.
484+
if rootdir is None:
485+
try:
486+
instrument = utils.header_to_instrument(parameters)
487+
except KeyError:
488+
log.verbose('Cannot find instrument in header. Trying from file itself...', verbosity=80)
489+
try:
490+
instrument = utils.file_to_instrument(refname)
491+
except FileNotFoundError:
492+
log.verbose('Cannot find instrument from non-existent file.', verbosity=80)
493+
log.verbose('Attempt to contact server for meta information', verbosity=80)
494+
495+
# If there is a server, get the instrument from there.
496+
instrument = api.get_file_info(api.get_default_context(observatory='roman'), os.path.basename(refname))['instrument']
497+
498+
rootdir = locate_dir(instrument, mode)
499+
476500
elif mode == "flat":
477501
rootdir = config.get_crds_refpath("jwst")
478502
else:

0 commit comments

Comments
 (0)