Skip to content

Commit

Permalink
Added a new "metastate" section type where one can combine states fro…
Browse files Browse the repository at this point in the history
…m different detectors

This fixes a problem where the "Quiet" and "Noisy" states were undefined in time, so the whole duration was used. This meant there was no distinction between the states as plotted for the summary pages.

A metastate would be defined as
```
[metastate-Quiet]
key = Quiet
name = SEI Quiet
uses = H1-quiet,L1-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
```

It is not super robust in that it's really only supposed to be used for combining some interval for H1 and some interval for L1. I'm not sure it's really ready to be heavily used in many situations

Addresses the comment in gwpy#358
  • Loading branch information
Evan Goetz committed Mar 16, 2023
1 parent 48150d1 commit 663fe76
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
5 changes: 4 additions & 1 deletion gwsumm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def load_states(self, section='states'):
"""Read and format a list of `SummaryState` definitions from the
given :class:`~configparser.ConfigParser`
"""
from .state import (register_state, SummaryState,
from .state import (register_state, SummaryState, SummaryMetaState,
ALLSTATE, generate_all_state, get_state)
# parse the [states] section into individual state definitions
try:
Expand All @@ -327,6 +327,9 @@ def load_states(self, section='states'):
if re.match(r'state[-\s]', section):
states.append(register_state(
SummaryState.from_ini(self, section)))
elif re.match(r'metastate[-\s]', section):
states.append(register_state(
SummaryMetaState.from_ini(self, section)))

# register All state
start = self.getint(section, 'gps-start-time')
Expand Down
5 changes: 4 additions & 1 deletion gwsumm/plot/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from ..data import (get_timeseries, get_spectrogram,
get_coherence_spectrogram, get_range_spectrogram,
get_spectrum, get_coherence_spectrum, get_range_spectrum)
from ..state import ALLSTATE
from ..state import ALLSTATE, SummaryMetaState
from .registry import (get_plot, register_plot)
from .mixins import DataLabelSvgMixin

Expand Down Expand Up @@ -508,6 +508,9 @@ def _draw(self):
else:
valid = SegmentList([self.span])

if isinstance(valid, SummaryMetaState):
valid = globalv.STATES[f'{channel.ifo}-{valid.uses[0][3:]}'.lower()]

if self.type == 'coherence-spectrum':
data = get_coherence_spectrum(
[str(channel), str(channel2)], valid, query=False)
Expand Down
4 changes: 2 additions & 2 deletions gwsumm/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"""

from .core import SummaryState
from .core import (SummaryState, SummaryMetaState)
from .registry import (get_state, get_states, register_state)
from .all import (ALLSTATE, generate_all_state)

__all__ = ['ALLSTATE', 'SummaryState', 'get_state', 'get_states',
'register_state', 'generate_all_state']
'register_state', 'generate_all_state', 'SummaryMetaState']
42 changes: 42 additions & 0 deletions gwsumm/state/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,45 @@ def copy(self):

def __str__(self):
return self.name


class SummaryMetaState(SummaryState):
"""A meta state where different states may be used"""

def __init__(self, name, known=SegmentList(), active=SegmentList(),
description=None, definition=None, hours=None, key=None,
filename=None, url=None, uses=[]):

super(SummaryMetaState, self).__init__(
name=name, known=known, active=active,
description=description, definition=definition, hours=hours,
key=key, filename=filename, url=url)

self.uses = uses

@classmethod
def from_ini(cls, config, section):
config = GWSummConfigParser.from_configparser(config)
# get parameters
params = dict(config.nditems(section))
# parse name
name = params.pop('name', section)
if re.match(r'metastate[-\s]', name):
name = section[10:]
# list states this uses
uses = params.pop('uses', section).split(',')

# generate metastate
return cls(name=name, uses=uses, **params)

def fetch(self, config=GWSummConfigParser(),
segmentcache=None, segdb_error='raise',
datacache=None, datafind_error='raise', nproc=1, nds=None,
**kwargs):

for idx, state in enumerate(self.uses):
globalv.STATES[state.lower()].fetch(
config=config, segmentcache=segmentcache,
segdb_error=segdb_error, datacache=datacache,
datafind_error=datafind_error, nproc=nproc, nds=nds,
**kwargs)
16 changes: 13 additions & 3 deletions gwsumm/tabs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
from ..data.utils import get_fftparams
from ..plot import get_plot
from ..segments import get_segments
from ..state import (generate_all_state, ALLSTATE, get_state)
from ..state import (generate_all_state, ALLSTATE, get_state,
SummaryMetaState)
from ..triggers import get_triggers
from ..utils import (re_flagdiv, vprint, safe_eval)

Expand Down Expand Up @@ -357,11 +358,20 @@ def process(self, config=ConfigParser(), nproc=1, **stateargs):
nproc=nproc, nds=stateargs.get('nds', None))
vprint("States finalised [%d total]\n" % len(self.states))
for state in self.states:
vprint(" {0.name}: {1} segments | {2} seconds".format(
state, len(state.active), abs(state.active)))
if isinstance(state, SummaryMetaState):
vprint(
f"Metastate {state.key} has {len(state.uses)} states")
else:
vprint(" {0.name}: {1} segments | {2} seconds".format(
state, len(state.active), abs(state.active)))
if state is self.defaultstate:
vprint(" [DEFAULT]")
vprint('\n')
if isinstance(state, SummaryMetaState):
for idx, this_state in enumerate(state.uses):
vprint(f" {this_state}: ")
vprint(f"{len(globalv.STATES[this_state.lower()].active)} segments | ")
vprint(f"{abs(globalv.STATES[this_state.lower()].active)} seconds\n")

# pre-process requests for 'all-data' plots
all_data = any([(p.all_data & p.new) for p in self.plots])
Expand Down

0 comments on commit 663fe76

Please sign in to comment.