dimine-python-sdk 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dimine_python_sdk/__init__.py +1 -1
- dimine_python_sdk/cli/commands/file.py +14 -19
- dimine_python_sdk/cli/commands/geometry.py +4 -4
- dimine_python_sdk/cli/utils/_utils.py +5 -5
- dimine_python_sdk/conn/base_conn_client.py +5 -1
- dimine_python_sdk/conn/conn_client.py +2 -2
- dimine_python_sdk/docs/guides/lib/io/SUMMARY.md +1 -0
- dimine_python_sdk/docs/guides/lib/io/dmd_file.md +198 -196
- dimine_python_sdk/docs/guides/lib/io/dmg_file.md +196 -192
- dimine_python_sdk/docs/guides/lib/io/dmo_file.md +159 -0
- dimine_python_sdk/docs/reference/SUMMARY.md +1 -0
- dimine_python_sdk/docs/reference/lib/io/dmo_file.md +3 -0
- dimine_python_sdk/lib/io/__init__.py +19 -0
- dimine_python_sdk/lib/io/dmo_file.py +327 -0
- dimine_python_sdk/lib/io/file_converter.py +3 -3
- dimine_python_sdk/lib/native/io.py +22 -10
- dimine_python_sdk/logger.py +1 -1
- dimine_python_sdk/site/404.html +28 -0
- dimine_python_sdk/site/examples/cli_usage.html +28 -0
- dimine_python_sdk/site/examples/contour_modeling_visualization.html +28 -0
- dimine_python_sdk/site/examples/import_csv_to_drill_db.html +28 -0
- dimine_python_sdk/site/examples/lib_file_usage.html +28 -0
- dimine_python_sdk/site/examples/reserve_estimation_pipeline.html +28 -0
- dimine_python_sdk/site/examples/summary.html +28 -0
- dimine_python_sdk/site/guides/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/cli.html +28 -0
- dimine_python_sdk/site/guides/conn/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/conn/data_edit.html +28 -0
- dimine_python_sdk/site/guides/conn/data_get.html +28 -0
- dimine_python_sdk/site/guides/conn/features.html +28 -0
- dimine_python_sdk/site/guides/conn/io.html +28 -0
- dimine_python_sdk/site/guides/lib/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/lib/exploitation/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/lib/exploitation/contour_modeling.html +28 -0
- dimine_python_sdk/site/guides/lib/exploitation/implicit_modeling.html +28 -0
- dimine_python_sdk/site/guides/lib/exploitation/laneway.html +28 -0
- dimine_python_sdk/site/guides/lib/io/SUMMARY.html +29 -0
- dimine_python_sdk/site/guides/lib/io/dmb_file.html +28 -0
- dimine_python_sdk/site/guides/lib/io/dmd_file.html +35 -4
- dimine_python_sdk/site/guides/lib/io/dmf_file.html +28 -0
- dimine_python_sdk/site/guides/lib/io/dmg_file.html +40 -6
- dimine_python_sdk/site/guides/lib/io/dmo_file.html +2335 -0
- dimine_python_sdk/site/guides/lib/io/dmt_file.html +29 -1
- dimine_python_sdk/site/guides/lib/io/file_conversion.html +28 -0
- dimine_python_sdk/site/guides/lib/prospecting/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/lib/prospecting/drill_db.html +28 -0
- dimine_python_sdk/site/guides/lib/prospecting/reserve_estimation.html +28 -0
- dimine_python_sdk/site/guides/lib/visualization/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/lib/visualization/visualization.html +28 -0
- dimine_python_sdk/site/guides/models/SUMMARY.html +28 -0
- dimine_python_sdk/site/guides/models/data_types.html +28 -0
- dimine_python_sdk/site/index.html +28 -0
- dimine_python_sdk/site/objects.inv +0 -0
- dimine_python_sdk/site/quickstart.html +28 -0
- dimine_python_sdk/site/reference/SUMMARY.html +29 -0
- dimine_python_sdk/site/reference/cli/commands/camera.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/convert.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/datatable.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/entity.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/feature.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/file.html +89 -63
- dimine_python_sdk/site/reference/cli/commands/geometry.html +35 -7
- dimine_python_sdk/site/reference/cli/commands/laneway.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/layer.html +28 -0
- dimine_python_sdk/site/reference/cli/commands/text.html +28 -0
- dimine_python_sdk/site/reference/conn/base_conn_client.html +50 -14
- dimine_python_sdk/site/reference/conn/conn_client.html +28 -0
- dimine_python_sdk/site/reference/lib/bridge.html +132 -82
- dimine_python_sdk/site/reference/lib/exploitation/api.html +28 -0
- dimine_python_sdk/site/reference/lib/exploitation/contour_modeling.html +28 -0
- dimine_python_sdk/site/reference/lib/exploitation/implicit_modeling.html +28 -0
- dimine_python_sdk/site/reference/lib/exploitation/lane_way.html +28 -0
- dimine_python_sdk/site/reference/lib/exploitation/models.html +28 -0
- dimine_python_sdk/site/reference/lib/io/dmb_file.html +28 -0
- dimine_python_sdk/site/reference/lib/io/dmd_file.html +28 -0
- dimine_python_sdk/site/reference/lib/io/dmf_file.html +28 -0
- dimine_python_sdk/site/reference/lib/io/dmg_file.html +28 -0
- dimine_python_sdk/site/reference/lib/io/dmo_file.html +3003 -0
- dimine_python_sdk/site/reference/lib/io/dmt_file.html +28 -0
- dimine_python_sdk/site/reference/lib/io/file_converter.html +32 -4
- dimine_python_sdk/site/reference/lib/io/models.html +28 -0
- dimine_python_sdk/site/reference/lib/native/algorithm.html +28 -0
- dimine_python_sdk/site/reference/lib/native/data_table.html +28 -0
- dimine_python_sdk/site/reference/lib/native/exploitation.html +28 -0
- dimine_python_sdk/site/reference/lib/native/geometry.html +28 -0
- dimine_python_sdk/site/reference/lib/native/io.html +132 -82
- dimine_python_sdk/site/reference/lib/native/models.html +28 -0
- dimine_python_sdk/site/reference/lib/native/prospecting.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/api.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/block_model.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/compositing.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/drill_db.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/ellipsoid.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/high_grade.html +28 -0
- dimine_python_sdk/site/reference/lib/prospecting/models.html +28 -0
- dimine_python_sdk/site/reference/lib/visualization/exceptions.html +28 -0
- dimine_python_sdk/site/reference/lib/visualization/models.html +28 -0
- dimine_python_sdk/site/reference/lib/visualization/tin_renderer.html +28 -0
- dimine_python_sdk/site/reference/logger.html +28 -0
- dimine_python_sdk/site/reference/models/conn.html +28 -0
- dimine_python_sdk/site/reference/models/errors.html +28 -0
- dimine_python_sdk/site/reference/models/types.html +28 -0
- dimine_python_sdk/site/search/search_index.json +1 -1
- dimine_python_sdk/site/sitemap.xml +90 -82
- dimine_python_sdk/site/sitemap.xml.gz +0 -0
- dimine_python_sdk/site/summary.html +28 -0
- {dimine_python_sdk-0.2.3.dist-info → dimine_python_sdk-0.2.5.dist-info}/METADATA +1 -1
- {dimine_python_sdk-0.2.3.dist-info → dimine_python_sdk-0.2.5.dist-info}/RECORD +111 -141
- {dimine_python_sdk-0.2.3.dist-info → dimine_python_sdk-0.2.5.dist-info}/top_level.txt +0 -2
- outline/build_dmd_from_scratch.py +0 -426
- outline/contour_extract.py +0 -450
- outline/contour_match.py +0 -1095
- outline/contour_pipeline.py +0 -586
- outline/contour_validate.py +0 -645
- outline/dmd_to_dmg.py +0 -164
- outline/drill_to_reserves.py +0 -825
- outline/ellipsoid_params.py +0 -106
- outline/implicit_modeling.py +0 -365
- outline/read_dmb.py +0 -200
- outline/read_dwg.py +0 -353
- outline/test_dmd_file.py +0 -322
- outline/test_dmg_to_segments.py +0 -317
- outline/test_extend_table.py +0 -193
- tests/conn_example.py +0 -70
- tests/conn_test.py +0 -269
- tests/test_conn_client_unit.py +0 -449
- tests/test_create_geometry_file_transfer.py +0 -289
- tests/test_csv_import_flow.py +0 -169
- tests/test_dmg_file.py +0 -467
- tests/test_dmt_file.py +0 -178
- tests/test_file_conversion.py +0 -544
- tests/test_high_grade_samples.py +0 -228
- tests/test_implicit_modeling.py +0 -284
- tests/test_laneway.py +0 -341
- tests/test_layer_isolation.py +0 -219
- tests/test_lib_file.py +0 -731
- tests/test_lib_refactor.py +0 -304
- tests/test_modeling.py +0 -338
- tests/test_native_unit.py +0 -353
- tests/test_prospecting_api.py +0 -1287
- tests/test_sample_compositing.py +0 -398
- tests/test_tin_renderer.py +0 -454
- tests/ws_client.py +0 -60
- tests/ws_server.py +0 -271
- {dimine_python_sdk-0.2.3.dist-info → dimine_python_sdk-0.2.5.dist-info}/WHEEL +0 -0
- {dimine_python_sdk-0.2.3.dist-info → dimine_python_sdk-0.2.5.dist-info}/entry_points.txt +0 -0
dimine_python_sdk/__init__.py
CHANGED
|
@@ -4,7 +4,7 @@ from pathlib import Path
|
|
|
4
4
|
from typing import Any
|
|
5
5
|
|
|
6
6
|
DOCS_PATH = Path(__file__).parent / "docs"
|
|
7
|
-
__VERSION__ = "0.2.
|
|
7
|
+
__VERSION__ = "0.2.5" # 由 build.bat 中的 generate_version.py 自动更新
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
_LAZY_IMPORTS: dict[str, Any] = {}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"""文件相关 CLI 命令。"""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
3
|
from dimine_python_sdk.cli.utils._utils import (
|
|
6
|
-
close_client,
|
|
7
4
|
get_client,
|
|
8
5
|
handle_sdk_error,
|
|
9
|
-
open_client,
|
|
10
6
|
output_error,
|
|
11
7
|
output_result,
|
|
12
8
|
raise_or_exit,
|
|
@@ -54,21 +50,20 @@ def cmd_file_save(fmt: str, output_path: str, file_id: str | None) -> None:
|
|
|
54
50
|
|
|
55
51
|
async def _run():
|
|
56
52
|
nonlocal file_id
|
|
53
|
+
client = await get_client()
|
|
57
54
|
if not file_id:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
async with open_client() as client:
|
|
71
|
-
await client.export_file(file_id=file_id, file_path=save_path)
|
|
55
|
+
files = await client.get_files()
|
|
56
|
+
if not files:
|
|
57
|
+
raise_or_exit("没有打开的文件。请先在 Dimine 中打开文件,或提供 --file-id 参数。", fmt)
|
|
58
|
+
if len(files) == 1:
|
|
59
|
+
file_id = files[0].id
|
|
60
|
+
else:
|
|
61
|
+
file_list = "\n".join([f" - id: {f.id}, name: {f.name}" for f in files])
|
|
62
|
+
raise_or_exit(
|
|
63
|
+
f"当前打开了 {len(files)} 个文件,请指定 --file-id:\n{file_list}",
|
|
64
|
+
fmt,
|
|
65
|
+
)
|
|
66
|
+
await client.export_file(file_id=file_id, file_path=save_path)
|
|
72
67
|
return {
|
|
73
68
|
"success": True,
|
|
74
69
|
"file_id": file_id,
|
|
@@ -77,7 +72,7 @@ def cmd_file_save(fmt: str, output_path: str, file_id: str | None) -> None:
|
|
|
77
72
|
}
|
|
78
73
|
|
|
79
74
|
try:
|
|
80
|
-
result =
|
|
75
|
+
result = run_cli_async(_run())
|
|
81
76
|
output_result(result, fmt)
|
|
82
77
|
except SystemExit:
|
|
83
78
|
raise
|
|
@@ -308,9 +308,9 @@ def _build_partial_geometry_objects(geometries: list) -> list:
|
|
|
308
308
|
return result
|
|
309
309
|
|
|
310
310
|
|
|
311
|
-
def
|
|
312
|
-
|
|
313
|
-
|
|
311
|
+
def cmd_geometry_list(fmt: str, file_id: str, layer_id: str | None,
|
|
312
|
+
entity_types: str | None = None, features: str | None = None,
|
|
313
|
+
with_geometry: bool = False) -> None:
|
|
314
314
|
"""获取图层中的几何体对象(需 Dimine 运行)。
|
|
315
315
|
|
|
316
316
|
默认只返回几何体的基础信息(id、file、layer、feature、type、color、properties)。
|
|
@@ -610,7 +610,7 @@ def register_commands(subparsers, format_parent) -> None:
|
|
|
610
610
|
|
|
611
611
|
|
|
612
612
|
COMMAND_HANDLERS = {
|
|
613
|
-
"geometry-list": lambda args:
|
|
613
|
+
"geometry-list": lambda args: cmd_geometry_list(args.format, args.file_id, args.layer_id,
|
|
614
614
|
args.entity_types, args.features,
|
|
615
615
|
args.with_geometry),
|
|
616
616
|
"geometry-create": lambda args: cmd_geometry_create(args.format, args.geometries,
|
|
@@ -26,17 +26,17 @@ if TYPE_CHECKING:
|
|
|
26
26
|
_SDK_AVAILABLE: bool | None = None # None = 尚未检查
|
|
27
27
|
_local_sdk_available: bool | None = None # None = 尚未检查
|
|
28
28
|
_import_error: str = ""
|
|
29
|
-
|
|
29
|
+
_open_client: Any = None # 惰性缓存的 open_client 函数(私有,勿直接 import)
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
def _check_remote_sdk() -> bool:
|
|
33
33
|
"""惰性检查远程 SDK 是否可用。首次调用时导入 conn 模块链并缓存结果。"""
|
|
34
|
-
global _SDK_AVAILABLE, _import_error,
|
|
34
|
+
global _SDK_AVAILABLE, _import_error, _open_client
|
|
35
35
|
if _SDK_AVAILABLE is not None:
|
|
36
36
|
return _SDK_AVAILABLE
|
|
37
37
|
try:
|
|
38
|
-
from dimine_python_sdk.conn.conn_client import open_client as
|
|
39
|
-
|
|
38
|
+
from dimine_python_sdk.conn.conn_client import open_client as _conn_open_client
|
|
39
|
+
_open_client = _conn_open_client
|
|
40
40
|
_SDK_AVAILABLE = True
|
|
41
41
|
except ImportError as e:
|
|
42
42
|
_import_error = str(e)
|
|
@@ -157,7 +157,7 @@ async def get_client()->ConnClient:
|
|
|
157
157
|
_client_loop_id = None
|
|
158
158
|
|
|
159
159
|
if _client_instance is None:
|
|
160
|
-
_client_ctx =
|
|
160
|
+
_client_ctx = _open_client()
|
|
161
161
|
_client_instance = await _client_ctx.__aenter__()
|
|
162
162
|
_client_loop_id = id(asyncio.get_running_loop())
|
|
163
163
|
return _client_instance
|
|
@@ -19,6 +19,7 @@ class BaseConnClient:
|
|
|
19
19
|
model_config = {"arbitrary_types_allowed": True}
|
|
20
20
|
|
|
21
21
|
url: Optional[str] = "ws://127.0.0.1:8000"
|
|
22
|
+
max_size: Optional[int] = None
|
|
22
23
|
is_connected: Optional[bool] = False
|
|
23
24
|
pending_requests: Dict[str, Tuple[asyncio.Future, Callable]] = field(default_factory=dict)
|
|
24
25
|
event_handlers: Dict[str, List[Callable]] = field(default_factory=dict)
|
|
@@ -106,7 +107,10 @@ class BaseConnClient:
|
|
|
106
107
|
|
|
107
108
|
async def connect(self)-> bool:
|
|
108
109
|
try:
|
|
109
|
-
|
|
110
|
+
connect_kwargs: Dict[str, Any] = {"close_timeout": 1}
|
|
111
|
+
if self.max_size is not None:
|
|
112
|
+
connect_kwargs["max_size"] = self.max_size
|
|
113
|
+
self.websocket = await websockets.connect(self.url, **connect_kwargs)
|
|
110
114
|
self.is_connected = True
|
|
111
115
|
logger.info("success connected to %s", self.url)
|
|
112
116
|
if self.receive_task is None or self.receive_task.done():
|
|
@@ -744,8 +744,8 @@ class ConnClient(BaseConnClient):
|
|
|
744
744
|
|
|
745
745
|
|
|
746
746
|
@asynccontextmanager
|
|
747
|
-
async def open_client(url:Optional[str]=None)->AsyncGenerator[ConnClient,None]:
|
|
748
|
-
client = ConnClient(url=url or "ws://127.0.0.1:8000")
|
|
747
|
+
async def open_client(url:Optional[str]=None, max_size:Optional[int]=None)->AsyncGenerator[ConnClient,None]:
|
|
748
|
+
client = ConnClient(url=url or "ws://127.0.0.1:8000", max_size=max_size)
|
|
749
749
|
await client.connect()
|
|
750
750
|
yield client
|
|
751
751
|
await client.close()
|
|
@@ -1,196 +1,198 @@
|
|
|
1
|
-
# DMD 钻孔数据库文件
|
|
2
|
-
|
|
3
|
-
`dimine_python_sdk.lib.io` 提供 `DmdFile` 类用于读写 Dimine 钻孔数据库文件(`.dmd`)。DMD 是钻孔数据库的主引用文件,内部引用孔口表、测斜表、岩性表、样品表及扩展表的 `.dmt` 子表文件。API 将各表映射为 `pandas.DataFrame`,支持加载、修改、保存全流程操作。
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 一、加载与保存
|
|
8
|
-
|
|
9
|
-
### 从文件加载
|
|
10
|
-
|
|
11
|
-
```python
|
|
12
|
-
from dimine_python_sdk.lib.io import DmdFile
|
|
13
|
-
|
|
14
|
-
dmd = DmdFile("钻孔数据.dmd")
|
|
15
|
-
print(dmd.collar.head())
|
|
16
|
-
print(dmd.info)
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### 保存到文件
|
|
20
|
-
|
|
21
|
-
```python
|
|
22
|
-
dmd.collar = modified_collar_df
|
|
23
|
-
dmd.save() # 覆盖原文件
|
|
24
|
-
dmd.save("output.dmd") # 另存为新文件
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### 创建空文件并保存
|
|
28
|
-
|
|
29
|
-
```python
|
|
30
|
-
dmd = DmdFile() # 空构造,可直接设表
|
|
31
|
-
dmd.collar = collar_df
|
|
32
|
-
dmd.survey = survey_df
|
|
33
|
-
dmd.lithology = lithology_df
|
|
34
|
-
dmd.sample = sample_df
|
|
35
|
-
dmd.save("新钻孔数据.dmd")
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### 上下文管理器
|
|
39
|
-
|
|
40
|
-
```python
|
|
41
|
-
from dimine_python_sdk.lib.io import dmd_conn
|
|
42
|
-
|
|
43
|
-
with dmd_conn("钻孔数据.dmd") as dmd:
|
|
44
|
-
print(dmd.info)
|
|
45
|
-
dmd.sample["CU"] = dmd.sample["CU"] * 1.1
|
|
46
|
-
dmd.save()
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## 二、核心表访问
|
|
52
|
-
|
|
53
|
-
DMD 文件包含四张核心表,均以 `pd.DataFrame` 形式读写:
|
|
54
|
-
|
|
55
|
-
### 孔口表(collar)
|
|
56
|
-
|
|
57
|
-
```python
|
|
58
|
-
dmd.collar.head()
|
|
59
|
-
# 工程号 横坐标 纵坐标 高程 勘探线 工程类型
|
|
60
|
-
# 0 ZK001 1000.0 2000.0 500.0 L1 坑内钻
|
|
61
|
-
|
|
62
|
-
dmd.collar = new_collar_df # 替换整个表(自动校验列名)
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 测斜表(survey)
|
|
66
|
-
|
|
67
|
-
```python
|
|
68
|
-
dmd.survey.head()
|
|
69
|
-
# 工程号 测斜深度 方位角 倾角
|
|
70
|
-
# 0 ZK001 0.0 45.0 90.0
|
|
71
|
-
|
|
72
|
-
dmd.survey = new_survey_df
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### 岩性表(lithology)
|
|
76
|
-
|
|
77
|
-
```python
|
|
78
|
-
dmd.lithology.head()
|
|
79
|
-
# 工程号 起始 结束 岩性编号
|
|
80
|
-
# 0 ZK001 0.0 10.0 花岗岩
|
|
81
|
-
|
|
82
|
-
dmd.lithology = new_lithology_df
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### 样品表(sample)
|
|
86
|
-
|
|
87
|
-
```python
|
|
88
|
-
dmd.sample.head()
|
|
89
|
-
# 工程号 样本编号 起始 结束 样长 CU
|
|
90
|
-
# 0 ZK001 S001 0.0 2.0 2.0 0.85
|
|
91
|
-
|
|
92
|
-
dmd.sample = new_sample_df
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
> **列名规范**:各表有必需的标准中文列名(孔口表需含 `工程号、横坐标、纵坐标、高程`,测斜表需含 `工程号、测斜深度、方位角、倾角` 等)。设置表数据时自动校验,缺列会抛出 `DmdError`。详细列名映射见 [钻孔数据库操作指南](../prospecting/drill_db.md#13-standard-column-mapping)。
|
|
96
|
-
|
|
97
|
-
### 统一表访问
|
|
98
|
-
|
|
99
|
-
```python
|
|
100
|
-
dmd["collar"] # 等价于 dmd.collar
|
|
101
|
-
dmd["survey"] # 等价于 dmd.survey
|
|
102
|
-
dmd["lithology"] # 等价于 dmd.lithology
|
|
103
|
-
dmd["sample"] # 等价于 dmd.sample
|
|
104
|
-
|
|
105
|
-
"collar" in dmd # True
|
|
106
|
-
len(dmd) # 表总数(含扩展表)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## 三、扩展表
|
|
112
|
-
|
|
113
|
-
DMD 支持附加自定义扩展表(如分层表),以 `NativeExtendTable` 形式管理:
|
|
114
|
-
|
|
115
|
-
```python
|
|
116
|
-
# 查看扩展表
|
|
117
|
-
for ext in dmd.extend_tables:
|
|
118
|
-
print(ext.table_name, ext.dmt_filename)
|
|
119
|
-
print(ext.df.head())
|
|
120
|
-
|
|
121
|
-
# 通过表名访问扩展表数据
|
|
122
|
-
ext_df = dmd["分层表"]
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
扩展表通过 `dmt_filename` 参数指定文件名(如 `分层表.dmt`),在 DMD 保存时一并写入伴随的 `.dmt` 文件。
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
## 四、文件信息
|
|
130
|
-
|
|
131
|
-
```python
|
|
132
|
-
dmd.name # "钻孔数据" — 文件名(不含扩展名)
|
|
133
|
-
dmd.file_path # "钻孔数据.dmd"
|
|
134
|
-
dmd.table_names # ["collar", "survey", "lithology", "sample", "分层表"]
|
|
135
|
-
dmd.ref_dict # .dmd 引用字典(只读)
|
|
136
|
-
|
|
137
|
-
dmd.info
|
|
138
|
-
# {
|
|
139
|
-
# "file": "钻孔数据.dmd",
|
|
140
|
-
# "name": "钻孔数据",
|
|
141
|
-
# "loaded": True,
|
|
142
|
-
# "tables": {
|
|
143
|
-
# "collar": {"columns": [...], "rows": 150},
|
|
144
|
-
# "survey": {"columns": [...], "rows": 300},
|
|
145
|
-
# "lithology": {"columns": [...], "rows": 80},
|
|
146
|
-
# "sample": {"columns": [...], "rows": 450},
|
|
147
|
-
# },
|
|
148
|
-
# "extend_table_count": 1,
|
|
149
|
-
# "extend_table_names": ["分层表"],
|
|
150
|
-
# "extend_tables": [...],
|
|
151
|
-
# }
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## 五、保存为 DMG
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
- `
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
- [
|
|
1
|
+
# DMD 钻孔数据库文件
|
|
2
|
+
|
|
3
|
+
`dimine_python_sdk.lib.io` 提供 `DmdFile` 类用于读写 Dimine 钻孔数据库文件(`.dmd`)。DMD 是钻孔数据库的主引用文件,内部引用孔口表、测斜表、岩性表、样品表及扩展表的 `.dmt` 子表文件。API 将各表映射为 `pandas.DataFrame`,支持加载、修改、保存全流程操作。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 一、加载与保存
|
|
8
|
+
|
|
9
|
+
### 从文件加载
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from dimine_python_sdk.lib.io import DmdFile
|
|
13
|
+
|
|
14
|
+
dmd = DmdFile("钻孔数据.dmd")
|
|
15
|
+
print(dmd.collar.head())
|
|
16
|
+
print(dmd.info)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 保存到文件
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
dmd.collar = modified_collar_df
|
|
23
|
+
dmd.save() # 覆盖原文件
|
|
24
|
+
dmd.save("output.dmd") # 另存为新文件
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 创建空文件并保存
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
dmd = DmdFile() # 空构造,可直接设表
|
|
31
|
+
dmd.collar = collar_df
|
|
32
|
+
dmd.survey = survey_df
|
|
33
|
+
dmd.lithology = lithology_df
|
|
34
|
+
dmd.sample = sample_df
|
|
35
|
+
dmd.save("新钻孔数据.dmd")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 上下文管理器
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from dimine_python_sdk.lib.io import dmd_conn
|
|
42
|
+
|
|
43
|
+
with dmd_conn("钻孔数据.dmd") as dmd:
|
|
44
|
+
print(dmd.info)
|
|
45
|
+
dmd.sample["CU"] = dmd.sample["CU"] * 1.1
|
|
46
|
+
dmd.save()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 二、核心表访问
|
|
52
|
+
|
|
53
|
+
DMD 文件包含四张核心表,均以 `pd.DataFrame` 形式读写:
|
|
54
|
+
|
|
55
|
+
### 孔口表(collar)
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
dmd.collar.head()
|
|
59
|
+
# 工程号 横坐标 纵坐标 高程 勘探线 工程类型
|
|
60
|
+
# 0 ZK001 1000.0 2000.0 500.0 L1 坑内钻
|
|
61
|
+
|
|
62
|
+
dmd.collar = new_collar_df # 替换整个表(自动校验列名)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 测斜表(survey)
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
dmd.survey.head()
|
|
69
|
+
# 工程号 测斜深度 方位角 倾角
|
|
70
|
+
# 0 ZK001 0.0 45.0 90.0
|
|
71
|
+
|
|
72
|
+
dmd.survey = new_survey_df
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 岩性表(lithology)
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
dmd.lithology.head()
|
|
79
|
+
# 工程号 起始 结束 岩性编号
|
|
80
|
+
# 0 ZK001 0.0 10.0 花岗岩
|
|
81
|
+
|
|
82
|
+
dmd.lithology = new_lithology_df
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 样品表(sample)
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
dmd.sample.head()
|
|
89
|
+
# 工程号 样本编号 起始 结束 样长 CU
|
|
90
|
+
# 0 ZK001 S001 0.0 2.0 2.0 0.85
|
|
91
|
+
|
|
92
|
+
dmd.sample = new_sample_df
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
> **列名规范**:各表有必需的标准中文列名(孔口表需含 `工程号、横坐标、纵坐标、高程`,测斜表需含 `工程号、测斜深度、方位角、倾角` 等)。设置表数据时自动校验,缺列会抛出 `DmdError`。详细列名映射见 [钻孔数据库操作指南](../prospecting/drill_db.md#13-standard-column-mapping)。
|
|
96
|
+
|
|
97
|
+
### 统一表访问
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
dmd["collar"] # 等价于 dmd.collar
|
|
101
|
+
dmd["survey"] # 等价于 dmd.survey
|
|
102
|
+
dmd["lithology"] # 等价于 dmd.lithology
|
|
103
|
+
dmd["sample"] # 等价于 dmd.sample
|
|
104
|
+
|
|
105
|
+
"collar" in dmd # True
|
|
106
|
+
len(dmd) # 表总数(含扩展表)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 三、扩展表
|
|
112
|
+
|
|
113
|
+
DMD 支持附加自定义扩展表(如分层表),以 `NativeExtendTable` 形式管理:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# 查看扩展表
|
|
117
|
+
for ext in dmd.extend_tables:
|
|
118
|
+
print(ext.table_name, ext.dmt_filename)
|
|
119
|
+
print(ext.df.head())
|
|
120
|
+
|
|
121
|
+
# 通过表名访问扩展表数据
|
|
122
|
+
ext_df = dmd["分层表"]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
扩展表通过 `dmt_filename` 参数指定文件名(如 `分层表.dmt`),在 DMD 保存时一并写入伴随的 `.dmt` 文件。
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 四、文件信息
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
dmd.name # "钻孔数据" — 文件名(不含扩展名)
|
|
133
|
+
dmd.file_path # "钻孔数据.dmd"
|
|
134
|
+
dmd.table_names # ["collar", "survey", "lithology", "sample", "分层表"]
|
|
135
|
+
dmd.ref_dict # .dmd 引用字典(只读)
|
|
136
|
+
|
|
137
|
+
dmd.info
|
|
138
|
+
# {
|
|
139
|
+
# "file": "钻孔数据.dmd",
|
|
140
|
+
# "name": "钻孔数据",
|
|
141
|
+
# "loaded": True,
|
|
142
|
+
# "tables": {
|
|
143
|
+
# "collar": {"columns": [...], "rows": 150},
|
|
144
|
+
# "survey": {"columns": [...], "rows": 300},
|
|
145
|
+
# "lithology": {"columns": [...], "rows": 80},
|
|
146
|
+
# "sample": {"columns": [...], "rows": 450},
|
|
147
|
+
# },
|
|
148
|
+
# "extend_table_count": 1,
|
|
149
|
+
# "extend_table_names": ["分层表"],
|
|
150
|
+
# "extend_tables": [...],
|
|
151
|
+
# }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 五、保存为 DMG(可选)
|
|
157
|
+
|
|
158
|
+
> **注意**:`.dmd` 文件可以直接在 Dimine 中打开并展示三维钻孔,无需转换。DMG 是另一种可视化格式,适用于需要特殊展示效果的场景。
|
|
159
|
+
|
|
160
|
+
可将钻孔数据库打包为 DMG 格式:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
dmd.save_as_dmg("output.dmg")
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
> 更多 DMG 操作见 [DMG 钻孔可视化指南](dmg_file.md)。
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## 六、异常处理
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from dimine_python_sdk.lib.io import DmdError, DmdLoadError, DmdSaveError
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
dmd = DmdFile("not_exist.dmd")
|
|
177
|
+
except DmdLoadError as e:
|
|
178
|
+
print(f"加载失败: {e}")
|
|
179
|
+
|
|
180
|
+
try:
|
|
181
|
+
dmd = DmdFile()
|
|
182
|
+
dmd.save() # 未指定路径
|
|
183
|
+
except DmdSaveError as e:
|
|
184
|
+
print(f"保存失败: {e}")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
异常层次:
|
|
188
|
+
- `DmdError(RuntimeError)` — 基类
|
|
189
|
+
- `DmdLoadError(DmdError)` — 加载失败
|
|
190
|
+
- `DmdSaveError(DmdError)` — 保存失败
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 参考链接
|
|
195
|
+
|
|
196
|
+
- [钻孔数据库操作指南](../prospecting/drill_db.md) — 完整的钻孔数据库使用场景(CSV 导入、列名映射、组合样、特高品位处理)
|
|
197
|
+
- [DMG 钻孔可视化](dmg_file.md) — 将 DMD 转为三维可视化格式
|
|
198
|
+
- [API 参考:dmd_file](../../../reference/lib/io/dmd_file.md)
|