Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
5
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
6eeb059e
Commit
6eeb059e
authored
1 year ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Reimplement Reftek130.to_stream()
parent
c54ff40b
No related branches found
No related tags found
1 merge request
!139
Change the way RT130 data is read for better performance
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sohstationviewer/model/reftek/from_rt2ms/core.py
+3
-70
3 additions, 70 deletions
sohstationviewer/model/reftek/from_rt2ms/core.py
with
3 additions
and
70 deletions
sohstationviewer/model/reftek/from_rt2ms/core.py
+
3
−
70
View file @
6eeb059e
...
...
@@ -46,7 +46,6 @@ class Reftek130Exception(ObsPyException):
class
Reftek130
(
obspy_rt130_core
.
Reftek130
):
def
to_stream
(
self
,
network
=
""
,
location
=
""
,
component_codes
=
None
,
include_mp123
=
False
,
include_mp456
=
False
,
headonly
=
False
,
verbose
=
False
,
...
...
@@ -56,8 +55,6 @@ class Reftek130(obspy_rt130_core.Reftek130):
:param headonly: Determines whether or not to unpack the data or just
read the headers.
"""
if
verbose
:
print
(
self
)
if
not
len
(
self
.
_data
):
msg
=
"
No packet data in Reftek130 object (file: {})
"
raise
Reftek130Exception
(
msg
.
format
(
self
.
_filename
))
...
...
@@ -99,20 +96,6 @@ class Reftek130(obspy_rt130_core.Reftek130):
eh
=
EHPacket
(
eh_packets
[
0
])
else
:
eh
=
EHPacket
(
et_packets
[
0
])
# only C0, C2, 16, 32 encodings supported right now
if
eh
.
data_format
==
b
"
C0
"
:
encoding
=
'
C0
'
elif
eh
.
data_format
==
b
"
C2
"
:
encoding
=
'
C2
'
elif
eh
.
data_format
==
b
"
16
"
:
encoding
=
'
16
'
elif
eh
.
data_format
==
b
"
32
"
:
encoding
=
'
32
'
else
:
msg
=
(
"
Reftek data encoding
'
{}
'
not implemented yet. Please
"
"
open an issue on GitHub and provide a small (< 50kb)
"
"
test file.
"
).
format
(
eh
.
data_format
)
raise
NotImplementedError
(
msg
)
header
=
{
"
unit_id
"
:
self
.
_data
[
'
unit_id
'
][
0
],
"
experiment_number
"
:
self
.
_data
[
'
experiment_number
'
][
0
],
...
...
@@ -158,45 +141,12 @@ class Reftek130(obspy_rt130_core.Reftek130):
sample_data
=
np
.
array
([],
dtype
=
np
.
int32
)
npts
=
packets_
[
"
number_of_samples
"
].
sum
()
else
:
if
encoding
in
(
'
C0
'
,
'
C2
'
):
sample_data
=
_unpack_C0_C2_data
(
packets_
,
encoding
)
elif
encoding
in
(
'
16
'
,
'
32
'
):
# rt130 stores in big endian
dtype
=
{
'
16
'
:
'
>i2
'
,
'
32
'
:
'
>i4
'
}[
encoding
]
# just fix endianness and use correct dtype
sample_data
=
np
.
require
(
packets_
[
'
payload
'
],
requirements
=
[
'
C_CONTIGUOUS
'
])
# either int16 or int32
sample_data
=
sample_data
.
view
(
dtype
)
# account for number of samples, i.e. some packets
# might not use the full payload size but have
# empty parts at the end that need to be cut away
number_of_samples_max
=
sample_data
.
shape
[
1
]
sample_data
=
sample_data
.
flatten
()
# go through packets starting at the back,
# otherwise indices of later packets would change
# while looping
for
ind
,
num_samps
in
reversed
([
(
ind
,
num_samps
)
for
ind
,
num_samps
in
enumerate
(
packets_
[
"
number_of_samples
"
])
if
num_samps
!=
number_of_samples_max
]):
# looping backwards we can easily find the
# start of each packet, since the earlier
# packets are still untouched and at maximum
# sample length in our big array with all
# packets
start_of_packet
=
ind
*
number_of_samples_max
start_empty_part
=
start_of_packet
+
num_samps
end_empty_part
=
(
start_of_packet
+
number_of_samples_max
)
sample_data
=
np
.
delete
(
sample_data
,
slice
(
start_empty_part
,
end_empty_part
))
sample_data
=
(
packets_
[
'
payload
'
][:,
:
4
])
sample_data
=
sample_data
.
view
(
np
.
dtype
(
'
>i4
'
)).
squeeze
()
npts
=
len
(
sample_data
)
tr
=
Trace
(
data
=
sample_data
,
header
=
copy
.
deepcopy
(
header
))
tr
.
stats
.
npts
=
packets_
[
'
number_of_samples
'
].
sum
()
# channel number is not included in the EH/ET packet
# payload, so add it to stats as well..
tr
.
stats
.
reftek130
[
'
channel_number
'
]
=
channel_number
...
...
@@ -236,22 +186,5 @@ class Reftek130(obspy_rt130_core.Reftek130):
continue
tr
.
stats
.
channel
=
"
MassPos%s
"
%
(
channel_number
+
1
)
# check if endtime of trace is consistent
t_last
=
packets_
[
-
1
][
'
time
'
]
npts_last
=
packets_
[
-
1
][
'
number_of_samples
'
]
try
:
if
not
headonly
:
assert
npts
==
len
(
sample_data
)
if
npts_last
:
assert
tr
.
stats
.
endtime
==
UTCDateTime
(
ns
=
t_last
)
+
(
npts_last
-
1
)
*
delta
if
npts
:
assert
tr
.
stats
.
endtime
==
(
tr
.
stats
.
starttime
+
(
npts
-
1
)
*
delta
)
except
AssertionError
:
msg
=
(
"
Reftek file has a trace with an inconsistent
"
"
endtime or number of samples. Please open an
"
"
issue on GitHub and provide your file for
"
"
testing.
"
)
raise
Reftek130Exception
(
msg
)
st
+=
tr
return
st
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