GEMScienceTools / gmpe-smtk

Python and OpenQuake-based Toolkit for Analysis of Strong Motions and Interpretation of GMPEs
GNU Affero General Public License v3.0
43 stars 33 forks source link

Common gmdb interface #116

Closed rizac closed 3 years ago

rizac commented 3 years ago

This PR makes easier to implement user defined Ground motion databases for residuals computation (e.g. via SQL database) .

  1. A new module rcrs is created, which implements ResidualsCompliantRecordSet: this is the abstract-like base interface for any database to be passed to gmpe_residuals.Residuals.get_residuals.

  2. sm_database.GroundMotionDatabase and sm_table.GroundMotionTable were refactored to subclass ResidualsCompliantRecordSet

  3. gmpe_residuals.Residuals.get_residuals has been slightly refactored to work with ResidualsCompliantRecordSetas input (minor stuff, most of the code was already implemented for that)

  4. Refactored sm_table because of some unused / unstructured code (nothing to do with this PR, but while I was at it ...)

  5. Fixed tests (with Python 3.8.1 and openquake 3.10.1)

============

Note: the context dicts (see method rcrs.ResidualsCompliantRecordSet.get_contexts) do not have anymore the 'EventIndex' key, which was mapped to the indices of the event's records. Let alone the naming ('RecordIndex' might be more suited) the key has been removed because it is not used anymore anywhere. Also, before being tempted to restore it, note that it assumed Ground motion databases storages to always be index-based, which is not true (it works for Python lists, but not for HDF table rows for instance)