Beispiel #1
0
 def test_get_available_magnitude_scalerel(self):
     self.assertEqual(
         {
             'PeerMSR': scalerel.peer.PeerMSR,
             'WC1994': scalerel.wc1994.WC1994,
             'CEUS2011': scalerel.ceus2011.CEUS2011
         }, dict(scalerel.get_available_magnitude_scalerel()))
    def setUp(self):
        self.imts = ["PGA", "PGV"]
        self.periods = [0.05, 0.075, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16,
                        0.17, 0.18, 0.19, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30,
                        0.32, 0.34, 0.36, 0.38, 0.40, 0.42, 0.44, 0.46, 0.48,
                        0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95,
                        1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0,
                        3.0, 4.001, 5.0, 7.5, 10.0]

        self.gsims = ["AbrahamsonEtAl2014", "AbrahamsonEtAl2014NSHMPLower",
                      "AbrahamsonEtAl2014NSHMPMean",
                      "AbrahamsonEtAl2014NSHMPUpper",
                      "AbrahamsonEtAl2014RegCHN",
                      "AbrahamsonEtAl2014RegJPN",
                      "AbrahamsonEtAl2014RegTWN",
                      "AkkarBommer2010SWISS01",
                      "AkkarBommer2010SWISS04",
                      "AkkarBommer2010SWISS08",
                      "AkkarEtAl2013", "AkkarEtAlRepi2014"]

        # this set of parameters raised exceptions, as e.g.
        # AkkarBommer2010SWISS01's PGV eas empty
        vs30 = 760.0
        self.params = {"magnitude": np.array([3, 4]),
                       "distance": np.array([10, 11, 12]),
                       "dip": 60, "aspect": 1.5, "rake": 0.0, "ztor": 0.0,
                       "strike": 0.0,
                       "msr": get_available_magnitude_scalerel()["WC1994"],
                       "initial_point": Point(0, 0), "hypocentre_location": [0.5, 0.5],
                       "vs30": vs30, "vs30_measured": True,
                       "line_azimuth": 0.0, "backarc": False,
                       "z1pt0": vs30_to_z1pt0_cy14(vs30),
                       "z2pt5": vs30_to_z2pt5_cb14(vs30)}
Beispiel #3
0
    def _simple_to_hazardlib(self, src):
        """Convert a NRML simple fault source to the HazardLib equivalent.

        See :mod:`openquake.nrmllib.models` and
        :mod:`openquake.hazardlib.source`.

        :param src:
            :class:`openquake.nrmllib.models.SimpleFaultRuptureModel` instance.
        :returns:
            The HazardLib representation of the input source.
        """
        shapely_line = wkt.loads(src.geometry.wkt)
        fault_trace = geo.Line([geo.Point(*x) for x in shapely_line.coords])

        mf_dist = self._mfd_to_hazardlib(src.mfd)
        msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

        simple = source.SimpleFaultSource(
            source_id=src.id,
            name=src.name,
            tectonic_region_type=src.trt,
            mfd=mf_dist,
            rupture_mesh_spacing=self.hc.rupture_mesh_spacing,
            magnitude_scaling_relationship=msr,
            rupture_aspect_ratio=src.rupt_aspect_ratio,
            upper_seismogenic_depth=src.geometry.upper_seismo_depth,
            lower_seismogenic_depth=src.geometry.lower_seismo_depth,
            fault_trace=fault_trace,
            dip=src.geometry.dip,
            rake=src.rake,
            temporal_occurrence_model=self.default_tom,
        )

        return simple
