def to_XMLCatalog(self): """ This function creates an xml eqcatalog entry for an rea file and returns the xmlstr value""" if self.catalog_report(): mag,type,agency=self.maximum_magnitude() cat=dict(entry='EQ',id=self.id) cat['latitude']="%.4f" % (self.ha['latitude']) cat['longitude']="%.4f" % (self.ha['longitude']) cat['depth']="%.2f" % (self.ha['depth']) cat['magnitude']="%.1f" % (mag) cat['magnitudetype']=type cat['laterror']="%.2f" % (self.error['latitude']) cat['lonerror']="%.2f" % (self.error['longitude']) cat['deptherror']="%.2f" % (self.error['depth']) cat['oterror']="%.2f" % (self.error['origintime']) cat['origintime']="%s" % (self.origin_time.isoformat(" ")) if eqcatalog.isdst(self.origin_time): ltime= self.origin_time - timedelta(hours=5.0) cat['localtime']="%s CDT" % (ltime.isoformat(" ")) else: ltime= self.origin_time - timedelta(hours=6.0) cat['localtime']="%s CST" % (ltime.isoformat(" ")) cat['nstas']="%i" % (self.no_sta) cat['rms']="%.2f" % (self.ha['rms']) cat['MaxMMI']=eqcatalog.roman_intensity(self.maximum_intensity) cat['updated']=datetime.utcfromtimestamp(self.file_mtime).isoformat("T") return eqcatalog.dict2xml(cat,2) else: return ''
def to_HTML(self,filename=None): """ object.to_HTML(filename) If filename is not defined then the output is directed to standard out. """ from eqcatalog import calc_localtime,isdst if not filename: fh=sys.stdout else: fh=open(filename,'w') fh.write("<html>\n") fh.write("<div style=\"width:600px,padding:20px;\">\n") fh.write("<h2>Earthquake Details: Magnitude %.1f - %s</h2>\n" % (self.preferred_magnitude()[0],self.origin_time.isoformat(" "))) fh.write("<table style=\"border: 1px solid black;\">\n") if isdst(self.origin_time): ltimestr="%s (CDT)" % (calc_localtime(self.origin_time)) else: ltimestr="%s (CST)" % (calc_localtime(self.origin_time)) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Origin Time</td><td>%s (UTC)<br />%s<br />Uncertainty: %.3f seconds</td>\n" % (self.origin_time.isoformat(" "),ltimestr,self.error['origintime'])) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Location</td><td>Latitude: %.4f° ± %.2f (km)<br />Longitude: %.4f° ± %.2f (km) <br />Depth: %.2f ± %.2f km</td>\n" % (self.latitude,self.error['latitude'],self.longitude,self.error['longitude'],self.depth,self.error['depth'])) magstr='' for i in range(0,len(self.magnitude)): # Build magnitude string magstr+="%.1f %s %s<br />" % (self.magnitude[i],self.magnitude_type[i],self.magnitude_agency[i]) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Magnitude</td><td>%s</td>\n" % (magstr)) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Maximum Modified Mercalli Intensity</td><td>%s</td>\n" % (eqcatalog.roman_intensity(self.maximum_intensity))) if self.focmec.has_key('strike'): mechstr="Strike: %.1f°<br />Dip: %.1f°<br />Rake: %.1f°<br />Agency: %s<br />Method: %s,<br />" % (self.focmec['strike'],self.focmec['dip'],self.focmec['rake'],self.focmec['agency'],self.focmec['source']) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Focal Mechanism</td><td>%s</td>\n" % (mechstr)) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Number of Stations</td><td>%d</td>\n" % (self.no_sta)) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Location RMS</td><td>%.2f</td>\n" % (self.rms)) fh.write("<tr><td style=\"font-weight:bold;vertical-align:top;\">Last Updated</td><td>%s UTC</td>\n" % (datetime.utcfromtimestamp(self.file_mtime).isoformat(" "))) fh.write("</table>") #Write out the end of file and close fh.write("</div>\n</html>\n") if filename: fh.close() return True