def read(self, nrml_file, validate=False, simple_fault_spacing=1.0, complex_mesh_spacing=5.0, mfd_spacing=0.1): """ Build the source model from nrml format """ self.source_file = nrml_file if validate: converter = SourceConverter(1.0, simple_fault_spacing, complex_mesh_spacing, mfd_spacing, 10.0) converter.fname = nrml_file root = nrml.read(nrml_file) if root['xmlns'] == 'http://openquake.org/xmlns/nrml/0.4': sg_nodes = [root.sourceModel.nodes] else: # NRML 0.5 sg_nodes = root.sourceModel.nodes sources = [] for sg_node in sg_nodes: for no, src_node in enumerate(sg_node, 1): if validate: print("Validating Source %s" % src_node.attrib["id"]) converter.convert_node(src_node) sources.append(src_node) return SourceModel(sources)
def read(self, input_shapefile, validate=False, simple_fault_spacing=1.0, complex_mesh_spacing=5.0, mfd_spacing=0.1): """ Build the source model from a shapefile """ reader = shapefile.Reader(input_shapefile) fields = [field[0] for field in reader.fields[1:]] shapes = reader.shapes() records = reader.records() sources = [] if validate: converter = SourceConverter(1.0, simple_fault_spacing, complex_mesh_spacing, mfd_spacing, 10.0) for iloc in range(reader.numRecords): # Build record dictionary record = record_to_dict(records[iloc], fields) shape = shapes[iloc] if "pointSource" in record["sourcetype"]: src = build_point_source_from_shp(shape, record) elif "areaSource" in record["sourcetype"]: src = build_area_source_from_shp(shape, record) elif "simpleFaultSource" in record["sourcetype"]: src = build_simple_fault_source_from_shp(shape, record) elif "complexFaultSource" in record["sourcetype"]: src = build_complex_fault_source_from_shp(shape, record) elif "characteristicFaultSource" in record["sourcetype"]: print("Characteristic Fault Source Not Yet Supported - Sorry!") src = None elif "multiPointSource" in record["sourcetype"]: print("Characteristic Fault Source Not Yet Supported - Sorry!") src = None if src and validate: print("Validating Source %s" % src.attrib["id"]) converter.convert_node(src) if src: sources.append(src) return SourceModel(sources)
def read(self, nrml_file, validate=False, simple_fault_spacing=1.0, complex_mesh_spacing=5.0, mfd_spacing=0.1): """ Build the source model from nrml format """ self.source_file = nrml_file if validate: converter = SourceConverter(1.0, simple_fault_spacing, complex_mesh_spacing, mfd_spacing, 10.0) converter.fname = nrml_file src_nodes = nrml.read(nrml_file).sourceModel sources = [] for no, src_node in enumerate(src_nodes, 1): if validate: print("Validating Source %s" % src_node.attrib["id"]) converter.convert_node(src_node) sources.append(src_node) return SourceModel(sources)