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): ...@@ -394,39 +394,65 @@ class StationAPI(object):
channels = streams if len(streams) else None channels = streams if len(streams) else None
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M', # It is not optimal to cycle through channels instead of reading them all at once
channels=channels) # However it is the best to merge time windows from files int one epoch
with t: # This allows to construct the generator returning one line at each iteration
lat = None for ch in channels:
lon = None cherrypy.log('Channel %s' % ch)
elev = None t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M',
samprate = None channels=[ch])
# stt = t.starttime result = dict()
# ent = t.endtime with t:
for data in t: lat = None
if lat is None: lon = None
lat = data[latkey] elev = None
if lon is None: samprate = None
lon = data[lonkey] # stt = t.starttime
if elev is None: # ent = t.endtime
elev = data[elevkey] for data in t:
if samprate is None: if lat is None:
samprate = data[srkey] lat = data[latkey]
if lon is None:
# if not data['data']: lon = data[lonkey]
# yield json.dumps(data, default=datetime.isoformat) if elev is None:
elev = data[elevkey]
if data['data']: if samprate is None:
stt = data['starttime'] samprate = data[srkey]
ent = data['endtime']
if level == 'station': # if not data['data']:
text = 'XX|%s||FH1|%s|%s|%s|SiteName|%s|%s\n' %\ # yield json.dumps(data, default=datetime.isoformat)
(data['id'], lat, lon, elev, stt.isoformat(), ent.isoformat())
else: if data['data']:
text = 'XX|%s||FH1|%s|%s|%s|depth|azimuth|dip|DAS|Scale|ScaleFrequency|ScaleUnits|%s|%s|%s\n' %\ # cherrypy.log('%s' % data)
(data['id'], lat, lon, elev, samprate, stt.isoformat(), ent.isoformat())
# yield json.dumps(data, default=datetime.isoformat) stt = data['starttime']
yield text 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 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