Beispiel #4
0
    def _simple_to_hazardlib(self, src):
        """Convert a NRML simple fault source to the HazardLib equivalent.

        See :mod:`openquake.nrmllib.models` and
        :mod:`openquake.hazardlib.source`.

        :param src:
            :class:`openquake.nrmllib.models.SimpleFaultRuptureModel` instance.
        :returns:
            The HazardLib representation of the input source.
        """
        shapely_line = wkt.loads(src.geometry.wkt)
        fault_trace = geo.Line([geo.Point(*x) for x in shapely_line.coords])

        mf_dist = self._mfd_to_hazardlib(src.mfd)
        msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

        simple = source.SimpleFaultSource(
            source_id=src.id,
            name=src.name,
            tectonic_region_type=src.trt,
            mfd=mf_dist,
            rupture_mesh_spacing=self.rupture_mesh_spacing,
            magnitude_scaling_relationship=msr,
            rupture_aspect_ratio=src.rupt_aspect_ratio,
            upper_seismogenic_depth=src.geometry.upper_seismo_depth,
            lower_seismogenic_depth=src.geometry.lower_seismo_depth,
            fault_trace=fault_trace,
            dip=src.geometry.dip,
            rake=src.rake,
            temporal_occurrence_model=self.default_tom,
        )

        return simple
Beispiel #5
0
 def test_get_available_magnitude_scalerel(self):
     self.assertEqual({'PeerMSR': scalerel.peer.PeerMSR,
                       'PointMSR': scalerel.point.PointMSR,
                       'WC1994': scalerel.wc1994.WC1994,
                       'CEUS2011': scalerel.ceus2011.CEUS2011,
                       'StrasserInterface': scalerel.strasser2010.StrasserInterface,
                       'StrasserIntraslab': scalerel.strasser2010.StrasserIntraslab},
                      dict(scalerel.get_available_magnitude_scalerel()))
Beispiel #6
0
def _area_to_hazardlib(src, mesh_spacing, bin_width, area_src_disc):
    """Convert a NRML area source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.PointSource` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :param float area_src_disc:
        Area source discretization, in km. Applies only to area sources.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_polygon = wkt.loads(src.geometry.wkt)
    hazardlib_polygon = geo.Polygon(
        # We ignore the last coordinate in the sequence here, since it is a
        # duplicate of the first. hazardlib will close the loop for us.
        [geo.Point(*x) for x in list(shapely_polygon.exterior.coords)[:-1]]
    )

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)

    # nodal plane distribution:
    npd = pmf.PMF(
        [(x.probability,
          geo.NodalPlane(strike=x.strike, dip=x.dip, rake=x.rake))
         for x in src.nodal_plane_dist]
    )

    # hypocentral depth distribution:
    hd = pmf.PMF([(x.probability, x.depth) for x in src.hypo_depth_dist])

    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()
    area = source.AreaSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        upper_seismogenic_depth=src.geometry.upper_seismo_depth,
        lower_seismogenic_depth=src.geometry.lower_seismo_depth,
        nodal_plane_distribution=npd, hypocenter_distribution=hd,
        polygon=hazardlib_polygon,
        area_discretization=area_src_disc
    )

    return area
Beispiel #7
0
def _area_to_hazardlib(src, mesh_spacing, bin_width, area_src_disc):
    """Convert a NRML area source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.PointSource` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :param float area_src_disc:
        Area source discretization, in km. Applies only to area sources.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_polygon = wkt.loads(src.geometry.wkt)
    hazardlib_polygon = geo.Polygon(
        # We ignore the last coordinate in the sequence here, since it is a
        # duplicate of the first. hazardlib will close the loop for us.
        [geo.Point(*x) for x in list(shapely_polygon.exterior.coords)[:-1]])

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)

    # nodal plane distribution:
    npd = pmf.PMF([(x.probability,
                    geo.NodalPlane(strike=x.strike, dip=x.dip, rake=x.rake))
                   for x in src.nodal_plane_dist])

    # hypocentral depth distribution:
    hd = pmf.PMF([(x.probability, x.depth) for x in src.hypo_depth_dist])

    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()
    area = source.AreaSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        upper_seismogenic_depth=src.geometry.upper_seismo_depth,
        lower_seismogenic_depth=src.geometry.lower_seismo_depth,
        nodal_plane_distribution=npd,
        hypocenter_distribution=hd,
        polygon=hazardlib_polygon,
        area_discretization=area_src_disc)

    return area
Beispiel #8
0
def _point_to_hazardlib(src, mesh_spacing, bin_width):
    """Convert a NRML point source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.PointSource` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_pt = wkt.loads(src.geometry.wkt)

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)

    # nodal plane distribution:
    npd = pmf.PMF(
        [(x.probability,
          geo.NodalPlane(strike=x.strike, dip=x.dip, rake=x.rake))
         for x in src.nodal_plane_dist]
    )

    # hypocentral depth distribution:
    hd = pmf.PMF([(x.probability, x.depth) for x in src.hypo_depth_dist])

    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

    point = source.PointSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        upper_seismogenic_depth=src.geometry.upper_seismo_depth,
        lower_seismogenic_depth=src.geometry.lower_seismo_depth,
        location=geo.Point(shapely_pt.x, shapely_pt.y),
        nodal_plane_distribution=npd,
        hypocenter_distribution=hd
    )

    return point
Beispiel #9
0
    def setUp(self):
        self.imts = ["PGA", "PGV"]
        self.periods = [
            0.05, 0.075, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18,
            0.19, 0.20, 0.22, 0.24, 0.26, 0.28, 0.30, 0.32, 0.34, 0.36, 0.38,
            0.40, 0.42, 0.44, 0.46, 0.48, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8,
            0.85, 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9,
            2.0, 3.0, 4.001, 5.0, 7.5, 10.0
        ]

        self.gsims = [
            "AbrahamsonEtAl2014",
            # "AbrahamsonEtAl2014NSHMPLower",
            # "AbrahamsonEtAl2014NSHMPMean",
            # "AbrahamsonEtAl2014NSHMPUpper",
            "AbrahamsonEtAl2014RegCHN",
            "AbrahamsonEtAl2014RegJPN",
            "AbrahamsonEtAl2014RegTWN",
            "AkkarBommer2010SWISS01",
            "AkkarBommer2010SWISS04",
            "AkkarBommer2010SWISS08",
            "AkkarEtAl2013",
            "AkkarEtAlRepi2014"
        ]

        # this set of parameters raised exceptions, as e.g.
        # AkkarBommer2010SWISS01's PGV eas empty
        vs30 = 760.0
        self.params = {
            "magnitude": np.array([3, 4]),
            "distance": np.array([10, 11, 12]),
            "dip": 60,
            "aspect": 1.5,
            "rake": 0.0,
            "ztor": 0.0,
            "strike": 0.0,
            "msr": get_available_magnitude_scalerel()["WC1994"],
            "initial_point": Point(0, 0),
            "hypocentre_location": [0.5, 0.5],
            "vs30": vs30,
            "vs30_measured": True,
            "line_azimuth": 0.0,
            "backarc": False,
            "z1pt0": vs30_to_z1pt0_cy14(vs30),
            "z2pt5": vs30_to_z2pt5_cb14(vs30)
        }
