Skip to content

Instantly share code, notes, and snippets.

@acrosby
Last active December 14, 2015 04:48
Show Gist options
  • Save acrosby/5030467 to your computer and use it in GitHub Desktop.
Save acrosby/5030467 to your computer and use it in GitHub Desktop.
'''
Only slighted modified from code provided by Laura De Cicco (USGS).
Laura De Cicco, A. Crosby
http://nwisvaws02.er.usgs.gov/ogc-swie/wml2/uv/sos?request=GetObservation&featureID=01446500&offering=UNIT&observedProperty=00060&beginPosition=2013-02-15
'''
from xml.dom import minidom, Node
import datetime
def parse_sos_GetObservations(xml):
timestamp = []
value = []
parameter_nm = str(xml.getElementsByTagName("om:observedProperty")[0].attributes["xlink:title"].value)
units = str(xml.getElementsByTagName("wml2:uom")[0].attributes["code"].value)
name = str(xml.getElementsByTagName("gml:name")[0].firstChild.nodeValue)
i = 0
length = xml.getElementsByTagName("wml2:value").length
for i in range(0,length):
timeText = xml.getElementsByTagName("wml2:time")[i].firstChild.nodeValue
timeText = timeText[:-6]
time = datetime.datetime.strptime(timeText, '%Y-%m-%dT%H:%M:%S')
timestamp.append(time)
value.append(float(xml.getElementsByTagName("wml2:value")[i].firstChild.nodeValue))
i += 1
return timestamp, value, parameter_nm, units
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment