Skip to content

Commit

Permalink
Merge branch 'release/0.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmmacleod committed Mar 11, 2019
2 parents 3069c91 + e7b36ad commit 785ddf2
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ build:centos: &build-centos
tar -xf gwosc-*.tar.gz;
rm -rf gwosc-*.tar.gz;
_version=$(grep "define version" gwosc-*/gwosc.spec | awk '{print $3}');
mv gwosc-* gwosc-${_version};
mv gwosc-* gwosc-${_version} || true;
tar -zcf gwosc-${_version}.tar.gz gwosc-${_version};
rm -rf gwosc-${_version}/;
# build src rpm
Expand Down
7 changes: 6 additions & 1 deletion RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ So, to release a new version of the package:
$ git flow release start 1.0.0
and then ``publish`` it, allowing CI to run, and others to contribute:
#. **Bump versions and add changelog entries in OS packaging files:**

- `/debian/changelog`
- `/gwosc.spec`

#. **Publish the release**, allowing CI to run, and others to contribute:

.. code-block:: bash
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
gwosc (0.4.2-1) unstable; urgency=low

* [#31] new function `gwosc.datasets.dataset_type`
* [#32] fixed critical bug in `gwosc.locate.get_urls`

-- Duncan Macleod <duncan.macleod@ligo.org> Mon, 11 Mar 2019 16:39:00 +0000

gwosc (0.4.1-1) unstable; urgency=low

* development release to include catalogue parsing
Expand Down
5 changes: 4 additions & 1 deletion gwosc.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%define name gwosc
%define version 0.4.1
%define version 0.4.2
%define release 1

Name: %{name}
Expand Down Expand Up @@ -94,6 +94,9 @@ rm -rf $RPM_BUILD_ROOT
# -- changelog

%changelog
* Mon Mar 11 2019 Duncan Macleod <duncan.macleod@ligo.org> - 0.4.2-1
- bug fix release, see github releases for details

* Thu Feb 28 2019 Duncan Macleod <duncan.macleod@ligo.org> - 0.4.1-1
- development release to include catalogue parsing

Expand Down
35 changes: 35 additions & 0 deletions gwosc/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,38 @@ def run_at_gps(gps, host=api.DEFAULT_URL):
if start <= gps < end:
return run
raise ValueError("no run dataset found containing GPS {0}".format(gps))


def dataset_type(dataset, host=api.DEFAULT_URL):
"""Returns the type of the named dataset
Parameters
----------
dataset : `str`
The name of the dataset to match
host : `str`, optional
the URL of the LOSC host to query
Returns
-------
type : `str`
the type of the dataset, one of 'run', 'event', or 'catalog'
Raises
-------
ValueError
if this dataset cannot be matched
Examples
--------
>>> from gwosc.datasets import dataset_type
>>> dataset_type('O1')
'run'
"""
for type_ in ("run", "catalog", "event"):
if dataset in find_datasets(type=type_):
return type_
raise ValueError(
"failed to determine type for dataset {0!r}".format(dataset),
)
8 changes: 6 additions & 2 deletions gwosc/locate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def get_urls(
),
]

if dataset:
dstype = datasets.dataset_type(dataset)
dataset_metadata = [(dstype, dict(dataset_metadata)[dstype])]

for dstype, _get_urls in dataset_metadata:
if dataset:
dsets = [dataset]
Expand All @@ -106,9 +110,9 @@ def get_urls(
segment=(start, end),
host=host,
)
for dataset in dsets:
for dst in dsets:
# get URL list for this dataset
urls = _get_urls(dataset)["strain"]
urls = _get_urls(dst)["strain"]

# match URLs to request
urls = lurls.match(
Expand Down
19 changes: 19 additions & 0 deletions gwosc/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,22 @@ def test_run_at_gps_local(fetch):
assert datasets.run_at_gps(0) == 'S1'
with pytest.raises(ValueError):
datasets.run_at_gps(10)


@pytest.mark.remote
def test_dataset_type():
assert datasets.dataset_type("O1") == "run"
assert datasets.dataset_type("GW150914") == "event"
assert datasets.dataset_type("GWTC-1-confident") == "catalog"
with pytest.raises(ValueError):
datasets.dataset_type("invalid")


@mock.patch(
'gwosc.datasets.find_datasets',
side_effect=[["testrun"], [], ["testevent"], [], [], []],
)
def test_dataset_type_local(find):
assert datasets.dataset_type("testevent") == "event"
with pytest.raises(ValueError):
datasets.dataset_type("invalid")
3 changes: 3 additions & 0 deletions gwosc/tests/test_locate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def test_get_urls():
dataset="GW170817",
)) == 2

# test for O1 data
assert len(locate.get_urls("L1", 1135136228, 1135140324)) == 2

# assert no hits raises exception
with pytest.raises(ValueError): # no data in 1980
locate.get_urls(detector, 0, 1)
Expand Down

0 comments on commit 785ddf2

Please sign in to comment.