Skip to content

feat: add Python APIs for surface-wave dispersion and modal summation#271

Open
YuanYusung wants to merge 2 commits into
Dengda98:mainfrom
YuanYusung:python-modal-api
Open

feat: add Python APIs for surface-wave dispersion and modal summation#271
YuanYusung wants to merge 2 commits into
Dengda98:mainfrom
YuanYusung:python-modal-api

Conversation

@YuanYusung

Copy link
Copy Markdown

Summary

This PR adds initial Python APIs for PyGRT surface-wave modal workflows:

  • PyModel1D.compute_dispersion(...)
  • PyModel1D.compute_surface_grn(...)
  • pygrt.PyDispersion

The implementation exposes Python access to the existing C modal solvers for eigenv and modsum, following the current ctypes-based PyGRT style.

Scope

This first PR focuses on:

  • Rayleigh/Love phase-velocity dispersion
  • Modal summation surface-wave Green's functions
  • Simple Python smoke tests integrated into existing test/eigenv and test/modsum shell tests

Out of scope for this PR:

  • eigenfn
  • group velocity
  • energy integrals
  • sensitivity kernels
  • Python NetCDF read/write helpers

These can be added in follow-up PRs.

Tests

Passed locally:

git diff --check
python -m compileall -q pygrt test/eigenv/test_eigenv.py test/modsum/test_modsum.py
cd test/eigenv && python -u test_eigenv.py
cd test/modsum && python -u test_modsum.py
cd test/eigenv && bash test_eigenv.sh
cd test/modsum && bash test_modsum.sh
git pull --rebase upstream main

compileall only reports pre-existing SyntaxWarnings in unrelated plotting strings.

@Dengda98

Dengda98 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

感谢你关注到PyGRT,也感谢你的首次PR!
这是一次很好的尝试!是使用AI辅助的吗,方便的话给一些推荐? 👀

事实上我感觉我的Python部分与C部分的业务逻辑存在重复,这对于后续推进维护会埋下隐患。因此近段时间的代码重构和更新我尽量还没有碰Python。

所以很抱歉我暂时还不能merge,我过段时间会仔细review,并且思考如何简化我的整个Python部分的写法,给出一个更简洁的框架。

再一次感谢你的贡献! ❤️ 👍

@YuanYusung

YuanYusung commented Jul 3, 2026

Copy link
Copy Markdown
Author

@Dengda98 ,你好!

感谢你的回复!

最近我在用 PyGRT 做面波模拟,发现目前还没有提供面波工作流程的 Python 接口。在 AI 的辅助下,我尝试实现了这个接口,并提交了这个 PR。我主要用了 ChatGPT 和 Codex,ChatGPT 主要帮我完善初版代码和 PR 说明;Codex 主要帮我理解 PyGRT 的整体结构、整理测试脚本,以及跑本地检查。

这个 PR 的初衷是先提供一个可用的 Python 面波合成接口,从而更方便地开展面波相关的研究。我也完全理解你对 Python 和 C 部分之间业务逻辑重复的担忧。如果之后你计划重构 Python 部分,我非常乐意根据新的框架调整这个 PR;如果还有其他我可以帮忙的地方,我也很愿意参与。

这也是我第一次尝试为开源项目做贡献,如果实现或 PR 流程中有不成熟的地方,还请多多包涵。

再次感谢你的耐心回复,也感谢你开发和维护 PyGRT!🫡 它是一个非常实用的波形合成软件,相信以后会有越来越多研究者使用。👍

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.

2 participants