Beispiel #1
0
    def from_model_files(cls,
                         limits,
                         input_model,
                         investigation_time=1.0,
                         simple_mesh_spacing=1.0,
                         complex_mesh_spacing=5.0,
                         mfd_width=0.1,
                         area_discretisation=10.0):
        """
        Reads the hazard model from a file
        :param list limits:
             Grid configuration [west, east, xspc, south, north, yspc,
                                 upper, lower, zspc]
        :param str input_model:
            Path to input source model
        :param float investigation_time:
            Investigation time of Poisson model
        :param float simple_mesh_spacing:
            Rupture mesh spacing of simple fault (km)
        :param float complex_mesh_spacing:
            Rupture mesh spacing of complex fault (km)
        :param float mfd_width:
            Spacing (in magnitude units) of MFD
        :param float area_discretisation:
            Spacing of discretisation of area source (km)
        """
        converter = SourceConverter(investigation_time, simple_mesh_spacing,
                                    complex_mesh_spacing, mfd_width,
                                    area_discretisation)

        parser = SourceModelParser(converter)
        sources = parser.parse_sources(input_model)
        return cls(limits, sources, area_discretisation)
Beispiel #2
0
    def from_model_files(
        cls,
        limits,
        input_model,
        investigation_time=1.0,
        simple_mesh_spacing=1.0,
        complex_mesh_spacing=5.0,
        mfd_width=0.1,
        area_discretisation=10.0,
    ):
        """
        Reads the hazard model from a file
        :param list limits:
             Grid configuration [west, east, xspc, south, north, yspc,
                                 upper, lower, zspc]
        :param str input_model:
            Path to input source model
        :param float investigation_time:
            Investigation time of Poisson model
        :param float simple_mesh_spacing:
            Rupture mesh spacing of simple fault (km)
        :param float complex_mesh_spacing:
            Rupture mesh spacing of complex fault (km)
        :param float mfd_width:
            Spacing (in magnitude units) of MFD
        :param float area_discretisation:
            Spacing of discretisation of area source (km)
        """
        converter = SourceConverter(
            investigation_time, simple_mesh_spacing, complex_mesh_spacing, mfd_width, area_discretisation
        )

        parser = SourceModelParser(converter)
        sources = parser.parse_sources(input_model)
        return cls(limits, sources, area_discretisation)
Beispiel #3
0
 def test_is_writeable(self):
     parser = SourceModelParser(SourceConverter(50., 1., 10, 0.1, 10.))
     groups = map(copy.deepcopy, parser.parse_groups(ALT_MFDS))
     # there are a SimpleFaultSource and a CharacteristicFaultSource
     fd, fname = tempfile.mkstemp(suffix='.xml')
     with os.fdopen(fd, 'wb'):
         write_source_model(fname, groups, 'Test Source Model')
Beispiel #4
0
def read_area_source(area_source_file, discretisation=200.):
    """Calls OpenQuake parsers to read area source model
    from source_mode.xml type file, convert to point sources
    and write to a new nrml source model file.
    :params area_source_file:
        nrml format file of the area source
    :params discretisation:
        Grid size (km) for the area source discretisation, 
        which defines the distance between resulting point
        sources.
    """
    converter = SourceConverter(50,
                                10,
                                width_of_mfd_bin=0.1,
                                area_source_discretization=discretisation)
    parser = SourceModelParser(converter)
    print[method
          for method in dir(parser)]  # if callable(getattr(parser, method))]
    try:
        sources = parser.parse_sources(area_source_file)
    except AttributeError:  # Handle version 2.1 and above
        sources = []
        groups = parser.parse_src_groups(area_source_file)
        for group in groups:
            for source in group:
                sources.append(source)
    for source in sources:
        print source.polygon
    return sources
Beispiel #5
0
 def test_is_writeable(self):
     parser = SourceModelParser(SourceConverter(50., 1., 10, 0.1, 10.))
     [sf, cf] = map(copy.deepcopy, parser.parse_sources(ALT_MFDS))
     # there are a SimpleFaultSource and a CharacteristicFaultSource
     fd, fname = tempfile.mkstemp(suffix='.xml')
     with os.fdopen(fd, 'w'):
         write_source_model(fname, [sf, cf], 'Test Source Model')
Beispiel #6
0
 def check_round_trip(self, fname):
     parser = SourceModelParser(SourceConverter(50., 1., 10, 0.1, 10.))
     groups = parser.parse_src_groups(fname)
     fd, name = tempfile.mkstemp(suffix='.xml')
     with os.fdopen(fd, 'wb'):
         write_source_model(name, groups, 'Test Source Model')
     if open(name).read() != open(fname).read():
         raise Exception('Different files: %s %s' % (name, fname))
     os.remove(name)
Beispiel #7
0
 def check_round_trip(self, fname):
     parser = SourceModelParser(SourceConverter(50., 1., 10, 0.1, 10.))
     sources = parser.parse_sources(fname)
     fd, name = tempfile.mkstemp(suffix='.xml')
     with os.fdopen(fd, 'w'):
         write_source_model(name, sources, 'Test Source Model')
     if open(name).read() != open(fname).read():
         raise Exception('Different files: %s %s' % (name, fname))
     os.remove(name)
Beispiel #8
0
 def test_duplicate_id(self):
     parser = SourceModelParser(s.SourceConverter(
         investigation_time=50.,
         rupture_mesh_spacing=1,
         complex_fault_mesh_spacing=1,
         width_of_mfd_bin=0.1,
         area_source_discretization=10,
     ))
     with self.assertRaises(DuplicatedID):
         parser.parse_sources(DUPLICATE_ID_SRC_MODEL)
