Last active
December 14, 2015 04:48
-
-
Save acrosby/5030467 to your computer and use it in GitHub Desktop.
This function parses wml2 like is returned by http://nwisvaws02.er.usgs.gov/ogc-swie/wml2/uv/sos?request=GetObservation&featureID=01446500&offering=UNIT&observedProperty=00060&beginPosition=2013-02-15 The function takes a minidom object as input ("xml").
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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