Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _try_priority_file_loaders(self, file_path):
fmts = self._get_matching_formats(file_path)
logging.warning("Loaders for '%s' matched for this data set. "
"Iterating based on priority."
"", ', '.join(fmts))
for fmt in fmts:
try:
speclist = SpectrumList.read(file_path, format=fmt)
return speclist
except IORegistryError:
logging.warning("Attempted load with '%s' failed, "
"trying next loader.", fmt)
raise IOError('Could not find appropriate loader for given file')
Format specified for the astropy io interface.
Returns
-------
: :class:`~specutils.SpectrumList`
A `~specutils.SpectrumList` instance containing the spectra loaded from the file
"""
# In the case that the user has selected auto load, loop through every
# available loader and choose the one that 1) the registry identifier
# function allows, and 2) is the highest priority.
try:
if file_loader:
if file_loader not in self._get_matching_formats(file_path):
msg = 'Given file can not be processed as specified file format ({})'
raise IOError(msg.format(file_loader))
speclist = SpectrumList.read(file_path, format=file_loader)
except IORegistryError as e:
# In this case, assume that the registry has found several
# loaders that fit the same identifier, choose the highest
# priority one.
speclist = self._try_priority_file_loaders(file_path)
return speclist