Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dastools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
geofon
dastools
Commits
fa6d251c
Project 'javier/dastools' was moved to 'geofon/dastools'. Please update any links and bookmarks that may still have the old path.
Commit
fa6d251c
authored
4 years ago
by
Javier Quinteros
Browse files
Options
Downloads
Patches
Plain Diff
Refactor and create __search_data to pay attention to gaps
parent
97a4b07a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
dasscripts/tdms.py
+52
-7
52 additions, 7 deletions
dasscripts/tdms.py
with
52 additions
and
7 deletions
dasscripts/tdms.py
+
52
−
7
View file @
fa6d251c
...
...
@@ -20,6 +20,14 @@ def tup2time(fraction, seconds):
return
result
class
PotentialGap
(
Exception
):
pass
class
NoData
(
Exception
):
pass
class
TDMS
(
object
):
"""
Class to read and export seismic waveforms in TDMS format
"""
...
...
@@ -30,7 +38,6 @@ class TDMS(object):
def
__enter__
(
self
):
"""
Method which allows to use the syntax
'
with object:
'
and use it inside
"""
# self.__select_file()
# Create a buffer space to store the signal coefficients to be
# convoluted during the decimation
...
...
@@ -190,19 +197,29 @@ class TDMS(object):
self
.
__sampleend
=
None
self
.
__samplecur
=
None
self
.
__select_file
()
try
:
self
.
__search_data
()
except
IndexError
:
raise
NoData
()
def
__select_file
(
self
):
logs
=
logging
.
getLogger
(
'
Select file
'
)
logs
.
setLevel
(
self
.
__loglevel
)
# print('select', self.__twstart, self.starttime, self.__currentfile)
if
self
.
__currentfile
is
None
:
for
idx
,
fi
in
enumerate
(
self
.
__available
):
# print(self.__twstart, fi['dt'])
if
self
.
__twstart
<
fi
[
'
dt
'
]:
if
not
idx
:
raise
Exception
(
'
Data not available in the specified time window
'
)
filename
=
os
.
path
.
join
(
self
.
__directory
,
self
.
__available
[
idx
-
1
][
'
name
'
])
self
.
__currentfile
=
idx
-
1
# print(self.__currentfile, filename)
logs
.
debug
(
'
Opening %s; Starttime: %s
'
%
(
self
.
__available
[
self
.
__currentfile
][
'
name
'
],
self
.
__twstart
))
break
else
:
raise
Exception
(
'
Data not available in the specified time window
'
)
...
...
@@ -218,8 +235,10 @@ class TDMS(object):
raise
IndexError
logs
.
debug
(
'
Opening %s; Starttime: %s
'
%
(
self
.
__available
[
self
.
__currentfile
][
'
name
'
],
self
.
__twstart
))
# print(self.__twstart)
# Reset some properties before opening the new file
self
.
starttime
=
self
.
__available
[
self
.
__currentfile
][
'
dt
'
]
# print(self.starttime)
self
.
endtime
=
None
self
.
metadata
=
dict
()
...
...
@@ -281,13 +300,33 @@ class TDMS(object):
logs
.
debug
(
'
BigEndian:
'
+
(
'
yes
'
if
self
.
__endian
==
'
<
'
else
'
no
'
))
logs
.
debug
(
'
DAQmx raw data:
'
+
(
'
yes
'
if
hasDAQmxRawData
else
'
no
'
))
# self.__readmetadata()
def
__search_data
(
self
):
"""
:raise: IndexError
"""
while
True
:
# Loop through files until there is nothing else (IndexError)
self
.
__select_file
()
# Read the metadata and calculate samples to read
# Skip to the next file if there is a gap
try
:
self
.
__readmetadata
()
return
except
PotentialGap
:
logging
.
debug
(
'
Potential gap detected!
'
)
self
.
__currentfile
+=
1
def
__resetcurrenttime
(
self
):
self
.
__twstart
=
self
.
__origstarttime
self
.
__twend
=
self
.
__origendtime
self
.
__currentfile
=
None
self
.
__select_file
()
self
.
__search_data
()
# print('reset', self.__twstart, self.starttime)
def
__readmetadata
(
self
):
# Metadata
...
...
@@ -375,10 +414,15 @@ class TDMS(object):
self
.
endtime
=
self
.
starttime
+
datetime
.
timedelta
(
seconds
=
(
self
.
__samples
-
1
)
/
self
.
sampling_rate
)
# Sample to start extraction from based on the initial datetime of the file (__twstart)
# print(self.__twstart, self.starttime)
self
.
__samplestart
=
max
(
floor
((
self
.
__twstart
-
self
.
starttime
).
total_seconds
()
*
self
.
sampling_rate
),
0
)
if
self
.
__samplestart
>=
self
.
__samples
:
raise
PotentialGap
(
'
Start reading at %s, but only %s samples
'
%
(
self
.
__samplestart
,
self
.
__samples
))
# Should I readjust __twstart to align it exactly with the time of the samples?
# print(self.__twstart, self.starttime + datetime.timedelta(seconds=self.__samplestart/self.sampling_rate))
self
.
__twstart
=
self
.
starttime
+
datetime
.
timedelta
(
seconds
=
self
.
__samplestart
/
self
.
sampling_rate
)
# print(self.__twstart, self.starttime, self.__samplestart)
self
.
__samplecur
=
self
.
__samplestart
...
...
@@ -546,6 +590,7 @@ class TDMS(object):
# Data
logs
=
logging
.
getLogger
(
'
Iterate Data
'
)
# print(self.__currentfile, self.__twstart, self.starttime, self.__samplestart, self.__samplecur, self.__sampleend)
# 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
):
...
...
@@ -571,7 +616,7 @@ class TDMS(object):
# No more data in this file. Skip to the next one.
self
.
__currentfile
+=
1
try
:
self
.
__se
lect_file
()
self
.
__se
arch_data
()
except
IndexError
:
break
else
:
...
...
@@ -600,7 +645,7 @@ class TDMS(object):
self
.
__currentfile
+=
1
try
:
logs
.
debug
(
'
Moving to next file...
'
)
self
.
__se
lect_file
()
self
.
__se
arch_data
()
except
IndexError
:
break
...
...
@@ -619,7 +664,7 @@ class TDMS(object):
# No more data in this file. Skip to the next one.
self
.
__currentfile
+=
1
try
:
self
.
__se
lect_file
()
self
.
__se
arch_data
()
except
IndexError
:
break
...
...
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