Commit 370a49a5 authored by Javier Quinteros's avatar Javier Quinteros

Add the level parameter to StationWS

Response level still not implemented
parent 566095f9
......@@ -30,7 +30,6 @@ import cherrypy
import argparse
from cherrypy.process import plugins
import os
import json
import logging
import logging.config
from datetime import datetime
......@@ -420,9 +419,9 @@ return StationXML.
enddt = None
cherrypy.response.headers['Content-Type'] = 'text/plain'
return self.__generatemetadata(liststa, startdt, enddt)
return self.__generatemetadata(liststa, startdt, enddt, level)
def __generatemetadata(self, streams, starttime=None, endtime=None):
def __generatemetadata(self, streams, starttime=None, endtime=None, level='station'):
"""Generator to extract metadata based on the selection
:param streams: List of streams (integers) to be extracted
......@@ -431,17 +430,42 @@ return StationXML.
:type starttime: datetime
:param endtime: End time of the time window to access
:type endtime: datetime
:param level: Level of metadata ('network', 'station', 'channel', 'response')
:type level: str
:returns: miniSEED data
:rtype: bytearray
"""
# Check parameters
if level not in ('network', 'station', 'channel', 'response'):
raise Exception('Level parameter invalid (%s)' % level)
# TODO Misspelling which could possibly be fixed in the future
latkey = 'SystemInfomation.GPS.Latitude'
lonkey = 'SystemInfomation.GPS.Longitude'
elevkey = 'SystemInfomation.GPS.Altitude'
stkey = 'GPSTimeStamp'
srkey = 'SamplingFrequency[Hz]'
if level == 'network':
t = TDMS(self.__experiment, directory=self.__directory, starttime=starttime, endtime=endtime, iterate='M')
with t:
t.readMetadata()
yield '# Network|Description|StartTime|EndTime|TotalStations\n'
text = '%s|Description|%s|%s|%s\n' % (self.__net, t.starttime.isoformat(), t.endtime.isoformat(),
self.numChannels)
yield text
return
if level == 'response':
raise Exception('Response level not implemented!')
# Level station and channel
if level == 'station':
yield '# Network|Station|Latitude|Longitude|Elevation|SiteName|StartTime|EndTime\n'
else:
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:
......@@ -465,8 +489,12 @@ return StationXML.
# yield json.dumps(data, default=datetime.isoformat)
if data['data']:
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 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
......@@ -495,9 +523,12 @@ return StationXML.
# yield json.dumps(data, default=datetime.isoformat)
if data['data']:
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)
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
......
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