mtpy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesemtpy - Magnetotelluric Analysis
mtpy - 大地电磁分析
Quick Reference
快速参考
python
from mtpy import MT, MTCollectionpython
from mtpy import MT, MTCollectionRead single station
读取单个测站数据
mt = MT('station001.edi')
mt = MT('station001.edi')
Access data
访问数据
Z = mt.Z # Complex impedance tensor
freq = mt.frequency # Frequency array
rho_xy = mt.apparent_resistivity[:, 0, 1] # Apparent resistivity
Z = mt.Z # 复阻抗张量
freq = mt.frequency # 频率数组
rho_xy = mt.apparent_resistivity[:, 0, 1] # 视电阻率
Station info
测站信息
print(mt.station, mt.latitude, mt.longitude)
print(mt.station, mt.latitude, mt.longitude)
Write EDI
写入EDI文件
mt.write_edi('output.edi')
undefinedmt.write_edi('output.edi')
undefinedKey Classes
核心类
| Class | Purpose |
|---|---|
| Single station MT data container |
| Multiple stations management |
| Plot impedance, resistivity, phase |
| Phase tensor ellipse visualization |
| Profile pseudosection display |
| Strike direction analysis |
| 类 | 用途 |
|---|---|
| 单个测站MT数据容器 |
| 多测站数据管理 |
| 绘制阻抗、电阻率、相位 |
| 相位张量椭圆可视化 |
| 剖面拟断面图展示 |
| 走向方向分析 |
Essential Operations
关键操作
Load and Inspect EDI
加载并检查EDI文件
python
from mtpy import MT
mt = MT('station001.edi')
print(f"Station: {mt.station}")
print(f"Location: ({mt.latitude}, {mt.longitude})")
print(f"Frequencies: {len(mt.frequency)} points")
print(f"Period range: {1/mt.frequency.max():.2f} - {1/mt.frequency.min():.0f} s")python
from mtpy import MT
mt = MT('station001.edi')
print(f"测站: {mt.station}")
print(f"位置: ({mt.latitude}, {mt.longitude})")
print(f"频率点数: {len(mt.frequency)} 个")
print(f"周期范围: {1/mt.frequency.max():.2f} - {1/mt.frequency.min():.0f} 秒")Load Multiple Stations
加载多个测站数据
python
from mtpy import MTCollection
mc = MTCollection()
mc.from_edis('survey_data/*.edi')
print(f"Loaded {len(mc)} stations")
for station in mc:
print(f" {station.station}: ({station.latitude:.4f}, {station.longitude:.4f})")python
from mtpy import MTCollection
mc = MTCollection()
mc.from_edis('survey_data/*.edi')
print(f"已加载 {len(mc)} 个测站")
for station in mc:
print(f" {station.station}: ({station.latitude:.4f}, {station.longitude:.4f})")Plot MT Response
绘制MT响应曲线
python
from mtpy import MT
from mtpy.imaging import PlotMTResponse
mt = MT('station001.edi')
plot = PlotMTResponse(mt)
plot.plot() # Apparent resistivity and phasepython
from mtpy import MT
from mtpy.imaging import PlotMTResponse
mt = MT('station001.edi')
plot = PlotMTResponse(mt)
plot.plot() # 绘制视电阻率和相位Phase Tensor Analysis
相位张量分析
python
from mtpy import MT
from mtpy.imaging import PlotPhaseTensor
mt = MT('station001.edi')python
from mtpy import MT
from mtpy.imaging import PlotPhaseTensor
mt = MT('station001.edi')Get phase tensor parameters
获取相位张量参数
phi_min = mt.phase_tensor.phimin
phi_max = mt.phase_tensor.phimax
skew = mt.phase_tensor.skew # 3D indicator
phi_min = mt.phase_tensor.phimin
phi_max = mt.phase_tensor.phimax
skew = mt.phase_tensor.skew # 三维结构指示值
Plot
绘图
pt = PlotPhaseTensor(mt)
pt.plot()
undefinedpt = PlotPhaseTensor(mt)
pt.plot()
undefinedRotate Impedance Tensor
旋转阻抗张量
python
from mtpy import MT
mt = MT('station001.edi')
mt_rotated = mt.rotate(30) # 30 degrees clockwise
mt.rotate_to_strike() # Auto-rotate to geoelectric strikepython
from mtpy import MT
mt = MT('station001.edi')
mt_rotated = mt.rotate(30) # 顺时针旋转30度
mt.rotate_to_strike() # 自动旋转到地电走向Create Pseudosection
创建拟断面图
python
from mtpy import MTCollection
from mtpy.imaging import PlotPseudoSection
mc = MTCollection()
mc.from_edis('profile/*.edi')
ps = PlotPseudoSection(mc)
ps.plot(plot_type='apparent_resistivity', mode='te') # or 'tm', 'det'python
from mtpy import MTCollection
from mtpy.imaging import PlotPseudoSection
mc = MTCollection()
mc.from_edis('profile/*.edi')
ps = PlotPseudoSection(mc)
ps.plot(plot_type='apparent_resistivity', mode='te') # 可选 'tm'、'det'Export Data
导出数据
python
from mtpy import MT
import pandas as pd
mt = MT('station001.edi')python
from mtpy import MT
import pandas as pd
mt = MT('station001.edi')Export to CSV
导出为CSV
df = pd.DataFrame({
'frequency': mt.frequency,
'rho_xy': mt.apparent_resistivity[:, 0, 1],
'rho_yx': mt.apparent_resistivity[:, 1, 0],
'phase_xy': mt.phase[:, 0, 1],
'phase_yx': mt.phase[:, 1, 0]
})
df.to_csv('mt_data.csv', index=False)
df = pd.DataFrame({
'frequency': mt.frequency,
'rho_xy': mt.apparent_resistivity[:, 0, 1],
'rho_yx': mt.apparent_resistivity[:, 1, 0],
'phase_xy': mt.phase[:, 0, 1],
'phase_yx': mt.phase[:, 1, 0]
})
df.to_csv('mt_data.csv', index=False)
Export for ModEM
导出为ModEM格式
mt.write_modem('station001.dat')
undefinedmt.write_modem('station001.dat')
undefinedImpedance Tensor Components
阻抗张量分量
| Component | Description | Mode |
|---|---|---|
| Zxx | Ex/Bx response | Diagonal (usually small) |
| Zxy | Ex/By response | TE mode |
| Zyx | Ey/Bx response | TM mode |
| Zyy | Ey/By response | Diagonal (usually small) |
| 分量 | 描述 | 模式 |
|---|---|---|
| Zxx | Ex/Bx响应 | 对角分量(通常值较小) |
| Zxy | Ex/By响应 | TE模式 |
| Zyx | Ey/Bx响应 | TM模式 |
| Zyy | Ey/By响应 | 对角分量(通常值较小) |
Phase Tensor Parameters
相位张量参数
| Parameter | Description | Interpretation |
|---|---|---|
| phi_min | Minimum phase | Relates to resistivity gradient |
| phi_max | Maximum phase | Relates to resistivity gradient |
| skew | Skew angle | >5 suggests 3D structure |
| ellipticity | (phi_max-phi_min)/(phi_max+phi_min) | 2D/3D indicator |
| 参数 | 描述 | 解释 |
|---|---|---|
| phi_min | 最小相位 | 与电阻率梯度相关 |
| phi_max | 最大相位 | 与电阻率梯度相关 |
| skew | 偏斜角 | >5 表明存在三维结构 |
| ellipticity | (phi_max-phi_min)/(phi_max+phi_min) | 二维/三维结构指示值 |
When to Use vs Alternatives
适用场景与替代工具对比
| Tool | Best For | Limitations |
|---|---|---|
| mtpy | Full MT workflow in Python, EDI I/O, visualization, modelling prep | Complex API, evolving between v1 and v2 |
| EMTF | USGS time-series to impedance processing | Fortran-based, processing only |
| WinGLink | Commercial integrated MT processing and inversion | Expensive commercial license |
Use mtpy when you need end-to-end MT analysis in Python: reading EDI files,
QC, phase tensor analysis, pseudosections, and preparing data for ModEM or other
inversion codes.
Consider alternatives when you need time-series to impedance processing from raw
field data (use EMTF), or a fully integrated commercial inversion package with GUI
(use WinGLink).
| 工具 | 适用场景 | 局限性 |
|---|---|---|
| mtpy | Python环境下完整MT工作流、EDI文件读写、可视化、建模准备 | API较复杂,v1与v2版本间存在演进变化 |
| EMTF | USGS时序数据转阻抗处理 | 基于Fortran,仅支持数据处理 |
| WinGLink | 商业化集成MT处理与反演工具 | 商业许可费用高昂 |
选择mtpy的场景:需要在Python环境中完成端到端MT分析,包括读取EDI文件、质量控制、相位张量分析、拟断面图绘制,以及为ModEM或其他反演代码准备数据。
考虑替代工具的场景:需要从野外原始时序数据转换为阻抗数据(使用EMTF),或需要带GUI的全集成商业化反演包(使用WinGLink)。
Common Workflows
常见工作流
Load, QC, and analyze MT station data
加载、质量控制与分析MT测站数据
- Load EDI file(s) with or
MT()MTCollection() - Inspect station metadata (location, frequency range)
- Plot apparent resistivity and phase with
PlotMTResponse - Check phase tensor parameters for dimensionality (skew > 5 = 3D)
- Identify and mask noisy data points using error thresholds
- Rotate impedance tensor to geoelectric strike if needed
- Create pseudosection for profile data
- Export cleaned data for inversion (ModEM format)
- 使用或
MT()加载EDI文件MTCollection() - 检查测站元数据(位置、频率范围)
- 使用绘制视电阻率和相位曲线
PlotMTResponse - 检查相位张量参数判断结构维数(偏斜角>5=三维结构)
- 根据误差阈值识别并屏蔽噪声数据点
- 必要时将阻抗张量旋转到地电走向
- 为剖面数据创建拟断面图
- 导出清理后的数据用于反演(ModEM格式)
Common Issues
常见问题
| Issue | Solution |
|---|---|
| No tipper data | Check |
| Bad data points | Use |
| Static shift | Apply correction before interpretation |
| Wrong rotation | Verify coordinate system (N vs E convention) |
| 问题 | 解决方案 |
|---|---|
| 无倾子数据 | 访问前先检查 |
| 不良数据点 | 使用 |
| 静态偏移 | 解释前先应用校正 |
| 旋转方向错误 | 验证坐标系(北/东约定) |
References
参考资料
- EDI Format - EDI file structure and sections
- Plotting Options - Visualization parameters and styles
- EDI格式 - EDI文件结构与章节说明
- 绘图选项 - 可视化参数与样式
Scripts
脚本
- scripts/mt_analysis.py - MT data analysis and QC
- scripts/mt_analysis.py - MT数据分析与质量控制脚本