Skip to main content

Python implementation of HASH for earthquake focal mechanism determination

Project description

CNCHASH

Python implementation of HASH for earthquake focal mechanism determination from P-wave polarities.

Python License Numba Numpy Ruff

Python uses Numba JIT compilation optimization and vectorization, achieving speed improvements while maintaining complete consistency with the core Fortran algorithm.

Speed Comparison

Performance

Metric Python+Numba Fortran Speedup
24 events 0.068s 0.473s 6.9x
Per event 2.85ms 19.7ms 6.9x
5000 events 13.0s 98.5s 7.6x
10000 events 26.0s 197.0s 7.6x

Accuracy Verification

Accuracy Verification

Key Results:

  • Python dip error median: 5.6° (Fortran: 11.1°)
  • Python rake error median: 24.1° (Fortran: 26.6°)
  • Python synthetic trials: 300/300 successful solutions
  • Fortran synthetic trials: 60/60 successful solutions (direct-runs)

Note: Strike differences (40-80°) are normal - focal mechanisms have two orthogonal nodal planes that both satisfy polarity data.

Quick Start

pip install cnchash

Basic Usage (P-wave polarities only)

from cnchash import run_hash
import numpy as np

# Azimuths, takeoff angles, polarities, quality
p_azi = np.array([45.0, 135.0, 225.0, 315.0])
p_the = np.array([30.0, 45.0, 60.0, 75.0])
p_pol = np.array([1, -1, 1, -1])  # 1=up, -1=down
p_qual = np.array([0, 0, 0, 0])

result = run_hash(p_azi, p_the, p_pol, p_qual)

print(f"Strike: {result['strike_avg']:.1f}")
print(f"Dip: {result['dip_avg']:.1f}")
print(f"Rake: {result['rake_avg']:.1f}")
print(f"Quality: {result['quality']}")

With S/P Amplitude Ratio

from cnchash import run_hash_with_amp
import numpy as np

# Same inputs as above, plus S/P amplitude ratios (log10 scale)
# sp_amp = 0.0 means no amplitude data for that station
sp_amp = np.array([0.3, -0.2, 0.5, 0.0])  # log10(S/P), 0.0 = no data

result = run_hash_with_amp(p_azi, p_the, p_pol, sp_amp)

print(f"Strike: {result['strike_avg']:.1f}")
print(f"Dip: {result['dip_avg']:.1f}")
print(f"Rake: {result['rake_avg']:.1f}")
print(f"Quality: {result['quality']}")
print(f"Polarity misfit: {result['mfrac']*100:.1f}%")
print(f"Amplitude misfit: {result['mavg']:.2f}")

Features

  • Grid search for focal mechanism determination
  • Monte Carlo uncertainty analysis
  • S/P amplitude ratio constraint
  • Quality rating (A-D, E, F)
  • Multiple phase file formats
  • Core algorithm matches Fortran exactly

Documentation

See https://cnchash.readthedocs.io/ for full documentation including:

  • API reference
  • Algorithm details
  • File format specifications
  • Performance optimization

Run Tests

jupyter notebook HASH_Tests.ipynb

Project Structure

cnchash/
├── core.py        # Grid search algorithm (focalmc)
├── amp_subs.py    # S/P amplitude ratio (focalamp_mc)
├── uncertainty.py # Uncertainty analysis (mech_prob)
├── driver.py      # Main driver (run_hash, run_hash_with_amp)
├── io.py          # File I/O
└── utils.py       # Utilities

HASH_complete/     # Complete Fortran code with examples

Author

He XingChen

License

BSD 3-Clause

References

Hardebeck, Jeanne L. and Peter M. Shearer, A new method for determining first-motion focal mechanisms, Bulletin of the Seismological Society of America, 92, 2264-2276, 2002.

Hardebeck, Jeanne L. and Peter M. Shearer, Using S/P Amplitude Ratios to Constrain the Focal Mechanisms of Small Earthquakes, Bulletin of the Seismological Society of America, 93, 2434-2444, 2003.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cnchash-1.0.1.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cnchash-1.0.1-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file cnchash-1.0.1.tar.gz.

File metadata

  • Download URL: cnchash-1.0.1.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for cnchash-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5079b2d4e69f41f64c354f1913b6a70b111863a36e418ede9b3f5aa542646f2d
MD5 50e9f45aa591a250ef90f4133549bd33
BLAKE2b-256 388f83491f7a2e56cc2bb4e4e9c60cbe37f300d94218be32804b8188c8ee7736

See more details on using hashes here.

File details

Details for the file cnchash-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: cnchash-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 44.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for cnchash-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 322fdef120066bd8cd0e953ec87d3daf8d69b84062c01f913813acd4e8607200
MD5 8cba9f1acd1e8dd1748203052960c5c1
BLAKE2b-256 7dea6cb03c3316b14b746223a29086dad102f8703d29b2290c09be257f8ae91b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page