Skip to content

block_model

业务层:块段模型管理器

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

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

BlockDataError

Bases: RuntimeError

块段模型操作异常基类

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

BlockModelCreateError

Bases: BlockDataError

创建块段模型失败

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

BlockModelEvaluationError

Bases: BlockDataError

块段模型估值失败

Source code in dimine_python_sdk\lib\prospecting\block_model.py
60
61
62
63
64
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

估值失败

ReservesCalculateError

储量计算失败

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

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

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

    Raises:
        BlockModelEvaluationError: 估值失败
        ReservesCalculateError: 储量计算失败
    """

    @staticmethod
    def distance_power_evaluation(
        block_model_file: str,
        constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
        evaluation_params: BlockModelDistancePowerParams,
        overwrite_result: bool = True,
    ) -> dict:
        """距离幂估值计算"""
        constraint_json = _serialize_constraints(constraint_params)
        evaluation_json = json.dumps(evaluation_params.to_dict(), ensure_ascii=False)
        try:
            return _native_distance_power_evaluation(
                block_model_file, constraint_json, evaluation_json, overwrite_result
            )
        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:
        """克里格估值计算"""
        constraint_json = _serialize_constraints(constraint_params)
        evaluation_json = json.dumps(evaluation_params.to_dict(), ensure_ascii=False)
        try:
            return _native_kriging_evaluation(
                block_model_file, constraint_json, evaluation_json, overwrite_result
            )
        except Exception as exc:
            raise BlockModelEvaluationError(f"克里格估值失败: {exc}") from exc

    @staticmethod
    def calculate_reserves(
        block_model_file: str,
        constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
        reserve_params: ReservesCalculateParam,
    ) -> dict:
        """储量计算"""
        constraint_json = _serialize_constraints(constraint_params)
        reserve_json = json.dumps(reserve_params.to_dict(), ensure_ascii=False)
        try:
            return _native_calculate_reserves(
                block_model_file, constraint_json, reserve_json
            )
        except Exception as exc:
            raise ReservesCalculateError(f"储量计算失败: {exc}") from exc

calculate_reserves(block_model_file, constraint_params, reserve_params) staticmethod

储量计算

Source code in dimine_python_sdk\lib\prospecting\block_model.py
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
@staticmethod
def calculate_reserves(
    block_model_file: str,
    constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
    reserve_params: ReservesCalculateParam,
) -> dict:
    """储量计算"""
    constraint_json = _serialize_constraints(constraint_params)
    reserve_json = json.dumps(reserve_params.to_dict(), ensure_ascii=False)
    try:
        return _native_calculate_reserves(
            block_model_file, constraint_json, reserve_json
        )
    except Exception as exc:
        raise ReservesCalculateError(f"储量计算失败: {exc}") from exc

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

距离幂估值计算

Source code in dimine_python_sdk\lib\prospecting\block_model.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
@staticmethod
def distance_power_evaluation(
    block_model_file: str,
    constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
    evaluation_params: BlockModelDistancePowerParams,
    overwrite_result: bool = True,
) -> dict:
    """距离幂估值计算"""
    constraint_json = _serialize_constraints(constraint_params)
    evaluation_json = json.dumps(evaluation_params.to_dict(), ensure_ascii=False)
    try:
        return _native_distance_power_evaluation(
            block_model_file, constraint_json, evaluation_json, overwrite_result
        )
    except Exception as exc:
        raise BlockModelEvaluationError(f"距离幂估值失败: {exc}") from exc

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

克里格估值计算

Source code in dimine_python_sdk\lib\prospecting\block_model.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
@staticmethod
def kriging_evaluation(
    block_model_file: str,
    constraint_params: list[BlockModelConstraintItem] | BlockModelConstraintItem,
    evaluation_params: BlockModelKrigingParams,
    overwrite_result: bool = True,
) -> dict:
    """克里格估值计算"""
    constraint_json = _serialize_constraints(constraint_params)
    evaluation_json = json.dumps(evaluation_params.to_dict(), ensure_ascii=False)
    try:
        return _native_kriging_evaluation(
            block_model_file, constraint_json, evaluation_json, overwrite_result
        )
    except Exception as exc:
        raise BlockModelEvaluationError(f"克里格估值失败: {exc}") from exc

BlockModelLoadError

Bases: BlockDataError

加载块段模型失败

Source code in dimine_python_sdk\lib\prospecting\block_model.py
50
51
52
class BlockModelLoadError(BlockDataError):
    """加载块段模型失败"""
    pass

DmBlockData

块段模型管理器

管理单个块段模型的加载与属性访问。所有几何数据属性直接返回, 无需 getter 前缀:

block = DmBlockData("model.dmb")
origin = block.origin           # np.ndarray
xyz_len = block.xyz_length      # list[float]
max_level = block.max_level     # int
fc = block.field_definitions    # list[dict]
total = block.total_block_count # int

# 遍历块段数据
for data in block.iter_blocks("品位"):
    print(data)

静态方法(无需实例化): result = DmBlockData.create_block_model(params) DmBlockData.block_constrain_to_dmc_file(block_file, constraint, output)

Source code in dimine_python_sdk\lib\prospecting\block_model.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
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
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
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
class DmBlockData:
    """
    块段模型管理器

    管理单个块段模型的加载与属性访问。所有几何数据属性直接返回,
    无需 getter 前缀:

        block = DmBlockData("model.dmb")
        origin = block.origin           # np.ndarray
        xyz_len = block.xyz_length      # list[float]
        max_level = block.max_level     # int
        fc = block.field_definitions    # list[dict]
        total = block.total_block_count # int

        # 遍历块段数据
        for data in block.iter_blocks("品位"):
            print(data)

    静态方法(无需实例化):
        result = DmBlockData.create_block_model(params)
        DmBlockData.block_constrain_to_dmc_file(block_file, constraint, output)
    """

    def __init__(self, file_path: str | None = None):
        """
        Args:
            file_path: 块段模型文件路径。为 None 时需手动调用 open()
        """
        self._session: BlockModelSession | None = None
        if file_path is not None:
            self.open(file_path)

    def open(self, file_path: str) -> None:
        """
        加载块段模型文件

        Raises:
            BlockModelLoadError: 加载失败时抛出
        """
        try:
            self._session = BlockModelSession.open(file_path)
        except Exception as exc:
            raise BlockModelLoadError(f"加载块段模型失败: {file_path}") from exc

    # ------------------------------------------------------------------
    # 属性(只读)
    # ------------------------------------------------------------------
    @property
    def origin(self):  # -> np.ndarray:
        """模型原点坐标"""
        self._check_open()

        origin = self._session.origin  # np.ndarray
        return origin

    @property
    def xyz_length(self) -> list:
        """模型 X/Y/Z 方向总长度"""
        self._check_open()
        return list(self._session.xyz_length)

    @property
    def max_level(self) -> int:
        """模型最大精度层级"""
        self._check_open()
        return self._session.max_level

    @property
    def min_size(self) -> list:
        """最小块段尺寸"""
        self._check_open()
        return list(self._session.min_size)

    @property
    def rotation(self) -> list:
        """模型旋转角度"""
        self._check_open()
        return list(self._session.rotation)

    @property
    def field_definitions(self) -> list:
        """字段定义列表"""
        self._check_open()
        return [
            {"name": d.name, "type": d.type, "size": d.size}
            for d in self._session.field_definitions
        ]

    @property
    def total_block_count(self) -> int:
        """块段总数量"""
        self._check_open()
        return self._session.total_block_count

    # ------------------------------------------------------------------
    # 迭代器
    # ------------------------------------------------------------------
    def iter_blocks(self, field_name: str) -> Generator[dict, None, None]:
        """遍历块段模型的所有块段数据"""
        self._check_open()
        return self._session.iter_blocks(field_name)

    # ------------------------------------------------------------------
    # 内部
    # ------------------------------------------------------------------
    def _check_open(self) -> None:
        if self._session is None:
            raise BlockDataError("请先调用 open() 加载块段模型")

    # ------------------------------------------------------------------
    # 静态方法
    # ------------------------------------------------------------------
    @staticmethod
    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

    @staticmethod
    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

field_definitions property

字段定义列表

max_level property

模型最大精度层级

min_size property

最小块段尺寸

origin property

模型原点坐标

rotation property

模型旋转角度

total_block_count property

块段总数量

xyz_length property

模型 X/Y/Z 方向总长度

__init__(file_path=None)

Parameters:

Name Type Description Default
file_path str | None

块段模型文件路径。为 None 时需手动调用 open()

None
Source code in dimine_python_sdk\lib\prospecting\block_model.py
114
115
116
117
118
119
120
121
def __init__(self, file_path: str | None = None):
    """
    Args:
        file_path: 块段模型文件路径。为 None 时需手动调用 open()
    """
    self._session: BlockModelSession | None = None
    if file_path is not None:
        self.open(file_path)

block_constrain_to_dmc_file(block_model_file, constrain_params, constrain_result_file) staticmethod

块约束保存到约束结果 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
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
@staticmethod
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) staticmethod

创建空块段模型

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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@staticmethod
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

iter_blocks(field_name)

遍历块段模型的所有块段数据

Source code in dimine_python_sdk\lib\prospecting\block_model.py
188
189
190
191
def iter_blocks(self, field_name: str) -> Generator[dict, None, None]:
    """遍历块段模型的所有块段数据"""
    self._check_open()
    return self._session.iter_blocks(field_name)

open(file_path)

加载块段模型文件

Raises:

Type Description
BlockModelLoadError

加载失败时抛出

Source code in dimine_python_sdk\lib\prospecting\block_model.py
123
124
125
126
127
128
129
130
131
132
133
def open(self, file_path: str) -> None:
    """
    加载块段模型文件

    Raises:
        BlockModelLoadError: 加载失败时抛出
    """
    try:
        self._session = BlockModelSession.open(file_path)
    except Exception as exc:
        raise BlockModelLoadError(f"加载块段模型失败: {file_path}") from exc

ReservesCalculateError

Bases: BlockDataError

储量计算失败

Source code in dimine_python_sdk\lib\prospecting\block_model.py
67
68
69
70
71
class ReservesCalculateError(BlockDataError):
    """储量计算失败"""
    def __init__(self, message: str, response: dict | None = None):
        super().__init__(message)
        self.response = response