Skip to content

Commit

Permalink
Ignore nan spectrogram values (#410)
Browse files Browse the repository at this point in the history
* dont sava nan spectrogram values

* avoid nan coherence specgrams

* add warning

* fix lint

* Apply suggestions from code review

Co-authored-by: Evan Goetz <[email protected]>

* Update gwsumm/data/coherence.py

* Update gwsumm/data/spectral.py

---------

Co-authored-by: Iara Ota <[email protected]>
Co-authored-by: Evan Goetz <[email protected]>
  • Loading branch information
3 people authored May 22, 2024
1 parent 105a704 commit 4ecb502
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions gwsumm/data/coherence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions gwsumm/data/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4ecb502

Please sign in to comment.