Skip to content

block

块模型相关 CLI 命令(本地操作,无需 Dimine 运行)。

cmd_block_constrain(fmt, block_file, constraint_type, constraint_file, output_path)

创建块模型约束 .dmc 文件(本地操作)。

Source code in dimine_python_sdk\cli\commands\block.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def cmd_block_constrain(fmt: str, block_file: str, constraint_type: str,
                         constraint_file: str, output_path: str) -> None:
    """创建块模型约束 .dmc 文件(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    block_path = resolve_path(block_file)
    output_file = resolve_path(output_path)

    from dimine_python_sdk.lib.prospecting import EntityConstraint, DmBlockData

    try:
        constraint = EntityConstraint(type=constraint_type, file=constraint_file)
        block = DmBlockData(block_path)
        block.block_constrain_to_dmc_file(constraint, output_file)
        output_result({
            "success": True,
            "block_file": block_path,
            "output": output_file,
            "message": f"约束文件已创建: {output_file}",
        }, fmt)
    except Exception as e:
        output_error(f"创建约束文件失败: {e}", fmt)

cmd_block_create(fmt, output_path, origin, rotate, size, length)

创建空块模型(本地操作)。

Source code in dimine_python_sdk\cli\commands\block.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def cmd_block_create(fmt: str, output_path: str, origin: str, rotate: str,
                      size: str, length: str) -> None:
    """创建空块模型(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    from dimine_python_sdk.lib.reserve.block_data import DmBlockData, CreateBlockModelParams

    try:
        origin_vals = parse_point3d(origin)
        rotate_vals = parse_point3d(rotate)
        size_vals = parse_point3d(size)
        length_vals = parse_point3d(length)
    except ValueError as e:
        output_error(str(e), fmt)

    try:
        file_name = resolve_path(output_path)
        params_data = {
            "file_name": output_path,
            "origin_x": origin_vals[0], "origin_y": origin_vals[1], "origin_z": origin_vals[2],
            "rotate_x": rotate_vals[0], "rotate_y": rotate_vals[1], "rotate_z": rotate_vals[2],
            "size_x": size_vals[0], "size_y": size_vals[1], "size_z": size_vals[2],
            "length_x": length_vals[0], "length_y": length_vals[1], "length_z": length_vals[2],
        }
        mt_param = CreateBlockModelParams(**params_data)
        result = DmBlockData.create_block_model(mt_param)
        output_result({
            "success": True,
            "file": file_name,
            "result": str(result),
            "message": f"块模型已创建: {file_name}",
        }, fmt)
    except Exception as e:
        output_error(f"创建块模型失败: {e}", fmt)

cmd_block_eval_idw(fmt, block_file, constraint_type, constraint_file, field_name, power, search_radius, min_samples, max_samples)

反距离加权估计(本地操作)。

Source code in dimine_python_sdk\cli\commands\block.py
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
142
def cmd_block_eval_idw(fmt: str, block_file: str, constraint_type: str,
                        constraint_file: str, field_name: str, power: float,
                        search_radius: float, min_samples: int,
                        max_samples: int) -> None:
    """反距离加权估计(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    block_path = resolve_path(block_file)
    power = safe_float(power)
    search_radius = safe_float(search_radius)
    min_samples = safe_int(min_samples)
    max_samples = safe_int(max_samples)

    from dimine_python_sdk.lib.reserve.block_data import EntityConstraint
    from dimine_python_sdk.lib.reserve.evaluator import BlockModelDistancePowerParams, BlockModelEvaluator

    try:
        constraint_obj = EntityConstraint(type=constraint_type, file=constraint_file)
        idw_params = BlockModelDistancePowerParams(
            field_name=field_name,
            power=power,
            search_radius=search_radius,
            min_samples=min_samples,
            max_samples=max_samples,
        )
        evaluator = BlockModelEvaluator(block_path)
        result = evaluator.distance_power_evaluation(constraint_obj, idw_params)
        output_result({
            "success": True,
            "block_file": block_path,
            "method": "idw",
            "result": str(result),
            "message": "IDW 估计完成",
        }, fmt)
    except Exception as e:
        output_error(f"IDW 估计失败: {e}", fmt)

cmd_block_eval_kriging(fmt, block_file, constraint_type, constraint_file, field_name, variogram_model, nugget, sill, variogram_range, search_radius, min_samples, max_samples)

克里金估计(本地操作)。

Source code in dimine_python_sdk\cli\commands\block.py
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
184
185
186
187
188
def cmd_block_eval_kriging(fmt: str, block_file: str, constraint_type: str,
                            constraint_file: str, field_name: str,
                            variogram_model: str, nugget: float, sill: float,
                            variogram_range: float, search_radius: float,
                            min_samples: int, max_samples: int) -> None:
    """克里金估计(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    block_path = resolve_path(block_file)
    nugget = safe_float(nugget)
    sill = safe_float(sill)
    variogram_range = safe_float(variogram_range)
    search_radius = safe_float(search_radius)
    min_samples = safe_int(min_samples)
    max_samples = safe_int(max_samples)

    from dimine_python_sdk.lib.reserve.block_data import EntityConstraint
    from dimine_python_sdk.lib.reserve.evaluator import BlockModelEvaluator, BlockModelKrigingParams

    try:
        constraint_obj = EntityConstraint(type=constraint_type, file=constraint_file)
        kriging_params = BlockModelKrigingParams(
            field_name=field_name,
            variogram_model=variogram_model,
            nugget=nugget,
            sill=sill,
            range=variogram_range,
            search_radius=search_radius,
            min_samples=min_samples,
            max_samples=max_samples,
        )
        evaluator = BlockModelEvaluator(block_path)
        result = evaluator.kriging_evaluation(constraint_obj, kriging_params)
        output_result({
            "success": True,
            "block_file": block_path,
            "method": "kriging",
            "result": str(result),
            "message": "Kriging 估计完成",
        }, fmt)
    except Exception as e:
        output_error(f"Kriging 估计失败: {e}", fmt)

cmd_block_info(fmt, file)

检查块模型文件(本地操作)。

Source code in dimine_python_sdk\cli\commands\block.py
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
def cmd_block_info(fmt: str, file: str) -> None:
    """检查块模型文件(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    file_path = resolve_path(file)

    from dimine_python_sdk.lib.reserve.block_data import DmBlockData

    try:
        block = DmBlockData(file_path)
        result = {
            "file": file_path,
        }
        for attr in ["origin", "xyz_length", "max_level", "min_size", "rotation",
                      "field_definitions", "total_block_count"]:
            if hasattr(block, attr):
                val = getattr(block, attr)
                if isinstance(val, list) and len(val) > 0 and hasattr(val[0], "tolist"):
                    val = val.tolist() if hasattr(val, "tolist") else val
                result[attr] = val
        output_result(result, fmt)
    except Exception as e:
        output_error(f"加载块模型失败: {e}", fmt)

cmd_block_reserves(fmt, block_file, constraint_type, constraint_file, grade_field, density, cutoff_grade)

储量/吨位计算(本地操作)。

Source code in dimine_python_sdk\cli\commands\block.py
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
def cmd_block_reserves(fmt: str, block_file: str, constraint_type: str,
                        constraint_file: str, grade_field: str, density: float,
                        cutoff_grade: float) -> None:
    """储量/吨位计算(本地操作)。"""
    err = require_local_sdk()
    if err:
        output_error(err, fmt)

    block_path = resolve_path(block_file)
    density = safe_float(density)
    cutoff_grade = safe_float(cutoff_grade)

    from dimine_python_sdk.lib.reserve.block_data import EntityConstraint
    from dimine_python_sdk.lib.reserve.evaluator import BlockModelEvaluator, ReservesCalculateParam

    try:
        constraint_obj = EntityConstraint(type=constraint_type, file=constraint_file)
        reserves_params = ReservesCalculateParam(
            grade_field=grade_field,
            density=density,
            cutoff_grade=cutoff_grade,
        )
        evaluator = BlockModelEvaluator(block_path)
        result = evaluator.calculate_reserves(constraint_obj, reserves_params)
        output_result({
            "success": True,
            "block_file": block_path,
            "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\block.py
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
def register_commands(subparsers, format_parent) -> None:
    """向 subparsers 注册块模型相关子命令。"""
    p = subparsers.add_parser("block-info", parents=[format_parent], help="检查块模型文件")
    p.add_argument("--file", required=True, help="块模型文件路径")

    p = subparsers.add_parser("block-create", parents=[format_parent], help="创建空块模型")
    p.add_argument("--output", required=True, dest="output_path", help="输出文件路径(如 D:\\项目\\块模型.dmb)")
    p.add_argument("--origin", required=True, help="原点坐标 x,y,z")
    p.add_argument("--rotate", default="0,0,0", help="旋转角度 x,y,z(默认 0,0,0)")
    p.add_argument("--size", required=True, help="块尺寸 x,y,z")
    p.add_argument("--length", required=True, help="模型各方向长度 x,y,z")

    p = subparsers.add_parser("block-constrain", parents=[format_parent], help="创建块模型约束文件")
    p.add_argument("--block-file", required=True, help="块模型文件路径")
    p.add_argument("--constraint-type", required=True, help="约束类型(如 dtm)")
    p.add_argument("--constraint-file", required=True, help="约束文件路径")
    p.add_argument("--output", required=True, dest="output_path", help="输出 .dmc 文件路径")

    p = subparsers.add_parser("block-eval-idw", parents=[format_parent], help="反距离加权估计")
    p.add_argument("--block-file", required=True, help="块模型文件路径")
    p.add_argument("--constraint-type", required=True, help="约束类型(如 dmc)")
    p.add_argument("--constraint-file", required=True, help="约束文件路径(.dmc)")
    p.add_argument("--field-name", required=True, help="估算字段名")
    p.add_argument("--power", type=float, required=True, help="距离幂次(通常 2)")
    p.add_argument("--search-radius", type=float, required=True, help="搜索半径")
    p.add_argument("--min-samples", type=int, required=True, help="最少样品数")
    p.add_argument("--max-samples", type=int, required=True, help="最多样品数")

    p = subparsers.add_parser("block-eval-kriging", parents=[format_parent], help="克里金估计")
    p.add_argument("--block-file", required=True, help="块模型文件路径")
    p.add_argument("--constraint-type", required=True, help="约束类型(如 dmc)")
    p.add_argument("--constraint-file", required=True, help="约束文件路径(.dmc)")
    p.add_argument("--field-name", required=True, help="估算字段名")
    p.add_argument("--variogram-model", required=True, choices=["spherical", "exponential", "gaussian"],
                   help="变异函数模型")
    p.add_argument("--nugget", type=float, required=True, help="块金值")
    p.add_argument("--sill", type=float, required=True, help="基台值")
    p.add_argument("--range", type=float, required=True, dest="variogram_range", help="变程")
    p.add_argument("--search-radius", type=float, required=True, help="搜索半径")
    p.add_argument("--min-samples", type=int, required=True, help="最少样品数")
    p.add_argument("--max-samples", type=int, required=True, help="最多样品数")

    p = subparsers.add_parser("block-reserves", parents=[format_parent], help="储量/吨位计算")
    p.add_argument("--block-file", required=True, help="块模型文件路径")
    p.add_argument("--constraint-type", required=True, help="约束类型(如 dmc)")
    p.add_argument("--constraint-file", required=True, help="约束文件路径(.dmc)")
    p.add_argument("--grade-field", required=True, help="品位字段名")
    p.add_argument("--density", type=float, required=True, help="矿石密度")
    p.add_argument("--cutoff-grade", type=float, required=True, help="边界品位")