Skip to content

Commit

Permalink
Update segments module to handle incoming changes from gwpy DataQuali…
Browse files Browse the repository at this point in the history
…tyDict updates
  • Loading branch information
Evan Goetz committed Dec 13, 2024
1 parent 41c4049 commit 332d620
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
52 changes: 22 additions & 30 deletions gwsumm/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,12 @@
)

__author__ = 'Duncan Macleod <[email protected]>'

SEGDB_URLS = [
'https://segdb.ligo.caltech.edu',
'https://metaserver.phy.syr.edu',
'https://geosegdb.atlas.aei.uni-hannover.de',
'http://10.20.50.30' # geosegdb internal
]
__credits__ = 'Evan Goetz <[email protected]>'


def get_segments(flag, validity=None, config=ConfigParser(), cache=None,
query=True, return_=True, coalesce=True, padding=None,
ignore_undefined=False, segdb_error='raise', url=None,
ignore_undefined=False, segdb_error='raise', host=None,
**read_kw):
"""Retrieve the segments for a given flag
Expand All @@ -83,8 +77,8 @@ def get_segments(flag, validity=None, config=ConfigParser(), cache=None,
- ``gps-start-time``, and ``gps-end-time``, if ``validity`` is
not given
- ``url`` (the remote hostname for the segment database) if
the ``url`` keyword is not given
- ``host`` (the remote hostname for the segment database) if
the ``host`` keyword is not given
cache : :class:`glue.lal.Cache`, optional
a cache of files from which to read segments, otherwise segments
Expand All @@ -111,7 +105,7 @@ def get_segments(flag, validity=None, config=ConfigParser(), cache=None,
segments
- ``'ignore'`` : silently ignore the error and return no segments
url : `str`, optional
host : `str`, optional
the remote hostname for the target segment database
return_ : `bool`, optional, default: `True`
Expand Down Expand Up @@ -211,40 +205,38 @@ def get_segments(flag, validity=None, config=ConfigParser(), cache=None,
new[f].active &= newsegs
if coalesce:
new[f].coalesce()
vprint(" Read %d segments for %s (%.2f%% coverage).\n"
% (len(new[f].active), f,
float(abs(new[f].known))/float(abs(newsegs))*100))
cov = float(abs(new[f].known))/float(abs(newsegs))*100
vprint(f" Read {len(new[f].active)} segments for "

Check warning on line 209 in gwsumm/segments.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/segments.py#L208-L209

Added lines #L208 - L209 were not covered by tests
f"{f} ({cov:.2f}%% coverage).\n")
else:
if len(newsegs) >= 10:
qsegs = span
else:
qsegs = newsegs
# parse configuration for query
kwargs = {}
if url is not None:
kwargs['url'] = url
if host is not None:
kwargs['host'] = host

Check warning on line 219 in gwsumm/segments.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/segments.py#L219

Added line #L219 was not covered by tests
else:
try:
kwargs['url'] = config.get('segment-database', 'url')
kwargs['host'] = config.get('segment-database', 'host')
except (NoSectionError, NoOptionError):
pass
if kwargs.get('url', None) in SEGDB_URLS:
query_func = DataQualityDict.query_segdb
else:
query_func = DataQualityDict.query_dqsegdb
try:
new = query_func(allflags, qsegs, on_error=segdb_error,
**kwargs)
new = DataQualityDict.query_dqsegdb(
allflags,
qsegs,
on_error=segdb_error,
**kwargs)
except Exception as e:
# ignore error from SegDB
if segdb_error in ['ignore', None]:
pass
# convert to warning
elif segdb_error in ['warn']:
print('%sWARNING: %sCaught %s: %s [gwsumm.segments]'
% (WARNC, ENDC, type(e).__name__, str(e)),
file=sys.stderr)
warnings.warn('%s: %s' % (type(e).__name__, str(e)))
print(f"{WARNC}WARNING: {ENDC}Caught {type(e).__name__}: "

Check warning on line 237 in gwsumm/segments.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/segments.py#L237

Added line #L237 was not covered by tests
f"{str(e)} [gwsumm.segments]", file=sys.stderr)
warnings.warn(f"{type(e).__name__}: {str(e)}")

Check warning on line 239 in gwsumm/segments.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/segments.py#L239

Added line #L239 was not covered by tests
# otherwise raise as normal
else:
raise
Expand All @@ -254,9 +246,9 @@ def get_segments(flag, validity=None, config=ConfigParser(), cache=None,
new[f].active &= newsegs
if coalesce:
new[f].coalesce()
vprint(" Downloaded %d segments for %s (%.2f%% coverage).\n"
% (len(new[f].active), f,
float(abs(new[f].known))/float(abs(newsegs))*100))
cov = float(abs(new[f].known))/float(abs(newsegs))*100
vprint(f" Downloaded {len(new[f].active)} segments for "
f"{f} ({cov:.2f}%% coverage).\n")
# record new segments
globalv.SEGMENTS += new
for f in new:
Expand Down
9 changes: 6 additions & 3 deletions gwsumm/state/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ class SummaryState(DataQualityFlag):
logical combination of flags that define known and active segments
for this state (see :attr:`documentation <SummaryState.definition>`
for details)
hours : optional
key : `str`, optional
registry key for this state, defaults to :attr:`~SummaryState.name`
filename : `str`, optional
host : `str`, optional
"""
MATH_DEFINITION = re.compile(r'(%s)' % '|'.join(MATHOPS.keys()))

def __init__(self, name, known=SegmentList(), active=SegmentList(),
description=None, definition=None, hours=None, key=None,
filename=None, url=None):
filename=None, host=None):
"""Initialise a new `SummaryState`
"""
# allow users to specify known as (start, end)
Expand All @@ -88,7 +91,7 @@ def __init__(self, name, known=SegmentList(), active=SegmentList(),
self.definition = None
self.key = key
self.hours = hours
self.url = url
self.host = host
if known and active:
self.ready = True
else:
Expand Down Expand Up @@ -244,7 +247,7 @@ def from_ini(cls, config, section):
return cls(name, known=[(start, end)], hours=hours, **params)

def _fetch_segments(self, config=GWSummConfigParser(), **kwargs):
kwargs.setdefault('url', self.url)
kwargs.setdefault('host', self.host)

Check warning on line 250 in gwsumm/state/core.py

View check run for this annotation

Codecov / codecov/patch

gwsumm/state/core.py#L250

Added line #L250 was not covered by tests
segs = get_segments([self.definition], self.known, config=config,
**kwargs)[self.definition].round(contract=True)
self.known = segs.known
Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ classifiers = [
]

dependencies = [
"astropy >=3.0.0",
"astropy >=5.0.0",
"dqsegdb2 >=1.2.0",
"gwdatafind >=1.1.1",
"gwdetchar >=2.2.7",
"gwpy >=2.0.0, <=3.0.8",
"gwpy >=3.0.10",
"gwtrigfind",
"lalsuite",
"ligo-segments",
"lscsoft-glue >=1.60.0",
"lxml",
"markdown",
"MarkupPy",
"matplotlib >=3.5",
"numpy >=1.16,<2.0",
"matplotlib >=3.1.0,<=3.7.1",
"numpy >=1.19.5",
"pygments >=2.7.0",
"python-dateutil",
"python-ligo-lw",
"scipy >=1.2.0, <1.14",
"scipy >=1.6.0",
]

dynamic = ["version"]
Expand Down

0 comments on commit 332d620

Please sign in to comment.