generated from ucgmsim/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor generate velocity model parameters #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
2f0d0bd
fix(generate-velocity-model-parameters): better crustal model assumpt…
lispandfound 317898c
use rrup_interpolant instead of pgv_interpolant
lispandfound 82ef20f
Merge branch 'pegasus' into vm_params_fixes
lispandfound afc9b27
Merge branch 'pegasus' into vm_params_fixes
lispandfound 0b91660
refactor(generate_velocity_model_parameters): extract domain computat…
lispandfound f2c1323
refactor(scripts): rename generate_velocity_model_parameters to gener…
lispandfound a9ba16b
refactor(generate_domain): refactor stage for better testing
lispandfound 7551ff9
deps: hard pin numba >= 0.63.0 for now
lispandfound 3061291
fix: pyproject missing comma
lispandfound 3590cb2
tests(cli): refactor to not require explicitly listing all modules
lispandfound b21b022
fix(generate_domain): unit convetions
lispandfound 0d7f483
refactor(generate_domain): fix parameter name and usage in average_rake
lispandfound c358f7d
Merge branch 'generate_domain_refactor' of github.com:ucgmsim/workflo…
lispandfound befe590
fix(utils): minor type and documentation typos
lispandfound bc12575
fix(generate_domain): catch some more unit conversions
lispandfound edf9717
Merge branch 'generate_domain_refactor' of github.com:ucgmsim/workflo…
lispandfound 7147b1e
Merge branch 'vm_params_fixes' into generate_domain_refactor
lispandfound 4de6baf
tests(generate_domain): add missing tests
lispandfound 548d56c
refactor(defaults): use Felipe's default rrup interpolants
lispandfound 6fc7583
docs(generate_domain): update domain docstring
lispandfound 474f534
fix(generate_domain): PR comments
lispandfound a5f38be
Merge branch 'generate_domain_refactor' of github.com:ucgmsim/workflo…
lispandfound ae7d13c
fix: PR suggestions
lispandfound 774ddf2
docs(generate_domain): correct estimate_r_surface documentation
lispandfound d5730b2
Merge branch 'generate_domain_refactor' of github.com:ucgmsim/workflo…
lispandfound ca9136d
deps: add lock file to make testing reproducible
lispandfound ea84d43
Merge branch 'pegasus' into generate_domain_refactor
lispandfound a2b4ad0
docs(generate_domain): remove blank lines
lispandfound 4c445bd
docs(generate-domain): update docs for max depth estimation
lispandfound 2800588
refactor(generate-domain): add fault buffer zone parameter
lispandfound 85a8b29
Merge branch 'pegasus' into generate_domain_refactor
lispandfound 4d89399
bump uv.lock
lispandfound 43ef59d
docs(generate-domain): clarify polygon buffer comment
lispandfound File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| import shapely | ||
| from hypothesis import given | ||
| from hypothesis import strategies as st | ||
|
|
||
| from source_modelling import sources | ||
| from workflow.realisations import ( | ||
| Magnitudes, | ||
| Rakes, | ||
| SourceConfig, | ||
| VelocityModelParameters, | ||
| ) | ||
| from workflow.scripts import generate_domain | ||
|
|
||
|
|
||
| # Slow because of openquake import | ||
| @pytest.mark.slow | ||
| def test_significant_duration_calculation() -> None: | ||
| """Basic integration test for OQW, tests that the interface works as we expect still.""" | ||
| ds595 = generate_domain.get_significant_duration( | ||
| magnitude=6.5, distance=100.0, vs30=500.0, rake=180.0, z1pt0=5.0 | ||
| ) | ||
| assert isinstance(ds595, float) # Should not be lying about the type | ||
| assert np.isfinite(ds595), "Ds595 is invalid" | ||
| # Check that ds595 is not in log-space or similar | ||
| assert ds595 > 0, "Ds595 should be positive" | ||
| assert ds595 < 1000, "Ds595 unrealistically high" | ||
| # Combined with type checking this should be enough to catch most of these problems. | ||
|
|
||
|
|
||
| def test_simulation_max_depth_increases_with_mw() -> None: | ||
| depth_mw5p0 = generate_domain.simulation_max_depth(magnitude=5.0, bottom_depth=10.0) | ||
| depth_mw7p0 = generate_domain.simulation_max_depth(magnitude=6.0, bottom_depth=10.0) | ||
| depth_mw9p0 = generate_domain.simulation_max_depth(magnitude=9.0, bottom_depth=10.0) | ||
| assert depth_mw5p0 < depth_mw7p0 < depth_mw9p0, ( | ||
| "Depths do not increase with magnitude" | ||
| ) | ||
|
|
||
|
|
||
| @given( | ||
| magnitude=st.floats(min_value=3.5, max_value=9.0), | ||
| depth=st.floats(min_value=1.0, max_value=250), | ||
| ) | ||
| def test_simulation_max_depth_more_than_bottom_depth( | ||
| magnitude: float, depth: float | ||
| ) -> None: | ||
| simulation_depth = generate_domain.simulation_max_depth(magnitude, depth) | ||
| assert np.isfinite(simulation_depth), "Invalid simulation depth" | ||
| assert depth <= simulation_depth <= 350, "Sensible simulation depths are applied" | ||
|
|
||
|
|
||
| def test_estimate_domain_contains_fault_geometry() -> None: | ||
| fault_coords = [(100000, 100000), (110000, 100000)] | ||
| fault_geom = shapely.LineString(fault_coords) | ||
|
|
||
| mock_fault = SimpleNamespace(geometry=fault_geom) | ||
| source_config = SimpleNamespace(source_geometries={"fault_a": mock_fault}) | ||
|
|
||
| rrups = {"fault_a": 5000.0} | ||
|
|
||
| nz_outline = shapely.box(0, 0, 500000, 500000) | ||
|
|
||
| result_domain = generate_domain.estimate_domain( | ||
| source_config=source_config, # type: ignore[invalid-argument-type] | ||
| rrups=rrups, | ||
| nz_outline=nz_outline, | ||
| fault_buffer=2000.0, | ||
| ) | ||
|
|
||
| assert result_domain.polygon.contains(fault_geom), ( | ||
| f"Domain polygon should contain the original fault geometry.\n" | ||
| f"Fault bounds: {fault_geom.bounds}\n" | ||
| f"Domain bounds: {result_domain.polygon.bounds}" | ||
| ) | ||
|
|
||
|
|
||
| # Slow because of openquake import | ||
| @pytest.mark.slow | ||
| def test_generate_domain() -> None: | ||
| """Basic E2E test to check that domain generation works without crashing or producing a silly domain.""" | ||
| source = sources.Point( | ||
| np.array([-43.0, -172.0, 10000.0]), | ||
| length_m=1000, | ||
| width_m=1000, | ||
| strike=90.0, | ||
| dip=45.0, | ||
| dip_dir=180.0, | ||
| ) | ||
| source_config = SourceConfig(dict(source=source)) | ||
| magnitudes = Magnitudes(dict(source=6.0)) | ||
| rakes = Rakes(dict(source=180.0)) | ||
|
|
||
| velocity_model_parameters = VelocityModelParameters( | ||
| min_vs=500.0, | ||
| version="2.09", | ||
| topo_type="BULLDOZED", | ||
| ds_multiplier=1.2, | ||
| vs30=500.0, | ||
| fault_buffer=2000, | ||
| s_wave_velocity=3500, | ||
| rrup_interpolants=np.array([[5.0, 8.0], [50.0, 50.0]]), | ||
| ) | ||
| domain_parameters = generate_domain.generate_domain( | ||
| source_config, | ||
| magnitudes, | ||
| rakes, | ||
| velocity_model_parameters, | ||
| ) | ||
| assert shapely.contains(domain_parameters.domain.polygon, source.geometry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.