コード例 #1
0
def read_simplefault_source(simplefault_source_file, rupture_mesh_spacing=10):
    """Read nrml source model into simpmle fault objects
    """
    converter = SourceConverter(50,
                                rupture_mesh_spacing,
                                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 [method for method in dir(fault)]
        # print [method for method in dir(fault.mfd)]

        #######Probably not actually needed now
        # Add max_mag attribute if needed:
        #        try:
        #            print fault.mfd.max_mag
        #        except AttributeError:
        #            min_mag, max_mag = fault.mfd.get_min_max_mag()
        #            fault.mfd.max_mag = max_mag
        #            print fault.mfd.max_mag
        pass
    return sources
コード例 #2
0
ファイル: sourcewriter_test.py プロジェクト: gem/oq-hazardlib
 def test_is_writeable(self):
     parser = SourceModelParser(SourceConverter(50., 1., 10, 0.1, 10.))
     groups = [copy.deepcopy(grp) for grp in 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')
コード例 #3
0
 def test_is_writeable(self):
     parser = SourceModelParser(SourceConverter(50., 1., 10, 0.1, 10.))
     groups = [copy.deepcopy(grp) for grp in 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')
コード例 #4
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 = []
        for grp in parser.parse_groups(input_model):
            sources.extend(grp.sources)
        return cls(limits, sources, area_discretisation)
コード例 #5
0
ファイル: rate_grids.py プロジェクト: gem/oq-hazardlib
    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 = []
        for grp in parser.parse_groups(input_model):
            sources.extend(grp.sources)
        return cls(limits, sources, area_discretisation)
コード例 #6
0
def get_source_model(source_file, inv_time, simple_mesh_spacing=1.0,
                     complex_mesh_spacing=10.0, mfd_spacing=0.1,
                     area_discretisation=10.):
    """
    Read and build a source model from an xml file
    """
    conv = SourceConverter(inv_time, simple_mesh_spacing, complex_mesh_spacing,
                           mfd_spacing, area_discretisation)
    parser = SourceModelParser(conv)
    return parser.parse_src_groups(source_file)
コード例 #7
0
ファイル: sourcewriter_test.py プロジェクト: gem/oq-hazardlib
 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')
     with hdf5.File.temporary() as f:
         for group in groups:
             hdf5write(f, group)
     print('written %s' % f.path)
     if open(name).read() != open(fname).read():
         raise Exception('Different files: %s %s' % (name, fname))
     os.remove(name)
コード例 #8
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')
     with hdf5.File.temporary() as f:
         for group in groups:
             hdf5write(f, group)
     print('written %s' % f.path)
     if open(name).read() != open(fname).read():
         raise Exception('Different files: %s %s' % (name, fname))
     os.remove(name)
コード例 #9
0
def read_pt_source(pt_source_file):
    """Read nrml source model into pt source objects
    """
    converter = SourceConverter(50, 2, width_of_mfd_bin=0.1,
                                area_source_discretization=10.)
    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)
#    for pt in sources:
#        print pt.mfd.max_mag
    return sources
コード例 #10
0
ファイル: gmf_calculator.py プロジェクト: mtoqeerpk/EQIAT
def get_sources(source_model_file, discretisation=50.):
    """Calls OpenQuake parsers to read  source model
    from source_mode.xml type file, 
    and return to calculate ruptures. A more generic verions
    than that above.
    :params source_model_file:
        nrml format file of source model
    :params discretisation:
        Grid size (km) for the area source discretisation, 
        which defines the distance between resulting point
        sources.
    :returns sources
        Source for the source model
    """
    converter = SourceConverter(50,
                                10,
                                width_of_mfd_bin=0.1,
                                area_source_discretization=discretisation)
    parser = SourceModelParser(converter)
    try:
        sources = parser.parse_sources(source_model_file)
    except AttributeError:  # Handle version 2.1 and above
        sources = []
        groups = parser.parse_src_groups(source_model_file)
        for group in groups:
            for source in group:
                sources.append(source)


#    name = 'test_point_model'
    new_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_sources[source.tectonic_region_type].append(source)
        except KeyError:
            new_sources[source.tectonic_region_type] = [source]
    return new_sources
コード例 #11
0
ファイル: area_sources.py プロジェクト: songzhenhe/NSHA2018
def nrml2sourcelist(area_source_file,
                    investigation_time=50,
                    rupture_mesh_spacing=10.,
                    width_of_mfd_bin=0.1,
                    area_source_discretisation=10.):
    """Parser nrml file containing area sources and read into
    a list of source objects
    """
    converter = SourceConverter(
        50,
        10,
        width_of_mfd_bin=0.1,
        area_source_discretization=area_source_discretisation)
    parser = SourceModelParser(converter)
    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)
    return sources