Beispiel #9
0
def area2pt_source(area_source_file, discretisation=200.):
    """Calls OpenQuake parsers to read area source model
    from source_mode.xml type file, convert to point sources
    and write to a new nrml source model file.
    :params area_source_file:
        nrml format file of the area source
    :params discretisation:
        Grid size (km) for the area source discretisation, 
        which defines the distance between resulting point
        sources.
    """
    converter = SourceConverter(50,
                                10,
                                width_of_mfd_bin=0.1,
                                area_source_discretization=discretisation)
    parser = SourceModelParser(converter)
    print[method
          for method in dir(parser)]  # if callable(getattr(parser, method))]
    try:
        sources = parser.parse_sources(area_source_file)
    except AttributeError:  # Handle version 2.1 and above
        sources = []
        groups = parser.parse_src_groups(area_source_file)
        for group in groups:
            for source in group:
                sources.append(source)
    name = 'test_point_model'
    new_pt_sources = {}
    for source in sources:
        pt_sources = area_to_point_sources(source)
        for pt in pt_sources:
            pt.source_id = pt.source_id.replace(':', '')
            pt.name = pt.name.replace(':', '_')
            try:
                new_pt_sources[pt.tectonic_region_type].append(pt)
            except KeyError:
                new_pt_sources[pt.tectonic_region_type] = [pt]
        # print [method for method in dir(pt) if callable(getattr(pt, method))]
        #  print [attribute for attribute in dir(pt)]
    nrml_pt_file = area_source_file[:-4] + '_pts.xml'
    source_group_list = []
    id = 0
    for trt, sources in new_pt_sources.iteritems():
        source_group = SourceGroup(trt, sources=sources, id=id)
        id += 1
        source_group_list.append(source_group)
    write_source_model(nrml_pt_file, source_group_list, name='Leonard2008')
Beispiel #10
0
def read_simplefault_source(simplefault_source_file):
    """Read nrml source model into simpmle fault objects
    """
    converter = SourceConverter(50, 2, width_of_mfd_bin=0.1,
                                area_source_discretization=200.)
    parser = SourceModelParser(converter)
    try:
        sources = parser.parse_sources(simplefault_source_file)
    except AttributeError: # Handle version 2.1 and above
        sources = []
        groups = parser.parse_src_groups(simplefault_source_file)
        for group in groups:
            for source in group:
                sources.append(source)
    for fault in sources:
        print fault.mfd.max_mag
    return sources
Beispiel #11
0
def read_pt_source(pt_source_file):
    """Read nrml source model into pt source objects
    """
    converter = SourceConverter(50,
                                10,
                                width_of_mfd_bin=0.1,
                                area_source_discretization=200.)
    parser = SourceModelParser(converter)
    try:
        sources = parser.parse_sources(pt_source_file)
    except AttributeError:  # Handle version 2.1 and above
        sources = []
        groups = parser.parse_src_groups(pt_source_file)
        for group in groups:
            for source in group:
                sources.append(source)
    return sources
Beispiel #12
0
 def setUpClass(cls):
     cls.parser = SourceModelParser(s.SourceConverter(
         investigation_time=50.,
         rupture_mesh_spacing=1,  # km
         complex_fault_mesh_spacing=1,  # km
         width_of_mfd_bin=1.,  # for Truncated GR MFDs
         area_source_discretization=1.))
     cls.source_collector = {
         sc.trt: sc for sc in cls.parser.parse_trt_models(MIXED_SRC_MODEL)}
     cls.sitecol = site.SiteCollection(cls.SITES)
Beispiel #13
0
 def test(self):
     mod = mock.Mock(
         reference_vs30_value=760,
         reference_vs30_type='measured',
         reference_depth_to_1pt0km_per_sec=100.,
         reference_depth_to_2pt5km_per_sec=5.0,
         reference_backarc=False)
     sitecol = site.SiteCollection.from_points([102.32], [-2.9107], mod)
     parser = SourceModelParser(s.SourceConverter(
         investigation_time=50.,
         rupture_mesh_spacing=1,  # km
         complex_fault_mesh_spacing=1,  # km
         width_of_mfd_bin=1.,  # for Truncated GR MFDs
         area_source_discretization=1.,  # km
     ))
     [[src]] = parser.parse_groups(self.bad_source)
     with self.assertRaises(AttributeError) as ctx, context(src):
         max_dist = 250
         # NB: with a distance of 200 km the error does not happen
         src.filter_sites_by_distance_to_source(max_dist, sitecol)
     self.assertIn('An error occurred with source id=61',
                   str(ctx.exception))
Beispiel #14
0
 def setUpClass(cls):
     cls.parser = SourceModelParser(s.SourceConverter(
         investigation_time=50.,
         rupture_mesh_spacing=1,  # km
         complex_fault_mesh_spacing=1,  # km
         width_of_mfd_bin=1.,  # for Truncated GR MFDs
         area_source_discretization=1.,  # km
     ))
     source_nodes = read_nodes(MIXED_SRC_MODEL, filter_sources, ValidNode)
     (cls.area, cls.point, cls.simple, cls.cmplx, cls.char_simple,
      cls.char_complex, cls.char_multi) = map(
         cls.parser.converter.convert_node, source_nodes)
     # the parameters here would typically be specified in the job .ini
     cls.investigation_time = 50.
     cls.rupture_mesh_spacing = 1  # km
     cls.complex_fault_mesh_spacing = 1  # km
     cls.width_of_mfd_bin = 1.  # for Truncated GR MFDs
     cls.area_source_discretization = 1.  # km