Skip to content

Commit

Permalink
Merge branch 'develop' into duncanmmacleod-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncan Macleod committed Mar 12, 2018
2 parents 8ed71f7 + d67d608 commit 029e5f5
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 88 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*.swp

# build files/directories to ignore
/dist/
/build/
/.cache/
/losc.egg-info/
/*.egg-info/
/.eggs/
__pycache__/
/.coverage
8 changes: 4 additions & 4 deletions losc/__init__.py → gwopensci/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright Duncan Macleod 2017
#
# This file is part of LOSC-Python.
# This file is part of GWOpenSci.
#
# LOSC-Python is free software: you can redistribute it and/or modify
# GWOpenSci is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LOSC-Python is distributed in the hope that it will be useful,
# GWOpenSci is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LOSC-Python. If not, see <http://www.gnu.org/licenses/>.
# along with GWOpenSci. If not, see <http://www.gnu.org/licenses/>.

from ._version import get_versions

Expand Down
4 changes: 2 additions & 2 deletions losc/_version.py → gwopensci/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def get_config():
cfg.VCS = "git"
cfg.style = "pep440"
cfg.tag_prefix = "v"
cfg.parentdir_prefix = "losc"
cfg.versionfile_source = "losc/_version.py"
cfg.parentdir_prefix = "gwopensci"
cfg.versionfile_source = "gwopensci/_version.py"
cfg.verbose = False
return cfg

Expand Down
8 changes: 4 additions & 4 deletions losc/api.py → gwopensci/api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright Duncan Macleod 2018
#
# This file is part of LOSC-Python.
# This file is part of GWOpenSci.
#
# LOSC-Python is free software: you can redistribute it and/or modify
# GWOpenSci is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LOSC-Python is distributed in the hope that it will be useful,
# GWOpenSci is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LOSC-Python. If not, see <http://www.gnu.org/licenses/>.
# along with GWOpenSci. If not, see <http://www.gnu.org/licenses/>.

import contextlib
import json
Expand Down
8 changes: 4 additions & 4 deletions losc/locate.py → gwopensci/locate.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright Duncan Macleod 2017
#
# This file is part of LOSC-Python.
# This file is part of GWOpenSci.
#
# LOSC-Python is free software: you can redistribute it and/or modify
# GWOpenSci is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LOSC-Python is distributed in the hope that it will be useful,
# GWOpenSci is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LOSC-Python. If not, see <http://www.gnu.org/licenses/>.
# along with GWOpenSci. If not, see <http://www.gnu.org/licenses/>.

"""Locate files within a given interval on losc.ligo.org
"""
Expand Down
82 changes: 41 additions & 41 deletions losc/test_losc.py → gwopensci/test_gwopensci.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright Duncan Macleod 2018
#
# This file is part of LOSC-Python.
# This file is part of GWOpenSci.
#
# LOSC-Python is free software: you can redistribute it and/or modify
# GWOpenSci is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LOSC-Python is distributed in the hope that it will be useful,
# GWOpenSci is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LOSC-Python. If not, see <http://www.gnu.org/licenses/>.
# along with GWOpenSci. If not, see <http://www.gnu.org/licenses/>.

"""Unit tests for python-losc
"""Unit tests for gwopensci
These tests can be executed using `python setup.py test`
"""
Expand All @@ -25,12 +25,12 @@

import pytest

from losc import (
api as losc_api,
locate as losc_locate,
timeline as losc_timeline,
urls as losc_urls,
utils as losc_utils,
from gwopensci import (
api as gwopensci_api,
locate as gwopensci_locate,
timeline as gwopensci_timeline,
urls as gwopensci_urls,
utils as gwopensci_utils,
)


Expand All @@ -43,19 +43,19 @@ def check_json_url_list(urllist, keys={'detector', 'format', 'url'}):

@pytest.fixture
def gw150914_urls(scope='module'):
return losc_api.fetch_event_json('GW150914')['strain']
return gwopensci_api.fetch_event_json('GW150914')['strain']


@pytest.fixture
def gw170817_urls(scope='module'):
return losc_api.fetch_event_json('GW170817')['strain']
return gwopensci_api.fetch_event_json('GW170817')['strain']


# -- losc.api -----------------------------------------------------------------
# -- gwopensci.api-------------------------------------------------------------

def test_api_fetch_json():
url = 'https://losc.ligo.org/archive/1126257414/1126261510/json/'
out = losc_api.fetch_json(url)
out = gwopensci_api.fetch_json(url)
assert isinstance(out, dict)
assert len(out['events']) == 1
assert sorted(out['events']['GW150914']['detectors']) == ['H1', 'L1']
Expand All @@ -64,22 +64,22 @@ def test_api_fetch_json():
# check errors (use legit URL that isn't JSON)
url2 = os.path.dirname(os.path.dirname(url))
with pytest.raises(ValueError) as exc:
losc_api.fetch_json(url2)
gwopensci_api.fetch_json(url2)
assert str(exc.value).startswith(
"Failed to parse LOSC JSON from {!r}: ".format(url2))


def test_api_fetch_dataset_json():
start = 934000000
end = 934100000
out = losc_api.fetch_dataset_json(start, end)
out = gwopensci_api.fetch_dataset_json(start, end)
assert not out['events']
assert set(out['runs'].keys()) == {'tenyear', 'S6'}


def test_api_fetch_event_json():
event = 'GW150914'
out = losc_api.fetch_event_json(event)
out = gwopensci_api.fetch_event_json(event)
assert int(out['GPS']) == 1126259462
assert out['dataset'] == event
check_json_url_list(out['strain'])
Expand All @@ -90,49 +90,49 @@ def test_api_fetch_run_json():
detector = 'L1'
start = 934000000
end = 934100000
out = losc_api.fetch_run_json(run, detector, start, end)
out = gwopensci_api.fetch_run_json(run, detector, start, end)
assert out['dataset'] == run
assert out['GPSstart'] == start
assert out['GPSend'] == end
check_json_url_list(out['strain'])


# -- losc.locate --------------------------------------------------------------
# -- gwopensci.locate ---------------------------------------------------------

def test_get_urls():
# test simple fetch for S6 data returns only files within segment
detector = 'L1'
start = 934000000
end = 934100000
span = (start, end)
urls = losc_locate.get_urls(detector, start, end)
urls = gwopensci_locate.get_urls(detector, start, end)
for url in urls:
assert os.path.basename(url).startswith(
'{}-{}'.format(detector[0], detector))
assert losc_utils.segments_overlap(
losc_utils.url_segment(url), span)
assert gwopensci_utils.segments_overlap(
gwopensci_utils.url_segment(url), span)


def test_get_event_urls(gw150914_urls):
# find latest version by brute force
latestv = sorted(
losc_urls.LOSC_URL_RE.match(
gwopensci_urls.URL_REGEX.match(
os.path.basename(u['url'])).groupdict()['version'] for
u in gw150914_urls)[-1]

event = 'GW150914'
urls = losc_locate.get_event_urls(event)
urls = gwopensci_locate.get_event_urls(event)
for url in urls:
assert url.endswith('.hdf5') # default format
assert '_4_' in url # default sample rate
assert '_{}-'.format(latestv) in url # highest matched version

urls = losc_locate.get_event_urls(event, version=1)
urls = gwopensci_locate.get_event_urls(event, version=1)
for url in urls:
assert '_V1-' in url


# -- losc.timeline ------------------------------------------------------------
# -- gwopensci.timeline -------------------------------------------------------

@pytest.mark.parametrize('flag, start, end, result', [
('H1_DATA', 1126051217, 1126151217, [
Expand All @@ -147,49 +147,49 @@ def test_get_event_urls(gw150914_urls):
])
])
def test_timeline_get_segments(flag, start, end, result):
assert losc_timeline.get_segments(flag, start, end) == result
assert gwopensci_timeline.get_segments(flag, start, end) == result


# -- losc.urls ----------------------------------------------------------------
# -- gwopensci.urls -----------------------------------------------------------

def test_urls_sieve(gw150914_urls):
nfiles = len(gw150914_urls)
sieved = list(losc_urls.sieve(gw150914_urls, detector='L1'))
sieved = list(gwopensci_urls.sieve(gw150914_urls, detector='L1'))
assert len(sieved) == nfiles // 2
sieved = list(losc_urls.sieve(gw150914_urls, detector='L1',
sieved = list(gwopensci_urls.sieve(gw150914_urls, detector='L1',
sample_rate=4096))
assert len(sieved) == nfiles // 4

with pytest.raises(KeyError):
list(losc_urls.sieve(gw150914_urls, blah=None))
list(gwopensci_urls.sieve(gw150914_urls, blah=None))


def test_urls_match(gw150914_urls, gw170817_urls):
urls = [u['url'] for u in gw150914_urls]
nfiles = len(urls)
matched = losc_urls.match(urls, version=1)
matched = gwopensci_urls.match(urls, version=1)
assert len(matched) == nfiles // 2
for url in matched:
assert '_V1-' in url

# test GW170817 for multiple tags
urls = [u['url'] for u in gw170817_urls]
with pytest.raises(ValueError) as exc:
losc_urls.match(urls)
gwopensci_urls.match(urls)
assert str(exc.value).startswith('multiple LOSC URL tags')

matched = losc_urls.match(urls, tag='CLN')
matched = gwopensci_urls.match(urls, tag='CLN')
for url in matched:
assert '_CLN_' in url

assert losc_urls.match(urls, tag='BLAH') == []
assert gwopensci_urls.match(urls, tag='BLAH') == []


# -- losc.utils ---------------------------------------------------------------
# -- gwopensci ----------------------------------------------------------------

def test_url_segment():
url = 'X-TEST-123-456.ext'
assert losc_utils.url_segment(url) == (123, 579)
assert gwopensci_utils.url_segment(url) == (123, 579)


@pytest.mark.parametrize('url, segment, result', [
Expand All @@ -199,7 +199,7 @@ def test_url_segment():
('A-B-10-1.ext', (11, 15), False),
])
def test_url_overlaps_segment(url, segment, result):
assert losc_utils.url_overlaps_segment(url, segment) is result
assert gwopensci_utils.url_overlaps_segment(url, segment) is result


@pytest.mark.parametrize('segment, result', [
Expand All @@ -209,7 +209,7 @@ def test_url_overlaps_segment(url, segment, result):
])
def test_full_coverage(gw150914_urls, segment, result):
urls = [u['url'] for u in gw150914_urls]
assert losc_utils.full_coverage(urls, segment) is result
assert gwopensci_utils.full_coverage(urls, segment) is result


@pytest.mark.parametrize('seg1, seg2, result', [
Expand All @@ -219,4 +219,4 @@ def test_full_coverage(gw150914_urls, segment, result):
((10, 11), (11, 15), False),
])
def test_segments_overlap(seg1, seg2, result):
assert losc_utils.segments_overlap(seg1, seg2) is result
assert gwopensci_utils.segments_overlap(seg1, seg2) is result
8 changes: 4 additions & 4 deletions losc/timeline.py → gwopensci/timeline.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright Duncan Macleod 2017
#
# This file is part of LOSC-Python.
# This file is part of GWOpenSci.
#
# LOSC-Python is free software: you can redistribute it and/or modify
# GWOpenSci is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LOSC-Python is distributed in the hope that it will be useful,
# GWOpenSci is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LOSC-Python. If not, see <http://www.gnu.org/licenses/>.
# along with GWOpenSci. If not, see <http://www.gnu.org/licenses/>.

from operator import itemgetter

Expand Down

0 comments on commit 029e5f5

Please sign in to comment.