Skip to content

Commit

Permalink
Properly handle empty dictionary in get_range_spectrogram (#407)
Browse files Browse the repository at this point in the history
* properly handle empty dictionary

* remove extra line

* fix lint

---------

Co-authored-by: Iara Ota <iara.ota@ligo.org>
  • Loading branch information
iaraota and Iara Ota committed Apr 18, 2024
1 parent dfaf81e commit 93fa5d8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions gwsumm/data/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,20 @@ def get_range_spectrogram(channel, segments, config=None, cache=None,

# return correct data, according to state segment
out = SpectrogramList()
for specgram in globalv.SPECTROGRAMS[key]:
for seg in segments:
if abs(seg) < specgram.dt.value:
continue
if specgram.span.intersects(seg):
common = specgram.span & type(seg)(seg[0],
seg[1] + specgram.dt.value)
s = specgram.crop(*common)
if s.shape[0]:
out.append(s)
try:
for specgram in globalv.SPECTROGRAMS[key]:
for seg in segments:
if abs(seg) < specgram.dt.value:
continue
if specgram.span.intersects(seg):
common = specgram.span & type(seg)(
seg[0], seg[1] + specgram.dt.value)
s = specgram.crop(*common)
if s.shape[0]:
out.append(s)
except KeyError:
# in case the key does not exist return empty SpectrogramList
return out
return out.coalesce()


Expand Down

0 comments on commit 93fa5d8

Please sign in to comment.