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 aStationList
object the first time a set of station files are processed. (Or, as an alternative, the user can callloadFromXML()
andfillTables()
sequentially.) This will create a database at the location specified by thedbfile
parameter tofromXML()
. Subsequent programs can use the default constructor to simply loaddbfile
.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
-
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
-
classmethod