<jupyter_start><jupyter_text>Obvious Open Mining Format (OOMF)> "Open Mining Format for humans"- toc: false- branch: master- badges: true- comments: true- categories: [Mining, OMF, Seequent, Open Mining Format, Geostatistics]- image: images/some_folder/your_image.png- hide: false- search_exclude: true The Open Mining Format (OMF) is a thoughtful proposal from the Global Mining Guidlines Group (GMG), suggesting a single data format for use in multiple mining software packages. This idea has been slow to gain support from some of the big players in this space. At this point the sole supporter of this concept (to my knowledge) is Seequent, the makers of Leapfrog3D software.  The use of multuiple commercial softwares or open source tools is becoming the norm for complex workflows focused on resource modeling. This necessiates the the ability to get data into and out-of commercial software packages. OMF is an attempt at this, unfortunately the oficial python tools for OMF are a bit clunky.[Obvious Open Mining Format aka OOMF](https://github.com/ericbdaniels/Oomf) is an attempt to make working with the Open Mining Format more accessible by a more pythonic API. This is a work in progress and it should be noted that GMG already has OMF 2.0 in the works which will likely come with some breaking changes. The aim of OOMF is based on my own experience where a common workflow involves extracting information from and OMF file and manipulating it using some GSLIB or Python based tools and saving the results back to an OMF file. All of this can be done using the [OMF package](https://omf.readthedocs.io/en/latest/index.html). A quick read of the docs may leave you wanting a simpler approach.   Aims of OOMF1. Provide a summary of OMF file contents.2. Allow user access data saved within the OMF file by name.3. Export to other common formats (CSV, VTK, GSLIB)4. Easily create OMF files from existing data in CSV, VTK or GLIB formats.5. Provide basic tools for visualization.> The examples below cover points 1 through 3. 4 and 5 need a bit more work when time allows.  Example usageTo demonstrate the purpose and use of OMF - consider the basic workflow of loading and exisiting OMF file, summarizing the contents, and exporting to another file format. Standard OMF approach<jupyter_code>import omf
import pandas as pd

# First read the file 
reader = omf.OMFReader('./data/test_file.omf')
project = reader.get_project()

# Now see whats in the file - for each element print the name, some basic info and the names of all associated data attributes
for e in project.elements:
    print(f'Element Name: {e.name}, Origin: {e.geometry.origin}, Size: {e.geometry.num_cells}')
    for d in e.data:
        print(f'\t Attribute Name: {d.name}')
# Now access the attributes on the wolfpass_WP_assay element
e = project.elements[1]

#now get the data itself
assay_df = pd.DataFrame({d.name:d.array[:] for d in e.data})

assay_df.head()<jupyter_output><empty_output><jupyter_text>> The OMF package works just fine, open the file get the data etc - no problem. Its just not inutitive because the user must access each element and attribute by its index in as list (or by its UUID which is even less user friendly in my opinion).  OOMF approach<jupyter_code>import oomf 

# read the file and summarize contents
prj = oomf.Project("./data/test_file.omf")
prj.summarize()
# now access the assay data
assay_df = prj.elements.wolfpass_WP_assay.to_pandas()
assay_df.head()<jupyter_output><empty_output><jupyter_text>* The nice summary above comes from `rich` which is an fantastic python package which allows for adding colored text, tables, summaries to any text output.* Notice that any element is accessible by name, and any attribute associated with that object is also accessed by name: `prj.elements.wolfpass_WP_assay.CU_pct`, and to get the data: `prj.elements.wolfpass_WP_assay.CU_pct[:]`* additionally, the coordinates are added to the dataframe by default. If using the stand OMF package coordinates exist separate from attributes.  Supported File FormatsAt this point export functions for CSV, VTK and GSLIB file formats are provided in addition to the pandas integration.<jupyter_code># to gslib
prj.elements.wolfpass_WP_assay.to_gslib("./data/gslib_export.dat")

# to csv 
prj.elements.wolfpass_WP_assay.to_csv("./data/csv_export.csv")

# to vtk 
prj.elements.wolfpass_WP_assay.to_vtk("./data/vtk_export.vtk")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06564748201438848, 'fraction_numerical': 0.002922661870503597, 'mean_word_length': 4.762953367875648, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '40913', 'license': 'Apache-2.0', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1246, 'n_words': 607, 'path': '_notebooks/2020-11-08-Oomf.ipynb', 'repo_name': 'ericbdaniels/blog', 'size': '4448'}