Пример #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)
Пример #2
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
Пример #3
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')
Пример #4
0
def get_source_model(source_file,
                     inv_time=50.0,
                     simple_mesh_spacing=1.0,
                     complex_mesh_spacing=10.0,
                     mfd_spacing=0.1,
                     area_discretisation=10.0):
    conv = SourceConverter(inv_time, simple_mesh_spacing, complex_mesh_spacing,
                           mfd_spacing, area_discretisation)
    return parse_source_model(source_file, conv)
Пример #5
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)
Пример #6
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')
Пример #7
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
Пример #8
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