def parse_location(self,xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) geogs = self._findall('geogLocation') self.geo_coords = list() self.srs = list() for g in geogs: self.geo_coords.append((testXMLValue(g.find(ns(self._ns) + 'longitude')),testXMLValue(g.find(ns(self._ns) + 'latitude')))) self.srs.append(g.attrib.get('srs')) locsite = self._findall('localSiteXY') self.local_sites = list() self.notes = list() self.projections = list() for ls in locsite: z = testXMLValue(ls.find(ns(self._ns) + 'Z')) if z is not None: self.local_sites.append((testXMLValue(ls.find(ns(self._ns) + 'X')),testXMLValue(ls.find(ns(self._ns) + 'Y')),z)) else: self.local_sites.append((testXMLValue(ls.find(ns(self._ns) + 'X')),testXMLValue(ls.find(ns(self._ns) + 'Y')),'0')) self.notes.append([testXMLValue(note) for note in ls.findall(ns(self._ns) + 'note')]) self.projections.append(ls.attrib.get('projectionInformation'))
def parse_siteinfo(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) self.site_name = xml_dict.get('site_name') self.site_codes = [ testXMLValue(code) for code in self._findall('siteCode') ] self.elevation = xml_dict.get('elevation_m') self.vertical_datum = xml_dict.get('vertical_datum') self.site_types = [ testXMLValue(typ) for typ in self._findall('siteType') ] self.site_properties = dict([ (prop.attrib.get('name'), testXMLValue(prop)) for prop in self._findall('siteProperty') ]) self.altname = xml_dict.get('altname') self.notes = [testXMLValue(note) for note in self._findall('note')] # sub-objects tzi = self._find('timeZoneInfo') if tzi is not None: self.time_zone_info = TimeZoneInfo(tzi, self._ns) self.location = Location(self._find('geoLocation'), self._ns)
def parse_criteria(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root, depth=4) self.method_called = self._root.attrib.get('MethodCalled') self.location_param = xml_dict.get('location_param') self.variable_param = xml_dict.get('variable_param') try: self.begin_date_time = parser.parse(xml_dict['begin_date_time']) except: self.begin_date_time = None try: self.end_date_time = parser.parse(xml_dict['end_date_time']) except: self.end_date_time = None self.parameters = [(param.attrib.get('name'), param.attrib.get('value')) for param in self._findall('parameter')]
def parse_values(self): xml_dict = _xml_to_dict(self._root) # method info self.methods = [Method(method,self._ns) for method in self._findall('method')] # source info self.sources = [Source(source,self._ns) for source in self._findall('source')] # quality control info self.qualit_control_levels = [QualityControlLevel(qal, self._ns) for qal in self._findall('qualityControlLevel')] # offset info self.offsets = [Offset(os,self._ns) for os in self._findall('offset')] # sample info self.samples = [Sample(sample,self._ns) for sample in self._findall('sample')] # censor codes self.censor_codes = [CensorCode(code, self._ns) for code in self._findall('censorCode')] # unit if self._ns == 'wml1.0': self.unit_abbreviation = self._root.attrib.get('unitsAbbreviation') self.unit_code = self._root.attrib.get('unitsCode') self.count = self._root.attrib.get('count') else: unit = self._find('unit') self.unit = Unit(unit, self._ns) if unit is not None else None # values self.values = [Value(val, self._ns) for val in self._findall('value')]
def parse_series(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root, depth=3) self.value_count = xml_dict.get('value_count') self.value_type = xml_dict.get('value_type') self.general_category = xml_dict.get('general_category') self.sample_medium = xml_dict.get('sample_medium') self.data_type = xml_dict.get('data_type') # date-time self.begin_date_time = parser.parse(xml_dict.get('begin_date_time')) self.begin_date_time_utc = parser.parse( xml_dict.get('begin_date_time_utc')) if xml_dict.get( 'begin_date_time_utc') is not None else None self.end_date_time = parser.parse(xml_dict.get('end_date_time')) self.end_date_time_utc = parser.parse( xml_dict.get('end_date_time_utc')) if xml_dict.get( 'end_date_time_utc') is not None else None # method info self.method_description = xml_dict.get('method_description') self.method_code = xml_dict.get('method_code') self.method_link = xml_dict.get('method_link') method = self._find('method') if method is not None: self.method_id = method.attrib.get('methodID') else: self.method_id = None # source info self.organization = xml_dict.get('organization') self.source_description = xml_dict.get('source_description') self.citation = xml_dict.get('citation') source = self._find('source') if source is not None: self.source_id = source.attrib.get('sourceID') else: self.source_id = None # quality control info self.quality_control_level_code = xml_dict.get( 'quality_control_level_code') self.definition = xml_dict.get('definition') qa = self._find('qualityControlLevel') if qa is not None: self.quality_control_level_id = qa.attrib.get( 'qualityControlLevelID') else: self.quality_control_level_id = None # properties self.properties = dict([(prop.attrib.get('name'), testXMLValue(prop)) for prop in self._findall('seriesProperty')]) # sub-objects self.variable = Variable(self._find('variable'), self._ns)
def parse_category(self): try: xml_dict = _xml_to_dict(self._root) self.data_value = xml_dict.get('data_value') self.description = xml_dict.get('description') self.id = self._root.attrib.get('categoryID') except: raise
def parse_censorcode(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('censor_code') self.description = xml_dict.get('censor_code_description') self.id = self._root.attrib.get('censorCodeID') except: raise
def parse_sample(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('lab_sample_code') self.type = xml_dict.get('sample_type') lm = self._find('labMethod') self.method = LabMethod(lm, self._ns) if lm is not None else None except: raise
def parse_method(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('method_code') self.description = xml_dict.get('method_description') self.link = xml_dict.get('method_link') self.id = self._root.attrib.get('methodID') except: raise
def parse_qcl(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('quality_control_level_code') self.definition = xml_dict.get('definition') self.explanation = xml_dict.get('explanation') self.id = self._root.attrib.get('qualityControlLevelID') except: raise
def parse_variable(self,xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) self.value_type = xml_dict.get('value_type') self.data_type = xml_dict.get('data_type') self.general_category = xml_dict.get('general_category') self.sample_medium = xml_dict.get('sample_medium') self.no_data_value = xml_dict.get('no_data_value') self.variable_name = xml_dict.get('variable_name') self.variable_code = xml_dict.get('variable_code') self.variable_description = xml_dict.get('variable_description') self.speciation = xml_dict.get('speciation') # notes and properties notes = [(note.attrib.get('title'),testXMLValue(note)) for note in self._findall('note')] none_notes = [note[1] for note in notes if note[0] is None] self.notes = dict([note for note in notes if note[0] is not None]) if len(none_notes) > 0: self.notes['none'] = none_notes self.properties = dict([(prop.attrib.get('name'),testXMLValue(prop)) for prop in self._findall('variableProperty')]) # related related = self._find('related') if related is not None: self.parent_codes = [dict([('network',code.attrib.get('network')),('vocabulary',code.attrib.get('vocabulary')),('default',code.attrib.get('default'))]) for code in related.findall(ns(self._ns) + 'parentCode')] self.related_codes = [dict([('network',d.get('network')),('vocabulary',d.get('vocabulary')),('default',d.get('default'))]) for code in related.findall(ns(self._ns) + 'relatedCode')] else: self.parent_codes = None self.related_codes = None # sub-objects if self._ns == 'wml1.0': unit = self._find('units') self.unit = Unit1_0(unit, self._ns) if unit is not None else None timesupport = self._find('timeSupport') self.time_support = TimeScale(timesupport, self._ns) if timesupport is not None else None else: unit = self._find('unit') self.unit = Unit(unit, self._ns) if unit is not None else None timescale = self._find('timeScale') self.time_scale = TimeScale(timescale, self._ns) if timescale is not None else None categories = self._find('categories') if categories is not None: self.categories = [Category(cat,self._ns) for cat in categories.findall(ns(self._ns) + 'category')] else: self.categories = None
def parse_contactinformation(self): try: xml_dict = _xml_to_dict(self._root) self.name = xml_dict.get('contact_name') self.type = xml_dict.get('type_of_contact') self.email = [testXMLValue(email) for email in self._findall('email')] self.phone = [testXMLValue(phone) for phone in self._findall('phone')] self.address = [testXMLValue(address) for address in self._findall('address')] except: raise
def parse_timescale(self): try: xml_dict = _xml_to_dict(self._root) self.time_spacing = xml_dict.get('time_spacing') self.time_support = xml_dict.get('time_support') self.time_interval = xml_dict.get('time_interval') unit = self._find('unit') self.unit = Unit(unit, self._ns) if unit is not None else None except: raise
def parse_unit(self): try: xml_dict = _xml_to_dict(self._root) self.name = xml_dict.get('unit_name') self.unit_type = xml_dict.get('unit_type') self.description = xml_dict.get('unit_description') self.abbreviation = xml_dict.get('unit_abbreviation') self.code = xml_dict.get('unit_code') self.id = self._root.attrib.get('UnitID') except: raise
def parse_series(self,xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root,depth=3) self.value_count = xml_dict.get('value_count') self.value_type = xml_dict.get('value_type') self.general_category = xml_dict.get('general_category') self.sample_medium = xml_dict.get('sample_medium') self.data_type = xml_dict.get('data_type') # date-time self.begin_date_time = parser.parse(xml_dict.get('begin_date_time')) self.begin_date_time_utc = parser.parse(xml_dict.get('begin_date_time_utc')) if xml_dict.get('begin_date_time_utc') is not None else None self.end_date_time = parser.parse(xml_dict.get('end_date_time')) self.end_date_time_utc = parser.parse(xml_dict.get('end_date_time_utc')) if xml_dict.get('end_date_time_utc') is not None else None # method info self.method_description = xml_dict.get('method_description') self.method_code = xml_dict.get('method_code') self.method_link = xml_dict.get('method_link') method = self._find('method') if method is not None: self.method_id = method.attrib.get('methodID') else: self.method_id = None # source info self.organization = xml_dict.get('organization') self.source_description = xml_dict.get('source_description') self.citation = xml_dict.get('citation') source = self._find('source') if source is not None: self.source_id = source.attrib.get('sourceID') else: self.source_id = None # quality control info self.quality_control_level_code = xml_dict.get('quality_control_level_code') self.definition = xml_dict.get('definition') qa = self._find('qualityControlLevel') if qa is not None: self.quality_control_level_id = qa.attrib.get('qualityControlLevelID') else: self.quality_control_level_id = None # properties self.properties = dict([(prop.attrib.get('name'),testXMLValue(prop)) for prop in self._findall('seriesProperty')]) # sub-objects self.variable = Variable(self._find('variable'),self._ns)
def parse_query_info(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: # create queryinfo object from dict xml_dict = _xml_to_dict(self._root) self.creation_time = parser.parse(xml_dict.get('creation_time')) if xml_dict.get('creation_time') is not None else None self.notes = [testXMLValue(note) for note in self._findall('note')] self.criteria = Criteria(self._find('criteria'), self._ns)
def parse_labmethod(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('lab_code') self.name = xml_dict.get('lab_name') self.organization = xml_dict.get('lab_organization') self.method_name = xml_dict.get('lab_method_name') self.method_description = xml_dict.get('lab_method_description') self.method_link = xml_dict.get('lab_method_link') # sub-objects source = self._find('labSourceDetails') self.source_details = Source(source,self._ns) if source is not None else None except: raise
def parse_query_info(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except Exception: self._root = xml # try: # create queryinfo object from dict xml_dict = _xml_to_dict(self._root) self.creation_time = parser.parse(xml_dict.get('creation_time')) \ if xml_dict.get('creation_time') is not None else None self.notes = [testXMLValue(note) for note in self._findall('note')] self.criteria = Criteria(self._find('criteria'), self._ns)
def parse_offset(self): try: xml_dict = _xml_to_dict(self._root) self.type_code = xml_dict.get('offset_type_code') self.value = xml_dict.get('offset_value') self.description = xml_dict.get('offset_description') self.is_vertical = xml_dict.get('offset_is_vertical') self.azimuth_degrees = xml_dict.get('offset_azimuth_degrees') unit = self._root.find('unit') if self._ns == 'wml1.0': self.unit = Unit1_0(unit, self._ns) if unit is not None else None else: self.unit = Unit(unit,self._ns) if unit is not None else None except: raise
def parse_labmethod(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('lab_code') self.name = xml_dict.get('lab_name') self.organization = xml_dict.get('lab_organization') self.method_name = xml_dict.get('lab_method_name') self.method_description = xml_dict.get('lab_method_description') self.method_link = xml_dict.get('lab_method_link') # sub-objects source = self._find('labSourceDetails') self.source_details = Source( source, self._ns) if source is not None else None except: raise
def parse_contactinformation(self): try: xml_dict = _xml_to_dict(self._root) self.name = xml_dict.get('contact_name') self.type = xml_dict.get('type_of_contact') self.email = [ testXMLValue(email) for email in self._findall('email') ] self.phone = [ testXMLValue(phone) for phone in self._findall('phone') ] self.address = [ testXMLValue(address) for address in self._findall('address') ] except: raise
def parse_offset(self): try: xml_dict = _xml_to_dict(self._root) self.type_code = xml_dict.get('offset_type_code') self.value = xml_dict.get('offset_value') self.description = xml_dict.get('offset_description') self.is_vertical = xml_dict.get('offset_is_vertical') self.azimuth_degrees = xml_dict.get('offset_azimuth_degrees') unit = self._root.find('unit') if self._ns == 'wml1.0': self.unit = Unit1_0(unit, self._ns) if unit is not None else None else: self.unit = Unit(unit, self._ns) if unit is not None else None except: raise
def parse_source(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('source_code') self.organization = xml_dict.get('organization') self.description = xml_dict.get('source_description') self.links = [testXMLValue(link) for link in self._findall('sourceLink')] self.citation = xml_dict.get('citation') # metadata self.topic_category = xml_dict.get('topic_category') self.title = xml_dict.get('title') self.abstract = xml_dict.get('abstract') self.profile_version = xml_dict.get('profile_version') self.metadata_link = xml_dict.get('metadata_link') # contact info self.contact_info = [ContactInformation(ci,self._ns) for ci in self._findall('contactInformation')] except: raise
def parse_timezoneinfo(self,xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) default = self._find('defaultTimeZone') if default is not None: self.zone_offset = default.attrib.get('zoneOffset') self.zone_abbreviation = default.attrib.get('zoneAbbreviation') daylight = self._find('daylightSavingsTimeZone') if daylight is not None: self.daylight_zone_offset = daylight.attrib.get('zoneOffset') self.daylight_zone_abbreviation = daylight.attrib.get('zoneAbbreviation')
def parse_timezoneinfo(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) default = self._find('defaultTimeZone') if default is not None: self.zone_offset = default.attrib.get('zoneOffset') self.zone_abbreviation = default.attrib.get('zoneAbbreviation') daylight = self._find('daylightSavingsTimeZone') if daylight is not None: self.daylight_zone_offset = daylight.attrib.get('zoneOffset') self.daylight_zone_abbreviation = daylight.attrib.get( 'zoneAbbreviation')
def parse_values(self): xml_dict = _xml_to_dict(self._root) # method info self.methods = [ Method(method, self._ns) for method in self._findall('method') ] # source info self.sources = [ Source(source, self._ns) for source in self._findall('source') ] # quality control info self.qualit_control_levels = [ QualityControlLevel(qal, self._ns) for qal in self._findall('qualityControlLevel') ] # offset info self.offsets = [Offset(os, self._ns) for os in self._findall('offset')] # sample info self.samples = [ Sample(sample, self._ns) for sample in self._findall('sample') ] # censor codes self.censor_codes = [ CensorCode(code, self._ns) for code in self._findall('censorCode') ] # unit if self._ns == 'wml1.0': self.unit_abbreviation = self._root.attrib.get('unitsAbbreviation') self.unit_code = self._root.attrib.get('unitsCode') self.count = self._root.attrib.get('count') else: unit = self._find('unit') self.unit = Unit(unit, self._ns) if unit is not None else None # values self.values = [Value(val, self._ns) for val in self._findall('value')]
def parse_location(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) geogs = self._findall('geogLocation') self.geo_coords = list() self.srs = list() for g in geogs: self.geo_coords.append( (testXMLValue(g.find(ns(self._ns) + 'longitude')), testXMLValue(g.find(ns(self._ns) + 'latitude')))) self.srs.append(g.attrib.get('srs')) locsite = self._findall('localSiteXY') self.local_sites = list() self.notes = list() self.projections = list() for ls in locsite: z = testXMLValue(ls.find(ns(self._ns) + 'Z')) if z is not None: self.local_sites.append( (testXMLValue(ls.find(ns(self._ns) + 'X')), testXMLValue(ls.find(ns(self._ns) + 'Y')), z)) else: self.local_sites.append( (testXMLValue(ls.find(ns(self._ns) + 'X')), testXMLValue(ls.find(ns(self._ns) + 'Y')), '0')) self.notes.append([ testXMLValue(note) for note in ls.findall(ns(self._ns) + 'note') ]) self.projections.append(ls.attrib.get('projectionInformation'))
def parse_source(self): try: xml_dict = _xml_to_dict(self._root) self.code = xml_dict.get('source_code') self.organization = xml_dict.get('organization') self.description = xml_dict.get('source_description') self.links = [ testXMLValue(link) for link in self._findall('sourceLink') ] self.citation = xml_dict.get('citation') # metadata self.topic_category = xml_dict.get('topic_category') self.title = xml_dict.get('title') self.abstract = xml_dict.get('abstract') self.profile_version = xml_dict.get('profile_version') self.metadata_link = xml_dict.get('metadata_link') # contact info self.contact_info = [ ContactInformation(ci, self._ns) for ci in self._findall('contactInformation') ] except: raise
def parse_criteria(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root,depth=4) self.method_called = self._root.attrib.get('MethodCalled') self.location_param = xml_dict.get('location_param') self.variable_param = xml_dict.get('variable_param') try: self.begin_date_time = parser.parse(xml_dict['begin_date_time']) except: self.begin_date_time = None try: self.end_date_time = parser.parse(xml_dict['end_date_time']) except: self.end_date_time = None self.parameters = [(param.attrib.get('name'),param.attrib.get('value')) for param in self._findall('parameter')]
def parse_siteinfo(self,xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) self.site_name = xml_dict.get('site_name') self.site_codes = [testXMLValue(code) for code in self._findall('siteCode')] self.elevation = xml_dict.get('elevation_m') self.vertical_datum = xml_dict.get('vertical_datum') self.site_types = [testXMLValue(typ) for typ in self._findall('siteType')] self.site_properties = dict([(prop.attrib.get('name'),testXMLValue(prop)) for prop in self._findall('siteProperty')]) self.altname = xml_dict.get('altname') self.notes = [testXMLValue(note) for note in self._findall('note')] # sub-objects tzi = self._find('timeZoneInfo') if tzi is not None: self.time_zone_info = TimeZoneInfo(tzi, self._ns) self.location = Location(self._find('geoLocation'), self._ns)
def parse_variable(self, xml=None): if xml is not None: try: self._root = etree.parse(xml) except: self._root = xml # try: xml_dict = _xml_to_dict(self._root) self.value_type = xml_dict.get('value_type') self.data_type = xml_dict.get('data_type') self.general_category = xml_dict.get('general_category') self.sample_medium = xml_dict.get('sample_medium') self.no_data_value = xml_dict.get('no_data_value') self.variable_name = xml_dict.get('variable_name') self.variable_code = xml_dict.get('variable_code') self.variable_description = xml_dict.get('variable_description') self.speciation = xml_dict.get('speciation') # notes and properties notes = [(note.attrib.get('title'), testXMLValue(note)) for note in self._findall('note')] none_notes = [note[1] for note in notes if note[0] is None] self.notes = dict([note for note in notes if note[0] is not None]) if len(none_notes) > 0: self.notes['none'] = none_notes self.properties = dict([(prop.attrib.get('name'), testXMLValue(prop)) for prop in self._findall('variableProperty')]) # related related = self._find('related') if related is not None: self.parent_codes = [ dict([('network', code.attrib.get('network')), ('vocabulary', code.attrib.get('vocabulary')), ('default', code.attrib.get('default'))]) for code in related.findall(ns(self._ns) + 'parentCode') ] self.related_codes = [ dict([('network', d.get('network')), ('vocabulary', d.get('vocabulary')), ('default', d.get('default'))]) for code in related.findall(ns(self._ns) + 'relatedCode') ] else: self.parent_codes = None self.related_codes = None # sub-objects if self._ns == 'wml1.0': unit = self._find('units') self.unit = Unit1_0(unit, self._ns) if unit is not None else None timesupport = self._find('timeSupport') self.time_support = TimeScale( timesupport, self._ns) if timesupport is not None else None else: unit = self._find('unit') self.unit = Unit(unit, self._ns) if unit is not None else None timescale = self._find('timeScale') self.time_scale = TimeScale( timescale, self._ns) if timescale is not None else None categories = self._find('categories') if categories is not None: self.categories = [ Category(cat, self._ns) for cat in categories.findall(ns(self._ns) + 'category') ] else: self.categories = None