示例#1
0
 def __init__(self, id, name, *args, **kwargs):  # @UnusedVariable
     # default
     self.id = id
     self.flag = ''
     self.name = name
     self.xseed_version = kwargs.get('xseed_version', None)
     self.seed_version = kwargs.get('version', None)
     self.mask = kwargs.get('mask', None)
     self.xpath = kwargs.get('xpath', None)
     if self.id:
         self.field_id = "F%02d" % self.id
     else:
         self.field_id = None
     self.field_name = kwargs.get('xml_tag', utils.toTag(self.name))
     self.attribute_name = utils.toTag(self.name)
     # options
     self.optional = kwargs.get('optional', False)
     self.ignore = kwargs.get('ignore', False)
     self.strict = kwargs.get('strict', False)
     self.compact = kwargs.get('compact', False)
     self.default_value = kwargs.get('default_value', self.default)
示例#2
0
 def __init__(self, name, index_field, data_fields, **kwargs):
     self.default = False
     Field.__init__(self, None, name, **kwargs)
     # initialize + default values
     if not isinstance(data_fields, list):
         data_fields = [data_fields]
     self.data_fields = data_fields
     self.index_field = utils.toTag(index_field)
     self.length = 0
     # loop types
     self.repeat_title = kwargs.get('repeat_title', False)
     self.omit_tag = kwargs.get('omit_tag', False)
     self.flat = kwargs.get('flat', False)
示例#3
0
 def __init__(self, **kwargs):
     self.debug = kwargs.get('debug', False)
     self.strict = kwargs.get('strict', False)
     self.compact = kwargs.get('compact', False)
     self.record_type = kwargs.get('record_type', None)
     self.record_id = kwargs.get('record_id', None)
     self.blockette_id = "%03d" % self.id
     self.blockette_name = utils.toTag(self.name)
     # debug
     if self.debug:
         print("----")
         print(str(self))
     # filter versions specific fields
     self.xseed_version = kwargs.get('xseed_version', DEFAULT_XSEED_VERSION)
     self.seed_version = kwargs.get('version', 2.4)
示例#4
0
文件: blockette.py 项目: bmorg/obspy
 def __init__(self, **kwargs):
     self.debug = kwargs.get('debug', False)
     self.strict = kwargs.get('strict', False)
     self.compact = kwargs.get('compact', False)
     self.record_type = kwargs.get('record_type', None)
     self.record_id = kwargs.get('record_id', None)
     self.blockette_id = "%03d" % self.id
     self.blockette_name = utils.toTag(self.name)
     # debug
     if self.debug:
         print("----")
         print(str(self))
     # filter versions specific fields
     self.xseed_version = kwargs.get('xseed_version', DEFAULT_XSEED_VERSION)
     self.seed_version = kwargs.get('version', 2.4)
示例#5
0
    def getXSEED(self, version=DEFAULT_XSEED_VERSION, split_stations=False):
        """
        Returns a XSEED representation of the current Parser object.

        :type version: float, optional
        :param version: XSEED version string (default is ``1.1``).
        :type split_stations: boolean, optional
        :param split_stations: Splits stations containing multiple channels
            into multiple documents.
        :rtype: str or dict
        :return: Returns either a string or a dict of strings depending
            on the flag ``split_stations``.
        """
        if version not in XSEED_VERSIONS:
            raise SEEDParserException("Unknown XML-SEED version!")
        doc = Element("xseed", version=version)
        # Nothing to write if not all necessary data is available.
        if not self.volume or not self.abbreviations or \
                len(self.stations) == 0:
            msg = 'No data to be written available.'
            raise SEEDParserException(msg)
        # Check blockettes:
        if not self._checkBlockettes():
            msg = 'Not all necessary blockettes are available.'
            raise SEEDParserException(msg)
        # Add blockettes 11 and 12 only for XSEED version 1.0.
        if version == '1.0':
            self._createBlockettes11and12(blockette12=True)
        # Now start actually filling the XML tree.
        # Volume header:
        sub = SubElement(doc, utils.toTag('Volume Index Control Header'))
        for blkt in self.volume:
            sub.append(blkt.getXML(xseed_version=version))
        # Delete blockettes 11 and 12 if necessary.
        if version == '1.0':
            self._deleteBlockettes11and12()
        # Abbreviations:
        sub = SubElement(doc,
                         utils.toTag('Abbreviation Dictionary Control Header'))
        for blkt in self.abbreviations:
            sub.append(blkt.getXML(xseed_version=version))
        if not split_stations:
            # Don't split stations
            for station in self.stations:
                sub = SubElement(doc, utils.toTag('Station Control Header'))
                for blkt in station:
                    sub.append(blkt.getXML(xseed_version=version))
            if version == '1.0':
                # To pass the XSD schema test an empty time span control header
                # is added to the end of the file.
                SubElement(doc, utils.toTag('Timespan Control Header'))
                # Also no data is present in all supported SEED files.
                SubElement(doc, utils.toTag('Data Records'))
            # Return single XML String.
            return tostring(doc,
                            pretty_print=True,
                            xml_declaration=True,
                            encoding='UTF-8')
        else:
            # generate a dict of XML resources for each station
            result = {}
            for station in self.stations:
                cdoc = copy.copy(doc)
                sub = SubElement(cdoc, utils.toTag('Station Control Header'))
                for blkt in station:
                    sub.append(blkt.getXML(xseed_version=version))
                if version == '1.0':
                    # To pass the XSD schema test an empty time span control
                    # header is added to the end of the file.
                    SubElement(doc, utils.toTag('Timespan Control Header'))
                    # Also no data is present in all supported SEED files.
                    SubElement(doc, utils.toTag('Data Records'))
                try:
                    id = station[0].end_effective_date.datetime
                except AttributeError:
                    id = ''
                result[id] = tostring(cdoc,
                                      pretty_print=True,
                                      xml_declaration=True,
                                      encoding='UTF-8')
            return result
