def locate_file(refname, mode=None): """Given a valid reffilename in CDBS or CRDS format, return a cache path for the file. The aspect of this which is complicated is determining instrument and an instrument specific sub-directory for it based on the filename alone, not the file contents. """ if mode is None: mode = config.get_crds_ref_subdir_mode(observatory="jwst") if mode == "instrument": instrument = utils.file_to_instrument(refname) rootdir = locate_dir(instrument, mode) elif mode == "flat": rootdir = config.get_crds_refpath("jwst") else: raise ValueError("Unhandled reference file location mode " + repr(mode)) return os.path.join(rootdir, os.path.basename(refname))
def locate_file(refname, mode=None): """Given a valid reffilename in CDBS or CRDS format, return a cache path for the file. The aspect of this which is complicated is determining instrument and an instrument specific sub-directory for it based on the filename alone, not the file contents. The mode=None test case is disabled because it mysteriously causes these tests to fail when running the runtests script: ERROR: test_throughput_lookup_generation (crds.tests.test_synphot_lookup_generator.TestSynphotLookupGenerator) FAIL: Doctest: crds.tests.test_bad_files.dt_bad_references_fast_mode FAIL: Doctest: crds.tests.test_bad_files.dt_bad_rules_jwst_getreferences_warning FAIL: Doctest: crds.tests.test_certify.certify_recursive FAIL: Doctest: crds.tests.test_certify.certify_table_comparison_context FAIL: Doctest: crds.tests.test_heavy_client.dt_getreferences_ignore_cache FAIL: Doctest: crds.tests.test_list.dt_list_cached_references FAIL: Doctest: crds.tests.test_synphot_hst.dt_synphot_core_integration_test FAIL: Doctest: crds.tests.test_synphot_hst.dt_synphot_core_integration_test XXXX TODO: Enable the mode=None test case and resolve the ensuing test failures in other modules. >> locate_file('tests/data/roman_wfi16_f158_flat_small.asdf', None) # doctest: +ELLIPSIS '.../references/roman/wfi/roman_wfi16_f158_flat_small.asdf' >>> locate_file('tests/data/roman_wfi16_f158_flat_small.asdf', 'instrument') # doctest: +ELLIPSIS '.../references/roman/wfi/roman_wfi16_f158_flat_small.asdf' >>> locate_file('tests/data/roman_wfi16_f158_flat_small.asdf', 'flat') # doctest: +ELLIPSIS '.../references/roman/roman_wfi16_f158_flat_small.asdf' >>> locate_file('tests/data/roman_wfi16_f158_flat_small.asdf', 'other') # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: Unhandled reference file location mode 'other' """ if mode is None: mode = config.get_crds_ref_subdir_mode(observatory="roman") if mode == "instrument": instrument = utils.file_to_instrument(refname) rootdir = locate_dir(instrument, mode) elif mode == "flat": rootdir = config.get_crds_refpath("roman") else: raise ValueError("Unhandled reference file location mode " + repr(mode)) return os.path.join(rootdir, os.path.basename(refname))