omfpandas.writer.OMFPandasWriter

class omfpandas.writer.OMFPandasWriter(filepath)[source]

A class to write pandas dataframes to an OMF file.

Methods are named to align with CRUD create -> create a new element on the omf file read -> read a dataframe from an element (using OMFPandasReader inheritance) update -> update (part of) an existing element by providing a dataframe # TODO delete -> delete an element from the omf file. # TODO

filepath

Path to the OMF file.

Type:

Path

__init__(filepath)[source]

Instantiate the OMFPandasWriter object.

Parameters:

filepath (Path) – Path to the OMF file.

Methods

__init__(filepath)

Instantiate the OMFPandasWriter object.

blockmodel_to_orc(blockmodel_name[, ...])

Convert blockmodel to an ORC file.

blockmodel_to_parquet(blockmodel_name[, ...])

Convert blockmodel to a Parquet file.

create_blockmodel(blocks, blockmodel_name[, ...])

Create an omf BlockModel from a dataframe.

create_calculated_blockmodel_attributes(...)

Create a calculated attribute for a BlockModel.

delete_blockmodel_attribute(blockmodel_name, ...)

Delete an attribute from a BlockModel.

find_nearest_centroid(x, y, z[, blockmodel_name])

Find the nearest centroid for provided x, y, z points using a math rounding approach considering the reference centroid.

get_bm_geometry(blockmodel_name)

Get the geometry of a BlockModel.

get_element_attribute_names(element_name)

Get the attribute names of an element.

get_element_by_name(element_name)

Get an element by its name.

persist_project()

Persist the omf project to file and reload the project property

plot_blockmodel(blockmodel_name, scalar[, ...])

Plot the BlockModel using PyVista.

profile_blockmodel(blockmodel_name[, query])

Profile a BlockModel.

read_block_models(blockmodel_attributes[, ...])

Return a DataFrame from multiple BlockModels.

read_blockmodel(blockmodel_name[, ...])

Return a DataFrame from a BlockModel.

view_block_model_profile(blockmodel_name[, ...])

View the profile of a BlockModel in the default web browser.

write_block_model_schema(blockmodel_name, ...)

Write a Pandera schema to the OMF file.

write_blockmodel_attribute(blockmodel_name, ...)

Write data to a specific attribute of a BlockModel.

write_to_changelog(element, action, description)

Write a change message to the OMF file.

Attributes

blockmodel_attributes

Attributes for blockmodel elements, keyed by element name, including composites.

changelog

Return the change log as a DataFrame.

element_types

Dictionary of elements keyed by name

blockmodel_to_orc(blockmodel_name, out_path=None, variables=None, allow_overwrite=False)[source]

Convert blockmodel to an ORC file.

Parameters:
  • blockmodel_name (str) – The BlockModel element to convert.

  • out_path (Optional[Path]) – The path to the ORC file to write. If None, a file with the blockmodel name is

  • created.

  • variables (Optional[list[str]]) – The variables to include in the DataFrame. If None, all variables are included.

  • allow_overwrite (bool) – If True, overwrite the existing ORC file. Default is False.

Raises:

FileExistsError – If the file already exists and allow_overwrite is False.

blockmodel_to_parquet(blockmodel_name, out_path=None, variables=None, allow_overwrite=False)[source]

Convert blockmodel to a Parquet file.

Parameters:
  • blockmodel_name (str) – The BlockModel element to convert.

  • out_path (Optional[Path]) – The path to the Parquet file to write. If None, a file with the blockmodel name is

  • created.

  • variables (Optional[list[str]]) – The variables to include in the DataFrame. If None, all variables are included.

  • allow_overwrite (bool) – If True, overwrite the existing Parquet file. Default is False.

Raises:

FileExistsError – If the file already exists and allow_overwrite is False.

create_blockmodel(blocks, blockmodel_name, pd_schema=None, allow_overwrite=False)[source]

Create an omf BlockModel from a dataframe.

Only dataframes with centroid (x, y, z) and block dims (dx, dy, dz) indexes are supported.

Parameters:
  • blocks (pd.DataFrame) – The dataframe to write to the BlockModel.

  • blockmodel_name (str) – The name of the BlockModel to write to. Use dot notation for composite (e.g., Composite.BlockModel).

  • pd_schema (Optional[Union[Path, dict]]) – The path to the Pandera schema file or a dict of the schema. Default is None. If provided, the schema will be used to validate the dataframe before writing.

  • allow_overwrite (bool) – If True, overwrite the existing BlockModel. Default is False.

Raises:

ValueError – If the element retrieved is not a BlockModel.

create_calculated_blockmodel_attributes(blockmodel_name, calc_definitions)[source]

Create a calculated attribute for a BlockModel.

Calculated attributes reduce storage space by storing the calculation expression instead of the data. When the attribute is accessed, the expression is evaluated and the result returned. The calculation expression must be a valid pandas expression, and is stored in the metadata of the blockmodel object. Only OMF2 supports this feature.

Parameters:
  • blockmodel_name (str) – The name of the BlockModel.

  • calc_definitions (dict[str, str]) – A dictionary of attribute names and calculation expressions.

delete_blockmodel_attribute(blockmodel_name, attribute_name)[source]

Delete an attribute from a BlockModel.

Parameters:
  • blockmodel_name (str) – The name of the BlockModel.

  • attribute_name (str) – The name of the attribute.

persist_project()[source]

Persist the omf project to file and reload the project property

profile_blockmodel(blockmodel_name, query=None)[source]

Profile a BlockModel.

Profiling will be skipped if the data has not changed.

Parameters:
  • blockmodel_name (str) – The name of the BlockModel to profile.

  • query (Optional[str]) – A query to filter the data before profiling.

Returns:

The profiled data.

Return type:

pd.DataFrame

write_block_model_schema(blockmodel_name, pd_schema_filepath)[source]

Write a Pandera schema to the OMF file.

Parameters:
  • blockmodel_name (str) – The name of the BlockModel.

  • pd_schema_filepath (Path) – The path to the Pandera schema yaml file.

write_blockmodel_attribute(blockmodel_name, series, allow_overwrite=False)[source]

Write data to a specific attribute of a BlockModel.

Parameters:
  • blockmodel_name (str) – The name of the BlockModel.

  • series (pd.Series) – The data to write to the attribute.

  • allow_overwrite (bool) – If True, overwrite the existing attribute. Default is False.

write_to_changelog(element, action, description)[source]

Write a change message to the OMF file.

Parameters:
  • element (str) – The name of the element that was changed

  • action (Literal['create', 'update', 'delete']) – The action taken on the object

  • description (str) – Description of the change

Returns: