Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bilby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matthew David Pitkin
bilby
Commits
34cbf86e
Commit
34cbf86e
authored
1 year ago
by
Colm Talbot
Committed by
Colm Talbot
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
TST: update frame reading tests for latest version of gwpy
parent
f8b004a8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bilby/gw/utils.py
+2
-2
2 additions, 2 deletions
bilby/gw/utils.py
test/gw/utils_test.py
+23
-7
23 additions, 7 deletions
test/gw/utils_test.py
with
25 additions
and
9 deletions
bilby/gw/utils.py
+
2
−
2
View file @
34cbf86e
...
...
@@ -398,7 +398,7 @@ def read_frame_file(file_name, start_time, end_time, resample=None, channel=None
strain
=
TimeSeries
.
read
(
source
=
file_name
,
channel
=
channel
,
start
=
start_time
,
end
=
end_time
,
**
kwargs
)
loaded
=
True
logger
.
info
(
'
Successfully loaded {}.
'
.
format
(
channel
))
except
RuntimeError
:
except
(
RuntimeError
,
ValueError
)
:
logger
.
warning
(
'
Channel {} not found. Trying preset channel names
'
.
format
(
channel
))
if
loaded
is
False
:
...
...
@@ -418,7 +418,7 @@ def read_frame_file(file_name, start_time, end_time, resample=None, channel=None
**
kwargs
)
loaded
=
True
logger
.
info
(
'
Successfully read strain data for channel {}.
'
.
format
(
channel
))
except
RuntimeError
:
except
(
RuntimeError
,
ValueError
)
:
pass
if
loaded
:
...
...
This diff is collapsed.
Click to expand it.
test/gw/utils_test.py
+
23
−
7
View file @
34cbf86e
import
unittest
import
os
from
shutil
import
rmtree
from
importlib.metadata
import
version
import
numpy
as
np
import
lal
...
...
@@ -89,12 +90,28 @@ class TestGWUtils(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
gwutils
.
get_event_time
(
"
GW010290
"
)
@pytest.mark.skipif
(
version
(
"
gwpy
"
)
<
"
3.0.8
"
,
reason
=
"
GWpy version < 3.0.8
"
)
def
test_read_frame_file
(
self
):
"""
Test that reading a frame file works as expected
for a few conditions.
1. Reading without time limits returns the full data
2. Reading with time limits returns the expected data
(inclusive of start time if present, exclusive of end time)
3. Reading without the channel name provided finds a standard name
4. Reading without the channel with a non-standard name returns None.
Notes
=====
There was a longstanding bug in gwpy that we previously tested for
here, but this has been fixed in gwpy 3.0.8.
"""
start_time
=
0
end_time
=
10
channel
=
"
H1:GDS-CALIB_STRAIN
"
N
=
100
times
=
np
.
linspace
(
start_time
,
end_time
,
N
)
times
=
np
.
linspace
(
start_time
,
end_time
,
N
,
endpoint
=
False
)
data
=
np
.
random
.
normal
(
0
,
1
,
N
)
ts
=
TimeSeries
(
data
=
data
,
times
=
times
,
t0
=
0
)
ts
.
channel
=
Channel
(
channel
)
...
...
@@ -107,7 +124,7 @@ class TestGWUtils(unittest.TestCase):
filename
,
start_time
=
None
,
end_time
=
None
,
channel
=
channel
)
self
.
assertEqual
(
strain
.
name
,
channel
)
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
[:
-
1
]
))
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
))
# Check reading with time limits
start_cut
=
2
...
...
@@ -115,19 +132,18 @@ class TestGWUtils(unittest.TestCase):
strain
=
gwutils
.
read_frame_file
(
filename
,
start_time
=
start_cut
,
end_time
=
end_cut
,
channel
=
channel
)
idxs
=
(
times
>
start_cut
)
&
(
times
<
end_cut
)
# Dropping the last element - for some reason gwpy drops the last element when reading in data
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
[
idxs
][:
-
1
]))
idxs
=
(
times
>=
start_cut
)
&
(
times
<
end_cut
)
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
[
idxs
]))
# Check reading with unknown channels
strain
=
gwutils
.
read_frame_file
(
filename
,
start_time
=
None
,
end_time
=
None
)
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
[:
-
1
]
))
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
))
# Check reading with incorrect channel
strain
=
gwutils
.
read_frame_file
(
filename
,
start_time
=
None
,
end_time
=
None
,
channel
=
"
WRONG
"
)
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
[:
-
1
]
))
self
.
assertTrue
(
np
.
all
(
strain
.
value
==
data
))
ts
=
TimeSeries
(
data
=
data
,
times
=
times
,
t0
=
0
)
ts
.
name
=
"
NOT-A-KNOWN-CHANNEL
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment