Skip to content

drill

钻孔数据库相关 CLI 命令(本地操作,无需 Dimine 运行)。

cmd_drill_highgrade(fmt, input_path, grade_field, process_mode, average_multiple, frequency, replace_method, assign_value, result_field)

高品位异常值处理(本地操作)。

Source code in dimine_python_sdk\cli\commands\drill.py
144
145
146
147
148
149
150
151
152
153
154
155
156
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
def cmd_drill_highgrade(fmt: str, input_path: str, grade_field: str,
                         process_mode: int, average_multiple: float,
                         frequency: float, replace_method: int,
                         assign_value: float, result_field: str) -> None:
    """高品位异常值处理(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    process_mode = safe_int(process_mode)
    average_multiple = safe_float(average_multiple)
    frequency = safe_float(frequency)
    replace_method = safe_int(replace_method)
    assign_value = safe_float(assign_value)

    from dimine_python_sdk.lib.prospecting.drill_db import DrillDBManager
    from dimine_python_sdk.lib.prospecting.models import HighGradeProcessParam

    try:
        input_file = resolve_path(input_path)
        hg_param = HighGradeProcessParam(
            input_file=input_path,
            grade_field=grade_field,
            process_mode=process_mode,
            average_multiple=average_multiple,
            frequency=frequency,
            replace_method=replace_method,
            assign_value=assign_value,
            result_field=result_field,
        )
        db = DrillDBManager(input_file)
        result = db.process_high_grade(hg_param)
        output_result({
            "success": True,
            "input": input_file,
            "result": str(result),
            "message": "高品位处理完成",
        }, fmt)
    except Exception as e:
        output_error(f"高品位处理失败: {e}", fmt)

cmd_drill_info(fmt, file, table=None)

加载并检查钻孔数据库文件(本地操作)。

Source code in dimine_python_sdk\cli\commands\drill.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def cmd_drill_info(fmt: str, file: str, table: str | None = None) -> None:
    """加载并检查钻孔数据库文件(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    file_path = resolve_path(file)

    from dimine_python_sdk.lib.prospecting.drill_db import DrillDBManager

    try:
        db = DrillDBManager(file_path)

        result = {"file": file_path}

        # 基本信息
        if hasattr(db, "info"):
            info = db.info if isinstance(db.info, dict) else {}
            result.update(info)
        else:
            if hasattr(db, "drill_count"):
                result["drill_count"] = db.drill_count
            if hasattr(db, "total_length"):
                result["total_length"] = db.total_length

        # 三大表(DmDataTable 实例)
        for tbl_name in ["collar", "survey", "lithology"]:
            tbl_data = getattr(db, tbl_name, None)
            if tbl_data is None:
                continue
            try:
                columns = tbl_data.columns if hasattr(tbl_data, "columns") else []
                info = {
                    "record_count": len(tbl_data),
                    "fields": columns,
                }
                if table == tbl_name:
                    records = []
                    for row in tbl_data:
                        if hasattr(row, "to_dict"):
                            records.append(row.to_dict())
                        else:
                            records.append(str(row))
                    info["records"] = records
                result[f"{tbl_name}_table"] = info
            except Exception:
                pass

        output_result(result, fmt)
    except Exception as e:
        output_error(f"加载钻孔数据库失败: {e}", fmt)

cmd_drill_sample_combine(fmt, input_path, combine_length, combine_percent, output_path)

样品长度组合处理(本地操作)。

Source code in dimine_python_sdk\cli\commands\drill.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def cmd_drill_sample_combine(fmt: str, input_path: str, combine_length: float,
                              combine_percent: float, output_path: str) -> None:
    """样品长度组合处理(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    combine_length = safe_float(combine_length)
    combine_percent = safe_float(combine_percent)

    from dimine_python_sdk.lib.prospecting.drill_db import DrillDBManager
    from dimine_python_sdk.lib.prospecting.models import SampleLengthCombineParam

    try:
        input_file = resolve_path(input_path)
        output_file = resolve_path(output_path)
        combine_param = SampleLengthCombineParam(
            input_file=input_path,
            combine_length=combine_length,
            combine_percent=combine_percent,
            output_file=output_path,
        )
        db = DrillDBManager(input_file)
        result = db.process_samples(combine_param)
        output_result({
            "success": True,
            "input": input_file,
            "output": output_file,
            "result": str(result),
            "message": "样品组合完成",
        }, fmt)
    except Exception as e:
        output_error(f"样品组合失败: {e}", fmt)

cmd_drill_step_combine(fmt, input_path, step_height, start_height, end_height, calculate_model, low_dip, output_path)

台阶/分段组合处理(本地操作)。

Source code in dimine_python_sdk\cli\commands\drill.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
def cmd_drill_step_combine(fmt: str, input_path: str, step_height: float,
                            start_height: float, end_height: float,
                            calculate_model: int, low_dip: float,
                            output_path: str) -> None:
    """台阶/分段组合处理(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    step_height = safe_float(step_height)
    start_height = safe_float(start_height)
    end_height = safe_float(end_height)
    calculate_model = safe_int(calculate_model)
    low_dip = safe_float(low_dip)

    from dimine_python_sdk.lib.prospecting.drill_db import DrillDBManager
    from dimine_python_sdk.lib.prospecting.models import StepCombineParam

    try:
        input_file = resolve_path(input_path)
        output_file = resolve_path(output_path)
        step_param = StepCombineParam(
            input_file=input_path,
            step_height=step_height,
            start_height=start_height,
            end_height=end_height,
            calculate_model=calculate_model,
            low_dip=low_dip,
            output_file=output_path,
        )
        db = DrillDBManager(input_file)
        result = db.process_steps(step_param)
        output_result({
            "success": True,
            "input": input_file,
            "output": output_file,
            "result": str(result),
            "message": "台阶组合完成",
        }, fmt)
    except Exception as e:
        output_error(f"台阶组合失败: {e}", fmt)

register_commands(subparsers, format_parent)

向 subparsers 注册钻孔相关子命令。

Source code in dimine_python_sdk\cli\commands\drill.py
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
def register_commands(subparsers, format_parent) -> None:
    """向 subparsers 注册钻孔相关子命令。"""
    p = subparsers.add_parser("drill-info", parents=[format_parent], help="检查钻孔数据库文件")
    p.add_argument("--file", required=True, help="钻孔 .dmf 文件路径")
    p.add_argument("--table", default=None, choices=["collar", "survey", "lithology"],
                   help="显示指定表的记录")

    p = subparsers.add_parser("drill-sample-combine", parents=[format_parent], help="样品长度组合")
    p.add_argument("--input", required=True, dest="input_path", help="输入样品文件路径")
    p.add_argument("--combine-length", type=float, required=True, help="组合长度,必须 > 0")
    p.add_argument("--combine-percent", type=float, required=True, help="组合百分比,0-1 之间(如 1.0 表示 100%)")
    p.add_argument("--output", required=True, dest="output_path", help="输出文件路径")

    p = subparsers.add_parser("drill-step-combine", parents=[format_parent], help="台阶/分段组合")
    p.add_argument("--input", required=True, dest="input_path", help="输入样品文件路径")
    p.add_argument("--step-height", type=float, required=True, help="台阶高度")
    p.add_argument("--start-height", type=float, required=True, help="起始高程")
    p.add_argument("--end-height", type=float, required=True, help="结束高程")
    p.add_argument("--calculate-model", type=int, default=0, help="计算方式(默认 0)")
    p.add_argument("--low-dip", type=float, default=5.0, help="忽略最小倾角(默认 5.0)")
    p.add_argument("--output", required=True, dest="output_path", help="输出文件路径")

    p = subparsers.add_parser("drill-highgrade", parents=[format_parent], help="高品位异常值处理")
    p.add_argument("--input", required=True, dest="input_path", help="输入样品文件路径")
    p.add_argument("--grade-field", required=True, help="品位字段名(如 Cu)")
    p.add_argument("--process-mode", type=int, default=0, help="处理模式: 0=国内标准")
    p.add_argument("--average-multiple", type=float, default=5.0, help="平均倍数(默认 5.0)")
    p.add_argument("--frequency", type=float, default=0.1, help="频率阈值(默认 0.1)")
    p.add_argument("--replace-method", type=int, default=1, choices=[0, 1, 2, 3, 4, 5],
                   help="替换方式: 0=剔除法 1=给定值 2=相邻样品平均值 3=矿体平均品位法 4=单一工程法 5=截止品位法")
    p.add_argument("--assign-value", type=float, default=0.0, help="替换给定值(replace-method=1 时生效)")
    p.add_argument("--result-field", required=True, help="结果字段名")