def serialize_gmf(self, ses): """ Write each GMF to an NRML file or to DB depending on job configuration. """ iml_list = self.job_ctxt['INTENSITY_MEASURE_LEVELS'] LOG.debug("IML: %s" % (iml_list)) files = [] nrml_path = '' for event_set in ses: for rupture in ses[event_set]: if self.job_ctxt['SAVE_GMFS']: common_path = os.path.join( self.job_ctxt.base_path, self.job_ctxt['OUTPUT_DIR'], "gmf-%s-%s" % (str(event_set.replace("!", "_")), str(rupture.replace("!", "_")))) nrml_path = "%s.xml" % common_path gmf_writer = hazard_output.create_gmf_writer( self.job_ctxt.job_id, self.job_ctxt.serialize_results_to, nrml_path) gmf_data = {} for site_key in ses[event_set][rupture]: site = ses[event_set][rupture][site_key] site_obj = shapes.Site(site['lon'], site['lat']) gmf_data[site_obj] = \ {'groundMotion': math.exp(float(site['mag']))} gmf_writer.serialize(gmf_data) files.append(nrml_path) return files
def _serialize_gmf(self, hashmap, imt, cnum): """Write the GMF as returned by the java calculator to file. The java calculator returns an implementation of java.util.Map where the key is an instance of org.opensha.commons.data.Site and the value is an instance of java.lang.Double. :param hashmap: map containing the ground motion field. :type hashmap: jpype wrapper around java.util.Map. The map contains instances of org.opensha.commons.data.Site as keys and java.lang.Double as values (the ground motion value for that specific site) :param str imt: the intensity measure type specified for this job. If the type is not "MMI" we need to save the exponential. :param int cnum: the calculation number, part of the GMF file name. :returns: `True` if the GMF contained in the `hashmap` was serialized, `False` otherwise. """ if not self.job_ctxt['SAVE_GMFS']: return False path = os.path.join(self.job_ctxt.base_path, self.job_ctxt['OUTPUT_DIR'], "gmf-%s.xml" % cnum) gmf_writer = hazard_output.create_gmf_writer( self.job_ctxt.job_id, self.job_ctxt.serialize_results_to, path) gmf_data = _prepare_gmf_serialization(hashmap, imt) gmf_writer.serialize(gmf_data) return True
def serialize_gmf(self, ses): """ Write each GMF to an NRML file or to DB depending on job configuration. """ iml_list = self.job_ctxt['INTENSITY_MEASURE_LEVELS'] LOG.debug("IML: %s" % (iml_list)) files = [] nrml_path = '' for event_set in ses: for rupture in ses[event_set]: if self.job_ctxt['SAVE_GMFS']: common_path = os.path.join( self.job_ctxt.base_path, self.job_ctxt['OUTPUT_DIR'], "gmf-%s-%s" % (str(event_set.replace( "!", "_")), str(rupture.replace("!", "_")))) nrml_path = "%s.xml" % common_path gmf_writer = hazard_output.create_gmf_writer( self.job_ctxt.job_id, self.job_ctxt.serialize_results_to, nrml_path) gmf_data = {} for site_key in ses[event_set][rupture]: site = ses[event_set][rupture][site_key] site_obj = shapes.Site(site['lon'], site['lat']) gmf_data[site_obj] = \ {'groundMotion': math.exp(float(site['mag']))} gmf_writer.serialize(gmf_data) files.append(nrml_path) return files