示例#6
0
    def getXSEED(self, version=DEFAULT_XSEED_VERSION, split_stations=False):
        """
        Returns a XSEED representation of the current Parser object.

        :type version: float, optional
        :param version: XSEED version string (default is ``1.1``).
        :type split_stations: boolean, optional
        :param split_stations: Splits stations containing multiple channels
            into multiple documents.
        :rtype: str or dict
        :return: Returns either a string or a dict of strings depending
            on the flag ``split_stations``.
        """
        if version not in XSEED_VERSIONS:
            raise SEEDParserException("Unknown XML-SEED version!")
        doc = Element("xseed", version=version)
        # Nothing to write if not all necessary data is available.
        if not self.volume or not self.abbreviations or \
                len(self.stations) == 0:
            msg = 'No data to be written available.'
            raise SEEDParserException(msg)
        # Check blockettes:
        if not self._checkBlockettes():
            msg = 'Not all necessary blockettes are available.'
            raise SEEDParserException(msg)
        # Add blockettes 11 and 12 only for XSEED version 1.0.
        if version == '1.0':
            self._createBlockettes11and12(blockette12=True)
        # Now start actually filling the XML tree.
        # Volume header:
        sub = SubElement(doc, utils.toTag('Volume Index Control Header'))
        for blkt in self.volume:
            sub.append(blkt.getXML(xseed_version=version))
        # Delete blockettes 11 and 12 if necessary.
        if version == '1.0':
            self._deleteBlockettes11and12()
        # Abbreviations:
        sub = SubElement(
            doc, utils.toTag('Abbreviation Dictionary Control Header'))
        for blkt in self.abbreviations:
            sub.append(blkt.getXML(xseed_version=version))
        if not split_stations:
            # Don't split stations
            for station in self.stations:
                sub = SubElement(doc, utils.toTag('Station Control Header'))
                for blkt in station:
                    sub.append(blkt.getXML(xseed_version=version))
            if version == '1.0':
                # To pass the XSD schema test an empty time span control header
                # is added to the end of the file.
                SubElement(doc, utils.toTag('Timespan Control Header'))
                # Also no data is present in all supported SEED files.
                SubElement(doc, utils.toTag('Data Records'))
            # Return single XML String.
            return tostring(doc, pretty_print=True, xml_declaration=True,
                            encoding='UTF-8')
        else:
            # generate a dict of XML resources for each station
            result = {}
            for station in self.stations:
                cdoc = copy.copy(doc)
                sub = SubElement(cdoc, utils.toTag('Station Control Header'))
                for blkt in station:
                    sub.append(blkt.getXML(xseed_version=version))
                if version == '1.0':
                    # To pass the XSD schema test an empty time span control
                    # header is added to the end of the file.
                    SubElement(doc, utils.toTag('Timespan Control Header'))
                    # Also no data is present in all supported SEED files.
                    SubElement(doc, utils.toTag('Data Records'))
                try:
                    id = station[0].end_effective_date.datetime
                except AttributeError:
                    id = ''
                result[id] = tostring(cdoc, pretty_print=True,
                                      xml_declaration=True, encoding='UTF-8')
            return result
示例#7
0
 def test_toTag(self):
     name = "Hello World"
     self.assertEqual("hello_world", toTag(name))
示例#8
0
 def test_toTag(self):
     name = "Hello World"
     self.assertEquals("hello_world", utils.toTag(name))