shakelib.station

class shakelib.station.StationList(db)[source]

Bases: object

A class to facilitate reading ShakeMap formatted XML fies of peak amplitudes and MMI, and produce tables of station data. Seismic stations are considered to be ‘instrumented’; MMI data is not instrumented and is indicated in the ShakeMap XML with a netid attribute of “DYFI,” “MMI,” “INTENSITY,” or “CIIM.”

Note

Typically the user will call the class method fromXML() to create a StationList object the first time a set of station files are processed. (Or, as an alternative, the user can call loadFromXML() and fillTables() sequentially.) This will create a database at the location specified by the dbfile parameter to fromXML(). Subsequent programs can use the default constructor to simply load dbfile.

The default constructor reads a pre-built SQLite database of station data.

Parameters:dbfile (str) – A SQLite database file containing pre-processed station data.
Returns:A StationList object.
classmethod loadFromSQL(sql, dbfile=':memory:')[source]

Create a new object from saved SQL code (see dumpToSQL()).

Parameters:
  • sql (str) – SQL code to create and populate the database
  • dbfile (str) – The path to a file in which the database will reside. The default is ‘:memory:’ for an in-memory database.
Returns:

Stationlist object.

dumpToSQL()[source]

Dump the database as a string of SQL code (see loadFromSQL()).

Parameters:None
Returns:A string of SQL sufficient to restore and repopulate the database.
classmethod loadFromXML(xmlfiles, dbfile=':memory:')[source]

Create a StationList object by reading one or more ShakeMap XML input files.

Parameters:
  • xmlfiles (sequence of str) – Sequence of ShakeMap XML input files to read.
  • dbfile (str) – Path to a file into which to write the SQLite database. The default is ‘:memory:’ for an in-memory database.
Returns:

StationList object

getGeoJson()[source]
addData(xmlfiles)[source]

Create a StationList object by reading one or more ShakeMap XML input files.

Parameters:xmlfiles (sequence of str) – Sequence of ShakeMap XML input files to read.
Returns:StationList object
getIMTtypes()[source]

Return a set of IMT types found in the database

Parameters:None
Returns:A set of IMT types
getStationDictionary(instrumented=True)[source]

Return a dictionary of the instrumented or non-instrumented stations. The keys describe the parameter, the values are Numpy arrays of the parameter in question.

For the standard set of ShakeMap IMTs (mmi, pga, pgv, psa03, psa10, psa30), the keys in the dictionary would be:

‘id’, ‘network’, ‘code’, ‘name’, ‘lat’, ‘lon’, ‘elev’, ‘vs30’, ‘instrumented’, ‘PGA’, ‘PGV’, ‘SA(0.3)’, ‘SA(1.0)’, ‘SA(3.0)’

For the non-instrumented dictionary, the keys would be:

‘id’, ‘network’, ‘code’, ‘name’, ‘lat’, ‘lon’, ‘elev’, ‘vs30’, ‘instrumented’, ‘MMI’

The id column is network and code concatenated with a period (“.”) between them.

All ground motion units are natural log units. Distances are in km.

Parameters:instrumented (bool) – Set to True if the dictionary is to contain the instrumented stations, or to False if the dictionary is to contain the non-instrumented (MMI) stations.
Returns:A dictionary of Numpy arrays.
Return type:dict
shakelib.station.get_imt_period(imt)[source]