Skip to content
Snippets Groups Projects

Draft: Resolve "Add tables and functions for ground-motion field data to be used in loss-calculator"

1 file
+ 55
16
Compare changes
  • Side-by-side
  • Inline
@@ -896,21 +896,22 @@ class SpatiaLiteExposure(SpatiaLiteDatabase, AbstractExposure):
def create_tables(self):
"""
Creates all necessary tables in the database. These are:
Entity : Stores data to identify entities (buildings or tiles)
Asset : Stores assets of an entity (either of a building or tile)
Building : Stores building geometries and parameters
Tile : Stores tile geometries and parameters
Taxonomy : Stores taxonomy strings
Assessment : Stores damage- and loss-assessment metadata
Damage : Stores damage values
DamageState : Stores damage-state names
BuildingLoss : Stores monetary loss values of buildings
HumanLoss : Stores number of fatalities
AssessmentSource: Stores damage- and loss-assessment source names
Boundary : Stores the district boundaries of the exposure model
EntityReference : Stores the entities of the baseline exposure model
AssetReference : Stores the assets of the baseline exposure model
AssetCountry : Stores the average country asset of the baseline exposure model
Entity : Stores data to identify entities (buildings or tiles)
Asset : Stores assets of an entity (either of a building or tile)
Building : Stores building geometries and parameters
Tile : Stores tile geometries and parameters
Taxonomy : Stores taxonomy strings
Assessment : Stores damage- and loss-assessment metadata
Damage : Stores damage values
DamageState : Stores damage-state names
BuildingLoss : Stores monetary loss values of buildings
HumanLoss : Stores number of fatalities
AssessmentSource : Stores damage- and loss-assessment source names
Boundary : Stores the district boundaries of the exposure model
EntityReference : Stores the entities of the baseline exposure model
AssetReference : Stores the assets of the baseline exposure model
AssetCountry : Stores the average country asset of the baseline exposure model
GroundMotionField: Stores the ground-motion fields used for damage/loss computations
"""
# Check if tables already exist (assuming that if table `Entity` exists, all tables do)
@@ -1184,12 +1185,50 @@ class SpatiaLiteExposure(SpatiaLiteDatabase, AbstractExposure):
self.connection.execute(sql_statement)
# Create index for table AssetCountry
sql_statement = """
CREATE INDEX idx_assetcountry_entityid
CREATE INDEX idx_assetcountry_countryisocode
ON AssetCountry(country_iso_code)
"""
self.connection.execute(sql_statement)
logger.debug("Table `AssetCountry` created")
# Create table GroundMotionField
sql_statement = """
CREATE TABLE GroundMotionField (
id INTEGER PRIMARY KEY AUTOINCREMENT,
entity_id INTEGER,
assessment_id INTEGER,
gm_type_id INTEGER,
gm_value REAL)
"""
self.connection.execute(sql_statement)
# Create indices for table GroundMotionField
sql_statement = """
CREATE INDEX idx_groundmotionfield_entityid
ON GroundMotionField(entity_id)
"""
self.connection.execute(sql_statement)
sql_statement = """
CREATE INDEX idx_groundmotionfield_assessmentid
ON GroundMotionField(assessment_id)
"""
self.connection.execute(sql_statement)
sql_statement = """
CREATE INDEX idx_groundmotionfield_gmtypeid
ON GroundMotionField(gm_type_id)
"""
self.connection.execute(sql_statement)
logger.debug("Table `GroundMotionField` created")
# Create table GroundMotionType
sql_statement = """
CREATE TABLE GroundMotionType (
id INTEGER PRIMARY KEY AUTOINCREMENT,
gm_type TEXT,
comment TEXT)
"""
self.connection.execute(sql_statement)
logger.debug("Table `GroundMotionType` created")
# Create views for easy plotting of exposure data
self.create_exposure_views()
Loading