diff --git a/gwsumm/data/coherence.py b/gwsumm/data/coherence.py index 6a1f7c2b..f3a2a4dc 100644 --- a/gwsumm/data/coherence.py +++ b/gwsumm/data/coherence.py @@ -286,8 +286,13 @@ def _get_coherence_spectrogram(channel_pair, segments, config=None, cxy, cxx, cyy = [_get_from_list( globalv.COHERENCE_COMPONENTS[ck], seg) for ck in ckeys] csg = abs(cxy)**2 / cxx / cyy - globalv.SPECTROGRAMS[key].append(csg) - globalv.SPECTROGRAMS[key].coalesce() + if not numpy.any(numpy.isnan(csg)): + globalv.SPECTROGRAMS[key].append(csg) + globalv.SPECTROGRAMS[key].coalesce() + else: + warnings.warn('NaN values found in the spectrogram.' + ' Spectrogram will not be appended to' + ' global memory value') if not return_: return diff --git a/gwsumm/data/spectral.py b/gwsumm/data/spectral.py index 48c9109b..680ca47a 100644 --- a/gwsumm/data/spectral.py +++ b/gwsumm/data/spectral.py @@ -239,12 +239,17 @@ def _get_spectrogram(channel, segments, config=None, cache=None, def add_spectrogram(specgram, key=None, coalesce=True): """Add a `Spectrogram` to the global memory cache """ - if key is None: - key = specgram.name or str(specgram.channel) - globalv.SPECTROGRAMS.setdefault(key, SpectrogramList()) - globalv.SPECTROGRAMS[key].append(specgram) - if coalesce: - globalv.SPECTROGRAMS[key].coalesce() + if not numpy.any(numpy.isnan(specgram)): + if key is None: + key = specgram.name or str(specgram.channel) + globalv.SPECTROGRAMS.setdefault(key, SpectrogramList()) + globalv.SPECTROGRAMS[key].append(specgram) + if coalesce: + globalv.SPECTROGRAMS[key].coalesce() + else: + warnings.warn('NaN values found in the spectrogram.' + ' Spectrogram will not be appended to' + ' global memory value') @use_segmentlist