Skip to content

Site Vs30 / Z values#90

Merged
joelridden merged 16 commits into4p4from
site_vs30
Feb 3, 2026
Merged

Site Vs30 / Z values#90
joelridden merged 16 commits into4p4from
site_vs30

Conversation

@joelridden
Copy link
Contributor

Adds Vs30 and Z values for sites that do not have data from Liam site db.
Fetches Z values from velocity_modelling and Vs30 from Jaehwi v1.0 new map.
Adds testing for these added functions.
Few merge issues from other PR's

# Conflicts:
#	nzgmdb/data_retrieval/sites.py
#	requirements.txt
# Conflicts:
#	nzgmdb/calculation/snr.py
#	nzgmdb/data_processing/process_observed.py
#	nzgmdb/data_processing/waveform_manipulation.py
#	nzgmdb/data_retrieval/sites.py
#	nzgmdb/data_retrieval/waveform_extraction.py
#	nzgmdb/mseed_management/reading.py
#	nzgmdb/phase_arrival/run_phasenet.py
@joelridden joelridden marked this pull request as draft January 14, 2026 00:26
@gemini-code-assist
Copy link

Summary of Changes

Hello @joelridden, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces significant improvements across the data processing pipeline, focusing on enhancing the accuracy and completeness of seismic data. Key updates include the automated computation of site-specific Vs30 and Z values, a more sophisticated approach to determining earthquake focal mechanisms, and the integration of a novel multi-event detection system. Furthermore, instrument response correction has been modernized, and the range of calculated intensity measures expanded to include PGD, all supported by comprehensive updates to data handling, configuration, and reporting tools.

Highlights

  • Automated Site Parameter Filling: Implemented logic to automatically compute and fill missing Vs30 and Z values (Z1.0, Z2.5) for sites, leveraging external data sources (GeoTIFF maps, velocity models) and spatial interpolation techniques like nearest-neighbor averaging.
  • Advanced Nodal Plane Selection: Enhanced the earthquake focal mechanism determination process with refined logic for Crustal, Interface, and Slab events, integrating new CMT solution data structures (reviewed/unreviewed) and associated geophysical models.
  • Multi-Event Detection System: Introduced a new module for detecting and scoring multi-event records using STA/LTA (Short-Term Average/Long-Term Average) triggers, improving the identification and filtering of complex seismic signals.
  • Modernized Instrument Response Correction: Transitioned from sensitivity removal to a more robust instrument response correction method, dynamically adapting to sensor types (acceleration or velocity) and utilizing comprehensive StationXML inventories for accurate waveform processing.
  • Expanded Data Outputs & Reporting: Added Peak Ground Displacement (PGD) as a new Intensity Measure (IM) and enhanced the report generation script to include detailed summaries and visualisations of low-quality site records.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant enhancements by incorporating new data sources for Vs30 and Z values, which improves the accuracy of site characterization. The changes are extensive, including updates to focal mechanism determination, performance optimizations through caching and batching, and a move to using remove_response which is a good practice. The addition of multi-event detection logic and comprehensive testing is also a valuable contribution.

I've identified a few issues, mainly related to data consistency and code duplication, which I've detailed in the comments. Once these are addressed, this will be a very strong PR.

@joelridden joelridden marked this pull request as ready for review January 23, 2026 02:58
claudio525
claudio525 previously approved these changes Jan 25, 2026
lispandfound
lispandfound previously approved these changes Feb 1, 2026
Copy link
Contributor

@lispandfound lispandfound left a comment

Choose a reason for hiding this comment

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

Just some minor type checking changes. If you fix those I'm happy for you to override the PR check and merge without another round of review.

def fill_gaps_with_nearest(
coords: np.ndarray,
values: np.ndarray,
invalid_mask: np.ndarray = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
invalid_mask: np.ndarray = None,
invalid_mask: np.ndarray | None = None,

values: np.ndarray,
invalid_mask: np.ndarray = None,
k: int = 8,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
):
) -> np.ndarray:

tect_merged_df.loc[vs30_mask, "Q_Vs30"] = "Q3"

except (FileNotFoundError, ValueError, RuntimeError) as e:
print(f"Warning: Could not compute thresholds for missing Z1.0 values: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than printing a warning here, perhaps raise a UserWarning? Advantage of this is that such warnings can be supressed and are visually distinct from other printed messages and so are easier to identify in the console.

file_path: Path,
latlon_points: np.ndarray,
band: int = 1,
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
):
) -> np.ndarray:

assert (site_df.loc[vs30_non_nan, "Vs30_Ref"] == "Foster et al. (2019)").all()
assert (site_df.loc[vs30_non_nan, "Q_Vs30"] == "Q3").all()
assert site_df.loc[~vs30_non_nan, "Vs30_Ref"].isna().all()
assert site_df.loc[~vs30_non_nan, "Q_Vs30"].isna().all()
Copy link
Contributor

Choose a reason for hiding this comment

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

My only concern with this test is that it is patching a lot of internals of the code it is testing, which makes it difficult to refactor that code because it will also break a lot of tests. This probably suggests that one of your functions is doing "too much" if it can't be tested in isolation of the NZCVM, numerical code, pooch fetching data, FDSN client and fiona. I would consider if this test is actually necessary or if the functions it tests can be unit tested in isolation without the need of an invasive integration test. Having said that, this is your codebase and if you feel the complexity of the test is not going to impose a refactor burden then I wouldn't hold up the PR for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair concern

@joelridden joelridden dismissed stale reviews from lispandfound and claudio525 via f148282 February 3, 2026 22:33
@joelridden joelridden merged commit 4bafc86 into 4p4 Feb 3, 2026
5 checks passed
@joelridden joelridden deleted the site_vs30 branch February 3, 2026 22:48
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.

3 participants