Skip to content

Commit

Permalink
Merge pull request #148 from alurban/gwdetchar-2.0.0
Browse files Browse the repository at this point in the history
Take advantage of changes introduced in gwdetchar-2.0.0
  • Loading branch information
Alex L. Urban authored Dec 13, 2020
2 parents 7ed4989 + 8a04218 commit b49a6d7
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 35 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ install:
- travis_retry conda install --quiet --yes --update-all --name hvetoci --file conda-reqs.txt
# clean up
- rm -f conda-reqs.txt parse-conda-requirements.py
# install this version
- python -m pip install .

script:
# run flake8
- python -m flake8 .
# run test suite
- python -m coverage run -m pytest --pyargs hveto
- python -m coverage run -m pytest --verbose --pyargs hveto
# test executables
- python -m coverage run --append --source hveto -m hveto --help
- python -m coverage run --append --source hveto -m hveto.cli.cache_events --help
Expand Down
8 changes: 7 additions & 1 deletion hveto/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@

IFO = os.getenv('IFO')
JOBSTART = time.time()
LOGGER = cli.logger(name='hveto')

# set up logger
PROG = ('python -m hveto' if sys.argv[0].endswith('.py')
else os.path.basename(sys.argv[0]))
LOGGER = cli.logger(name=PROG.split('python -m ').pop())

__author__ = 'Duncan Macleod <[email protected]>'
__credits__ = ('Joshua Smith <[email protected]>, '
Expand Down Expand Up @@ -125,6 +129,7 @@ def create_parser():
"""Create a command-line parser for this entry point
"""
parser = cli.create_parser(
prog=PROG,
description=__doc__,
version=__version__,
)
Expand Down Expand Up @@ -245,6 +250,7 @@ def main(args=None):
htmlv = {
'title': '%s Hveto | %d-%d' % (ifo, start, end),
'config': None,
'prog': PROG,
'context': ifo.lower(),
}

Expand Down
13 changes: 9 additions & 4 deletions hveto/cli/cache_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
as given in the configuration files
"""

import h5py
import os
import warnings
import multiprocessing
from pathlib import Path
import sys
import warnings

import h5py
from pathlib import Path

from astropy.table import vstack

Expand Down Expand Up @@ -57,7 +58,10 @@

IFO = os.getenv('IFO')

LOGGER = cli.logger(name='hveto.cache_events')
# set up logger
PROG = ('python -m hveto.cli.cache_events' if sys.argv[0].endswith('.py')
else os.path.basename(sys.argv[0]))
LOGGER = cli.logger(name=PROG.split('python -m ').pop())


# -- parse command line -------------------------------------------------------
Expand All @@ -70,6 +74,7 @@ def create_parser():
"""Create a command-line parser for this entry point
"""
parser = cli.create_parser(
prog=PROG,
description=__doc__,
version=__version__,
)
Expand Down
7 changes: 6 additions & 1 deletion hveto/cli/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

__author__ = 'Joshua Smith <[email protected]>'

PROG = ('python -m hveto.cli.trace' if sys.argv[0].endswith('.py')
else os.path.basename(sys.argv[0]))


# -- parse command line -------------------------------------------------------

Expand All @@ -42,6 +45,7 @@ def create_parser():
"""Create a command-line parser for this entry point
"""
parser = cli.create_parser(
prog=PROG,
description=__doc__,
version=__version__,
)
Expand Down Expand Up @@ -80,7 +84,8 @@ def main(args=None):
args = parser.parse_args(args=args)
directory = args.directory

logger = cli.logger(name='hveto.trace', level=args.loglevel)
logger = cli.logger(name=PROG.split('python -m ').pop(),
level=args.loglevel)
logger.debug('Running in verbose mode')
logger.debug('Search directory: %s' % directory)

Expand Down
12 changes: 8 additions & 4 deletions hveto/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ def decorated_func(ifo, start, end, *args, **kwargs):
else:
iargs = initargs.copy()
aboutdir = os.path.join(outdir, 'about')
prog = kwargs.pop('prog', None)
if iargs['base'] == os.path.curdir:
iargs['base'] = os.path.pardir
about = write_about_page(ifo, start, end, config, outdir=aboutdir,
**iargs)
about = write_about_page(
ifo, start, end, config, prog=prog, outdir=aboutdir, **iargs)
if os.path.basename(about) == 'index.html':
about = about[:-10]
# open page
Expand Down Expand Up @@ -410,7 +411,7 @@ def write_null_page(reason, context='info'):


@wrap_html
def write_about_page(configfile):
def write_about_page(configfile, prog=None):
"""Write a page explaining how an hveto analysis was completed
Parameters
Expand All @@ -423,6 +424,9 @@ def write_about_page(configfile):
the GPS end time of the analysis
configfile : `str`
the path of the configuration file to embed
prog : `str`, optional
name of the program which produced this page, defaults to
the script run on the command-line
outdir : `str`, optional
the output directory for the HTML
Expand All @@ -431,4 +435,4 @@ def write_about_page(configfile):
index : `str`
the path of the HTML written for this analysis
"""
return gwhtml.about_this_page(configfile)
return gwhtml.about_this_page(configfile, prog=prog)
22 changes: 15 additions & 7 deletions hveto/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"""Tests for `hveto.plot`
"""

import os
import pytest
import tempfile
import shutil

from numpy import random

Expand All @@ -31,14 +32,21 @@


@pytest.mark.parametrize('num', (10, 50, 200))
def test_drop_plot(num):
def test_drop_plot(num, tmpdir):
random.seed(0)
outdir = str(tmpdir)
# this test just makes sure the drop plot code runs end-to-end
channels = ['X1:TEST-%d' % i for i in range(num)]
old = dict(zip(channels, random.normal(size=num)))
new = dict(zip(channels, random.normal(size=num)))
with tempfile.NamedTemporaryFile(suffix='.png') as png:
plot.significance_drop(png.name, old, new)

with tempfile.NamedTemporaryFile(suffix='.svg') as svg:
plot.significance_drop(svg.name, old, new)
# test PNG files
plot.significance_drop(os.path.join(outdir, 'test.png'),
old, new)
# test SVG files, which raise UserWarnings
with pytest.warns(UserWarning) as record:
plot.significance_drop(os.path.join(outdir, 'test.svg'),
old, new)
for rec in record:
assert rec.message.args[0].startswith("Failed to recover tooltip")
# clean up
shutil.rmtree(outdir, ignore_errors=True)
19 changes: 10 additions & 9 deletions hveto/tests/test_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
"""

import os
import pytest
import shutil
from tempfile import NamedTemporaryFile
from unittest import mock

import pytest
from unittest import mock

from gwpy.segments import (Segment, SegmentList,
DataQualityFlag, DataQualityDict)
Expand Down Expand Up @@ -57,12 +56,14 @@ def test_query(dqflag):


@pytest.mark.parametrize('ncol', (2, 4))
def test_write_segments_ascii(ncol):
with NamedTemporaryFile(suffix='.txt', delete=False) as tmp:
segments.write_ascii(tmp.name, TEST_SEGMENTS, ncol=ncol)
tmp.delete = True
a = SegmentList.read(tmp.name, gpstype=float, strict=False)
assert a == TEST_SEGMENTS_2
def test_write_segments_ascii(ncol, tmpdir):
outdir = str(tmpdir)
out = os.path.join(outdir, 'test.txt')
segments.write_ascii(out, TEST_SEGMENTS, ncol=ncol)
a = SegmentList.read(out, gpstype=float, strict=False)
assert a == TEST_SEGMENTS_2
# clean up
shutil.rmtree(outdir, ignore_errors=True)


def test_write_segments_ascii_failure():
Expand Down
2 changes: 1 addition & 1 deletion hveto/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def find_auxiliary_channels(etg, gps='*', ifo='*', cache=None):


def _sanitize_name(name):
return re.sub("[-_\.]", "_", name).lower() # noqa: W605
return re.sub(r"[-_\.]", "_", name).lower()


def _format_params(channel, etg, fmt, trigfind_kwargs, read_kwargs):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# development
gwdetchar >= 1.1.0
gwdetchar >= 2.0.0
gwpy >= 2.0.0
gwtrigfind
lxml
Expand All @@ -9,6 +9,6 @@ numpy >= 1.10
python-ligo-lw >= 1.5.0
scipy
# testing
coverage
flake8
pytest >= 3.1.0
coverage
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ python_requires = >=3.6
setup_requires =
setuptools >=30.3.0
install_requires =
gwdetchar >= 1.1.0
gwdetchar >= 2.0.0
gwpy >=2.0.0
gwtrigfind
lxml
Expand All @@ -58,9 +58,9 @@ install_requires =
python-ligo-lw >= 1.5.0
scipy
tests_require =
coverage
flake8
pytest >=3.1.0
coverage

[options.entry_points]
console_scripts =
Expand All @@ -78,7 +78,7 @@ doc =

[tool:pytest]
; print skip reasons
addopts = --verbose -r s
addopts = -r s

; -- tools ------------------

Expand Down

0 comments on commit b49a6d7

Please sign in to comment.