Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import crds
from crds import CrdsLookupError
if download:
try:
reffile_mapping = crds.getreferences(parameter_dict, reftypes=reffile_types)
except CrdsLookupError as e:
raise ValueError("ERROR: CRDSLookupError when trying to find reference files for parameters: {}".format(parameter_dict))
else:
# If the files will not be downloaded, still return the same local
# paths that are returned when the files are downloaded. Note that
# this follows the directory structure currently assumed by CRDS.
crds_path = os.environ.get('CRDS_PATH')
try:
reffile_mapping = crds.getrecommendations(parameter_dict, reftypes=reffile_types)
except CrdsLookupError as e:
raise ValueError("ERROR: CRDSLookupError when trying to find reference files for parameters: {}".format(parameter_dict))
for key, value in reffile_mapping.items():
# Check for NOT FOUND must be done here because the following
# line will raise an exception if NOT FOUND is present
if "NOT FOUND" in value:
reffile_mapping[key] = "NOT FOUND"
else:
instrument = value.split('_')[1]
reffile_mapping[key] = os.path.join(crds_path, 'references/jwst', instrument, value)
return reffile_mapping