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()
).
- 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 loadFromFiles(filelist, min_nresp=3, dbfile=':memory:')[source]¶
Create a StationList object by reading one or more ShakeMap XML or JSON input files.
- Parameters:
filelist (sequence of str) – Sequence of ShakeMap XML and/or JSON input files to read.
min_nresp (int) – The minimum number of DYFI observations required to form and valid observation. Default is 3.
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(filelist, min_nresp)[source]¶
Add data from XML or JSON files to the existing StationList.
- Parameters:
filelist – A list of ShakeMap XML or JSON input files.
min_nresp (int) – The minimum number of DYFI observations required to form and valid observation.
- Returns:
Nothing.
- Return type:
nothing
- getIMTtypes()[source]¶
Return a set of IMT types found in the database
- Parameters:
None –
- Returns:
A set of IMT types
- getStationDictionary(instrumented=True, min_nresp=1)[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’, ‘stddev’, ‘instrumented’, ‘PGA’, ‘PGA_sd’, ‘PGV’, ‘PGA_sd’, ‘SA(0.3)’, ‘SA(0.3)_sd, ‘SA(1.0)’, ‘SA(1.0)_sd’, ‘SA(3.0)’, ‘SA(3.0)_sd’
For the non-instrumented dictionary, the keys would be:
‘id’, ‘network’, ‘code’, ‘name’, ‘lat’, ‘lon’, ‘elev’, ‘vs30’, ‘stddev’, ‘instrumented’, ‘MMI’, ‘MMI_sd’, ‘nresp’
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:
- Returns:
A dictionary of Numpy arrays, and a set specifying the IMTs found in the dictionary.
- Return type:
- Raises:
TypeError – if “instrumented” argument is not type bool.
- shakelib.station.get_imt_period(imt)[source]¶
Get the period from a string like psa3p0, psa3.0, or psa30 (the first being favored). Return the floating point period.
- Parameters:
imt (str) – a string starting with “psa” and ending with something that can reasonably be converted to a floating point number.
- Returns:
The period of the psa input.
- Return type:
TODO: Could do a lot more error checking here, but I guess we’re assuming that the people who send us data aren’t idiots.