Skip to content

block_model

业务层:块段模型创建、估值与储量计算

直接调用 native 层 dimine_python_sdk.lib.native.prospecting, 不经过 _adapter

职责:Pydantic 参数模型序列化、异常翻译、用户友好的 API

.. note::

DMB 文件的读取/遍历请使用 ``dimine_python_sdk.lib.io.DmbFile``。

BlockDataError

Bases: RuntimeError

块段模型操作异常基类

Source code in dimine_python_sdk\lib\prospecting\block_model.py
48
49
50
class BlockDataError(RuntimeError):
    """块段模型操作异常基类"""
    pass

BlockModelCreateError

Bases: BlockDataError

创建块段模型失败

Source code in dimine_python_sdk\lib\prospecting\block_model.py
53
54
55
class BlockModelCreateError(BlockDataError):
    """创建块段模型失败"""
    pass

BlockModelEvaluationError

Bases: BlockDataError

块段模型估值失败

Source code in dimine_python_sdk\lib\prospecting\block_model.py
58
59
60
61
62
class BlockModelEvaluationError(BlockDataError):
    """块段模型估值失败"""
    def __init__(self, message: str, response: dict | None = None):
        super().__init__(message)
        self.response = response

BlockModelEvaluator

块段模型估值与储量计算器

所有方法接受块段模型文件路径,失败时抛出自定义异常(不返回 tuple):

evaluator = BlockModelEvaluator()
result = evaluator.distance_power_evaluation(
    "model.dmb", constraint, idw_params
)
# result -> {"success": True, "message": "..."}

Raises:

Type Description
BlockModelEvaluationError

估值失败

Source code in dimine_python_sdk\lib\prospecting\block_model.py
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
class BlockModelEvaluator:
    """
    块段模型估值与储量计算器

    所有方法接受块段模型文件路径,失败时抛出自定义异常(不返回 tuple):

        evaluator = BlockModelEvaluator()
        result = evaluator.distance_power_evaluation(
            "model.dmb", constraint, idw_params
        )
        # result -> {"success": True, "message": "..."}

    Raises:
        BlockModelEvaluationError: 估值失败
    """

    @staticmethod
    def distance_power_evaluation(
        block_model_file: str,
        constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
        evaluation_params: BlockModelDistancePowerParams,
        overwrite_result: bool = True,
    ) -> DistancePowerEvaluationResult:
        """距离幂估值计算

        Returns:
            DistancePowerEvaluationResult: 估值结果对象,包含 success / message / elements
        """
        constraint_json = _serialize_constraints(constraint_params)
        evaluation_json = json.dumps(evaluation_params.to_dict(), ensure_ascii=False)
        try:
            result = _native_distance_power_evaluation(
                block_model_file, constraint_json, evaluation_json, overwrite_result
            )
            logger.info(f"距离幂估值结果: {result}")
            message = result.get("message", "")
            elements = _parse_evaluation_message(message)
            return DistancePowerEvaluationResult(
                success=True,
                elements=elements,
            )
        except Exception as exc:
            raise BlockModelEvaluationError(f"距离幂估值失败: {exc}") from exc

    @staticmethod
    def kriging_evaluation(
        block_model_file: str,
        constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
        evaluation_params: BlockModelKrigingParams,
        overwrite_result: bool = True,
    ) -> dict:
        """克里格估值计算

        克里格算法底层仅支持单元素估值,当 variables 包含多个元素(逗号分隔)时,
        自动按元素拆分,依次调用底层接口实现多元素估值效果。

        """
        constraint_json = _serialize_constraints(constraint_params)
        params_dict = evaluation_params.to_dict()

        # 估值变量:直接使用 list[str],逐个调用克里格估值
        elements = evaluation_params.variables
        if not elements:
            raise BlockModelEvaluationError("克里格估值失败: variables 不能为空")

        results = []
        for element in elements:
            params_dict["variable"] = element
            evaluation_json = json.dumps(params_dict, ensure_ascii=False)
            try:
                result = _native_kriging_evaluation(
                    block_model_file, constraint_json, evaluation_json, overwrite_result
                )
                logger.info(f"克里格估值结果(元素={element}): {result}")
                results.append(result)
            except Exception as exc:
                raise BlockModelEvaluationError(
                    f"克里格估值失败(元素={element}): {exc}"
                ) from exc

        # 返回最后一个结果(与底层约定一致),附加全部结果列表
        final = results[-1] if results else {}
        final["all_results"] = results
        return final

distance_power_evaluation(block_model_file, constraint_params, evaluation_params, overwrite_result=True) staticmethod

距离幂估值计算

Returns:

Name Type Description
DistancePowerEvaluationResult DistancePowerEvaluationResult

估值结果对象,包含 success / message / elements

