Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 280 additions & 69 deletions nzgmdb/calculation/distances.py

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions nzgmdb/data_retrieval/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ def create_site_table_response() -> pd.DataFrame:
station.end_date,
]
)
sta_df = pd.DataFrame(station_info, columns=["net", "sta", "lat", "lon", "elev", "creation_date", "end_date"])
sta_df = sta_df.drop_duplicates().reset_index(drop=True)
sta_df = pd.DataFrame(
station_info,
columns=["net", "sta", "lat", "lon", "elev", "creation_date", "end_date"],
)
sta_df = sta_df.drop_duplicates(["net", "sta"]).reset_index(drop=True)

# Get the Geonet metadata summary information
geo_meta_summary_df = pd.read_csv(
Expand Down Expand Up @@ -77,17 +80,19 @@ def create_site_table_response() -> pd.DataFrame:
)

merged_df = geo_meta_summary_df.merge(
sta_df[["net", "elev", "sta"]], on="sta", how="left"
sta_df[["net", "elev", "sta", "creation_date", "end_date"]],
on="sta",
how="left",
)
# Fill Elevation NaN values from sta_df
merged_df["elev"] = merged_df["Elevation"].combine_first(merged_df["elev"])
# Specify the required files for fiona
NZGMDB_DATA.fetch("TectonicDomains_Feb2021_8_NZTM.shp")
NZGMDB_DATA.fetch("TectonicDomains_Feb2021_8_NZTM.dbf")
NZGMDB_DATA.fetch("TectonicDomains_Feb2021_8_NZTM.shx")
NZGMDB_DATA.fetch("nt_domains_kiran.shp")
NZGMDB_DATA.fetch("nt_domains_kiran.dbf")
NZGMDB_DATA.fetch("nt_domains_kiran.shx")

# Shape file for determining neotectonic domain
shapes = list(
fiona.open(Path(NZGMDB_DATA.abspath) / "TectonicDomains_Feb2021_8_NZTM.shp")
)
shapes = list(fiona.open(Path(NZGMDB_DATA.abspath) / "nt_domains_kiran.shp"))
tect_merged_df = tect_domain.find_domain_from_shapes(merged_df, shapes)

# Rename the domain column
Expand Down
20 changes: 9 additions & 11 deletions nzgmdb/data_retrieval/tect_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
from pyproj import Transformer

