Commit 8e8997f9 authored by Javier Quinteros's avatar Javier Quinteros

Refactor __generatemseed and __generatemetadata to cycle through arbitrary channels

parent 0fb49fc0
......@@ -392,70 +392,40 @@ class StationAPI(object):
yield '# Network|Station|Location|Channel|Latitude|Longitude|Elevation|Depth|Azimuth|Dip|Sensor ' \
'Description|Scale|ScaleFrequency|ScaleUnits|SampleRate|StartTime|EndTime\n'
if not len(streams):
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M')
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']:
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
return
for stream in streams:
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime,
chstart=stream, chstop=stream, iterate='M')
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']:
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 text
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']:
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
return
@cherrypy.expose
......@@ -677,30 +647,20 @@ class DataselectAPI(object):
:rtype: bytearray
"""
if not len(streams):
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime)
with t:
for data in t:
# Create the Trace
tr0 = Trace(data=data[0], header=data[1])
auxout = BytesIO()
tr0.write(auxout, format='MSEED', reclen=512)
yield auxout.getvalue()
auxout.close()
channels = streams if len(streams) else None
return
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime,
channels=channels)
with t:
for data in t:
# Create the Trace
tr0 = Trace(data=data[0], header=data[1])
auxout = BytesIO()
tr0.write(auxout, format='MSEED', reclen=512)
yield auxout.getvalue()
auxout.close()
for stream in streams:
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime,
chstart=stream, chstop=stream)
with t:
for data in t:
# Create the Trace
tr0 = Trace(data=data[0], header=data[1])
auxout = BytesIO()
tr0.write(auxout, format='MSEED', reclen=512)
yield auxout.getvalue()
auxout.close()
return
def main():
......
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