Commit 423de6d0 authored by Javier Quinteros's avatar Javier Quinteros

Cycle through files reading all epochs from channels in a dictionary and later send them merged

parent df41da69
......@@ -392,61 +392,52 @@ class StationAPI(object):
yield '# Network|Station|Location|Channel|Latitude|Longitude|Elevation|Depth|Azimuth|Dip|Sensor ' \
'Description|Scale|ScaleFrequency|ScaleUnits|SampleRate|StartTime|EndTime\n'
# List of channels or None (all channels)
channels = streams if len(streams) else None
# It is not optimal to cycle through channels instead of reading them all at once
# However it is the best to merge time windows from files int one epoch
# This allows to construct the generator returning one line at each iteration
# FIXME If there is no stream selected via the "station" parameter this will raise an Exception
for ch in channels:
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M',
channels=[ch])
result = dict()
with t:
lat = None
lon = None
elev = None
samprate = None
# stt = t.starttime
# ent = t.endtime
for data in t:
if lat is None:
lat = data[latkey]
if lon is None:
lon = data[lonkey]
if elev is None:
elev = data[elevkey]
if samprate is None:
samprate = data[srkey]
# if not data['data']:
# yield json.dumps(data, default=datetime.isoformat)
if data['data']:
stt = data['starttime']
ent = data['endtime']
if level == 'station':
key = 'XX|%s||FH1|%s|%s|%s|SiteName' % (data['id'], lat, lon, elev)
else:
key = 'XX|%s||FH1|%s|%s|%s|depth|azimuth|dip|DAS|Scale|ScaleFrequency|ScaleUnits|%s' % \
(data['id'], lat, lon, elev, samprate)
if key in result:
# Get the minimum starttime
stt = stt if stt < result[key][0] else result[key][0]
# Get the maximum endtime
ent = ent if ent > result[key][1] else result[key][1]
result[key] = (stt, ent)
# Send the epoch(s)
for key in result:
# Key is in the proper format for station or channel level. We only need to add the start and end time
text = '%s|%s|%s\n' % (key, stt.isoformat(), ent.isoformat())
yield text
# Cycle through files, not channels, and merge epochs in a dictionary
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M',
channels=channels)
result = dict()
with t:
lat = None
lon = None
elev = None
samprate = None
for data in t:
if lat is None:
lat = data[latkey]
if lon is None:
lon = data[lonkey]
if elev is None:
elev = data[elevkey]
if samprate is None:
samprate = data[srkey]
if data['data']:
stt = data['starttime']
ent = data['endtime']
if level == 'station':
key = 'XX|%s||FH1|%s|%s|%s|SiteName' % (data['id'], lat, lon, elev)
else:
key = 'XX|%s||FH1|%s|%s|%s|depth|azimuth|dip|DAS|Scale|ScaleFrequency|ScaleUnits|%s' % \
(data['id'], lat, lon, elev, samprate)
if key in result:
# Get the minimum starttime
stt = stt if stt < result[key][0] else result[key][0]
# Get the maximum endtime
ent = ent if ent > result[key][1] else result[key][1]
result[key] = (stt, ent)
# Send the epoch(s)
for key in result:
# Key is in the proper format for station or channel level. We only need to add the start and end time
text = '%s|%s|%s\n' % (key, stt.isoformat(), ent.isoformat())
yield text
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment