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, wqx_ns): self._root = element des = self._root.find(nsp("ActivityDescription", wqx_ns)) if des is not None: self.id = testXMLValue(des.find(nsp("ActivityIdentifier", wqx_ns))) self.type = testXMLValue(des.find(nsp("ActivityTypeCode", wqx_ns))) self.media = testXMLValue( des.find(nsp("ActivityMediaName", wqx_ns))) # Date/Time sd = testXMLValue(des.find(nsp("ActivityStartDate", wqx_ns))) # YYYY-MM-DD parse_string = "%s" % sd st = des.find(nsp("ActivityStartTime", wqx_ns)) # If no time is defined, skip trying to pull it out and just use the date if st is not None: t = testXMLValue(st.find(nsp("Time", wqx_ns))) tz = testXMLValue(st.find(nsp("TimeZoneCode", wqx_ns))) parse_string = "%s %s" % (parse_string, t) if tz is not None: parse_string = "%s %s" % (parse_string, tz) self.start_time = AsaTime.parse(parse_string) if self.start_time.tzinfo is None: self.start_time = self.start_time.replace(tzinfo=pytz.utc) self.project = testXMLValue(des.find(nsp("ProjectIdentifier", wqx_ns))) self.location_id = testXMLValue( des.find(nsp("MonitoringLocationIdentifier", wqx_ns))) self.comment = testXMLValue( des.find(nsp("ActivityCommentText", wqx_ns))) self.method_id = None self.method_name = None self.method_context = None # Method smpl = self._root.find(nsp("SampleDescription", wqx_ns)) if smpl is not None: self.sample_collection_equipment_name = testXMLValue( smpl.find(nsp("SampleCollectionEquipmentName", wqx_ns))) smplcol = smpl.find(nsp("SampleCollectionMethod", wqx_ns)) if smplcol is not None: self.method_id = testXMLValue( smplcol.find(nsp("MethodIdentifier", wqx_ns))) self.method_context = testXMLValue( smplcol.find(nsp("MethodIdentifierContext", wqx_ns))) self.method_name = testXMLValue( smplcol.find(nsp("MethodName", wqx_ns))) self.results = [] for res in self._root.findall(nsp("Result", wqx_ns)): self.results.append(WqxResult(res, wqx_ns))
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 __init__(self, element, wqx_ns): self._root = element des = self._root.find(nsp("ActivityDescription", wqx_ns)) if des is not None: self.id = testXMLValue(des.find(nsp("ActivityIdentifier", wqx_ns))) self.type = testXMLValue(des.find(nsp("ActivityTypeCode", wqx_ns))) self.media = testXMLValue(des.find(nsp("ActivityMediaName", wqx_ns))) # Date/Time sd = testXMLValue(des.find(nsp("ActivityStartDate", wqx_ns))) # YYYY-MM-DD parse_string = "%s" % sd st = des.find(nsp("ActivityStartTime", wqx_ns)) # If no time is defined, skip trying to pull it out and just use the date if st is not None: t = testXMLValue(st.find(nsp("Time", wqx_ns))) tz = testXMLValue(st.find(nsp("TimeZoneCode", wqx_ns))) parse_string = "%s %s" % (parse_string, t) if tz is not None: parse_string = "%s %s" % (parse_string, tz) self.start_time = AsaTime.parse(parse_string) if self.start_time.tzinfo is None: self.start_time = self.start_time.replace(tzinfo=pytz.utc) self.project = testXMLValue(des.find(nsp("ProjectIdentifier", wqx_ns))) self.location_id = testXMLValue(des.find(nsp("MonitoringLocationIdentifier", wqx_ns))) self.comment = testXMLValue(des.find(nsp("ActivityCommentText", wqx_ns))) self.method_id = None self.method_name = None self.method_context = None # Method smpl = self._root.find(nsp("SampleDescription", wqx_ns)) if smpl is not None: self.sample_collection_equipment_name = testXMLValue( smpl.find(nsp("SampleCollectionEquipmentName", wqx_ns)) ) smplcol = smpl.find(nsp("SampleCollectionMethod", wqx_ns)) if smplcol is not None: self.method_id = testXMLValue(smplcol.find(nsp("MethodIdentifier", wqx_ns))) self.method_context = testXMLValue(smplcol.find(nsp("MethodIdentifierContext", wqx_ns))) self.method_name = testXMLValue(smplcol.find(nsp("MethodName", wqx_ns))) self.results = [] for res in self._root.findall(nsp("Result", wqx_ns)): self.results.append(WqxResult(res, wqx_ns))