Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Software Public
PASSOFT
SOHViewer
Commits
6f9391c6
Commit
6f9391c6
authored
2 years ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for trim_downsample_SOHChan
parent
a286221e
No related branches found
No related tags found
1 merge request
!27
Draft: Add tests for functions in handling_data.py
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_model/test_handling_data.py
+118
-1
118 additions, 1 deletion
tests/test_model/test_handling_data.py
with
118 additions
and
1 deletion
tests/test_model/test_handling_data.py
+
118
−
1
View file @
6f9391c6
...
@@ -33,7 +33,8 @@ from sohstationviewer.model.handling_data import (
...
@@ -33,7 +33,8 @@ from sohstationviewer.model.handling_data import (
sortData
,
sortData
,
squash_gaps
,
squash_gaps
,
downsample
,
downsample
,
chunk_minmax
chunk_minmax
,
trim_downsample_SOHChan
)
)
from
sohstationviewer.model.reftek.from_rt2ms.core
import
Reftek130
from
sohstationviewer.model.reftek.from_rt2ms.core
import
Reftek130
...
@@ -854,3 +855,119 @@ class TestChunkMinmax(TestCase):
...
@@ -854,3 +855,119 @@ class TestChunkMinmax(TestCase):
times
,
data
=
chunk_minmax
(
self
.
times
,
self
.
data
,
req_points
)
times
,
data
=
chunk_minmax
(
self
.
times
,
self
.
data
,
req_points
)
self
.
assertEqual
(
times
.
size
,
0
)
self
.
assertEqual
(
times
.
size
,
0
)
self
.
assertEqual
(
data
.
size
,
0
)
self
.
assertEqual
(
data
.
size
,
0
)
class
TestTrimDownsampleSohChan
(
TestCase
):
@staticmethod
def
downsample
(
times
,
data
,
req_points
):
return
times
,
data
def
setUp
(
self
)
->
None
:
self
.
channel_info
=
{}
self
.
org_trace
=
{
'
times
'
:
np
.
arange
(
1000
),
'
data
'
:
np
.
arange
(
1000
)
}
self
.
channel_info
[
'
orgTrace
'
]
=
self
.
org_trace
self
.
start_time
=
250
self
.
end_time
=
750
self
.
first_time
=
False
patcher
=
patch
(
'
sohstationviewer.model.handling_data.downsample
'
)
self
.
addCleanup
(
patcher
.
stop
)
self
.
mock_downsample
=
patcher
.
start
()
self
.
mock_downsample
.
side_effect
=
self
.
downsample
def
num_points_outside_time_range
(
self
,
start_time
,
end_time
):
return
len
([
data_point
for
data_point
in
self
.
org_trace
[
'
times
'
]
if
not
start_time
<=
data_point
<=
end_time
])
def
test_mseed_start_time_later_than_times_data
(
self
):
self
.
start_time
=
250
self
.
end_time
=
1250
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
self
.
assertGreaterEqual
(
self
.
channel_info
[
'
times
'
].
min
(),
self
.
start_time
)
self
.
assertEqual
(
self
.
org_trace
[
'
times
'
].
size
-
self
.
channel_info
[
'
times
'
].
size
,
self
.
num_points_outside_time_range
(
self
.
start_time
,
self
.
end_time
)
)
def
test_mseed_end_time_earlier_than_times_data
(
self
):
self
.
start_time
=
-
250
self
.
end_time
=
750
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
self
.
assertLessEqual
(
self
.
channel_info
[
'
times
'
].
max
(),
self
.
end_time
)
self
.
assertEqual
(
self
.
org_trace
[
'
times
'
].
size
-
self
.
channel_info
[
'
times
'
].
size
,
self
.
num_points_outside_time_range
(
self
.
start_time
,
self
.
end_time
)
)
def
test_mseed_start_time_earlier_than_times_data
(
self
):
self
.
start_time
=
-
250
self
.
end_time
=
750
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
self
.
assertEqual
(
self
.
channel_info
[
'
times
'
].
min
(),
self
.
channel_info
[
'
orgTrace
'
][
'
times
'
].
min
())
self
.
assertEqual
(
self
.
org_trace
[
'
times
'
].
size
-
self
.
channel_info
[
'
times
'
].
size
,
self
.
num_points_outside_time_range
(
self
.
start_time
,
self
.
end_time
)
)
def
test_mseed_end_time_later_than_times_data
(
self
):
self
.
start_time
=
250
self
.
end_time
=
1250
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
self
.
assertEqual
(
self
.
channel_info
[
'
times
'
].
max
(),
self
.
channel_info
[
'
orgTrace
'
][
'
times
'
].
max
())
self
.
assertEqual
(
self
.
org_trace
[
'
times
'
].
size
-
self
.
channel_info
[
'
times
'
].
size
,
self
.
num_points_outside_time_range
(
self
.
start_time
,
self
.
end_time
)
)
def
test_mseed_times_data_contained_in_time_range
(
self
):
self
.
start_time
=
-
250
self
.
end_time
=
1250
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
np
.
testing
.
assert_array_equal
(
self
.
channel_info
[
'
times
'
],
self
.
org_trace
[
'
times
'
])
def
test_mseed_time_range_is_the_same_as_times_data
(
self
):
self
.
start_time
=
0
self
.
end_time
=
999
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
np
.
testing
.
assert_array_equal
(
self
.
channel_info
[
'
times
'
],
self
.
org_trace
[
'
times
'
])
def
test_mseed_time_range_does_not_overlap_times_data
(
self
):
self
.
start_time
=
2000
self
.
end_time
=
3000
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
self
.
assertEqual
(
self
.
channel_info
[
'
times
'
].
size
,
0
)
self
.
assertEqual
(
self
.
channel_info
[
'
data
'
].
size
,
0
)
def
test_mseed_data_is_downsampled
(
self
):
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
self
.
assertTrue
(
self
.
mock_downsample
.
called
)
def
test_mseed_processed_data_is_stored_in_appropriate_location
(
self
):
trim_downsample_SOHChan
(
self
.
channel_info
,
self
.
start_time
,
self
.
end_time
,
self
.
first_time
)
expected_keys
=
(
'
orgTrace
'
,
'
times
'
,
'
data
'
)
self
.
assertTupleEqual
(
tuple
(
self
.
channel_info
.
keys
()),
expected_keys
)
@expectedFailure
def
test_reftek
(
self
):
self
.
fail
()
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