shakelib.utils.containers

class shakelib.utils.containers.InputContainer(hdfobj)[source]

Bases: mapio.gridcontainer.GridHDFContainer

HDF container for Shakemap input data.

This class provides methods for getting and setting information on:
  • configuration
  • event (lat,lon,depth,etc.)
  • rupture
  • station data (can also be updated)
  • version history

Instantiate an HDFContainer from an open h5py File Object.

Parameters:hdfobj – Open h5py File Object.
classmethod createFromInput(filename, config, eventfile, rupturefile=None, datafiles=None, version_history=None)[source]

Instantiate an InputContainer from ShakeMap input data.

Parameters:
  • filename (str) – Path to HDF5 file that will be created to encapsulate all input data.
  • config (dict) – Dictionary containing all configuration information necessary for ShakeMap ground motion and other calculations.
  • eventfile (str) – Path to ShakeMap event.xml file.
  • rupturefile (str) – Path to ShakeMap rupture text or JSON file.
  • datafiles (list) – List of ShakeMap data (DYFI, strong motion) files.
  • version_history (dict) – Dictionary containing version history.
Returns:

Instance of InputContainer.

Return type:

InputContainer

setConfig(config)[source]

Add the config as a dictionary to the HDF file.

Parameters:config (dict--like) – Dict–like object with configuration information.
setEvent(event_file)[source]

Store the information found in an event.xml file as a dictionary.

Note: setEvent will attempt to extract productcode as an attribute of the event.xml file earthquake tag. If this fails, productcode will be extracted from the directory tree, which should look something like this:

  • ~/ShakeMap/[PROFILE]/data/[PRODUCTCODE]/current/event.xml

where [PROFILE] is the current ShakeMap profile, and [PRODUCTCODE] is something like “us2017abcd”.

Parameters:event_file (str) – String path to an event.xml file.
Raises:KeyError – if event_file contains ‘productcode’ and it doesn’t match the directory name containing the data for a given event.
setRupture(rupture_file)[source]

Store data found in either JSON or text format rupture file.

Parameters:rupture_file (str) – File containing either JSON formatted rupture data or older style fault.txt format.
setStationData(datafiles)[source]

Insert observed ground motion data into the container.

Parameters:datafiles (str) – Path to an XML-formatted file containing ground motion observations, (macroseismic or instrumented).
addStationData(datafiles)[source]

Add observed ground motion data into the container.

Parameters:datafiles (str) – Path to an XML-formatted file containing ground motion observations, (macroseismic or instrumented).
setVersionHistory(history_dict)[source]

Store a dictionary containing version history in the container.

Parameters:history_dict (dict) – Dictionary containing version history. ??
getConfig()[source]

Return the configuration information as a dictionary.

Returns:Dictionary of configuration information.
Return type:dict
getRupture()[source]

Get rupture object from data stored in container.

Returns:An instance of a sub-class of a Rupture object
Return type:Rupture
getStationList()[source]

Return the StationList object stored in this container.

Returns:StationList object.
Return type:StationList
getVersionHistory()[source]

Return the dictionary containing version history.

Returns:Dictionary containing version history. ??
Return type:dict
getOrigin()[source]

Extract an Origin object from the event dictionary stored in container.

Returns:Origin object.
Return type:Origin
class shakelib.utils.containers.OutputContainer(hdfobj)[source]

Bases: mapio.gridcontainer.GridHDFContainer

HDF container for Shakemap output data.

This class provides methods for getting and setting IMT data. The philosophy here is that an IMT consists of both the mean results and the standard deviations of those results, thus getIMT() returns a dictionary with both, plus metadata for each data layer.

Instantiate an HDFContainer from an open h5py File Object.

Parameters:hdfobj – Open h5py File Object.
setIMT(imt_name, imt_mean, mean_metadata, imt_std, std_metadata, component, compression=True)[source]

Store IMT mean and standard deviation objects as datasets.

Parameters:
  • name (str) – Name of the IMT (MMI,PGA,etc.) to be stored.
  • imt_mean (Grid2D) – Grid2D object of IMT mean values to be stored.
  • mean_metadata (dict) – Dictionary containing metadata for mean IMT grid.
  • imt_std (Grid2D) – Grid2D object of IMT standard deviation values to be stored.
  • std_metadata (dict) – Dictionary containing metadata for mean IMT grid.
  • component (str) – Component type, i.e. ‘Larger’,’rotd50’,etc.
  • compression (bool) – Boolean indicating whether dataset should be compressed using the gzip algorithm.
Returns:

HDF Group containing IMT grids and metadata.

getIMT(imt_name, component)[source]

Retrieve a Grid2D object and any associated metadata from the container.

Parameters:imt_name (str) – The name of the Grid2D object stored in the container.
Returns:
Dictionary containing 4 items:
  • mean Grid2D object for IMT mean values.
  • mean_metadata Dictionary containing any metadata describing mean layer.
  • std Grid2D object for IMT standard deviation values.
  • std_metadata Dictionary containing any metadata describing standard deviation layer.
Return type:dict
getIMTs(component)[source]

Return list of names of IMTs matching input component type.

Parameters:component (str) – Name of component (‘Larger’,’rotd50’,etc.)
Returns:List of names of IMTs matching component stored in container.
Return type:list
getComponents(imt_name)[source]

Return list of components for given IMT.

Parameters:imt_name (str) – Name of IMT (‘MMI’,’PGA’,etc.)
Returns:List of names of components for given IMT.
Return type:list
dropIMT(imt_name)[source]

Delete IMT datasets from container.

Parameters:name (str) – The name of the IMT to be deleted.