parq_blockmodel.blockmodel.ParquetBlockModel
- class parq_blockmodel.blockmodel.ParquetBlockModel(blockmodel_path, name=None, geometry=None)[source]
A class to represent a regular Parquet block model.
Block ordering is c-style, ordered by x, y, z coordinates.
- blockmodel_path
The file path to the blockmodel Parquet file. This file is the source of the block model data. Consider a .pbm.parquet extension to imply a ParquetBlockModel file.
- Type:
Path
- name
The name of the block model, derived from the file name.
- Type:
str
- geometry
The geometry of the block model, derived from the Parquet file.
- Type:
Methods
__init__
(blockmodel_path[, name, geometry])create_demo_block_model
(filename[, shape, ...])Create a demo block model with specified parameters.
create_report
([columns, column_batch_size, ...])Create a ydata-profiling report for the block model.
from_geometry
(geometry, path[, name])Create a ParquetBlockModel from a RegularGeometry object.
from_parquet
(parquet_path[, columns, ...])Create a ParquetBlockModel instance from a Parquet file.
plot
(scalar[, grid_type, threshold, ...])Plot the block model using PyVista.
read
([columns, with_index, dense])Read the Parquet file and return a DataFrame.
to_dense_parquet
(filepath[, chunk_size, ...])Save the block model to a Parquet file.
to_pyvista
([grid_type, attributes])validate_sparse
()Attributes
Get the centroid index of the block model.
column_categorical_ordered
Zero-based C-order (x, y, z) indices for the dense grid.
Zero-based F-order (z, y, x) indices for the dense grid.
is_sparse
sparsity
- property centroid_index: MultiIndex
Get the centroid index of the block model.
- Returns:
The MultiIndex representing the centroid coordinates (x, y, z).
- Return type:
pd.MultiIndex
- classmethod create_demo_block_model(filename, shape=(3, 3, 3), block_size=(1, 1, 1), corner=(-0.5, -0.5, -0.5), axis_azimuth=0.0, axis_dip=0.0, axis_plunge=0.0)[source]
Create a demo block model with specified parameters.
- Parameters:
filename (Path) – The file path where the Parquet file will be saved.
shape (tuple) – The shape of the block model.
block_size (tuple) – The size of each block.
corner (tuple) – The coordinates of the corner of the block model.
axis_azimuth (float) – The azimuth angle in degrees for rotation.
axis_dip (float) – The dip angle in degrees for rotation.
axis_plunge (float) – The plunge angle in degrees for rotation.
- Returns:
An instance of ParquetBlockModel with demo data.
- Return type:
- create_report(columns=None, column_batch_size=10, show_progress=True, open_in_browser=False)[source]
Create a ydata-profiling report for the block model. The report will be of the same name as the block model, with a ‘.html’ extension.
- Parameters:
columns (
Optional
[list
[str
]]) – List of column names to include in the profile. If None, all columns are used.column_batch_size (
int
) – The number of columns to process in each batch. If None, processes all columns at once.show_progress (
bool
) – bool: If True, displays a progress bar during profiling.open_in_browser (
bool
) – bool: If True, opens the report in a web browser after generation.
- Return type:
Path
- Returns
Path: The path to the generated profile report.
- classmethod from_geometry(geometry, path, name=None)[source]
Create a ParquetBlockModel from a RegularGeometry object.
The model will have no attributes.
- Parameters:
geometry (RegularGeometry) – The geometry of the block model.
path (Path) – The file path where the Parquet file will be saved.
name (Optional[str]) – The name of the block model. If None, the name will be derived from the path.
- Returns:
An instance of ParquetBlockModel with the specified geometry.
- Return type:
- classmethod from_parquet(parquet_path, columns=None, overwrite=False, axis_azimuth=0.0, axis_dip=0.0, axis_plunge=0.0)[source]
Create a ParquetBlockModel instance from a Parquet file.
- Parameters:
parquet_path (Path) – The path to the Parquet file.
columns (Optional[list[str]]) – The list of columns to extract from the Parquet file.
overwrite (bool) – If True, allows overwriting an existing ParquetBlockModel file. Defaults to False.
axis_azimuth (float) – The azimuth angle in degrees for rotation. Defaults to 0.0.
axis_dip (float) – The dip angle in degrees for rotation. Defaults to 0.0.
axis_plunge (float) – The plunge angle in degrees for rotation. Defaults to 0.0.
- Return type:
- property index_c: ndarray
Zero-based C-order (x, y, z) indices for the dense grid.
- property index_f: ndarray
Zero-based F-order (z, y, x) indices for the dense grid.
- plot(scalar, grid_type='image', threshold=True, show_edges=True, show_axes=True, enable_picking=False, picked_attributes=None)[source]
Plot the block model using PyVista.
- Parameters:
scalar (
str
) – The name of the scalar attribute to visualize.grid_type (
Literal
['image'
,'structured'
,'unstructured'
]) – The type of grid to use for plotting. Options are “image”, “structured”, or “unstructured”.threshold (
bool
) – The thresholding option for the mesh. If True, applies a threshold to the scalar values.show_edges (
bool
) – Show edges of the mesh.show_axes (
bool
) – Show the axes in the plot.enable_picking (
bool
) – If True, enables picking mode to interactively select cells in the plot.picked_attributes (
Optional
[list
[str
]]) – A list of attributes that will be returned in picking mode. If None, all attributes are returned.
- Return type:
Plotter
Returns:
- read(columns=None, with_index=True, dense=False)[source]
Read the Parquet file and return a DataFrame.
- Parameters:
columns (
Optional
[list
[str
]]) – List of column names to read. If None, all columns are read.with_index (
bool
) – If True, includes the index (‘x’, ‘y’, ‘z’) in the DataFrame.dense (
bool
) – If True, reads the data as a dense grid. If False, reads the data as a sparse grid.
- Returns:
The DataFrame containing the block model data.
- Return type:
pd.DataFrame
- to_dense_parquet(filepath, chunk_size=100000, show_progress=False)[source]
Save the block model to a Parquet file.
This method saves the block model as a Parquet file by chunk. If dense is True, it saves the block model as a dense grid, :type filepath:
Path
:param filepath: The file path where the Parquet file will be saved. :type filepath: Path :type chunk_size:int
:param chunk_size: The number of blocks to save in each chunk. Defaults to 100_000. :type chunk_size: int :type show_progress:bool
:param show_progress: If True, show a progress bar. Defaults to False. :type show_progress: bool- Return type:
None