Skip to content

Commit 2f2ab9b

Browse files
committed
source_residuals: do not filter by runid if not all residuals have a runid attribute
1 parent aa6ee0f commit 2f2ab9b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

sourcespec/source_residuals.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,20 @@ def _filter_by_runid(residual_dict, runid='latest'):
9393
"""
9494
if runid is None:
9595
return residual_dict
96+
# Residuals generated by older versions of SourceSpec may not have a runid
97+
# attribute. In this case, we cannot filter by runid.
98+
if not all(
99+
hasattr(spec.stats, 'runid')
100+
for spec_st in residual_dict.values()
101+
for spec in spec_st
102+
):
103+
print(
104+
'Warning: not all residuals have a "runid" attribute. '
105+
'Filtering by runid will not be applied.'
106+
)
107+
return residual_dict
96108
if not isinstance(runid, str):
97-
raise ValueError("runid must be a string.")
109+
raise ValueError('runid must be a string.')
98110
filt_residual_dict = defaultdict(SpectrumStream)
99111
if runid not in ['latest', 'earliest']:
100112
for spec_st in residual_dict.values():
@@ -166,8 +178,7 @@ def read_residuals(resfiles_dir, runid=None, exclude_subdirs=[]):
166178
residual_st = read_spectra(resfile)
167179
for spec in residual_st:
168180
residual_dict[spec.id].append(spec)
169-
#return _filter_by_runid(residual_dict, runid)
170-
return residual_dict
181+
return _filter_by_runid(residual_dict, runid)
171182

172183

173184
def compute_mean_residuals(residual_dict, min_spectra=20):

0 commit comments

Comments
 (0)