Commit ed328950 authored by Javier Quinteros's avatar Javier Quinteros

Iterate channel by channel in StationWS to be able to merge the epochs and...

Iterate channel by channel in StationWS to be able to merge the epochs and keep the generator as it is
parent 28fc855a
......@@ -394,39 +394,65 @@ class StationAPI(object):
channels = streams if len(streams) else None
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M',
channels=channels)
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':
text = 'XX|%s||FH1|%s|%s|%s|SiteName|%s|%s\n' %\
(data['id'], lat, lon, elev, stt.isoformat(), ent.isoformat())
else:
text = 'XX|%s||FH1|%s|%s|%s|depth|azimuth|dip|DAS|Scale|ScaleFrequency|ScaleUnits|%s|%s|%s\n' %\
(data['id'], lat, lon, elev, samprate, stt.isoformat(), ent.isoformat())
# yield json.dumps(data, default=datetime.isoformat)
yield text
# 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
for ch in channels:
cherrypy.log('Channel %s' % ch)
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']:
# cherrypy.log('%s' % data)
stt = data['starttime']
ent = data['endtime']
if level == 'station':
key = 'XX|%s||FH1|%s|%s|%s|SiteName' % (data['id'], lat, lon, elev)
# text = 'XX|%s||FH1|%s|%s|%s|SiteName|%s|%s\n' %\
# (data['id'], lat, lon, elev, stt.isoformat(), ent.isoformat())
else:
key = 'XX|%s||FH1|%s|%s|%s|depth|azimuth|dip|DAS|Scale|ScaleFrequency|ScaleUnits|%s' % \
(data['id'], lat, lon, elev, samprate)
# text = 'XX|%s||FH1|%s|%s|%s|depth|azimuth|dip|DAS|Scale|ScaleFrequency|ScaleUnits|%s|%s|%s\n' %\
# (data['id'], lat, lon, elev, samprate, stt.isoformat(), ent.isoformat())
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 json.dumps(data, default=datetime.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