Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dastools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
9
Issues
9
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Javier Quinteros
dastools
Commits
ffb87982
Commit
ffb87982
authored
Jul 31, 2020
by
Javier Quinteros
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify code of __iter_data
parent
0f2a23fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
60 deletions
+28
-60
dasscripts/tdms.py
dasscripts/tdms.py
+28
-60
No files found.
dasscripts/tdms.py
View file @
ffb87982
...
...
@@ -612,65 +612,26 @@ class TDMS(object):
# Data
logs
=
logging
.
getLogger
(
'Iterate Data'
)
# Data is stored with values from one channel in a continuous array
if
not
self
.
__hasInterleavedData
:
#
for ch in range(self.__chstart, self.__chstop + 1, self.__chstep):
while
(
self
.
__twend
is
None
)
or
(
self
.
__twstart
<
self
.
__twend
):
data
=
self
.
__readdata
(
channels
=
self
.
__channels
)
#
Loop through channels
for
ch
in
self
.
__channels
:
self
.
__resetcurrenttime
()
while
(
self
.
__twend
is
None
)
or
(
self
.
__twstart
<
self
.
__twend
):
# Loop through channels
while
self
.
__samplecur
<=
self
.
__sampleend
:
data
=
self
.
__readdata
(
channels
=
[
ch
])
stats
=
{
'network'
:
'XX'
,
'station'
:
'%05d'
%
ch
,
'location'
:
''
,
'channel'
:
'FH1'
,
'npts'
:
len
(
data
[
ch
]),
'sampling_rate'
:
self
.
sampling_rate
,
'starttime'
:
UTCDateTime
(
self
.
__twstart
),
'mseed'
:
{
'byteorder'
:
self
.
__endian
,
'reclen'
:
512
}}
# logs.debug('Stats: %s' % stats)
logs
.
debug
(
'Data length: %d; First component: %s'
%
(
len
(
data
[
ch
]),
data
[
ch
][
0
]))
yield
data
[
ch
],
stats
# Update the current sample number
self
.
__samplecur
+=
len
(
data
[
ch
])
# No more data in this file. Skip to the next one.
self
.
__currentfile
+=
1
try
:
self
.
__search_data
()
except
IndexError
:
break
else
:
# channels = list(range(self.__chstart, self.__chstop + 1, self.__chstep))
while
(
self
.
__twend
is
None
)
or
(
self
.
__twstart
<
self
.
__twend
):
# Loop through channels
while
self
.
__samplecur
<=
self
.
__sampleend
:
data
=
self
.
__readdata
(
channels
=
self
.
__channels
)
# for ch in channels:
for
ch
in
self
.
__channels
:
stats
=
{
'network'
:
'XX'
,
'station'
:
'%05d'
%
ch
,
'location'
:
''
,
'channel'
:
'FH1'
,
'npts'
:
len
(
data
[
ch
]),
'sampling_rate'
:
self
.
sampling_rate
,
'starttime'
:
UTCDateTime
(
self
.
__twstart
),
'mseed'
:
{
'byteorder'
:
self
.
__endian
,
'reclen'
:
512
}}
# logs.debug('Stats: %s' % stats)
logs
.
debug
(
'Data length: %d; First component: %s'
%
(
len
(
data
[
ch
]),
data
[
ch
][
0
]))
yield
data
[
ch
],
stats
# Update the current sample number based on first channel
# We assume that all chunks of different channels have the same length
self
.
__samplecur
+=
len
(
data
[
self
.
__channels
[
0
]])
# No more data in this file. Skip to the next one.
self
.
__currentfile
+=
1
try
:
logs
.
debug
(
'Moving to next file...'
)
self
.
__search_data
()
except
IndexError
:
break
stats
=
{
'network'
:
'XX'
,
'station'
:
'%05d'
%
ch
,
'location'
:
''
,
'channel'
:
'FH1'
,
'npts'
:
len
(
data
[
ch
]),
'sampling_rate'
:
self
.
sampling_rate
,
'starttime'
:
UTCDateTime
(
self
.
__twstart
),
'mseed'
:
{
'byteorder'
:
self
.
__endian
,
'reclen'
:
512
}}
logs
.
debug
(
'Data length: %d; First component: %s'
%
(
len
(
data
[
ch
]),
data
[
ch
][
0
]))
yield
data
[
ch
],
stats
# No more data in this file. Skip to the next one.
self
.
__currentfile
+=
1
try
:
logs
.
debug
(
'Moving to next file...'
)
self
.
__search_data
()
except
IndexError
:
break
def
__iter_metadata__
(
self
):
# Metadata
...
...
@@ -758,7 +719,8 @@ class TDMS(object):
return
struct
.
unpack
(
'%cI'
%
self
.
__endian
,
self
.
__fi
.
read
(
4
))[
0
]
def
__readdata
(
self
,
channels
=
None
):
"""Read a chunk of data from the specified channels
"""Read a chunk of data from the specified channels.
Update the attribute __samplecur
:param channels: List of channel numbers to read data from
:type channels: list
...
...
@@ -792,6 +754,10 @@ class TDMS(object):
# Read all selected data from the channel in one step
result
[
ch
]
=
np
.
fromfile
(
self
.
__fi
,
dtype
=
self
.
__datatype
,
count
=
numsamples
)
# Update the current sample number based on the number of components read
self
.
__samplecur
+=
numsamples
return
result
# Seek where the raw data starts and add the offset to the first
...
...
@@ -809,5 +775,7 @@ class TDMS(object):
for
ch
in
channels
:
result
[
ch
][
sample
]
=
allchannels
[
ch
]
# print(result)
# Update the current sample number based on the number of components read
self
.
__samplecur
+=
numsamples
return
result
Javier Quinteros
@javier
mentioned in issue
#9 (closed)
·
Jul 31, 2020
mentioned in issue
#9 (closed)
mentioned in issue #9
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment