shakemap.coremods.kml

class shakemap.coremods.kml.KMLModule(eventid)[source]

Bases: CoreModule

kml – Generate KML/KMZ files for ShakeMap.

Instantiate a KMLModule class with an event ID.

command_name = 'kml'
targets = ['products/shakemap\\.kmz']
dependencies = [('products/shake_result.hdf', True)]
execute()[source]

Create KML files.

Raises:
shakemap.coremods.kml.create_kmz(container, datadir, logger, contents)[source]
shakemap.coremods.kml.place_legend(datadir, document)[source]

Place the ShakeMap intensity legend in the upper left corner of the viewer’s map.

Parameters:
  • datadir (str) – Path to data directory where output KMZ will be written.

  • document (Element) – LXML KML Document element.

Returns:

Path to output intensity legend file.

Return type:

str

shakemap.coremods.kml.create_epicenter(container, document)[source]

Place a star marker at earthquake epicenter.

Parameters:
  • container (ShakeMapOutputContainer) – Results of model.conf.

  • document (Element) – LXML KML Document element.

shakemap.coremods.kml.create_polygons(container, document)[source]
shakemap.coremods.kml.create_contours(container, document)[source]

Create a KML file containing MMI contour lines.

Parameters:
  • container (ShakeMapOutputContainer) – Results of model.conf.

  • datadir (str) – Path to data directory where output KMZ will be written.

  • document (Element) – LXML KML Document element.

shakemap.coremods.kml.set_look(document, container)[source]

Set the view location, altitude, and angle.

Parameters:
  • document (Element) – LXML KML Document element.

  • container (ShakeMapOutputContainer) – Results of model.conf.

shakemap.coremods.kml.create_line_styles()[source]

Create line styles for contour KML.

Args:

shakemap.coremods.kml.create_overlay(container, datadir, document)[source]

Create a KML file and intensity map.

Parameters:
  • container (ShakeMapOutputContainer) – Results of model.conf.

  • datadir (str) – Path to data directory where output KMZ will be written.

  • document (SubElement) – KML document where the overlay tags should go.

Returns:

(Path to output KMZ file, Path to output overlay image)

Return type:

tuple

shakemap.coremods.kml.create_overlay_image(container, filename)[source]

Create a semi-transparent PNG image of intensity.

Parameters:
  • container (ShakeMapOutputContainer) – Results of model.conf.

  • filename (str) – Path to desired output PNG file.

Returns:

GeoDict object for the intensity grid.

Return type:

GeoDict

shakemap.coremods.kml.create_stations(container, datadir, document)[source]

Create a KMZ file containing station KML and necessary icons files.

Parameters:
  • container (ShakeMapOutputContainer) – Results of model.conf.

  • datadir (str) – Path to data directory where output KMZ will be written.

  • document (Element) – LXML KML Document element.

Returns:

Path to output KMZ file.

Return type:

str

shakemap.coremods.kml.make_placemark(folder, station, cpalette, style_map)[source]

Create a placemark element in station KML.

Parameters:
  • folder (Element) – KML Folder element.

  • station (dict) – Dictionary containing station data.

  • cpalette (ColorPalette) – Object allowing user to convert MMI to color.

  • style_map (skml.StyleMap) – The style map for the station type.

shakemap.coremods.kml.get_intensity(station)[source]

Retrieve the intensity value from a station dictionary.

Parameters:

station (dict) – Dictionary containing station data.

Returns:

Intensity value.

Return type:

float

shakemap.coremods.kml.get_description_table(station)[source]

Get station description as HTML table.

Parameters:

station (dict) – Dictionary containing station data.

Returns:

String containing HTML table describing station.

Return type:

str

shakemap.coremods.kml.imt_to_string(imt)[source]
shakemap.coremods.kml.make_row(table, key, value)[source]

Create a row in the description table.

Parameters:
  • table (Element) – LXML Element for table tag.

  • key (str) – Text for left hand column of row.

  • value (str) – Text for right hand column of row.

shakemap.coremods.kml.get_description(station)[source]

Get station description as HTML definition list.

Parameters:

station (dict) – Dictionary containing station data.

Returns:

String containing HTML definition list describing station.

Return type:

str

shakemap.coremods.kml.get_imt_text(station, imt)[source]

Get a text string describing the value of input IMT.

Parameters:
  • station (dict) – Dictionary containing station data.

  • imt (str) – IMT string (pga,pgv, sa(0.3), etc.)

Returns:

IMT text string (i.e., “7.1 cm/sec”)

Return type:

str

shakemap.coremods.kml.create_styles(document, icon_text, scale_normal, scale_highlight, color)[source]

Create styles/style maps for station KML.

Parameters:

document (Element) – LXML KML Document element.

shakemap.coremods.kml.add_icon_style(document, icon_text, icon_scale, label_scale, color)[source]

Create Style tag around Icon in KML.

Parameters:
  • document (Element) – LXML KML Document element.

  • icon_text (str) – The name of the icon file.

  • icon_scale (float) – The icon scale.

  • label_scale (float) – The label scale.

shakemap.coremods.kml.flip_rgb(rgb)[source]

Reverse order of RGB hex string, prepend ‘ff’ for transparency.

Parameters:

rgb – RGB hex string (#E1C2D3)

Returns:

ABGR hex string (#ffd3c2e1).

Return type:

str