Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state bar #416

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions 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, SummaryState)
from .registry import (get_plot, register_plot)
from .mixins import DataLabelSvgMixin

Expand Down Expand Up @@ -95,13 +95,23 @@
method.
"""
# allow user to disable the state segments axes

state = self.state

Check warning on line 99 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L99

Added line #L99 was not covered by tests
# If the state is not set or is set to "All",
# update the state to match the statebar's state.
# This allows the statebar's state to be included
# as a segment in the time series plot.
if isinstance(self.statebar, SummaryState) and (

Check warning on line 104 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L104

Added line #L104 was not covered by tests
state is None or (state.name.lower() == ALLSTATE)):
state = self.statebar

Check warning on line 106 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L106

Added line #L106 was not covered by tests

if self.pargs.pop('no-state-segments', False):
visible = False
if visible is None and self.state is not None and (
self.state.name.lower() != ALLSTATE):
if visible is None and state is not None and (

Check warning on line 110 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L110

Added line #L110 was not covered by tests
state.name.lower() != ALLSTATE):
visible = True
if visible:
sax = self.plot.add_segments_bar(self.state, ax, height=.14,
sax = self.plot.add_segments_bar(state, ax, height=.14,

Check warning on line 114 in gwsumm/plot/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/plot/builtin.py#L114

Added line #L114 was not covered by tests
pad=.1, **kwargs)
sax.tick_params(axis='y', which='major', labelsize=12)
sax.yaxis.set_ticks_position('none')
Expand Down
4 changes: 3 additions & 1 deletion gwsumm/plot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ class DataPlot(SummaryPlot):

def __init__(self, channels, start, end, state=None, outdir='.',
tag=None, pid=None, href=None, new=True, all_data=False,
read=True, fileformat='png', caption=None, **pargs):
read=True, fileformat='png', caption=None, statebar=None,
**pargs):
super(DataPlot, self).__init__(href=href, new=new, caption=caption)
if isinstance(channels, str):
channels = split_channels(channels)
self.channels = channels
self.span = (start, end)
self.state = state
self.statebar = statebar
self._outdir = outdir
if tag is not None:
self.tag = tag
Expand Down
27 changes: 26 additions & 1 deletion gwsumm/tabs/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
"""
type = 'state'

def __init__(self, name, states=list(), **kwargs):
def __init__(self, name, states=list(), statebar=None, **kwargs):
"""Initialise a new `Tab`.
"""
if kwargs.get('mode', None) is None:
Expand All @@ -609,6 +609,9 @@
states = [states]
self.states = states

# process statebar
self.statebar = statebar

# -------------------------------------------
# StateTab properties

Expand Down Expand Up @@ -665,6 +668,16 @@
def defaultstate(self, state):
self._defaultstate = state

@property
def statebar(self):
return self._statebar

@statebar.setter
def statebar(self, state):
if not isinstance(state, SummaryState) and state is not None:
state = get_state(state)

Check warning on line 678 in gwsumm/tabs/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/tabs/builtin.py#L678

Added line #L678 was not covered by tests
self._statebar = state

@property
def frames(self):
# write page for each state
Expand All @@ -689,6 +702,18 @@
else:
# otherwise use 'all' state - full span with no gaps
kwargs.setdefault('states', ['All'])

# Load statebar, used for adding a state segment to a timeseries plot.
# This is only applied to the "All" or unassigned (None) state.
if cp.has_option(section, 'statebar'):
# statebar should be a single element
# if a list is given, consider just the first element
kwargs.setdefault(

Check warning on line 711 in gwsumm/tabs/builtin.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/tabs/builtin.py#L711

Added line #L711 was not covered by tests
'statebar', [re_quote.sub('', s).strip() for s in
cp.get(section, 'statebar').split(',')][0])
else:
kwargs.setdefault('statebar', None)

# parse core Tab information
return super(StateTab, cls).from_ini(cp, section, *args, **kwargs)

Expand Down
24 changes: 18 additions & 6 deletions gwsumm/tabs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@
if type_:
plot = PlotClass.from_ini(cp, pdef, start, end, sources,
state=None, outdir=plotdir,
**mods)
statebar=job.statebar, **mods)
else:
plot = PlotClass(sources, start, end, state=None,
outdir=plotdir, **mods)
statebar=job.statebar, outdir=plotdir,
**mods)
job.plots.append(plot)
if subidx == index:
for span in subplots:
Expand All @@ -305,10 +306,12 @@
if type_:
plot = PlotClass.from_ini(cp, pdef, start, end,
sources, state=state,
statebar=job.statebar,
outdir=plotdir, **mods)
else:
plot = PlotClass(sources, start, end, state=state,
outdir=plotdir, **mods)
statebar=job.statebar, outdir=plotdir,
**mods)
job.plots.append(plot)
if subidx == index:
for span in subplots:
Expand All @@ -334,6 +337,10 @@
allstate.fetch(config=config, segdb_error=segdb_error, **kwargs)
for state in self.states:
state.fetch(config=config, segdb_error=segdb_error, **kwargs)
# finilize statebar
if self.statebar is not None:
self.statebar.fetch(config=config, segdb_error=segdb_error,

Check warning on line 342 in gwsumm/tabs/data.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/tabs/data.py#L342

Added line #L342 was not covered by tests
**kwargs)

def process(self, config=ConfigParser(), nproc=1, **stateargs):
"""Process data for this tab
Expand All @@ -356,13 +363,18 @@
segdb_error=stateargs.get('segdb_error', 'raise'),
datafind_error=stateargs.get('datafind_error', 'raise'),
nproc=nproc, nds=stateargs.get('nds', None))
vprint("States finalised [%d total]\n" % len(self.states))
vprint(f"States finalised [{len(self.states) + len([self.statebar])}"
" total]\n")
for state in self.states:
vprint(" {0.name}: {1} segments | {2} seconds".format(
state, len(state.active), abs(state.active)))
vprint(f" {state.name}: {len(state.active)} segments"
f" | {abs(state.active)} seconds")
if state is self.defaultstate:
vprint(" [DEFAULT]")
vprint('\n')
if self.statebar is not None:
vprint(f" {self.statebar.name}: {len(self.statebar.active)}"

Check warning on line 375 in gwsumm/tabs/data.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/tabs/data.py#L375

Added line #L375 was not covered by tests
f" segments | {abs(state.active)} seconds")
vprint('\n')

Check warning on line 377 in gwsumm/tabs/data.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/tabs/data.py#L377

Added line #L377 was not covered by tests

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