Beispiel #10
0
def _point_to_hazardlib(src, mesh_spacing, bin_width):
    """Convert a NRML point source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.PointSource` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_pt = wkt.loads(src.geometry.wkt)

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)

    # nodal plane distribution:
    npd = pmf.PMF([(x.probability,
                    geo.NodalPlane(strike=x.strike, dip=x.dip, rake=x.rake))
                   for x in src.nodal_plane_dist])

    # hypocentral depth distribution:
    hd = pmf.PMF([(x.probability, x.depth) for x in src.hypo_depth_dist])

    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

    point = source.PointSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        upper_seismogenic_depth=src.geometry.upper_seismo_depth,
        lower_seismogenic_depth=src.geometry.lower_seismo_depth,
        location=geo.Point(shapely_pt.x, shapely_pt.y),
        nodal_plane_distribution=npd,
        hypocenter_distribution=hd)

    return point
Beispiel #11
0
def _complex_to_hazardlib(src, mesh_spacing, bin_width):
    """Convert a NRML complex fault source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.ComplexFaultRuptureModel` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :returns:
        The HazardLib representation of the input source.
    """
    edges_wkt = []
    edges_wkt.append(src.geometry.top_edge_wkt)
    edges_wkt.extend(src.geometry.int_edges)
    edges_wkt.append(src.geometry.bottom_edge_wkt)

    edges = []

    for edge in edges_wkt:
        shapely_line = wkt.loads(edge)
        line = geo.Line([geo.Point(*x) for x in shapely_line.coords])
        edges.append(line)

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)
    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

    cmplx = source.ComplexFaultSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        edges=edges,
        rake=src.rake,
    )

    return cmplx
Beispiel #12
0
def _complex_to_hazardlib(src, mesh_spacing, bin_width):
    """Convert a NRML complex fault source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.ComplexFaultRuptureModel` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :returns:
        The HazardLib representation of the input source.
    """
    edges_wkt = []
    edges_wkt.append(src.geometry.top_edge_wkt)
    edges_wkt.extend(src.geometry.int_edges)
    edges_wkt.append(src.geometry.bottom_edge_wkt)

    edges = []

    for edge in edges_wkt:
        shapely_line = wkt.loads(edge)
        line = geo.Line([geo.Point(*x) for x in shapely_line.coords])
        edges.append(line)

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)
    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

    cmplx = source.ComplexFaultSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        edges=edges,
        rake=src.rake,
    )

    return cmplx
Beispiel #13
0
    def _complex_to_hazardlib(self, src):
        """Convert a NRML complex fault source to the HazardLib equivalent.

        See :mod:`openquake.nrmllib.models` and
        :mod:`openquake.hazardlib.source`.

        :param src:
            :class:`openquake.nrmllib.models.ComplexFaultRuptureModel` instance
        :returns:
            The HazardLib representation of the input source.
        """
        edges_wkt = []
        edges_wkt.append(src.geometry.top_edge_wkt)
        edges_wkt.extend(src.geometry.int_edges)
        edges_wkt.append(src.geometry.bottom_edge_wkt)

        edges = []

        for edge in edges_wkt:
            shapely_line = wkt.loads(edge)
            line = geo.Line([geo.Point(*x) for x in shapely_line.coords])
            edges.append(line)

        mf_dist = self._mfd_to_hazardlib(src.mfd)
        msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

        cmplx = source.ComplexFaultSource(
            source_id=src.id,
            name=src.name,
            tectonic_region_type=src.trt,
            mfd=mf_dist,
            rupture_mesh_spacing=self.hc.rupture_mesh_spacing,
            magnitude_scaling_relationship=msr,
            rupture_aspect_ratio=src.rupt_aspect_ratio,
            edges=edges,
            rake=src.rake,
            temporal_occurrence_model=self.default_tom,
        )

        return cmplx
Beispiel #14
0
    def _complex_to_hazardlib(self, src):
        """Convert a NRML complex fault source to the HazardLib equivalent.

        See :mod:`openquake.nrmllib.models` and
        :mod:`openquake.hazardlib.source`.

        :param src:
            :class:`openquake.nrmllib.models.ComplexFaultRuptureModel` instance
        :returns:
            The HazardLib representation of the input source.
        """
        edges_wkt = []
        edges_wkt.append(src.geometry.top_edge_wkt)
        edges_wkt.extend(src.geometry.int_edges)
        edges_wkt.append(src.geometry.bottom_edge_wkt)

        edges = []

        for edge in edges_wkt:
            shapely_line = wkt.loads(edge)
            line = geo.Line([geo.Point(*x) for x in shapely_line.coords])
            edges.append(line)
        mf_dist = self._mfd_to_hazardlib(src.mfd)
        msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

        cmplx = source.ComplexFaultSource(
            source_id=src.id,
            name=src.name,
            tectonic_region_type=src.trt,
            mfd=mf_dist,
            rupture_mesh_spacing=self.rupture_mesh_spacing,
            magnitude_scaling_relationship=msr,
            rupture_aspect_ratio=src.rupt_aspect_ratio,
            edges=edges,
            rake=src.rake,
            temporal_occurrence_model=self.default_tom,
        )

        return cmplx
Beispiel #15
0
def _simple_to_hazardlib(src, mesh_spacing, bin_width):
    """Convert a NRML simple fault source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.SimpleFaultRuptureModel` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_line = wkt.loads(src.geometry.wkt)
    fault_trace = geo.Line([geo.Point(*x) for x in shapely_line.coords])

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)
    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

    simple = source.SimpleFaultSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        upper_seismogenic_depth=src.geometry.upper_seismo_depth,
        lower_seismogenic_depth=src.geometry.lower_seismo_depth,
        fault_trace=fault_trace,
        dip=src.geometry.dip,
        rake=src.rake
    )

    return simple
Beispiel #16
0
def _simple_to_hazardlib(src, mesh_spacing, bin_width):
    """Convert a NRML simple fault source to the HazardLib equivalent.

    See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`.

    :param src:
        :class:`openquake.nrmllib.models.SimpleFaultRuptureModel` instance.
    :param float mesh_spacing:
        Rupture mesh spacing, in km.
    :param float bin_width:
        Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin
        width.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_line = wkt.loads(src.geometry.wkt)
    fault_trace = geo.Line([geo.Point(*x) for x in shapely_line.coords])

    mf_dist = _mfd_to_hazardlib(src.mfd, bin_width)
    msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]()

    simple = source.SimpleFaultSource(
        source_id=src.id,
        name=src.name,
        tectonic_region_type=src.trt,
        mfd=mf_dist,
        rupture_mesh_spacing=mesh_spacing,
        magnitude_scaling_relationship=msr,
        rupture_aspect_ratio=src.rupt_aspect_ratio,
        upper_seismogenic_depth=src.geometry.upper_seismo_depth,
        lower_seismogenic_depth=src.geometry.lower_seismo_depth,
        fault_trace=fault_trace,
        dip=src.geometry.dip,
        rake=src.rake)

    return simple