Source code in dimine_python_sdk\lib\prospecting\block_model.py
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
@staticmethod
def distance_power_evaluation(
    block_model_file: str,
    constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
    evaluation_params: BlockModelDistancePowerParams,
    overwrite_result: bool = True,
) -> DistancePowerEvaluationResult:
    """距离幂估值计算

    Returns:
        DistancePowerEvaluationResult: 估值结果对象,包含 success / message / elements
    """
    constraint_json = _serialize_constraints(constraint_params)
    evaluation_json = json.dumps(evaluation_params.to_dict(), ensure_ascii=False)
    try:
        result = _native_distance_power_evaluation(
            block_model_file, constraint_json, evaluation_json, overwrite_result
        )
        logger.info(f"距离幂估值结果: {result}")
        message = result.get("message", "")
        elements = _parse_evaluation_message(message)
        return DistancePowerEvaluationResult(
            success=True,
            elements=elements,
        )
    except Exception as exc:
        raise BlockModelEvaluationError(f"距离幂估值失败: {exc}") from exc

kriging_evaluation(block_model_file, constraint_params, evaluation_params, overwrite_result=True) staticmethod

克里格估值计算

克里格算法底层仅支持单元素估值,当 variables 包含多个元素(逗号分隔)时, 自动按元素拆分,依次调用底层接口实现多元素估值效果。

Source code in dimine_python_sdk\lib\prospecting\block_model.py
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
@staticmethod
def kriging_evaluation(
    block_model_file: str,
    constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
    evaluation_params: BlockModelKrigingParams,
    overwrite_result: bool = True,
) -> dict:
    """克里格估值计算

    克里格算法底层仅支持单元素估值,当 variables 包含多个元素(逗号分隔)时,
    自动按元素拆分,依次调用底层接口实现多元素估值效果。

    """
    constraint_json = _serialize_constraints(constraint_params)
    params_dict = evaluation_params.to_dict()

    # 估值变量:直接使用 list[str],逐个调用克里格估值
    elements = evaluation_params.variables
    if not elements:
        raise BlockModelEvaluationError("克里格估值失败: variables 不能为空")

    results = []
    for element in elements:
        params_dict["variable"] = element
        evaluation_json = json.dumps(params_dict, ensure_ascii=False)
        try:
            result = _native_kriging_evaluation(
                block_model_file, constraint_json, evaluation_json, overwrite_result
            )
            logger.info(f"克里格估值结果(元素={element}): {result}")
            results.append(result)
        except Exception as exc:
            raise BlockModelEvaluationError(
                f"克里格估值失败(元素={element}): {exc}"
            ) from exc

    # 返回最后一个结果(与底层约定一致),附加全部结果列表
    final = results[-1] if results else {}
    final["all_results"] = results
    return final

block_constrain_to_dmc_file(block_model_file, constrain_params, constrain_result_file)

块约束保存到约束结果 dmc 文件

Parameters:

Name Type Description Default
block_model_file str

块段模型文件路径

required
constrain_params list[BlockModelConstraintItem] | BlockModelConstraintItem

约束参数

required
constrain_result_file str

约束结果文件路径

required

Returns:

Type Description
bool

bool

Source code in dimine_python_sdk\lib\prospecting\block_model.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
def block_constrain_to_dmc_file(
    block_model_file: str,
    constrain_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
    constrain_result_file: str,
) -> bool:
    """
    块约束保存到约束结果 dmc 文件

    Args:
        block_model_file: 块段模型文件路径
        constrain_params: 约束参数
        constrain_result_file: 约束结果文件路径

    Returns:
        bool
    """
    json_param = _serialize_constraints(constrain_params)
    try:
        _native_block_constrain_to_dmc_file(
            block_model_file, json_param, constrain_result_file
        )
    except Exception as exc:
        raise BlockDataError(
            f"块约束保存失败: 源文件={block_model_file}, 约束文件={constrain_result_file}"
        ) from exc
    return True

create_block_model(params)

创建空块段模型

Parameters:

Name Type Description Default
params CreateBlockModelParams

CreateBlockModelParams 参数实例

required

Returns:

Name Type Description
dict dict

创建结果 {"state": "ok", ...}

Raises:

Type Description
BlockModelCreateError

创建失败时抛出

Source code in dimine_python_sdk\lib\prospecting\block_model.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def create_block_model(params: CreateBlockModelParams) -> dict:
    """
    创建空块段模型

    Args:
        params: CreateBlockModelParams 参数实例

    Returns:
        dict: 创建结果 {"state": "ok", ...}

    Raises:
        BlockModelCreateError: 创建失败时抛出
    """
    json_param = json.dumps(params.to_dict(), ensure_ascii=False)
    try:
        response = _native_create_block_model(json_param)
    except Exception as exc:
        raise BlockModelCreateError(f"创建块段模型失败: {exc}") from exc
    if response.get("state") == "failed":
        raise BlockModelCreateError(f"创建块段模型失败: {response.get('message')}")
    return response