dmd_file
DMD 钻孔数据库文件操作
提供 DmdFile 类直接打开、修改、保存 .dmd 钻孔数据库文件。 遵循 io 模块统一接口模式:load / save / close / 上下文管理器。
禁止 import DmPyBindInterface;通过 lib.native.prospecting 间接使用 C++ 扩展。
DmdError
Bases: RuntimeError
DMD 操作异常基类
Source code in dimine_python_sdk\lib\io\dmd_file.py
40 41 42 | |
DmdFile
DMD 钻孔数据库文件管理器。
DMD 文件是 Dimine 钻孔数据库的主引用文件(单行 CDataTable), 包含孔口表、测斜表、岩性表、样品表及扩展表的列名映射和 伴随 .dmt 文件路径。实际数据存储在伴随的 .dmt 子表文件中。
用法::
# 从文件加载
dmd = DmdFile("钻孔数据.dmd")
print(dmd.collar.head())
dmd.survey = new_survey_df
dmd.save()
# 上下文管理器
with dmd_conn("钻孔数据.dmd") as dmd:
print(dmd.info)
for name in dmd.table_names:
print(name, len(dmd[name]))
# 创建空文件并保存
dmd = DmdFile()
dmd.collar = collar_df
dmd.survey = survey_df
dmd.save("output.dmd")
Source code in dimine_python_sdk\lib\io\dmd_file.py
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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
collar
property
writable
钻孔孔口表(pd.DataFrame)
extend_tables
property
writable
扩展表列表。
每项为 NativeExtendTable: - df: pd.DataFrame 扩展表数据(保留 DMT 原始列名) - dmt_filename: str .dmt 文件名(如 "分层表.dmt") - field_list: str 字段元数据(4 个逗号分隔值,用于 roundtrip) - table_name: str 表名(优先 display_title,其次 dmt 文件名) - hole_id_column: str|None 钻孔编号对应列名(field_list[0]) - from_column: str|None 起始深度对应列名(field_list[1]) - to_column: str|None 结束深度对应列名(field_list[2]) - display_title: str|None 标题名称(field_list[3])
file_path
property
当前文件路径
info
property
DMD 文件摘要信息
lithology
property
writable
钻孔岩性表(pd.DataFrame)
name
property
文件名(不含扩展名)
ref_dict
property
钻孔数据库引用字典(.dmd 文件内容,只读)
sample
property
writable
钻孔样品表(pd.DataFrame)
survey
property
writable
钻孔测斜表(pd.DataFrame)
table_names
property
所有表名列表(含扩展表)
__bool__()
已加载返回 True,已关闭返回 False
Source code in dimine_python_sdk\lib\io\dmd_file.py
582 583 584 | |
__contains__(table_name)
检查表名是否存在
Source code in dimine_python_sdk\lib\io\dmd_file.py
590 591 592 | |
__getitem__(table_name)
统一表访问:dmd['collar'], dmd['survey'], dmd['lithology'], dmd['sample']
Source code in dimine_python_sdk\lib\io\dmd_file.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | |
__iter__()
按表名迭代
Source code in dimine_python_sdk\lib\io\dmd_file.py
594 595 596 | |
__len__()
返回表总数(含扩展表)
Source code in dimine_python_sdk\lib\io\dmd_file.py
586 587 588 | |
close()
释放资源,解除文件占用
Source code in dimine_python_sdk\lib\io\dmd_file.py
343 344 345 346 347 348 349 | |
load(file_path)
加载 .dmd 文件及其伴随 .dmt 子表。
临时创建 DrillSession 读取全部表数据到缓存后立即关闭, 不持有持久化的 C++ session。
Returns:
| Type | Description |
|---|---|
'DmdFile'
|
self,支持链式调用 |
Raises:
| Type | Description |
|---|---|
DmdLoadError
|
文件不存在或加载失败 |
Source code in dimine_python_sdk\lib\io\dmd_file.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
save(output_path=None)
保存钻孔数据库(.dmd 引用文件 + 伴随 .dmt 子表)。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Optional[Union[str, Path]]
|
保存路径。为 None 时使用加载时的路径。 |
None
|
Raises:
| Type | Description |
|---|---|
DmdSaveError
|
未指定保存路径或保存失败 |
Source code in dimine_python_sdk\lib\io\dmd_file.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
save_as_dmg(output_path)
保存为 .dmg 可视化格式。
通过临时 .dmd 文件中转:先将当前表数据保存为临时 .dmd, 再用临时 DrillSession 加载并转换为 .dmg。
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Union[str, Path]
|
目标 .dmg 文件路径(无扩展名时自动补全) |
required |
Raises:
| Type | Description |
|---|---|
DmdSaveError
|
保存失败 |
Source code in dimine_python_sdk\lib\io\dmd_file.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
DmdLoadError
Bases: DmdError
加载 .dmd 文件失败
Source code in dimine_python_sdk\lib\io\dmd_file.py
45 46 47 | |
DmdSaveError
Bases: DmdError
保存 .dmd 文件失败
Source code in dimine_python_sdk\lib\io\dmd_file.py
50 51 52 | |
dmd_conn(file_path=None)
DMD 文件连接上下文管理器
Usage::
with dmd_conn("钻孔数据.dmd") as dmd:
print(dmd.collar.head())
Source code in dimine_python_sdk\lib\io\dmd_file.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 | |