コード例 #1
0
ファイル: sourceconverter.py プロジェクト: ispingos/oq-engine
    def convert_nonParametricSeismicSource(self, node):
        """
        Convert the given node into a non parametric source object.

        :param node:
            a node with tag areaGeometry
        :returns:
            a :class:`openquake.hazardlib.source.NonParametricSeismicSource`
            instance
        """
        trt = node.attrib.get('tectonicRegion')
        rup_pmf_data = []
        rups_weights = None
        if 'rup_weights' in node.attrib:
            tmp = node.attrib.get('rup_weights')
            rups_weights = numpy.array([float(s) for s in tmp.split()])
        for i, rupnode in enumerate(node):
            probs = pmf.PMF(valid.pmf(rupnode['probs_occur']))
            rup = RuptureConverter.convert_node(self, rupnode)
            rup.tectonic_region_type = trt
            rup.weight = None if rups_weights is None else rups_weights[i]
            rup_pmf_data.append((rup, probs))
        nps = source.NonParametricSeismicSource(node['id'], node['name'], trt,
                                                rup_pmf_data)
        nps.splittable = 'rup_weights' not in node.attrib
        return nps
コード例 #2
0
    def convert_nonParametricSeismicSource(self, node):
        """
        Convert the given node into a non parametric source object.

        :param node:
            a node with tag areaGeometry
        :returns:
            a :class:`openquake.hazardlib.source.NonParametricSeismicSource`
            instance
        """
        trt = node.attrib.get('tectonicRegion')
        rup_pmf_data = []
        rups_weights = None
        if 'rup_weights' in node.attrib:
            rups_weights = F64(node['rup_weights'].split())
        num_probs = None
        for i, rupnode in enumerate(node):
            po = rupnode['probs_occur']
            probs = pmf.PMF(valid.pmf(po))
            if num_probs is None:  # first time
                num_probs = len(probs.data)
            elif len(probs.data) != num_probs:
                # probs_occur must have uniform length for all ruptures
                raise ValueError(
                    'prob_occurs=%s has %d elements, expected %s' %
                    (po, len(probs.data), num_probs))
            rup = RuptureConverter.convert_node(self, rupnode)
            rup.tectonic_region_type = trt
            rup_pmf_data.append((rup, probs))
        nps = source.NonParametricSeismicSource(node['id'], node['name'], trt,
                                                rup_pmf_data, rups_weights)
        nps.splittable = 'rup_weights' not in node.attrib
        return nps
コード例 #3
0
def convert_nonParametricSeismicSource(fname, node):
    """
    Convert the given node into a non parametric source object.

    :param fname:
        full pathname to the XML file associated to the node
    :param node:
        a Node object coming from an XML file
    :returns:
        a :class:`openquake.hazardlib.source.NonParametricSeismicSource`
        instance
    """
    trt = node.attrib.get('tectonicRegion')
    rups_weights = None
    if 'rup_weights' in node.attrib:
        rups_weights = F64(node['rup_weights'].split())
    nps = source.NonParametricSeismicSource(node['id'], node['name'], trt, [],
                                            [])
    nps.splittable = 'rup_weights' not in node.attrib
    path = os.path.splitext(fname)[0] + '.hdf5'
    hdf5_fname = path if os.path.exists(path) else None
    if hdf5_fname:
        # read the rupture data from the HDF5 file
        assert node.text is None, node.text
        with hdf5.File(hdf5_fname, 'r') as h:
            dic = {k: d[:] for k, d in h[node['id']].items()}
        nps.fromdict(dic, rups_weights)
        num_probs = len(dic['probs_occur'])
    else:
        # read the rupture data from the XML nodes
        num_probs = None
        for i, rupnode in enumerate(node):
            po = rupnode['probs_occur']
            probs = pmf.PMF(valid.pmf(po))
            if num_probs is None:  # first time
                num_probs = len(probs.data)
            elif len(probs.data) != num_probs:
                # probs_occur must have uniform length for all ruptures
                raise ValueError(
                    'prob_occurs=%s has %d elements, expected %s' %
                    (po, len(probs.data), num_probs))
            rup = RuptureConverter(5.).convert_node(rupnode)
            rup.tectonic_region_type = trt
            rup.weight = None if rups_weights is None else rups_weights[i]
            nps.data.append((rup, probs))
    nps.num_probs_occur = num_probs
    return nps
コード例 #4
0
    def convert_nonParametricSeismicSource(self, node):
        """
        Convert the given node into a non parametric source object.

        :param node: a node with tag areaGeometry
        :returns: a :class:`openquake.hazardlib.source.NonParametricSeismicSource` instance
        """
        trt = node['tectonicRegion']
        rup_pmf_data = []
        for rupnode in node:
            probs = pmf.PMF(rupnode['probs_occur'])
            rup = RuptureConverter.convert_node(self, rupnode)
            rup.tectonic_region_type = trt
            rup_pmf_data.append((rup, probs))
        nps = source.NonParametricSeismicSource(node['id'], node['name'], trt,
                                                rup_pmf_data)
        return nps