Beispiel #17
0
#  You should have received a copy of the GNU Affero General Public License
#  along with OpenQuake.  If not, see <http://www.gnu.org/licenses/>.

"""
Validation library for the engine, the desktop tools, and anything else
"""

import re
import ast
import logging
from decimal import Decimal
from openquake.hazardlib import imt, scalerel
from openquake.commonlib.general import distinct

SCALEREL = scalerel.get_available_magnitude_scalerel()


def compose(*validators):
    """
    Implement composition of validators. For instance

    >>> utf8_not_empty = compose(utf8, not_empty)
    >>> utf8_not_empty  # doctest: +ELLIPSIS
    <function compose(utf8,not_empty) at ...>
    """
    def composed_validator(value):
        out = value
        for validator in reversed(validators):
            out = validator(out)
        return out
Beispiel #18
0
import re
import ast
import logging
import textwrap
import collections
from decimal import Decimal
import numpy

from openquake.baselib.python3compat import with_metaclass
from openquake.baselib.general import distinct
from openquake.baselib import hdf5
from openquake.hazardlib import imt, scalerel, gsim
from openquake.hazardlib.calc import disagg
from openquake.hazardlib.calc.filters import IntegrationDistance

SCALEREL = scalerel.get_available_magnitude_scalerel()

GSIM = gsim.get_available_gsims()

disagg_outs = ['_'.join(tup) for tup in sorted(disagg.pmf_map)]


def disagg_outputs(value):
    """
    Validate disaggregation outputs. For instance

    >>> disagg_outputs('TRT Mag_Dist')
    ['TRT', 'Mag_Dist']
    """
    values = value.split()
    for val in values:
Beispiel #19
0
 def _test_get_available_magnitude_scalerel(self):
     self.assertGreater(len(get_available_magnitude_scalerel()), 0)
 def test_get_available_magnitude_scalerel(self):
     self.assertEqual({'PeerMSR': scalerel.peer.PeerMSR,
                       'PointMSR': scalerel.point.PointMSR,
                       'WC1994': scalerel.wc1994.WC1994,
                       'CEUS2011': scalerel.ceus2011.CEUS2011},
                      dict(scalerel.get_available_magnitude_scalerel()))
Beispiel #21
0
 def _test_get_available_magnitude_scalerel(self):
     self.assertGreater(len(get_available_magnitude_scalerel()), 0)
Beispiel #22
0
class MsrField(_DictChoiceField):
    '''A ChoiceField handling the selected Magnitude Scaling Relation object'''
    _base_choices = get_available_magnitude_scalerel()