from cmt_solutions import cmt_data
from nzgmdb.management import config as cfg
from nzgmdb.management.data_registry import NZGMDB_DATA
from qcore import geo, point_in_polygon
Expand Down Expand Up @@ -473,18 +474,15 @@ def add_tect_domain(
The number of processes to use
"""
# Specify the required files for fiona
NZGMDB_DATA.fetch("TectonicDomains_Feb2021_8_NZTM.shp")
NZGMDB_DATA.fetch("TectonicDomains_Feb2021_8_NZTM.dbf")
NZGMDB_DATA.fetch("TectonicDomains_Feb2021_8_NZTM.shx")
NZGMDB_DATA.fetch("nt_domains_kiran.shp")
NZGMDB_DATA.fetch("nt_domains_kiran.dbf")
NZGMDB_DATA.fetch("nt_domains_kiran.shx")

# Shape file for determining neotectonic domain
shapes = list(
fiona.open(Path(NZGMDB_DATA.abspath) / "TectonicDomains_Feb2021_8_NZTM.shp")
)
shapes = list(fiona.open(Path(NZGMDB_DATA.abspath) / "nt_domains_kiran.shp"))

# Read the geonet CMT and event data
config = cfg.Config()
geonet_cmt_df = pd.read_csv(config.get_value("cmt_url"), dtype={"evid": str})
# Read the CMT and event data
cmt_df = cmt_data.get_cmt_data()
event_df = pd.read_csv(event_csv_ffp, dtype={"evid": str})

# Merge in the Reyners Catalogue data for relocations
Expand All @@ -493,8 +491,8 @@ def add_tect_domain(
)
event_df = merge_reyners_catalogue_on_events(event_df, reyners_catalogue_df)

# Replace the geonet CMT data on the event data (override the reyners relocations)
event_df = replace_cmt_data_on_event(event_df, geonet_cmt_df)
# Replace the CMT data on the event data (override the reyners relocations)
event_df = replace_cmt_data_on_event(event_df, cmt_df)

# Merge the NZSMDB data
event_df = merge_NZSMDB_flatfile_on_events(event_df)
Expand Down
14 changes: 14 additions & 0 deletions nzgmdb/management/data_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
"TectonicDomains_Feb2021_8_NZTM.shx": "sha256:9ca42e270e5604f4740b3d99ea6a72daa75eaae0e6c6bda3c4e5c86a72369403",
"TectonicDomains_Feb2021_8_NZTM.dbf": "sha256:534c644c5d4d6a08106752e2fe33894bc820645efa017e0137ef5b8d44e8200c",
"tectonic_domain_polygon_points.csv": "sha256:a54c30a4e68bb078c6ce9d99bd30f902a9627d57fd39392b403064de61b1f1a4",
"nt_domains_kiran.dbf": "sha256:97e86ca9b8ea50ea0d8eec32025513a1ec0026a602a7bae2777999f6ba9f7ac4",
"nt_domains_kiran.shp": "sha256:edfa412b9395258a1ca0e9de61070108567b427ca59d309e09c531b462ccd490",
"nt_domains_kiran.shx": "sha256:721a99e549961dcc22a342750f8bd9d62946a73dfbf6a1dc4e9ba8a11d578ac0",
"hik_focmec.npy": "sha256:3a13e4c31b99b80da9976e2cb38b5f0f69cccf860140bea0598f32f9ed075767",
"puy_focmec.npy": "sha256:6493cba83722cdbea24ceafadd192d8b7a9e5160423e0b5fef3357748cf3e66f",
"nzfocmecmod.json": "sha256:1612c364b0ddf6251bb4044c3cde1a36b36e672525465e71cf0e4007bc97b446",
"slab-faulting2.json": "sha256:debe5e1a082716dd9d3deaad79fc859de7aeaaf4a41e40632f26a6593b020c83",
"brendon_set.csv": "sha256:a62d8c69f7f7bc6ccf0318a113a152befb35cfb21c56ab4806c58f24f221ce2e",
"lee_large.csv": "sha256:e4077746552937cd0a48be723b0188d33d4a73c2364716f085c0cd55ab78ec58",
"lee_small.csv": "sha256:b274bc99fcacb2747623f754b92d594c3b6729cfcfd0d046365ad3c6fba706c1",
Expand All @@ -42,6 +49,13 @@
"TectonicDomains_Feb2021_8_NZTM.dbf": "https://www.dropbox.com/scl/fi/o2z83zbg3yvxq8yqiwkqk/TectonicDomains_Feb2021_8_NZTM.dbf?rlkey=o4imoxtoj8psa3ndvryqrx2qk&st=qvcwp7hj&dl=1",
"TectonicDomains_Feb2021_8_NZTM.shp": "https://www.dropbox.com/scl/fi/69qwsa48gvtzx056vqirs/TectonicDomains_Feb2021_8_NZTM.shp?rlkey=qjkzra3xu0z9xjkb3dcji4max&st=kfsh8gaw&dl=1",
"TectonicDomains_Feb2021_8_NZTM.shx": "https://www.dropbox.com/scl/fi/3qyw5v3cw0dzi41d6wnp8/TectonicDomains_Feb2021_8_NZTM.shx?rlkey=ducg84xqhi2ua6ku2qhbiutrg&st=flmk11e0&dl=1",
"nt_domains_kiran.dbf": "https://www.dropbox.com/scl/fi/eexo36xpy8zw4m4kqua5i/nt_domains_kiran.dbf?rlkey=79buc3tge8glyerhcv1mvhur0&st=rjozdfq5&dl=1",
"nt_domains_kiran.shp": "https://www.dropbox.com/scl/fi/szdddwmefe19wcpgjpmcr/nt_domains_kiran.shp?rlkey=4vfrmtvbh17xezu9bovw94y7m&st=ohbz9bcw&dl=1",
"nt_domains_kiran.shx": "https://www.dropbox.com/scl/fi/17vh8bzrr0ahbxx3p49d4/nt_domains_kiran.shx?rlkey=mf5f5ibq0tiju0826anx7i18o&st=8obiawck&dl=1",
"hik_focmec.npy": "https://www.dropbox.com/scl/fi/1fn9yy68kacot6zsrhhan/hik_focmec.npy?rlkey=sgr1p2jlr4r4fbxegszzjfbep&st=12uqjyid&dl=1",
"puy_focmec.npy": "https://www.dropbox.com/scl/fi/9d0ycs5387lmdw3izkobv/puy_focmec.npy?rlkey=ognpq4lxr3bxxhw5iify8r9lt&st=zbrd62da&dl=1",
"nzfocmecmod.json": "https://www.dropbox.com/scl/fi/5zhftxo8uyfzzr6fj5kiz/nzfocmecmod.json?rlkey=a6hs5kgcqeagk4mosrg7akz13&st=o8xxr9v0&dl=1",
"slab-faulting2.json": "https://www.dropbox.com/scl/fi/u6o5jiuz9dwh1bl666nxj/slab-faulting2.json?rlkey=q7gzx6j8hmo61ic13co28vftj&st=hjnu7akb&dl=1",
"2013p543824.srf": "https://www.dropbox.com/scl/fi/013i860bt3os1k80leai5/2013p543824.srf?rlkey=ww3clc60gud4sycwfzmgopvix&st=jpu99tse&dl=1",
"2013p613797.srf": "https://www.dropbox.com/scl/fi/7wx7glahf8cufo1g7umzc/2013p613797.srf?rlkey=1x9e5yb2nkf5468rs0bogm8ev&st=dut8d2uw&dl=1",
"2016p661332.srf": "https://www.dropbox.com/scl/fi/pp7s6iqilrdgbrs00wi55/2016p661332.srf?rlkey=bhgcddk3bcdpxoycorlhp2in6&st=b8o2bk4w&dl=1",
Expand Down
3 changes: 2 additions & 1 deletion nzgmdb/phase_arrival/run_phasenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import argparse
from pathlib import Path
from typing import Union

import h5py
import mseedlib
Expand Down Expand Up @@ -302,7 +303,7 @@ def process_mseed(mseed_file: Path, h5_ffp: Path, bypass_row: pd.Series = None):


def run_phasenet(
mseed_files_ffp: Path, output_dir: Path, bypass_ffp: Path | None = None
mseed_files_ffp: Path, output_dir: Path, bypass_ffp: Union[Path, None] = None
):
"""
Run PhaseNet on the mseed files.
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ openquake-engine @ git+https://github.com/gem/oq-engine.git@v3.23.2
qcore @ git+https://github.com/ucgmsim/qcore.git
IM_calculation @ git+https://github.com/ucgmsim/IM_calculation.git
velocity_modelling @ git+https://github.com/ucgmsim/velocity_modelling.git
source-modelling @ git+https://github.com/ucgmsim/source_modelling.git
source-modelling @ git+https://github.com/ucgmsim/source_modelling.git
cmt-solutions @ git+https://github.com/ucgmsim/cmt_solutions.git
8 changes: 4 additions & 4 deletions wiki/Add-Tectonic-Domain.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ Relocations are applied from the Reyners Catalogue to improve location accuracy:
- Sets `reloc` field to "reyners" for successfully relocated events

### 🔹 2. Centroid Moment Tensor (CMT) Solutions
GeoNet CMT location solutions are applied, which override Reyners relocations when overlapping:
GeoNet and John Townend CMT location solutions are applied, which override Reyners relocations when overlapping:

**GeoNet CMT Solutions**
**CMT Solutions**

- Applies Centroid Moment Tensor (CMT) solutions from GeoNet
- Applies Centroid Moment Tensor (CMT) solutions from GeoNet and John Townend study
- Overrides previous relocations (including Reyners) when CMT solutions are available
- Updates source parameters: mag (Mw), lat, lon, depth
- Sets metadata fields: mag_type="Mw", mag_method="CMT", loc_type="CMT", loc_grid="CMT", reloc="no"

Expand Down Expand Up @@ -128,7 +129,6 @@ The enhanced earthquake source table contains all original fields plus:
The step uses several configuration parameters from `config.yaml`:

- **nzsmdb_url**: URL for NZ Strong Motion Database flatfile
- **cmt_url**: URL for GeoNet CMT solutions
- **ll_num**: WGS84 coordinate system identifier
- **nztm_num**: NZTM coordinate system identifier

Expand Down
7 changes: 2 additions & 5 deletions wiki/Calculate-Distances.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ The system determines the correct nodal plane through the following hierarchy:
- Extract nodal plane parameters and SRF points
- Calculate weighted average of strike, dip, rake based on plane areas

2. **Check Modified CMT Solutions** (Custom review for most likely nodal plane):
2. **Check Reviewed CMT Solutions** (Custom review for most likely nodal plane):
- Use predetermined preferred nodal plane
- Extract strike, dip, rake values
- Apply CCLD Method A

3. **Check Standard CMT Solutions**: Search GeoNet CMT catalogue:
3. **Check Standard CMT Solutions**: Search CMT catalogue:
- Apply CCLD Method C with both nodal planes

4. **Use Domain Default**: For events without CMT solutions:
Expand Down Expand Up @@ -244,9 +244,6 @@ Key parameters from `config.yaml` that control distance calculations:
### 🔹 Fault Discretisation
- `points_per_km`: Resolution for SRF point generation (default: typically 2-4 points/km)

### 🔹 External Data Sources
- `cmt_url`: URL for GeoNet CMT solutions catalogue

---

## 📦 Output
Expand Down
Loading