focsphere 是一个面向地震学的 Python 包,提供震源机制球(beachball)的计算、立体投影与绘制工具。
要求 Python 3.10 或更高版本。
- 震源机制表示:
FocalMechanism、NodalPlane,遵循 Aki & Richards 走滑角约定 - 矩张量:NED 坐标系下的对称矩张量,支持与 strike-dip-rake 互转
- P 波辐射花样:双力偶源的初动极性计算
- 立体投影:下半球等角度(Wulff)与等面积(Schmidt)投影
- Beachball 绘制:基于 Matplotlib 的震源机制球图
pip install focsphere绘图功能需要 Matplotlib:
pip install focsphere[plot]import focsphere as fs
# 定义震源机制 (strike, dip, rake)
fm = fs.FocalMechanism(strike=295, dip=63, rake=-174)
# 两个节面
np1, np2 = fm.nodal_planes()
print(np1, np2)
# 矩张量
mt = fm.moment_tensor()
print(mt.as_matrix())
# 从一般矩张量提取最小二乘双力偶机制
best_dc = mt.to_strike_dip_rake()
print(mt.double_couple_percentage())
# P 波初动符号 (+ 压缩, - 膨胀)
sign = fm.p_wave_sign(azimuth_deg=180, takeoff_deg=45)
# 绘制 beachball
fs.beachball(295, 63, -174)仓库包含一个独立的 TypeScript 交互式网页:左侧调节 strike、dip、rake,中间拖拽查看 三维 P 波辐射球,右侧同步显示矩张量、主轴、节面和初动极性,底部生成可下载的 PNG beachball。网页与 Python 包不共享运行时依赖,但遵循相同的 NED、SDR、双力偶矩张量和 P 波辐射约定,并通过参考结果测试保持数值一致。
网页目录结构、科学计算边界和扩展约定见
web/README.md。
本地开发:
npm --prefix web ci
npm --prefix web run dev打开 http://127.0.0.1:5173。生产构建及预览:
npm --prefix web run build
npm --prefix web run preview.github/workflows/pages.yml 会在 main 分支更新后构建并部署 Studio,也可在
Actions 页面手动触发。首次部署前,需要在仓库的 Settings → Pages → Build and
deployment 中将 Source 设为 GitHub Actions。
Studio 完全在浏览器中运行,无需后端服务。部署构建会根据 Pages 提供的 base_path
自动适配项目子路径。
| 模块 | 说明 |
|---|---|
focsphere.mechanism |
震源机制与节面转换 |
focsphere.tensor |
矩张量表示与分解 |
focsphere.geometry |
NED 坐标系球面几何 |
focsphere.projection |
立体投影 |
focsphere.radiation |
P 波辐射花样 |
focsphere.plot |
Beachball 绘图 |
web/ |
独立的 React、TypeScript 科学计算与 WebGL 交互界面 |
推荐使用独立 conda 环境(勿在 base 中开发):
conda env create -f environment-dev.yml
conda activate focsphere-dev
pip install -e .
pytest质量检查:
ruff check .
mypy src/focsphere
pytest --cov=focsphere
python -m build
python -m twine check dist/*- 坐标系采用 North-East-Down(NED),向量顺序为
[north, east, down] - strike 从正北顺时针计,dip 从水平面向下计,rake 遵循 Aki & Richards 约定
- takeoff angle 从 Down 轴计,
0°为正下方,90°为水平 FocalMechanism表示纯双力偶源;一般MomentTensor转换返回最小二乘双力偶分量- P 波振幅统一采用
rᵀMr;单位标量矩时等于2(n·r)(d·r) - 水平断层的 strike/rake 不可独立识别,向量反演返回 rake 为
0°的规范等价表示
conda env create -f environment-release.yml
conda activate focsphere-release
python -m build
python -m twine check dist/*
python -m twine upload dist/*- Aki & Richards (2002), Quantitative Seismology, 2nd ed.
- Vavryčuk (2015), Moment tensor decompositions revisited, Geophys. J. Int.