Skip to content
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

Nshm organisational refactor #4

Merged
merged 39 commits into from
Jun 6, 2024
Merged

Conversation

lispandfound
Copy link
Collaborator

@lispandfound lispandfound commented May 17, 2024

This PR requires ucgmsim/qcore#305 and ucgmsim/qcore#303.

This pull request represents my current vision for how I think the nshmdb should work going forward. The purpose of this tool is as follows:

  1. Provide a script to produce an SQLite database to efficiently query fault geometry (and other things going forward).
  2. To provide any code relying on NSHM2022 data a simple API to work with.
  3. To provide missing visualisation tools for NSHM (essentially, plugging gaps in the rupture explorer).

To this end we now have three modules and one script.

  • nshmdb. This module provides an interface to query the database.
  • fault. Contains the classes defining a fault geometry.
  • plotting.rupture. The plotting package contains extra visualisation tools, for now just a tool to visualise a rupture scenario with pygmt.

The script has also been improved. It now uses the Python zipfile module to read the CRU solution zip file directly (i.e. without the user specifying the paths of the individial files). It does not extract need an extracted zip either, it's all read in binary. This means that the user does not need to understand the CRU solution zip's many undocumented files to generate the database. It is as simple as downloading the CRU solution zip file and running:

$ python nshmdb/scripts/nshm_db_generator.py ~/Downloads/CRU_fault_system_solution.zip nshmdb.db

or if they've installed the package the script lives in their path so this also works

$ nshm-db-generator ~/Downloads/CRU_fault_system_solution.zip nshmdb.db

The script now gives live updates via tqdm on the database build progress (which varies from 5 minutes on my home desktop, to 15 minutes on my work desktop).

Here is an example of how you can use the new API:

>>> from nshmdb import nshmdb
>>> from nshmdb.plotting import rupture
>>> db = nshmdb.NSHMDB('nshmdb.db')
>>> rupture_100 = db.get_rupture_faults(100)
>>> akatarawa = rupture_100[0]
>>> plane = akatarawa.planes[0]
>>> np.round(plane.dip)
75.0
>>> plane.bottom_m
20000.0
>>> rupture.plot_rupture('Rupture 100', rupture_100)
# see plot below

The above code produces the following plot of the faults involved in the rupture.

image

@lispandfound lispandfound marked this pull request as ready for review May 21, 2024 00:27
Copy link

@joelridden joelridden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decent work! Not that strong on some of the math side for some of the fault calculations but I'm sure it works. Just a few minor comments.

Love the documentation

nshmdb/fault.py Outdated Show resolved Hide resolved
nshmdb/fault.py Outdated Show resolved Hide resolved
nshmdb/nshmdb.py Outdated Show resolved Hide resolved
nshmdb/plotting/rupture.py Outdated Show resolved Hide resolved
nshmdb/scripts/nshm_db_generator.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
sungeunbae
sungeunbae previously approved these changes May 29, 2024
claudio525
claudio525 previously approved these changes May 29, 2024
nshmdb/fault.py Show resolved Hide resolved
joelridden
joelridden previously approved these changes May 29, 2024
@lispandfound
Copy link
Collaborator Author

we can probably merge this after @claudio525 and @sungeunbae approve.

claudio525
claudio525 previously approved these changes May 30, 2024
sungeunbae
sungeunbae previously approved these changes May 31, 2024
@lispandfound lispandfound requested a review from claudio525 May 31, 2024 03:40
@lispandfound
Copy link
Collaborator Author

Sorry @claudio525, just had to switch to optional so it works on nesi 🫤

@lispandfound lispandfound merged commit eb10cbe into main Jun 6, 2024
2 checks passed
@lispandfound lispandfound deleted the nshm_organisational_refactor branch June 6, 2024 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants