gwpy / gwsumm

Gravitational-wave interferometer summary information system
GNU General Public License v3.0
12 stars 23 forks source link

Fix spectrum plots for different states #403

Closed iaraota closed 5 months ago

iaraota commented 5 months ago

This PR addresses a bug related to computing the spectrum for different states. Previously, the same spectrogram was being plotted for different states despite having different segments, due to a global variable storing spectrum data with identical keys for all states. This issue has been resolved by introducing the state argument to the get_spectrum and get_spectrum_range functions, using the state name as a key to differentiate spectrum data.

The original intention behind the removed snippet below

if isinstance(segments, DataQualityFlag):   
    name = ','.join([channel.ndsname, segments.name])
    segments = segments.active
else:
    name = channel.ndsname

was to incorporate the state into the name variable. However, this condition always failed because of the decorator use_segmentlist, which was already reseting segments = segments.active, therefore making it impossible to insert the state in the name variable. With the introduction of the state variable, this redundant condition has been removed.

Additionally, the range spectrogram also required fixing as it failed to change with the state. The code introduced mirrors that used in _get_spectrogram to ensure the correct data is returned.

Example:

codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 15.38462% with 22 lines in your changes are missing coverage. Please review.

Project coverage is 49.56%. Comparing base (720bd0c) to head (8f6113b). Report is 3 commits behind head on master.

Files Patch % Lines
gwsumm/data/range.py 0.00% 18 Missing :warning:
gwsumm/data/spectral.py 66.67% 2 Missing :warning:
gwsumm/plot/builtin.py 0.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #403 +/- ## ========================================== - Coverage 49.64% 49.56% -0.08% ========================================== Files 60 60 Lines 8823 8828 +5 ========================================== - Hits 4380 4375 -5 - Misses 4443 4453 +10 ``` | [Flag](https://app.codecov.io/gh/gwpy/gwsumm/pull/403/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy) | Coverage Δ | | |---|---|---| | [Linux](https://app.codecov.io/gh/gwpy/gwsumm/pull/403/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy) | `49.56% <15.38%> (-0.08%)` | :arrow_down: | | [macOS](https://app.codecov.io/gh/gwpy/gwsumm/pull/403/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy) | `49.56% <15.38%> (?)` | | | [python3.10](https://app.codecov.io/gh/gwpy/gwsumm/pull/403/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy) | `49.56% <15.38%> (-0.08%)` | :arrow_down: | | [python3.11](https://app.codecov.io/gh/gwpy/gwsumm/pull/403/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy) | `49.56% <15.38%> (-0.08%)` | :arrow_down: | | [python3.9](https://app.codecov.io/gh/gwpy/gwsumm/pull/403/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy) | `49.56% <15.38%> (-0.08%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gwpy#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

eagoetz commented 5 months ago

@iaraota Thanks for finding the source of this bug! I think that we also need to fix the spectrograms, correct? For example, check out quiet and noisy state spectrograms here: https://ldas-jobs.ligo.caltech.edu/~detchar/summary/day/20240101/sei/bs/

iaraota commented 5 months ago

@iaraota Thanks for finding the source of this bug! I think that we also need to fix the spectrograms, correct? For example, check out quiet and noisy state spectrograms here: https://ldas-jobs.ligo.caltech.edu/~detchar/summary/day/20240101/sei/bs/

I didn't realize that, as the spectrogram for the strain works fine. I will have a look, thank you!

iaraota commented 5 months ago

@eagoetz I was looking into the problem of quiet and noise spectrograms and it seem to me that the problem is having a different definition for H1 and L1, in the configuration file we have:

[state-Quiet]
key = Quiet
name = SEI Quiet

[state-H1-Quiet]
name = SEI Quiet
key = H1-quiet
hours = 1-5,H1

[state-L1-Quiet]
name = SEI Quiet
key = L1-quiet
hours = 2-6,L1

And this page uses the state Quiet and intersect the options for L1 and H1, and that is causing the problem. For example, when using the state H1-quiet/noisy, the issue doesn't arise: https://ldas-jobs.ligo.caltech.edu/~iara.ota/summary/day/20240404/sei/bs

Thus, the issue does not lie within the get_spectrogram function, but rather in how the states are generated, considering the discrepancies between the two sites. In my view, this problem falls outside the scope of this PR and should be addressed separately in another PR.

eagoetz commented 5 months ago

@iaraota Yeah, I had a feeling it was more complicated, but at least we have some fixes for the spectra. Let's go ahead with this PR and continue working on the spectrogram issue in another PR