def write_to_nrml(self, output_filename, mmin, upper_depth=0., lower_depth=50., source_model_name="POINT SOURCE MODEL", trt=DEFAULT_TRT, msr=DEFAULT_MSR, aspect=ASPECT_RATIO, hdd=None): """ Converts the smoothed seismicity data to a set of oq-nrml point sources and writes to the output file """ writer = SourceModelXMLWriter(output_filename) source_model = models.SourceModel(source_model_name) source_model.sources = [] print 'Building source model ...' for iloc, row in enumerate(self.data): # Geometry #trt =(row[18]) geom = models.PointGeometry( "POINT (%9.4f %9.4f)" % (row[0], row[1]), upper_depth, lower_depth) if hdd: src_hdd = [] #each tuple with probality and depth for d in hdd: src_hdd.append(models.HypocentralDepth(d[1], d[0])) else: src_hdd = [models.HypocentralDepth(Decimal("1.0"), row[2])] npd = [models.NodalPlane(1, 0, 90, 0)] #if row[5]==1: # npd = [models.NodalPlane(row[6], row[7], row[9], row[8])] #elif row[5] ==2: # npd = [models.NodalPlane(row[6], row[7], row[9], row[8]), models.NodalPlane(row[10], row[11], row[13], row[12])] #else: # npd = [models.NodalPlane(row[6], row[7], row[9], row[8]), models.NodalPlane(row[10], row[11], row[13], row[12]), models.NodalPlane(row[14], row[15], row[17], row[16])] source_model.sources.append( models.PointSource(str(iloc), "PNT_%s" % str(iloc), trt, geom, msr, aspect, self.get_mfd(iloc, row, mmin), npd, src_hdd)) print 'done!' print 'Writing to file ...' writer.serialize(source_model) print 'done!'
def serialise_to_nrml(self, filename, use_defaults=False): ''' Writes the source model to a nrml source model file given by the filename :param str filename: Path to output file :param bool use_defaults: Boolean to indicate whether to use default values (True) or not. If set to False, ValueErrors will be raised when an essential attribute is missing. ''' output_model = models.SourceModel(name=self.name, sources=[]) for source in self.sources: output_model.sources.append( source.create_oqnrml_source(use_defaults)) writer = SourceModelXMLWriter(filename) writer.serialize(output_model)