Skip to content

Commit

Permalink
Add dsra hexgrid indices (#166)
Browse files Browse the repository at this point in the history
* add additional ES indices for dsra/psra/exposure

* run modified es index scripts

* run dsra shkmap script + exposure script bug fix

* add additional ES indices for dsra/psra/exposure

* run modified es index scripts

* run dsra shkmap script + exposure script bug fix

* remove global fabric - null value bug
  • Loading branch information
drotheram authored Feb 7, 2022
1 parent dc84db5 commit 8371831
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 183 deletions.
24 changes: 12 additions & 12 deletions python/add_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -892,16 +892,17 @@ export_to_elasticsearch() {
# Load Deterministic Model Indicators
# shellcheck disable=SC2154
if [[ "$loadDsraScenario" = true ]]; then
for eqscenario in "${EQSCENARIO_LIST[@]}"; do
LOG "Creating Elasticsearch indexes for DSRA"
#RUN python3 dsra_postgres2es.py --eqScenario="$eqscenario" --dbview="indicators" --idField="building"
RUN python3 dsra_postgres2es.py --eqScenario="$eqscenario"

# LOG "Creating DSRA Kibana Index Patterns"
# Need to develop saved object workflow for automated index patern generation
# RUN curl -X POST -H "Content-Type: application/json" "${KIBANA_ENDPOINT}/s/gsc-cgc/api/saved_objects/index-pattern/opendrr_dsra_${eqscenario}_indicators_s" -H "kbn-xsrf: true" -d "{ 'attributes': { 'title':'opendrr_dsra_${eqscenario}_indicators_s'}}"
# RUN curl -X POST -H "Content-Type: application/json" "${KIBANA_ENDPOINT}/s/gsc-cgc/api/saved_objects/index-pattern/opendrr_dsra_${eqscenario}_indicators_b" -H "kbn-xsrf: true" -d "{ 'attributes': { 'title':'opendrr_dsra_${eqscenario}_indicators_b'}}"
done
for eqscenario in "${EQSCENARIO_LIST[@]}"; do
LOG "Creating Elasticsearch indexes for DSRA"
#RUN python3 dsra_postgres2es.py --eqScenario="$eqscenario" --dbview="indicators" --idField="building"
RUN python3 dsra_postgres2es.py --eqScenario="$eqscenario"
RUN python3 dsraShakemap_postgres2es.py --eqScenario="$eqscenario"

# LOG "Creating DSRA Kibana Index Patterns"
# Need to develop saved object workflow for automated index patern generation
# RUN curl -X POST -H "Content-Type: application/json" "${KIBANA_ENDPOINT}/s/gsc-cgc/api/saved_objects/index-pattern/opendrr_dsra_${eqscenario}_indicators_s" -H "kbn-xsrf: true" -d "{ 'attributes': { 'title':'opendrr_dsra_${eqscenario}_indicators_s'}}"
# RUN curl -X POST -H "Content-Type: application/json" "${KIBANA_ENDPOINT}/s/gsc-cgc/api/saved_objects/index-pattern/opendrr_dsra_${eqscenario}_indicators_b" -H "kbn-xsrf: true" -d "{ 'attributes': { 'title':'opendrr_dsra_${eqscenario}_indicators_b'}}"
done
RUN python3 dsraExtents_postgres2es.py
fi

Expand All @@ -921,8 +922,7 @@ done
# shellcheck disable=SC2154
if [[ $loadPhysicalExposure = true ]]; then
LOG "Creating Elasticsearch indexes for Physical Exposure"
RUN python3 exposure_postgres2es.py --aggregation="building" --geometry=geom_point
RUN python3 exposure_postgres2es.py --aggregation="sauid" --geometry=geom_poly
RUN python3 exposure_postgres2es.py

LOG "Creating Exposure Kibana Index Patterns"
RUN curl -X POST -H "Content-Type: application/json" "${KIBANA_ENDPOINT}/s/gsc-cgc/api/saved_objects/index-pattern/opendrr_nhsl_physical_exposure_indicators_s" -H "kbn-xsrf: true" -d '{ "attributes": { "title":"opendrr_nhsl_physical_exposure_indicators_s"}}'
Expand Down
44 changes: 0 additions & 44 deletions python/calculate_all_dsra_jenks.py

This file was deleted.

189 changes: 189 additions & 0 deletions python/dsraShakemap_postgres2es.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#!/usr/bin/python3
# =================================================================
# SPDX-License-Identifier: MIT
#
# Copyright (C) 2020-2021 Government of Canada
#
# Main Authors: Drew Rotheram <drew.rotheram-clarke@canada.ca>
# Joost van Ulden <joost.vanulden@canada.ca>
# =================================================================

import utils
import argparse


def main():
args = parse_args()

# Create shakemap object and load to ES
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'coordinates': {
'type': 'geo_point'
},
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap \
ORDER BY dsra_{eqScenario}_shakemap."SiteID" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()

# Create load 5km shakemap hexbin
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap_hexbin_5km".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap_hexbin_5km \
ORDER BY dsra_{eqScenario}_shakemap_hexbin_5km."gridid_5" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()

# Create load 10km shakemap hexbin
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap_hexbin_10km".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap_hexbin_10km \
ORDER BY dsra_{eqScenario}_shakemap_hexbin_10km."gridid_10" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()

# Create load 25km shakemap hexbin
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap_hexbin_25km".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap_hexbin_25km \
ORDER BY dsra_{eqScenario}_shakemap_hexbin_25km."gridid_25" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()

# Create load 50km shakemap hexbin
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap_hexbin_50km".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap_hexbin_50km \
ORDER BY dsra_{eqScenario}_shakemap_hexbin_50km."gridid_50" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()

# Create load 100km shakemap hexbin
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap_hexbin_100km".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap_hexbin_100km \
ORDER BY dsra_{eqScenario}_shakemap_hexbin_100km."gridid_100" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()

return


def parse_args():
parser = argparse.ArgumentParser(description="script description")
parser.add_argument("--eqScenario", type=str, help="Earthquake scenario id", required=True)
args = parser.parse_args()

return args


if __name__ == '__main__':
main()
57 changes: 0 additions & 57 deletions python/dsra_postgres2es.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,63 +96,6 @@ def main():
)
dsraTable.postgis2es()

# Create shakemap object and load to ES
# dsraTable = utils.PostGISPointDataset(
# utils.PostGISConnection(),
# utils.ESConnection(settings={
# 'settings': {
# 'number_of_shards': 1,
# 'number_of_replicas': 0
# },
# 'mappings': {
# 'properties': {
# 'coordinates': {
# 'type': 'geo_point'
# },
# 'geometry': {
# 'type': 'geo_shape'
# }
# }
# }
# }),
# view = "opendrr_dsra_{eqScenario}_shakemap".format(**{
# 'eqScenario': args.eqScenario}).lower(),
# sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
# FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap \
# ORDER BY dsra_{eqScenario}_shakemap."SiteID" \
# LIMIT {{limit}} \
# OFFSET {{offset}}'.format(**{
# 'eqScenario': args.eqScenario})
# )
# dsraTable.postgis2es()
# Create shakemap object and load to ES
dsraTable = utils.PostGISdataset(
utils.PostGISConnection(),
utils.ESConnection(settings={
'settings': {
'number_of_shards': 1,
'number_of_replicas': 0
},
'mappings': {
'properties': {
'coordinates': {
'type': 'geo_point'
},
'geometry': {
'type': 'geo_shape'
}
}
}
}),
view="opendrr_dsra_{eqScenario}_shakemap".format(**{
'eqScenario': args.eqScenario}).lower(),
sqlquerystring='SELECT *, ST_AsGeoJSON(geom) \
FROM results_dsra_{eqScenario}.dsra_{eqScenario}_shakemap \
ORDER BY dsra_{eqScenario}_shakemap."SiteID" \
LIMIT {{limit}} \
OFFSET {{offset}}'.format(**{'eqScenario': args.eqScenario})
)
dsraTable.postgis2es()
return


Expand Down
Loading

0 comments on commit 8371831

Please sign in to comment.