Example #1
0
 def __init__(self, filename, validate=True, seed=0, num_samples=0):
     self.filename = filename
     self.basepath = os.path.dirname(filename)
     self.seed = seed
     self.num_samples = num_samples
     self.branches = {}
     self.open_ends = set()
     try:
         tree = parse(filename)
     except etree.ParseError as exc:
         # Wrap etree parsing exception to :exc:`ParsingError`.
         raise ParsingError(self.filename, str(exc))
     [tree] = tree.findall('{%s}logicTree' % self.NRML)
     self.root_branchset = None
     self.parse_tree(tree, validate)
Example #2
0
 def __init__(self, filename, validate=True, seed=0, num_samples=0):
     self.filename = filename
     self.basepath = os.path.dirname(filename)
     self.seed = seed
     self.num_samples = num_samples
     self.branches = {}
     self.open_ends = set()
     try:
         tree = parse(filename)
     except etree.ParseError as exc:
         # Wrap etree parsing exception to :exc:`ParsingError`.
         raise ParsingError(self.filename, str(exc))
     [tree] = tree.findall("{%s}logicTree" % self.NRML)
     self.root_branchset = None
     self.parse_tree(tree, validate)
Example #3
0
def read(source, chatty=True):
    """
    Convert a NRML file into a validated LiteralNode object. Keeps
    the entire tree in memory.

    :param source:
        a file name or file object open for reading
    """
    nrml = parse(source).getroot()
    assert striptag(nrml.tag) == "nrml", nrml.tag
    # extract the XML namespace URL ('http://openquake.org/xmlns/nrml/0.5')
    xmlns = nrml.tag.split("}")[0][1:]
    if xmlns != NRML05 and chatty:
        logging.warn("%s is at an outdated version: %s", source, xmlns)
    subnodes = []
    for elem in nrml:
        nodecls = nodefactory[striptag(elem.tag)]
        subnodes.append(node_from_elem(elem, nodecls))
    return LiteralNode("nrml", {"xmlns": xmlns, "xmlns:gml": GML_NAMESPACE}, nodes=subnodes)
Example #4
0
def read(source):
    """
    Convert a NRML file into a validated LiteralNode object. Keeps
    the entire tree in memory.

    :param source:
        a file name or file object open for reading
    """
    nrml = parse(source).getroot()
    assert striptag(nrml.tag) == 'nrml', nrml.tag
    # extract the XML namespace URL ('http://openquake.org/xmlns/nrml/0.5')
    xmlns = nrml.tag.split('}')[0][1:]
    subnodes = []
    for elem in nrml:
        nodecls = nodefactory[striptag(elem.tag)]
        subnodes.append(node_from_elem(elem, nodecls))
    return LiteralNode(
        'nrml', {'xmlns': xmlns, 'xmlns:gml': GML_NAMESPACE},
        nodes=subnodes)
Example #5
0
def read(source, chatty=True):
    """
    Convert a NRML file into a validated LiteralNode object. Keeps
    the entire tree in memory.

    :param source:
        a file name or file object open for reading
    """
    nrml = parse(source).getroot()
    assert striptag(nrml.tag) == 'nrml', nrml.tag
    # extract the XML namespace URL ('http://openquake.org/xmlns/nrml/0.5')
    xmlns = nrml.tag.split('}')[0][1:]
    if xmlns != NRML05 and chatty:
        logging.warn('%s is at an outdated version: %s', source, xmlns)
    subnodes = []
    for elem in nrml:
        nodecls = nodefactory[striptag(elem.tag)]
        subnodes.append(node_from_elem(elem, nodecls))
    return LiteralNode('nrml', {
        'xmlns': xmlns,
        'xmlns:gml': GML_NAMESPACE
    },
                       nodes=subnodes)