toshi-hazard-post 0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toshi_hazard_post-0.7.1/LICENSE +21 -0
- toshi_hazard_post-0.7.1/PKG-INFO +65 -0
- toshi_hazard_post-0.7.1/README.md +36 -0
- toshi_hazard_post-0.7.1/pyproject.toml +115 -0
- toshi_hazard_post-0.7.1/scripts/__init__.py +0 -0
- toshi_hazard_post-0.7.1/scripts/calc_time.py +34 -0
- toshi_hazard_post-0.7.1/scripts/cli.py +36 -0
- toshi_hazard_post-0.7.1/scripts/cli_old.py +213 -0
- toshi_hazard_post-0.7.1/scripts/container_task.sh +5 -0
- toshi_hazard_post-0.7.1/tests/__init__.py +1 -0
- toshi_hazard_post-0.7.1/tests/fixtures/__init__.py +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calc/agg_rates.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calc/branch_probs.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calc/branch_rates.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calc/hazard_agg.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calc/quantiles_expected.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calculators/agg_0p2.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calculators/branch_rates.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calculators/rates.json +1 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calculators/weights.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/calculators/weights_and_values.json +24 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/__init__.py +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/aggregations_275_PGA_WLG.npy +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/gmcm_logic_tree_complete.json +462 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/hazard.toml +15 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/rlz/vs30=275/nloc_0=-41.0~175.0/8da8aecc-6e40-4a18-90cc-645167b52056-part-0.parquet +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/rlz/vs30=275/nloc_0=-41.0~175.0/_metadata.csv +2 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/rlz_probs_WLG.pq +0 -0
- toshi_hazard_post-0.7.1/tests/fixtures/end_to_end/srm_logic_tree_small.json +957 -0
- toshi_hazard_post-0.7.1/tests/fixtures/glt.json +91 -0
- toshi_hazard_post-0.7.1/tests/fixtures/hazard.toml +21 -0
- toshi_hazard_post-0.7.1/tests/fixtures/hazard_lt_files.toml +19 -0
- toshi_hazard_post-0.7.1/tests/fixtures/sites.csv +3 -0
- toshi_hazard_post-0.7.1/tests/fixtures/sites_vs30s.csv +3 -0
- toshi_hazard_post-0.7.1/tests/fixtures/sites_vs30s_lt0.csv +3 -0
- toshi_hazard_post-0.7.1/tests/fixtures/sites_vs30s_str.csv +3 -0
- toshi_hazard_post-0.7.1/tests/fixtures/sites_w_vs30.csv +3 -0
- toshi_hazard_post-0.7.1/tests/fixtures/slt.json +2580 -0
- toshi_hazard_post-0.7.1/tests/test_args.py +154 -0
- toshi_hazard_post-0.7.1/tests/test_calc.py +144 -0
- toshi_hazard_post-0.7.1/tests/test_calculators.py +86 -0
- toshi_hazard_post-0.7.1/tests/test_data.py +45 -0
- toshi_hazard_post-0.7.1/tests/test_end_to_end.py +36 -0
- toshi_hazard_post-0.7.1/tests/test_get_inputs.py +59 -0
- toshi_hazard_post-0.7.1/tests/test_logic_tree.py +72 -0
- toshi_hazard_post-0.7.1/tests/test_task_generator.py +38 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/__init__.py +6 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/aggregation.py +174 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/aggregation_args.py +215 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/aggregation_calc.py +286 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/aggregation_setup.py +122 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/calculators.py +97 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/constants.py +4 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/data.py +186 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/local_config.py +44 -0
- toshi_hazard_post-0.7.1/toshi_hazard_post/logic_tree.py +211 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022, Chris B Chamberlain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: toshi-hazard-post
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: Hazard post-processing pipeline as serverless AWS infrastructure.
|
|
5
|
+
License: AGPL-3.0
|
|
6
|
+
Author: Chris DiCaprio
|
|
7
|
+
Author-email: christopher.dicaprio@gmail.com
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Requires-Dist: click (>=8.1.8)
|
|
16
|
+
Requires-Dist: numba (<0.61.0)
|
|
17
|
+
Requires-Dist: numpy (<2)
|
|
18
|
+
Requires-Dist: nzshm-common (>=0.8.4)
|
|
19
|
+
Requires-Dist: nzshm-model (>=0.13.5)
|
|
20
|
+
Requires-Dist: pandas (>=2.0.3)
|
|
21
|
+
Requires-Dist: pyarrow[pandas] (>=15.0)
|
|
22
|
+
Requires-Dist: pydantic (>=2.10.6)
|
|
23
|
+
Requires-Dist: python-dotenv (>=1.0.1)
|
|
24
|
+
Requires-Dist: tomlkit (>=0.13.2)
|
|
25
|
+
Requires-Dist: toshi-hazard-store (>=1.1.0)
|
|
26
|
+
Requires-Dist: tzdata (>=2025.2,<2026.0)
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# toshi-hazard-post
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
[](https://pypi.org/project/toshi-hazard-post/)
|
|
33
|
+
[](https://pypi.org/project/toshi-hazard-post/)
|
|
34
|
+
[](https://github.com/gns-science/toshi-hazard-post/actions/workflows/dev.yml)
|
|
35
|
+
[](https://codecov.io/github/gns-science/toshi-hazard-post)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Seismic hazard from pre-calculated relizations. This application impliments the hazard calculation method described in [Calculation of National Seismic Hazard Models with Large Logic Trees: Application to the NZ NSHM 2022](https://doi.org/10.1785/0220230226).
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
* Documentation: <https://gns-science.github.io/toshi-hazard-post>
|
|
42
|
+
* GitHub: <https://github.com/gns-science/toshi-hazard-post>
|
|
43
|
+
* PyPI: <https://pypi.org/project/toshi-hazard-post/>
|
|
44
|
+
* Free software: AGPL-3.0
|
|
45
|
+
|
|
46
|
+
## Requirements
|
|
47
|
+
|
|
48
|
+
toshi-hazard-post requires python 3.10 - 3.11. It relies on other GNS-Science NSHM libraries:
|
|
49
|
+
|
|
50
|
+
- nzshm-model: <https://github.com/GNS-Science/nzshm-model>
|
|
51
|
+
- nzshm-common: <https://github.com/GNS-Science/nzshm-common-py>
|
|
52
|
+
- toshi-hazard-store: <https://github.com/GNS-Science/toshi-hazard-store>
|
|
53
|
+
|
|
54
|
+
In addition, it requires a small number of scientific computation packages such as numba, numpy, and pandas. See [installation notes](docs/installation.md) for more details on how to install the application.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
Getting started
|
|
60
|
+
```
|
|
61
|
+
thp --help
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
See [usage documentation page](docs/usage.md) for more info.
|
|
65
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# toshi-hazard-post
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[](https://pypi.org/project/toshi-hazard-post/)
|
|
5
|
+
[](https://pypi.org/project/toshi-hazard-post/)
|
|
6
|
+
[](https://github.com/gns-science/toshi-hazard-post/actions/workflows/dev.yml)
|
|
7
|
+
[](https://codecov.io/github/gns-science/toshi-hazard-post)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Seismic hazard from pre-calculated relizations. This application impliments the hazard calculation method described in [Calculation of National Seismic Hazard Models with Large Logic Trees: Application to the NZ NSHM 2022](https://doi.org/10.1785/0220230226).
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
* Documentation: <https://gns-science.github.io/toshi-hazard-post>
|
|
14
|
+
* GitHub: <https://github.com/gns-science/toshi-hazard-post>
|
|
15
|
+
* PyPI: <https://pypi.org/project/toshi-hazard-post/>
|
|
16
|
+
* Free software: AGPL-3.0
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
toshi-hazard-post requires python 3.10 - 3.11. It relies on other GNS-Science NSHM libraries:
|
|
21
|
+
|
|
22
|
+
- nzshm-model: <https://github.com/GNS-Science/nzshm-model>
|
|
23
|
+
- nzshm-common: <https://github.com/GNS-Science/nzshm-common-py>
|
|
24
|
+
- toshi-hazard-store: <https://github.com/GNS-Science/toshi-hazard-store>
|
|
25
|
+
|
|
26
|
+
In addition, it requires a small number of scientific computation packages such as numba, numpy, and pandas. See [installation notes](docs/installation.md) for more details on how to install the application.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Getting started
|
|
32
|
+
```
|
|
33
|
+
thp --help
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
See [usage documentation page](docs/usage.md) for more info.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "toshi-hazard-post"
|
|
3
|
+
version = "0.7.1"
|
|
4
|
+
readme = "README.md"
|
|
5
|
+
description = "Hazard post-processing pipeline as serverless AWS infrastructure."
|
|
6
|
+
authors = [
|
|
7
|
+
{name = "Chris DiCaprio", email = "christopher.dicaprio@gmail.com"},
|
|
8
|
+
{name = "Chris Chamberlain", email = "chrisbc@artisan.co.nz"},
|
|
9
|
+
]
|
|
10
|
+
license = "AGPL-3.0"
|
|
11
|
+
requires-python = ">=3.10,<3.13"
|
|
12
|
+
classifiers=[
|
|
13
|
+
'Development Status :: 2 - Pre-Alpha',
|
|
14
|
+
'Intended Audience :: Developers',
|
|
15
|
+
'License :: OSI Approved :: MIT License',
|
|
16
|
+
'Natural Language :: English',
|
|
17
|
+
'Programming Language :: Python :: 3',
|
|
18
|
+
'Programming Language :: Python :: 3.10',
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"pandas (>=2.0.3)",
|
|
22
|
+
"click (>=8.1.8)",
|
|
23
|
+
"python-dotenv (>=1.0.1)",
|
|
24
|
+
"pyarrow[pandas] (>=15.0)",
|
|
25
|
+
"nzshm-common (>=0.8.4)",
|
|
26
|
+
"nzshm-model (>=0.13.5)",
|
|
27
|
+
"pydantic (>=2.10.6)",
|
|
28
|
+
"tomlkit (>=0.13.2)",
|
|
29
|
+
"numba (<0.61.0)",
|
|
30
|
+
"toshi-hazard-store (>=1.1.0)",
|
|
31
|
+
"numpy (<2)",
|
|
32
|
+
"tzdata (>=2025.2,<2026.0)",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[tool.poetry]
|
|
36
|
+
packages = [
|
|
37
|
+
{ include = "toshi_hazard_post" },
|
|
38
|
+
{ include = "tests", format = "sdist" },
|
|
39
|
+
{ include = "scripts" },
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.poetry.scripts]
|
|
43
|
+
thp = 'scripts.cli:thp'
|
|
44
|
+
|
|
45
|
+
[tool.mypy]
|
|
46
|
+
plugins = "numpy.typing.mypy_plugin"
|
|
47
|
+
ignore_missing_imports = true
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
[tool.poetry.group.dev.dependencies]
|
|
51
|
+
black = "^25.1.0"
|
|
52
|
+
isort = "^6.0.0"
|
|
53
|
+
flake8 = "^7.1.2"
|
|
54
|
+
pytest = "^8.3.4"
|
|
55
|
+
pytest-cov = "^6.0.0"
|
|
56
|
+
twine = "^6.1.0"
|
|
57
|
+
bump2version = "^1.0.1"
|
|
58
|
+
types-toml = "^0.10.8.20240310"
|
|
59
|
+
types-requests = "^2.32.0.20241016"
|
|
60
|
+
tox = "^4.24.1"
|
|
61
|
+
mypy = "^1.15.0"
|
|
62
|
+
flake8-docstrings = "^1.7.0"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
[tool.poetry.group.doc.dependencies]
|
|
66
|
+
mkdocs = "^1.6.1"
|
|
67
|
+
mkdocs-include-markdown-plugin = "^7.1.4"
|
|
68
|
+
mkdocs-material = "^9.6.5"
|
|
69
|
+
mkdocs-material-extensions = "^1.3.1"
|
|
70
|
+
mkdocs-autorefs = "^1.4.0"
|
|
71
|
+
mkdocs-pymdownx-material-extras = "^2.7"
|
|
72
|
+
pymdown-extensions = "^10.14.3"
|
|
73
|
+
mkdocstrings = "^0.28.2"
|
|
74
|
+
mkdocstrings-python = "^1.16.2"
|
|
75
|
+
|
|
76
|
+
[tool.poetry.extras]
|
|
77
|
+
aws = ["boto3"]
|
|
78
|
+
|
|
79
|
+
[tool.black]
|
|
80
|
+
line-length = 120
|
|
81
|
+
skip-string-normalization = true
|
|
82
|
+
target-version = ['py310', 'py311']
|
|
83
|
+
include = '\.pyi?$'
|
|
84
|
+
exclude = '''
|
|
85
|
+
/(
|
|
86
|
+
\.eggs
|
|
87
|
+
| \.git
|
|
88
|
+
| \.hg
|
|
89
|
+
| \.mypy_cache
|
|
90
|
+
| \.tox
|
|
91
|
+
| \.venv
|
|
92
|
+
| _build
|
|
93
|
+
| buck-out
|
|
94
|
+
| build
|
|
95
|
+
| dist
|
|
96
|
+
)/
|
|
97
|
+
'''
|
|
98
|
+
|
|
99
|
+
[tool.isort]
|
|
100
|
+
multi_line_output = 3
|
|
101
|
+
include_trailing_comma = true
|
|
102
|
+
force_grid_wrap = 0
|
|
103
|
+
use_parentheses = true
|
|
104
|
+
ensure_newline_before_comments = true
|
|
105
|
+
line_length = 120
|
|
106
|
+
skip_gitignore = true
|
|
107
|
+
# you can skip files as below
|
|
108
|
+
#skip_glob = docs/conf.py
|
|
109
|
+
|
|
110
|
+
[build-system]
|
|
111
|
+
requires = ["poetry-core>=1.0.0"]
|
|
112
|
+
build-backend = "poetry.core.masonry.api"
|
|
113
|
+
|
|
114
|
+
[tool.pytest.ini_options]
|
|
115
|
+
addopts = "--ignore=scratch"
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
def main(log_filepath):
|
|
5
|
+
log_filepath = Path(log_filepath)
|
|
6
|
+
|
|
7
|
+
times_jobtable = []
|
|
8
|
+
times_batchtable = []
|
|
9
|
+
times_calc = []
|
|
10
|
+
with log_filepath.open() as f:
|
|
11
|
+
for line in f.readlines():
|
|
12
|
+
if "starting" in line and "calculations with" in line:
|
|
13
|
+
nproc = int(line.split(' ')[-2])
|
|
14
|
+
elif "time to create batch table" in line:
|
|
15
|
+
times_batchtable.append(float(line.split(' ')[-2]))
|
|
16
|
+
elif "time to create job table" in line:
|
|
17
|
+
times_jobtable.append(float(line.split(' ')[-2]))
|
|
18
|
+
elif "time to perform one aggregation" in line:
|
|
19
|
+
times_calc.append(float(line.split(' ')[-2]))
|
|
20
|
+
elif "time to perform aggregations after job setup" in line:
|
|
21
|
+
total_time = float(line.split(' ')[-1])
|
|
22
|
+
|
|
23
|
+
print(f"Number of workers: {nproc}")
|
|
24
|
+
print(f"Total number of partitions used: {len(times_batchtable)}")
|
|
25
|
+
print(f"Total number of aggregate calculations: {len(times_calc)}")
|
|
26
|
+
print(f"Mean Partition Table Creation Time: {sum(times_batchtable)/len(times_batchtable):.02f} seconds")
|
|
27
|
+
print(f"Mean Job Table Creation Time: {sum(times_jobtable)/len(times_jobtable):.02f} seconds")
|
|
28
|
+
print(f"Mean Agg Calc Time: {sum(times_calc)/len(times_calc):.02f} seconds")
|
|
29
|
+
print(f"Total Time: {total_time} seconds")
|
|
30
|
+
print(f"Mean time per calculation (including I/O): {nproc * total_time/len(times_calc):.02f} CPU seconds")
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
filepath = sys.argv[1]
|
|
34
|
+
main(filepath)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
import click
|
|
5
|
+
|
|
6
|
+
from toshi_hazard_post.aggregation import run_aggregation
|
|
7
|
+
from toshi_hazard_post.aggregation_args import load_input_args
|
|
8
|
+
import toshi_hazard_store
|
|
9
|
+
|
|
10
|
+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
11
|
+
logging.getLogger('toshi_hazard_post').setLevel(logging.INFO)
|
|
12
|
+
# logging.getLogger('toshi_hazard_post.aggregation_calc').setLevel(logging.DEBUG)
|
|
13
|
+
# logging.getLogger('toshi_hazard_post.aggregation').setLevel(logging.DEBUG)
|
|
14
|
+
# logging.getLogger('toshi_hazard_post.aggregation_calc').setLevel(logging.DEBUG)
|
|
15
|
+
# logging.getLogger('toshi_hazard_post.logic_tree').setLevel(logging.DEBUG)
|
|
16
|
+
logging.getLogger('toshi_hazard_store').setLevel(logging.ERROR)
|
|
17
|
+
logging.getLogger('toshi_hazard_post').setLevel(logging.INFO)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.group()
|
|
21
|
+
def thp():
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@thp.command(name='aggregate', help='aggregate hazard curves')
|
|
26
|
+
@click.argument('input_file', type=click.Path(exists=True))
|
|
27
|
+
def aggregate(input_file):
|
|
28
|
+
|
|
29
|
+
args = load_input_args(input_file)
|
|
30
|
+
click.echo("Toshi Hazard Post: hazard curve aggregation")
|
|
31
|
+
click.echo("=================================================")
|
|
32
|
+
run_aggregation(args)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
thp() # pragma: no cover
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""Console script for toshi_hazard_post."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
import toml
|
|
9
|
+
from toshi_hazard_store.model import migrate as migrate_ths
|
|
10
|
+
|
|
11
|
+
# from toshi_hazard_post.hazard_aggregation import AggregationConfig, process_aggregation, process_deaggregation
|
|
12
|
+
from toshi_hazard_post.hazard_aggregation.aggregation import process_aggregation
|
|
13
|
+
from toshi_hazard_post.hazard_aggregation.aggregation_config import AggregationConfig
|
|
14
|
+
from toshi_hazard_post.hazard_aggregation.aws_aggregation import distribute_aggregation, push_test_message
|
|
15
|
+
from toshi_hazard_post.hazard_aggregation.aws_deaggregation import distribute_deaggregation
|
|
16
|
+
from toshi_hazard_post.hazard_aggregation.deaggregation import process_deaggregation
|
|
17
|
+
from toshi_hazard_post.hazard_grid.aws_gridded_hazard import distribute_gridded_hazard
|
|
18
|
+
from toshi_hazard_post.hazard_grid.gridded_hazard import calc_gridded_hazard
|
|
19
|
+
from toshi_hazard_post.hazard_grid.misc import get_filter_locations, get_site_lists, migrate
|
|
20
|
+
|
|
21
|
+
log = logging.getLogger()
|
|
22
|
+
logging.basicConfig(level=logging.INFO)
|
|
23
|
+
logging.getLogger('nshm_toshi_client.toshi_client_base').setLevel(logging.INFO)
|
|
24
|
+
logging.getLogger('urllib3').setLevel(logging.INFO)
|
|
25
|
+
logging.getLogger('botocore').setLevel(logging.INFO)
|
|
26
|
+
logging.getLogger('pynamodb').setLevel(logging.INFO)
|
|
27
|
+
logging.getLogger('toshi_hazard_post').setLevel(logging.INFO)
|
|
28
|
+
logging.getLogger('toshi_hazard_store').setLevel(logging.INFO)
|
|
29
|
+
logging.getLogger('gql.transport.requests').setLevel(logging.WARN)
|
|
30
|
+
|
|
31
|
+
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
|
32
|
+
screen_handler = logging.StreamHandler(stream=sys.stdout)
|
|
33
|
+
screen_handler.setFormatter(formatter)
|
|
34
|
+
log.addHandler(screen_handler)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@click.group()
|
|
38
|
+
def thp():
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@thp.command(name='build-grid', help='calculate hazard grids used to create maps')
|
|
43
|
+
@click.option('-H', '--hazard_model_ids', help='comma-delimted list of hazard model ids.')
|
|
44
|
+
@click.option('-L', '--site-list', help='A site list ENUM.')
|
|
45
|
+
@click.option('-I', '--imts', help='comma-delimited list of imts.')
|
|
46
|
+
@click.option('-A', '--aggs', help='comma-delimited list of aggs.')
|
|
47
|
+
@click.option('-V', '--vs30s', help='comma-delimited list of vs30s.')
|
|
48
|
+
@click.option('-P', '--poes', help='comma-delimited list of poe_levels.')
|
|
49
|
+
@click.option('-c', '--config', type=click.Path(exists=True)) # help="path to a valid THU configuration file."
|
|
50
|
+
@click.option('-lsl', '--list-site-lists', help='print the list of sites list ENUMs and exit', is_flag=True)
|
|
51
|
+
@click.option('-v', '--verbose', is_flag=True)
|
|
52
|
+
@click.option('-d', '--dry-run', is_flag=True)
|
|
53
|
+
@click.option('-m', '--migrate-tables', is_flag=True)
|
|
54
|
+
@click.option('-f', '--force', is_flag=True)
|
|
55
|
+
@click.option(
|
|
56
|
+
'--mode',
|
|
57
|
+
'-m',
|
|
58
|
+
default='LOCAL',
|
|
59
|
+
type=click.Choice(['AWS_BATCH', 'LOCAL'], case_sensitive=True),
|
|
60
|
+
)
|
|
61
|
+
@click.option(
|
|
62
|
+
'--iter-method',
|
|
63
|
+
'-i',
|
|
64
|
+
default='product',
|
|
65
|
+
type=click.Choice(['product', 'zip'], case_sensitive=True),
|
|
66
|
+
)
|
|
67
|
+
@click.option('-w', '--num-workers', default=4, show_default=True)
|
|
68
|
+
def cli_gridded_hazard(
|
|
69
|
+
hazard_model_ids,
|
|
70
|
+
site_list,
|
|
71
|
+
imts,
|
|
72
|
+
aggs,
|
|
73
|
+
vs30s,
|
|
74
|
+
poes,
|
|
75
|
+
config,
|
|
76
|
+
list_site_lists,
|
|
77
|
+
verbose,
|
|
78
|
+
dry_run,
|
|
79
|
+
migrate_tables,
|
|
80
|
+
force,
|
|
81
|
+
mode,
|
|
82
|
+
iter_method,
|
|
83
|
+
num_workers,
|
|
84
|
+
):
|
|
85
|
+
"""Process gridded hazard for a given set of arguments."""
|
|
86
|
+
|
|
87
|
+
if list_site_lists:
|
|
88
|
+
click.echo("ENUM name\tDetails")
|
|
89
|
+
click.echo("===============\t======================================================================")
|
|
90
|
+
for rg in get_site_lists():
|
|
91
|
+
click.echo(f"{rg.name}\t{rg.value}")
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
# site_lists = site_lists.split(',') if site_lists else None
|
|
95
|
+
|
|
96
|
+
hazard_model_ids = hazard_model_ids.split(',') if hazard_model_ids else None
|
|
97
|
+
vs30s = vs30s.split(',') if vs30s else None
|
|
98
|
+
imts = imts.split(',') if imts else None
|
|
99
|
+
aggs = aggs.split(',') if aggs else None
|
|
100
|
+
poes = poes.split(',') if poes else None
|
|
101
|
+
filter_sites = None
|
|
102
|
+
|
|
103
|
+
if config:
|
|
104
|
+
conf = toml.load(config)
|
|
105
|
+
if verbose:
|
|
106
|
+
click.echo(f"using settings in {config} for export")
|
|
107
|
+
|
|
108
|
+
site_list = site_list or conf.get('site_list')
|
|
109
|
+
hazard_model_ids = hazard_model_ids or conf.get('hazard_model_ids')
|
|
110
|
+
imts = imts or conf.get('imts')
|
|
111
|
+
vs30s = vs30s or conf.get('vs30s')
|
|
112
|
+
aggs = aggs or conf.get('aggs')
|
|
113
|
+
poes = poes or conf.get('poes')
|
|
114
|
+
filter_sites = filter_sites or conf.get('filter_sites')
|
|
115
|
+
|
|
116
|
+
if verbose:
|
|
117
|
+
click.echo(f"{hazard_model_ids} {imts} {vs30s}")
|
|
118
|
+
|
|
119
|
+
if dry_run:
|
|
120
|
+
click.echo(f"dry-run {site_list} {hazard_model_ids} {imts} {vs30s}")
|
|
121
|
+
return
|
|
122
|
+
|
|
123
|
+
if migrate_tables:
|
|
124
|
+
click.echo("Ensuring that dynamodb tables are available in target region & stage.")
|
|
125
|
+
migrate()
|
|
126
|
+
|
|
127
|
+
if mode == "LOCAL":
|
|
128
|
+
try:
|
|
129
|
+
click.echo(filter_sites)
|
|
130
|
+
filter_locations = get_filter_locations(filter_sites)
|
|
131
|
+
click.echo(filter_locations)
|
|
132
|
+
calc_gridded_hazard(
|
|
133
|
+
location_grid_id=site_list,
|
|
134
|
+
poe_levels=poes,
|
|
135
|
+
hazard_model_ids=hazard_model_ids,
|
|
136
|
+
vs30s=vs30s,
|
|
137
|
+
imts=imts,
|
|
138
|
+
aggs=aggs,
|
|
139
|
+
num_workers=num_workers,
|
|
140
|
+
force=force,
|
|
141
|
+
filter_locations=filter_locations,
|
|
142
|
+
iter_method=iter_method,
|
|
143
|
+
)
|
|
144
|
+
except Exception as err:
|
|
145
|
+
click.echo(err)
|
|
146
|
+
raise click.UsageError('An error occurred, pls check usage.')
|
|
147
|
+
|
|
148
|
+
# haggs = query_v3.get_hazard_curves(locations, vs30s, hazard_model_ids, imts=imts, aggs=aggs)
|
|
149
|
+
click.echo('Done!')
|
|
150
|
+
elif mode == "AWS_BATCH":
|
|
151
|
+
try:
|
|
152
|
+
click.echo(filter_sites)
|
|
153
|
+
filter_locations = get_filter_locations(filter_sites)
|
|
154
|
+
click.echo(filter_locations)
|
|
155
|
+
distribute_gridded_hazard(
|
|
156
|
+
location_grid_id=site_list,
|
|
157
|
+
poe_levels=poes,
|
|
158
|
+
hazard_model_ids=hazard_model_ids,
|
|
159
|
+
vs30s=vs30s,
|
|
160
|
+
imts=imts,
|
|
161
|
+
aggs=aggs,
|
|
162
|
+
force=force,
|
|
163
|
+
filter_locations=filter_locations,
|
|
164
|
+
iter_method=iter_method,
|
|
165
|
+
)
|
|
166
|
+
except Exception as err:
|
|
167
|
+
click.echo(err)
|
|
168
|
+
raise click.UsageError('An error occurred, pls check usage.')
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
@thp.command(name='aggregate', help='aggregate hazard curves or disaggregations')
|
|
172
|
+
@click.option(
|
|
173
|
+
'--mode',
|
|
174
|
+
'-m',
|
|
175
|
+
default=lambda: os.environ.get("NZSHM22_THP_MODE", 'LOCAL'),
|
|
176
|
+
type=click.Choice(['AWS', 'AWS_BATCH', 'LOCAL'], case_sensitive=True),
|
|
177
|
+
)
|
|
178
|
+
@click.option('--deagg', '-d', is_flag=True)
|
|
179
|
+
@click.option('--push-sns-test', '-pt', is_flag=True)
|
|
180
|
+
@click.option('--migrate-tables', '-M', is_flag=True)
|
|
181
|
+
@click.argument('config', type=click.Path(exists=True)) # help="path to a valid THP configuration file."
|
|
182
|
+
def aggregate(config, mode, deagg, push_sns_test, migrate_tables):
|
|
183
|
+
"""Main entrypoint."""
|
|
184
|
+
click.echo("Hazard post-processing pipeline as serverless AWS infrastructure.")
|
|
185
|
+
click.echo(f"mode: {mode}")
|
|
186
|
+
|
|
187
|
+
agconf = AggregationConfig(config)
|
|
188
|
+
# click.echo(agconf)
|
|
189
|
+
# log.info("Doit")
|
|
190
|
+
|
|
191
|
+
if push_sns_test:
|
|
192
|
+
push_test_message()
|
|
193
|
+
return
|
|
194
|
+
|
|
195
|
+
if mode == 'LOCAL':
|
|
196
|
+
if deagg:
|
|
197
|
+
process_deaggregation(agconf)
|
|
198
|
+
else:
|
|
199
|
+
process_aggregation(agconf)
|
|
200
|
+
return
|
|
201
|
+
if 'AWS_BATCH' in mode: # TODO: multiple vs30s
|
|
202
|
+
if migrate_tables:
|
|
203
|
+
click.echo("Ensuring that dynamodb tables are available in target region & stage.")
|
|
204
|
+
migrate_ths()
|
|
205
|
+
if deagg:
|
|
206
|
+
distribute_deaggregation(agconf, mode)
|
|
207
|
+
else:
|
|
208
|
+
distribute_aggregation(agconf, mode)
|
|
209
|
+
return
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if __name__ == "__main__":
|
|
213
|
+
thp() # pragma: no cover
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""The tests package."""
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[0.019156457392332, 0.040571554784402, 0.064849989807042, 0.092877386139271, 0.126026760101808, 0.16659831488621, 0.218904146241079, 0.292625074988018, 0.418651835089826]
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"weights": [
|
|
3
|
+
0.447077835475027,
|
|
4
|
+
0.058470204772802,
|
|
5
|
+
0.869074768834212,
|
|
6
|
+
0.77857878253347,
|
|
7
|
+
0.588413020406674,
|
|
8
|
+
0.849791015005617,
|
|
9
|
+
0.743044887843583,
|
|
10
|
+
0.273707026202851,
|
|
11
|
+
0.82405809555373
|
|
12
|
+
],
|
|
13
|
+
"values": [
|
|
14
|
+
6.90142303832663,
|
|
15
|
+
1.54115132087442,
|
|
16
|
+
1.64338018395884,
|
|
17
|
+
4.82202052695663,
|
|
18
|
+
9.43809367161881,
|
|
19
|
+
1.0831467357305,
|
|
20
|
+
6.01064665810539,
|
|
21
|
+
6.51800796017942,
|
|
22
|
+
3.98688564815937
|
|
23
|
+
]
|
|
24
|
+
}
|
|
File without changes
|