Skip to content

Commit

Permalink
Merge pull request #150 from OpenDRR/updates_july2022
Browse files Browse the repository at this point in the history
Updates july2022
  • Loading branch information
wkhchow authored Feb 23, 2023
2 parents adc68cf + 63afdc3 commit adf56fb
Show file tree
Hide file tree
Showing 49 changed files with 10,104 additions and 1,029 deletions.
36 changes: 36 additions & 0 deletions LISEZMOI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# model-factory
![PyPI - Version Python](https://img.shields.io/pypi/pyversions/openquake.engine)

model-factory est un référentiel utilisé en conjonction avec le référentiel [opendrr-api](https://github.com/OpenDRR/opendrr-api).
Il contient de la documentation, et des scripts (python et sql) pour transformer les données sources d'opendrr (exposition, recensement, et sorties OpenQuake etc.) en indicateurs de profil de risque pour :

- [Couche nationale des établissements humains](https://github.com/OpenDRR/national-human-settlement)
- [Exposition physique](https://github.com/OpenDRR/national-human-settlement/tree/main/physical-exposure)
- [Tissu social](https://github.com/OpenDRR/national-human-settlement/tree/main/social-fabric)
- [Scénarios de tremblement de terre](https://github.com/OpenDRR/earthquake-scenarios)
- [Risque sismique probabiliste](https://github.com/OpenDRR/seismic-risk-model)


- **documentation/**
- Taxonomie du profil de risque.xls
- Documentation des indicateurs de profil de risque v1.0 pour examen et commentaires.
- [opendrr.drawio](https://github.com/OpenDRR/opendrr-data-store/blob/master/scripts/Diagrams)
- Diagramme de la base de données postgis actuelle d'opendrr, créé dans draw.io.
- **scripts/**
- Série de scripts python et sql qui sont utilisés dans le référentiel opendrr-api pour construire la base de données PostGIS.
- exigences.txt
- liste des modules et des versions à installer. `$ pip install -r requirements.txt`

Consultez la [section des versions](https://github.com/OpenDRR/model-factory/releases) pour connaître les derniers changements de version.


### Comment fonctionne le script
- La plupart des scripts de ce référentiel sont exécutés avec des arguments sous forme de mots-clés.

Exemple :
```
$ python3 DSRA_outputs2postgres.py --dsraModelDir="https://github.com/OpenDRR/openquake-models/tree/master/deterministic/outputs" --columnsINI="DSRA_outputs2postgres.ini"
```
Ou demandez de l'aide aux scripts pour savoir comment les exécuter :
```
$ python3 DSRA_outputs2postgres.py --help
37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
# model-factory
OpenQuake compilation and data manipulation scripts

![PyPI - Python Version](https://img.shields.io/pypi/pyversions/openquake.engine)

model-factory is a repository used in conjunction with [opendrr-api](https://github.com/OpenDRR/opendrr-api) repository.
It contains documentation, and scripts (python and sql) to transform opendrr source data (exposure, census, and OpenQuake outputs etc.) into risk profile indicators for:

## Install dependencies
`$ pip install -r requirements.txt`
- [National Human Settlement Layer](https://github.com/OpenDRR/national-human-settlement)
- [Physical Exposure](https://github.com/OpenDRR/national-human-settlement/tree/main/physical-exposure)
- [Social Fabric](https://github.com/OpenDRR/national-human-settlement/tree/main/social-fabric)
- [Earthquake Scenarios](https://github.com/OpenDRR/earthquake-scenarios)
- [Probabilistic Earthquake Risk](https://github.com/OpenDRR/seismic-risk-model)

## Run Scripts With Keyword Arguments
Example:

```
$ python3 DSRA_outputs2postgres.py --dsraModelDir="https://github.com/OpenDRR/openquake-models/tree/master/deterministic/outputs" --columnsINI="DSRA_outputs2postgres.ini"
```
- **documentation/**
- RiskProfileTaxonomy.xls
- Documentation of v1.0 risk profile indicators for review and comments.
- [opendrr.drawio](https://github.com/OpenDRR/opendrr-data-store/blob/master/scripts/Diagrams)
- diagram of current opendrr postgis database, created in draw.io
- **scripts/**
- Series of python and sql scripts that are used in opendrr-api repository to build the PostGIS database.
- requirements.txt
- list of modules and versions required to be installed. `$ pip install -r requirements.txt`

Or ask scripts for help on how to run them:
Refer to the [releases section](https://github.com/OpenDRR/model-factory/releases) for latest version changes.


### How the script works
- Most scripts in this repository are run with keyword arguments.

Example:
```
$ python3 DSRA_outputs2postgres.py --help
$ python3 DSRA_outputs2postgres.py --dsraModelDir="https://github.com/OpenDRR/openquake-models/tree/master/deterministic/outputs" --columnsINI="DSRA_outputs2postgres.ini"
```
Or ask scripts for help on how to run them:
```
$ python3 DSRA_outputs2postgres.py --help
46 changes: 23 additions & 23 deletions scripts/Create_all_tables_update.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-- update tables in one script

-- create master dsra table
DROP TABLE IF EXISTS dsra.dsra_all_scenarios_tbl CASCADE;
CREATE TABLE dsra.dsra_all_scenarios_tbl(
assetid varchar,
sauid varchar,
dauid varchar,
csduid varchar,
csdname varchar,
fsauid varchar,
cduid varchar,
cdname varchar,
eruid varchar,
ername varchar,
pruid varchar,
prname varchar,
sh_rupname varchar,
sh_mag varchar,
sh_hypolon float,
sh_hypolat float,
sh_hypodepth float,
sh_rake varchar,
geom_point geometry
);
-- -- create master dsra table
-- DROP TABLE IF EXISTS dsra.dsra_all_scenarios_tbl CASCADE;
-- CREATE TABLE dsra.dsra_all_scenarios_tbl(
-- assetid varchar,
-- sauid varchar,
-- dauid varchar,
-- csduid varchar,
-- csdname varchar,
-- fsauid varchar,
-- cduid varchar,
-- cdname varchar,
-- eruid varchar,
-- ername varchar,
-- pruid varchar,
-- prname varchar,
-- sh_rupname varchar,
-- sh_mag varchar,
-- sh_hypolon float,
-- sh_hypolat float,
-- sh_hypodepth float,
-- sh_rake varchar,
-- geom_point geometry
-- );

-- create gmf scenario extents table temp
DROP TABLE IF EXISTS gmf.shakemap_scenario_extents_temp CASCADE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

-- clipped
-- 1km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km_4326 AS
SELECT
b.gridid_1,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -28,8 +28,8 @@ LEFT JOIN boundaries."HexGrid_1km" c ON b.gridid_1 = c.gridid_1
GROUP BY b.gridid_1,c.geom;

-- 5km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km_4326 AS
SELECT
b.gridid_5,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -54,8 +54,8 @@ GROUP BY b.gridid_5,c.geom;


-- 10km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km_4326 AS
SELECT
b.gridid_10,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -79,8 +79,8 @@ LEFT JOIN boundaries."HexGrid_10km" c ON b.gridid_10 = c.gridid_10
GROUP BY b.gridid_10,c.geom;

-- 25km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km_4326 AS
SELECT
b.gridid_25,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand Down Expand Up @@ -132,8 +132,8 @@ GROUP BY b.gridid,c.geom;

-- unclipped
-- 1km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km_uc;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km_uc AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km_uc_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_1km_uc_4326 AS
SELECT
b.gridid_1,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -157,8 +157,8 @@ LEFT JOIN boundaries."HexGrid_1km_unclipped" c ON b.gridid_1 = c.gridid_1
GROUP BY b.gridid_1,c.geom;

-- 5km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km_uc;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km_uc AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km_uc_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_5km_uc_4326 AS
SELECT
b.gridid_5,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -183,8 +183,8 @@ GROUP BY b.gridid_5,c.geom;


-- 10km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km_uc;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km_uc AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km_uc_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_10km_uc_4326 AS
SELECT
b.gridid_10,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -208,8 +208,8 @@ LEFT JOIN boundaries."HexGrid_10km_unclipped" c ON b.gridid_10 = c.gridid_10
GROUP BY b.gridid_10,c.geom;

-- 25km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km_uc;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km_uc AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km_uc_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_25km_uc_4326 AS
SELECT
b.gridid_25,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -234,8 +234,8 @@ GROUP BY b.gridid_25,c.geom;


-- 50km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_50km_uc;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_50km_uc AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_50km_uc_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_50km_uc_4326 AS
SELECT
b.gridid_50,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand All @@ -259,8 +259,8 @@ LEFT JOIN boundaries."HexGrid_50km_unclipped" c ON b.gridid_50 = c.gridid_50
GROUP BY b.gridid_50,c.geom;

-- 100km
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_100km_uc;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_100km_uc AS
DROP VIEW IF EXISTS results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_100km_uc_4326;
CREATE VIEW results_nhsl_hazard_threat.nhsl_hazard_threat_prioritization_hexgrid_100km_uc_4326 AS
SELECT
b.gridid_100,
SUM("Et_BldgNum" * b.area_ratio) AS "Et_BldgNum",
Expand Down
Loading

0 comments on commit adf56fb

Please sign in to comment.