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)
     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)
    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 nrml format
        """
        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(0, 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!"
            else:
                pass
            if validate:
                print "Validating Source %s" % src.attrib["id"]
                converter.convert_node(src)
            sources.append(src)
        return SourceModel(sources)