def __init__(self, element): wqx_ns = "http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" if isinstance(element, str) or isinstance(element, unicode): try: self._root = etree.fromstring(element) except ValueError: # Strip out the XML header due to UTF8 encoding declaration self._root = etree.fromstring(element[38:]) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() org = self._root.find(nsp("Organization", wqx_ns)) self.failed = False if org is None: self.failed = True else: self.organization = WqxOrganizationDescription( org.find(nsp("OrganizationDescription", wqx_ns)), wqx_ns) self.location = None ml = org.find(nsp("MonitoringLocation", wqx_ns)) if ml is not None: self.location = WqxMonitoringLocation(ml, wqx_ns) self.activities = [] for act in org.findall(nsp("Activity", wqx_ns)): self.activities.append(WqxActivity(act, wqx_ns))
def __init__(self, element): wqx_ns = "http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" if isinstance(element, str) or isinstance(element, unicode): try: self._root = etree.fromstring(element) except ValueError: # Strip out the XML header due to UTF8 encoding declaration self._root = etree.fromstring(element[38:]) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() org = self._root.find(nsp("Organization", wqx_ns)) self.failed = False if org is None: self.failed = True else: self.organization = WqxOrganizationDescription(org.find(nsp("OrganizationDescription",wqx_ns)), wqx_ns) self.location = None ml = org.find(nsp("MonitoringLocation",wqx_ns)) if ml is not None: self.location = WqxMonitoringLocation(ml, wqx_ns) self.activities = [] for act in org.findall(nsp("Activity", wqx_ns)): self.activities.append(WqxActivity(act, wqx_ns))
def _makesoap(self, xmlelement): request = """<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> REQUEST </SOAP-ENV:Body> </SOAP-ENV:Envelope> """ enve = etree.fromstring(request) body = enve.find(".//{%s}Body" % "http://schemas.xmlsoap.org/soap/envelope/") body.append(xmlelement) headers = { "SOAPAction": "\"\"", } r = requests.post(self.wsdl_url, data=etree.tostring(enve), headers=headers) return etree.fromstring(r.text[38:]).find(".//returnData")
def get_stations(self): if self.wildcard is not None: xml_str = """ <exportStationCodesXMLNew xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <wildcard xsi:type="xsd:string">OPTIONALVALUE</wildcard> </exportStationCodesXMLNew> """ xml_obj = etree.fromstring(xml_str) xml_obj.find(".//wildcard").text = self.wildcard else: """<exportStationCodesXMLNew />""" xml_obj = etree.Element("exportStationCodesXMLNew") env = self._makesoap(xml_obj) stats = [] for data in env.findall(".//data"): s = {} for child in data: val = testXMLValue(child) if val is None: val = "" s[child.tag] = val lon = float(s["Longitude"]) s["Longitude"] = lon if lon < 0 else -lon s["Latitude"] = float(s["Latitude"]) stats.append(s) return stats
def _build_exportSingleParamXMLNew(self, feature): xml_str = """ <exportSingleParamXMLNew xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <station_code xsi:type="xsd:string">FILLME</station_code> <recs xsi:type="xsd:string">FILLME</recs> <param xsi:type="xsd:string">FILLME</param> <wildcard xsi:type="xsd:string">OPTIONALVALUE</wildcard> </exportSingleParamXMLNew> """ xml_obj = etree.fromstring(xml_str) if self.wildcard is not None: xml_obj.find(".//wildcard").text = self.wildcard # Set parameters feature_vars = self.list_variables(feature=feature) if len(feature_vars) == 0: # This feature has no variables, skip it return None else: if self.variables is not None: # Query for vars this station has queryvars = set(self.variables).intersection(feature_vars) if len(queryvars) == 0: # Skip this feature.. it doesn't have any of the requested variables return None xml_obj.find(".//param").text = ",".join(queryvars) else: # No variable subset requested xml_obj.find(".//param").text = ",".join(feature_vars) # Set station and recs xml_obj.find(".//station_code").text = feature xml_obj.find(".//recs").text = "100" return xml_obj
def __new__(cls, element): if isinstance(element, str): root = etree.fromstring(element) else: root = element if hasattr(root, 'getroot'): root = root.getroot() XLINK_NS = ns.get_namespace("xlink") GML_NS = [ns.get_versioned_namespace('gml', '3.1.1')] version = None for g in GML_NS: try: version = testXMLValue( root.find( "{%s}metaDataProperty[@{%s}title='ioosTemplateVersion']/{%s}version" % (g, XLINK_NS, g))) break except: continue if version == "1.0": from pyoos.parsers.ioos.one.get_observation import GetObservation as GO10 return super(IoosGetObservation, cls).__new__(GO10, element=root) else: raise ValueError("Unsupported IOOS version. Supported: [1.0]")
def test_timeseries_profile_single_station(self): swe = open( resource_file( 'ioos_swe/SWE-SingleStation-TimeSeriesProfile_QC.xml')).read() data_record = etree.fromstring(swe) station = TimeSeriesProfile(data_record).feature assert isinstance(station, StationProfile) assert station.uid == "urn:ioos:station:wmo:41001" assert station.name == "wmo_41001" assert station.location.x == -75.415 assert station.location.y == 32.382 assert station.location.z == 0.5 # should have three profiles assert len(station.elements) == 3 station.calculate_bounds() # should all be at the same point bounds = station.get_bbox() assert isinstance(bounds, Point) assert bounds.x == -75.415 assert bounds.y == 32.382 # time time_range = station.get_time_range() assert time_range[0].strftime( "%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z" assert time_range[-1].strftime( "%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T02:00:00Z" # depth bounds depth_range = station.get_depth_range() assert depth_range[0] == -39.5 assert depth_range[-1] == -4.5 # spot check values profile = station.elements[0] assert profile.time.strftime( "%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z" assert len(profile.elements) == 4 assert [e.location.z for e in profile.elements] == [-39.5, -19.5, -9.5, -4.5] assert len(profile.elements[0].members) == 2 assert [m['name'] for m in profile.elements[0].members ] == ['direction_of_sea_water_velocity', 'sea_water_speed'] assert [m['value'] for m in profile.elements[0].members] == [352.0, 9.6] sensor = station.sensors['wmo_41001_sensor1'] assert 'sensor_orientation' in sensor assert sensor['sensor_orientation']['X'][ 'name'] == 'platform_pitch_angle' assert sensor['sensor_orientation']['Y'][ 'name'] == 'platform_roll_angle' assert sensor['sensor_orientation']['Z'][ 'name'] == 'platform_orientation'
def __new__(cls, element): if isinstance(element, str): root = etree.fromstring(element) else: root = element sml_str = ".//{{{0}}}identifier/{{{0}}}Term[@definition='http://mmisw.org/ont/ioos/definition/%s']".format(SML_NS) if hasattr(root, 'getroot'): root = root.getroot() # circular dependencies are bad. consider a reorganization # find the the proper type for the DescribeSensor from pyoos.parsers.ioos.one.describe_sensor import (NetworkDS, StationDS, SensorDS) for ds_type, constructor in [('networkID', NetworkDS), ('stationID', StationDS), ('sensorID', SensorDS)]: if root.find(sml_str % ds_type) is not None: return super(IoosDescribeSensor, cls).__new__(constructor) # NOAA CO-OPS sml_str = ".//{{{0}}}identifier/{{{0}}}Term[@definition='urn:ioos:def:identifier:NOAA::networkID']".format(SML_NS) if root.find(sml_str) is not None: return super(IoosDescribeSensor, cls).__new__(NetworkDS) # if we don't find the proper request from the IOOS definitions, # try to adapt a generic DescribeSensor request to the dataset from pyoos.parsers.ioos.one.describe_sensor import GenericSensor return super(IoosDescribeSensor, cls).__new__(GenericSensor)
def get_stations(self): if self.wildcard is not None: xml_str = """ <exportStationCodesXMLNew xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <wildcard xsi:type="xsd:string">OPTIONALVALUE</wildcard> </exportStationCodesXMLNew> """ xml_obj = etree.fromstring(xml_str) xml_obj.find(".//wildcard").text = self.wildcard else: """<exportStationCodesXMLNew />""" xml_obj = etree.Element("exportStationCodesXMLNew") env = self._makesoap(xml_obj) stats = [] for data in env.findall(".//data"): s = {} for child in data: val = testXMLValue(child) if val is None: val = "" s[child.tag] = val lon = float(s['Longitude']) s['Longitude'] = lon if lon < 0 else -lon s['Latitude'] = float(s['Latitude']) stats.append(s) return stats
def test_timeseries_single_station_single_sensor(self): swe = open( resource_file( 'ioos_swe/SWE-SingleStation-SingleProperty-TimeSeries.xml') ).read() data_record = etree.fromstring(swe) station = TimeSeries(data_record).feature assert isinstance(station, Station) assert station.uid == "urn:ioos:station:wmo:41001" assert station.name == "wmo_41001" assert station.location.x == -75.415 assert station.location.y == 32.382 assert station.location.z == 0.5 assert sorted( map(lambda x: x.time.strftime("%Y-%m-%dT%H:%M:%SZ"), station.elements)) == sorted([ "2009-05-23T00:00:00Z", "2009-05-23T01:00:00Z", "2009-05-23T02:00:00Z" ]) first_members = station.elements[0].members assert sorted(map(lambda x: x['value'], first_members)) == sorted([2.0, 15.4, 280]) assert sorted(map(lambda x: x['standard'], first_members)) == sorted([ "http://mmisw.org/ont/cf/parameter/air_temperature", "http://mmisw.org/ont/cf/parameter/wind_to_direction", "http://mmisw.org/ont/cf/parameter/wind_speed" ])
def _build_exportSingleParamXMLNew(self, feature): xml_str = """ <exportSingleParamXMLNew xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <station_code xsi:type="xsd:string">FILLME</station_code> <recs xsi:type="xsd:string">FILLME</recs> <param xsi:type="xsd:string">FILLME</param> </exportSingleParamXMLNew> """ xml_obj = etree.fromstring(xml_str) # Set parameters feature_vars = self.list_variables(feature=feature) if len(feature_vars) == 0: # This feature has no variables, skip it return None else: if self.variables is not None: # Query for vars this station has queryvars = set(self.variables).intersection(feature_vars) if len(queryvars) == 0: # Skip this feature.. it doesn't have any of the requested variables return None xml_obj.find(".//param").text = ",".join(queryvars) else: # No variable subset requested xml_obj.find(".//param").text = ",".join(feature_vars) # Set station and recs xml_obj.find(".//station_code").text = feature xml_obj.find(".//recs").text = "100" return xml_obj
def _build_exportAllParamsDateRangeXMLNew(self, feature): xml_str = """ <exportAllParamsDateRangeXMLNew xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <station_code xsi:type="xsd:string">owcowmet</station_code> <mindate xsi:type="xsd:string">05/29/2013</mindate> <maxdate xsi:type="xsd:string">05/31/2013</maxdate> <param xsi:type="xsd:string">WSpd,WDir</param> </exportAllParamsDateRangeXMLNew> """ xml_obj = etree.fromstring(xml_str) xml_obj.find(".//mindate").text = self.start_time.strftime('%m/%d/%Y') xml_obj.find(".//maxdate").text = self.end_time.strftime('%m/%d/%Y') feature_vars = self.list_variables(feature=feature) if len(feature_vars) == 0: # This feature has no variables, skip it return None else: if self.variables is not None: # Query for vars this station has queryvars = set(self.variables).intersection(feature_vars) if len(queryvars) == 0: # Skip this feature.. it doesn't have any of the requested variables return None xml_obj.find(".//param").text = ",".join(queryvars) else: # No variable subset requested xml_obj.find(".//param").text = ",".join(feature_vars) # Set station and recs xml_obj.find(".//station_code").text = feature return xml_obj
def test_timeseries_multi_station_multi_sensor(self): swe = open(resource_file('ioos_swe/SWE-MultiStation-TimeSeries.xml'), 'rb').read() data_record = etree.fromstring(swe) collection = TimeSeries(data_record).feature assert isinstance(collection, StationCollection) assert len(collection.elements) == 3
def __new__(cls, element): if isinstance(element, ElementType): root = element else: root = etree.fromstring(element) sml_str = ".//{{{0}}}identifier/{{{0}}}Term[@definition='http://mmisw.org/ont/ioos/definition/%s']".format( SML_NS) if hasattr(root, 'getroot'): root = root.getroot() # Circular dependencies are bad. consider a reorganization # find the the proper type for the DescribeSensor. from pyoos.parsers.ioos.one.describe_sensor import (NetworkDS, StationDS, SensorDS) for ds_type, constructor in [('networkID', NetworkDS), ('stationID', StationDS), ('sensorID', SensorDS)]: if root.find(sml_str % ds_type) is not None: return super(IoosDescribeSensor, cls).__new__(constructor) # NOAA CO-OPS sml_str = ".//{{{0}}}identifier/{{{0}}}Term[@definition='urn:ioos:def:identifier:NOAA::networkID']".format( SML_NS) if root.find(sml_str) is not None: return super(IoosDescribeSensor, cls).__new__(NetworkDS) # If we don't find the proper request from the IOOS definitions, # try to adapt a generic DescribeSensor request to the dataset. from pyoos.parsers.ioos.one.describe_sensor import GenericSensor return super(IoosDescribeSensor, cls).__new__(GenericSensor)
def __init__(self, response_list, nerrs_stations=None): assert isinstance(response_list, dict) if nerrs_stations is None: from pyoos.collectors.nerrs.nerrs_soap import NerrsSoap nerrs_stations = NerrsSoap().stations def get_station(feature): for s in nerrs_stations: if s['Station_Code'].lower() == feature.lower(): return s skip_tags = ["DateTimeStamp", "utcStamp", "data", "MaxWSpdT"] stations = [] for feature, response in response_list.iteritems(): if not isinstance(response, etree._Element): response = etree.fromstring(response) feature = get_station(feature) s = Station() s.uid = feature['Station_Code'] s.name = feature['Station_Name'] s.location = sPoint(float(feature['Longitude']), float(feature['Latitude']), 0) s.set_property("state", feature['State']) s.set_property("siteid", feature['NERR_Site_ID']) s.set_property("horizontal_crs", "EPSG:4326") s.set_property("vertical_units", "m") s.set_property("vertical_crs", "EPSG:4297") s.set_property("location_description", feature['Reserve_Name']) for data in response.findall(".//data"): p = Point() t = AsaTime.parse(testXMLValue(data.find("utcStamp"))) t = t.replace(tzinfo=pytz.utc) p.time = t p.location = s.location for child in data: if child.tag not in skip_tags: try: val = float(child.text) p.add_member( Member(value=val, unit=units(child.tag), name=child.tag, description=child.tag, standard=standard(child.tag))) except TypeError: # Value was None pass s.add_element(p) stations.append(s) self.feature = StationCollection(elements=stations)
def __init__(self, element): # Get individual om:Observations has a hash or name:ob if isinstance(element, str): self._root = etree.fromstring(element) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() self.observations = []
def __init__(self, element): # Get individual om:Observations has a hash or name:ob. if isinstance(element, ElementType): self._root = element else: self._root = etree.fromstring(element) if hasattr(self._root, 'getroot'): self._root = self._root.getroot() self.observations = []
def __init__(self, element): # Get individual om:Observations has a hash or name:ob. if isinstance(element, ElementType): self._root = element else: self._root = etree.fromstring(element) if hasattr(self._root, "getroot"): self._root = self._root.getroot() self.observations = []
def __new__(cls, element): if isinstance(element, str): root = etree.fromstring(element) else: root = element if hasattr(root, 'getroot'): root = root.getroot() XLINK_NS = ns.get_namespace("xlink") SWE_NS = [ns.get_versioned_namespace('swe', '1.0.1')] version = None for g in SWE_NS: try: version = testXMLValue( root.find( ".//{%s}field[@name='ioosTemplateVersion']/{%s}Text/{%s}value" % (g, g, g))) break except: raise if version == "1.0": SML_NS = ns.get_versioned_namespace('sml', '1.0.1') try: assert testXMLValue( root.find( ".//{%s}identifier[@name='networkID']/{%s}Term[@definition='http://mmisw.org/ont/ioos/definition/networkID']/{%s}value" % (SML_NS, SML_NS, SML_NS))) from pyoos.parsers.ioos.one.describe_sensor import NetworkDS return super(IoosDescribeSensor, cls).__new__(NetworkDS) except AssertionError: try: assert testXMLValue( root.find( ".//{%s}identifier[@name='stationID']/{%s}Term[@definition='http://mmisw.org/ont/ioos/definition/stationID']/{%s}value" % (SML_NS, SML_NS, SML_NS))) from pyoos.parsers.ioos.one.describe_sensor import StationDS return super(IoosDescribeSensor, cls).__new__(StationDS) except AssertionError: try: assert testXMLValue( root.find( ".//{%s}identifier[@name='sensorID']/{%s}Term[@definition='http://mmisw.org/ont/ioos/definition/sensorID']/{%s}value" % (SML_NS, SML_NS, SML_NS))) from pyoos.parsers.ioos.one.describe_sensor import SensorDS return super(IoosDescribeSensor, cls).__new__(SensorDS) except AssertionError: raise ValueError( "Could not determine if this was a Network, Station, or Sensor SensorML document" ) else: raise ValueError( "Unsupported IOOS version (%s). Supported: [1.0]" % version)
def __init__(self, response_list, nerrs_stations=None): assert isinstance(response_list, dict) if nerrs_stations is None: from pyoos.collectors.nerrs.nerrs_soap import NerrsSoap nerrs_stations = NerrsSoap().stations def get_station(feature): for s in nerrs_stations: if s['Station_Code'].lower() == feature.lower(): return s skip_tags = ["DateTimeStamp", "utcStamp", "data", "MaxWSpdT"] stations = [] for feature, response in response_list.items(): if not isinstance(response, etree._Element): response = etree.fromstring(response) feature = get_station(feature) s = Station() s.uid = feature['Station_Code'] s.name = feature['Station_Name'] s.location = sPoint(feature['Longitude'], feature['Latitude'], 0) s.set_property("state", feature['State']) s.set_property("siteid", feature['NERR_Site_ID']) s.set_property("horizontal_crs", "EPSG:4326") s.set_property("vertical_units", "m") s.set_property("vertical_crs", "EPSG:4297") s.set_property("location_description", feature['Reserve_Name']) for data in response.findall(".//data"): p = Point() t = AsaTime.parse(testXMLValue(data.find("utcStamp"))) t = t.replace(tzinfo=pytz.utc) p.time = t p.location = s.location for child in data: if child.tag not in skip_tags: try: val = float(child.text) p.add_member(Member(value=val, name=child.tag, description=child.tag, unit=units(child.tag), standard=standard(child.tag))) except TypeError: # Value was None pass s.add_element(p) stations.append(s) self.feature = StationCollection(elements=stations)
def _makesoap(self, xmlelement): request = """<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> REQUEST </SOAP-ENV:Body> </SOAP-ENV:Envelope> """ enve = etree.fromstring(request) body = enve.find(".//{%s}Body" % "http://schemas.xmlsoap.org/soap/envelope/") body.append(xmlelement) headers = { "SOAPAction" : "\"\"", } r = requests.post(self.wsdl_url, data=etree.tostring(enve), headers=headers) return etree.fromstring(r.text[38:]).find(".//returnData")
def __init__(self, element): if isinstance(element, str): self._root = etree.fromstring(element) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() # Get individual om:Observations self.observations = {} for ob in self._root.findall(nsp("member/Observation", ns.get_versioned_namespace('om','1.0'))): ob_ele = OmObservation(ob) self.observations[ob_ele.name] = ob_ele
def test_timeseries_profile_single_station(self): swe = open(resource_file('ioos_swe/SWE-SingleStation-TimeSeriesProfile_QC.xml'), 'rb').read() data_record = etree.fromstring(swe) station = TimeSeriesProfile(data_record).feature assert isinstance(station, StationProfile) assert station.uid == "urn:ioos:station:wmo:41001" assert station.name == "wmo_41001" assert station.location.x == -75.415 assert station.location.y == 32.382 assert station.location.z == 0.5 # should have three profiles assert len(station.elements) == 3 station.calculate_bounds() # should all be at the same point bounds = station.get_bbox() assert isinstance(bounds, Point) assert bounds.x == -75.415 assert bounds.y == 32.382 # time time_range = station.get_time_range() assert time_range[0].strftime("%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z" assert time_range[-1].strftime("%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T02:00:00Z" # depth bounds depth_range = station.get_depth_range() assert depth_range[0] == -39.5 assert depth_range[-1] == -4.5 # spot check values profile = station.elements[0] assert profile.time.strftime("%Y-%m-%dT%H:%M:%SZ") == "2009-05-23T00:00:00Z" assert len(profile.elements) == 4 assert [e.location.z for e in profile.elements] == [-39.5, -19.5, -9.5, -4.5] assert len(profile.elements[0].members) == 2 assert [m['name'] for m in profile.elements[0].members] == ['direction_of_sea_water_velocity', 'sea_water_speed'] assert [m['value'] for m in profile.elements[0].members] == [352.0, 9.6] sensor = station.sensors['wmo_41001_sensor1'] assert 'sensor_orientation' in sensor assert sensor['sensor_orientation']['X']['name'] == 'platform_pitch_angle' assert sensor['sensor_orientation']['Y']['name'] == 'platform_roll_angle' assert sensor['sensor_orientation']['Z']['name'] == 'platform_orientation'
def __init__(self, element): wqx_ns = "http://qwwebservices.usgs.gov/schemas/WQX-Outbound/2_0/" if isinstance(element, text_type): try: self._root = etree.fromstring(element) except ValueError: # Strip out the XML header due to UTF8 encoding declaration self._root = etree.fromstring(element[38:]) else: self._root = element if hasattr(self._root, "getroot"): self._root = self._root.getroot() self.failed = False self.organizations = [] orgs = self._root.findall(nsp("Organization", wqx_ns)) if orgs is None: self.failed = True else: for org in orgs: self.organizations.append(WqxOrganization(org, wqx_ns))
def __init__(self, element): if isinstance(element, str): self._root = etree.fromstring(element) else: self._root = element if hasattr(self._root, 'getroot'): self._root = self._root.getroot() # Get individual om:Observations self.observations = {} for ob in self._root.findall( nsp("member/Observation", ns.get_versioned_namespace('om', '1.0'))): ob_ele = OmObservation(ob) self.observations[ob_ele.name] = ob_ele
def parse_response(self,response): if response is None: return None xml = etree.fromstring(response) time_series = self._read_xml(xml) if len(time_series) > 1: # retval is a StationCollection retval = StationCollection() for ts in time_series: st = self._timeseries_to_station(ts) retval.add_element(st) else: # retval is a Station retval = self._timeseries_to_station(time_series[0]) return retval
def test_timeseries_single_station_single_sensor(self): swe = open(resource_file('ioos_swe/SWE-SingleStation-SingleProperty-TimeSeries.xml'), 'rb').read() data_record = etree.fromstring(swe) station = TimeSeries(data_record).feature assert isinstance(station, Station) assert station.uid == "urn:ioos:station:wmo:41001" assert station.name == "wmo_41001" assert station.location.x == -75.415 assert station.location.y == 32.382 assert station.location.z == 0.5 assert sorted([x.time.strftime("%Y-%m-%dT%H:%M:%SZ") for x in station.elements]) == sorted(["2009-05-23T00:00:00Z", "2009-05-23T01:00:00Z", "2009-05-23T02:00:00Z"]) first_members = station.elements[0].members assert sorted([x['value'] for x in first_members]) == sorted([2.0, 15.4, 280]) assert sorted([x['standard'] for x in first_members]) == sorted(["http://mmisw.org/ont/cf/parameter/air_temperature", "http://mmisw.org/ont/cf/parameter/wind_to_direction", "http://mmisw.org/ont/cf/parameter/wind_speed"])
def __new__(cls, element): if isinstance(element, str): root = etree.fromstring(element) else: root = element if hasattr(root, 'getroot'): root = root.getroot() XLINK_NS = ns.get_namespace("xlink") SWE_NS = [ns.get_versioned_namespace('swe','1.0.1')] version = None for g in SWE_NS: try: version = testXMLValue(root.find(".//{%s}field[@name='ioosTemplateVersion']/{%s}Text/{%s}value" % (g,g,g))) break except: raise if version == "1.0": SML_NS = ns.get_versioned_namespace('sml', '1.0.1') try: assert testXMLValue(root.find(".//{%s}identifier[@name='networkID']/{%s}Term[@definition='http://mmisw.org/ont/ioos/definition/networkID']/{%s}value" % (SML_NS, SML_NS, SML_NS))) from pyoos.parsers.ioos.one.describe_sensor import NetworkDS return super(IoosDescribeSensor, cls).__new__(NetworkDS) except AssertionError: try: assert testXMLValue(root.find(".//{%s}identifier[@name='stationID']/{%s}Term[@definition='http://mmisw.org/ont/ioos/definition/stationID']/{%s}value" % (SML_NS, SML_NS, SML_NS))) from pyoos.parsers.ioos.one.describe_sensor import StationDS return super(IoosDescribeSensor, cls).__new__(StationDS) except AssertionError: try: assert testXMLValue(root.find(".//{%s}identifier[@name='sensorID']/{%s}Term[@definition='http://mmisw.org/ont/ioos/definition/sensorID']/{%s}value" % (SML_NS, SML_NS, SML_NS))) from pyoos.parsers.ioos.one.describe_sensor import SensorDS return super(IoosDescribeSensor, cls).__new__(SensorDS) except AssertionError: raise ValueError("Could not determine if this was a Network, Station, or Sensor SensorML document") else: raise ValueError("Unsupported IOOS version (%s). Supported: [1.0]" % version)
def __new__(cls, element): if isinstance(element, ElementType): root = element else: root = etree.fromstring(element) if hasattr(root, 'getroot'): root = root.getroot() XLINK_NS = ns.get_namespace("xlink") GML_NS = [ns.get_versioned_namespace('gml', '3.1.1')] version = None for g in GML_NS: try: version = testXMLValue(root.find("{%s}metaDataProperty[@{%s}title='ioosTemplateVersion']/{%s}version" % (g, XLINK_NS, g))) break except: continue if version == "1.0": from pyoos.parsers.ioos.one.get_observation import GetObservation as GO10 return super(IoosGetObservation, cls).__new__(GO10) else: raise ValueError("Unsupported IOOS version {}. Supported: [1.0]".format(version))
except HTTPError, e: if e.getcode() == 500: raise ValueError('Invalid value(s) in request, please check input and try again') else: raise return None except: raise return None self.response_soap = self.response.read() self.response.close() # pass in the etree object that points to the return/response point xml_root = None try: xml_root = etree.fromstring(self.response_soap) except Exception, e: xml_root = etree.fromstring(self.response_soap[38:]) if hasattr(xml_root, 'getroot'): xml_root = xml_root.getroot() xml_root = xml_root.find(nspath('Body',namespace=self._SOAPENV)) xml_root = xml_root.find(".//returnData") if xml is True: return xml_root return Reply(xml_root)
def get_characterisic_types(self, **kwargs): root = etree.fromstring( requests.get(self.characteristic_types_url).text) return (x.get("value") for x in root.findall("Code"))
def get_characteristics(self, **kwargs): root = etree.fromstring(requests.get(self.characteristics_url).text) return (x.get('value') for x in root.findall('Code'))
def list_variables(self): root = etree.fromstring(requests.get(self.characteristics_url).text) return (x.get('value') for x in root.findall('Code'))
def get_characterisic_types(self, **kwargs): root = etree.fromstring( requests.get(self.characteristic_types_url).text ) return (x.get("value") for x in root.findall("Code"))
def list_variables(self): root = etree.fromstring(requests.get(self.characteristics_url).text) return (x.get("value") for x in root.findall("Code"))