Datamine Studio RM is a mining software that commonly used for geological modeling and resource estimation. Usually we run the process from the graphical interface or using macro. In this post, I would like to share how I use Python to run Studio RM commands from Jupyter notebook.
The package that I use is dmstudio-rm. This package is based on Sean D. Horan original dmstudio (2018, MIT License). I continue the development and add some extra tools for reading/writing Datamine file into pandas. Please note that this is not official Datamine product. You still need a valid licensed Studio RM installed on Windows computer to run this workflow.
Prerequisites
Before we start, we need to have:
- Windows OS (Studio RM only run on Windows)
- Licensed Datamine Studio RM installed
- Python 3.9 or newer (Anaconda / Miniconda is preferred)
- Studio RM already opened with a project file (
.rmproj)
Installation
The easiest way is installing the package from PyPI. Open command prompt or Anaconda prompt and run:
# Installing dmstudio-rm package
# pip install dmstudio-rm
If we clone the repository, we can also install it on editable mode using pip install -e . inside the repo folder.
Connecting to Studio RM
Make sure the project is already opened in Studio RM, then we can initialize the command wrapper.
# Importing dmstudio command wrappers
from dmstudio import dmcommands
# Connect to the opened Studio RM session
cmd = dmcommands.init()
Running Datamine Process
Here is a simple example. First we sort the assay table by Hole ID and FROM, then we filter the sample that have gold grade greater than 1.5.
# Sort assay table by BHID and FROM
cmd.mgsort(in_i='assays', out_o='sorted_assays', keys_f=['BHID', 'FROM'])
# Filter samples with AU greater than 1.5
cmd.copy(in_i='sorted_assays', out_o='high_grade_assays', retrieval='AU > 1.5')
Note that the suffix on the argument name have meaning:
_i: Input file_o: Output file_f: Field name_p: Parameter value
This suffix is used to translate Datamine command argument into python parameter. There are around 280 wrappers on the package. Some of them already tested, the others still experimental and will give a warning when we call it.
Reading Datamine File into Pandas
Instead of using OUTPUT process to export the table, we can read .dm or .dmx file directly into pandas DataFrame.
# Importing dm_io module
from dmstudio import dm_io
# Read Datamine file directly into DataFrame
df = dm_io.read_datamine('high_grade_assays.dm')
print(df.head())
print(df['AU'].describe())
# Write DataFrame back to Datamine file if needed
dm_io.to_datamine(df, 'from_pandas.dm')
This is useful when we want to check the statistic or plot the data using python, without making extra CSV file.
Some Notes when Scripting
There are some things that we need to consider when running Studio RM from python:
- Do not pass file path that contain space or backslash into the command. Datamine parser will fail. Better to work inside the project folder and use the file name only.
- File name that start with underscore (example:
_sorted) is stored in memory, it will not written to the disk. - If Studio RM show a dialog box, the python script will wait forever. We can wrap the command using dialog dismisser.
from dmstudio import dialog
# Auto close blocking dialog
with dialog.dialog_dismiss_context():
cmd.copy(in_i='nonexistent', out_o='temp')
Also, start the Jupyter notebook from the same folder with the Datamine project. If python working directory and Studio RM project folder is different, the file that created by Datamine will not found by python.
Closing Remark
By using dmstudio in python, we can build the workflow that suits of our project scale. The notebook can be rerun when the input is changing, so we don’t need to click the same process again and again.
If you want to try, the package and the tutorial notebook is available on github.
Reference
-
Horan, S. D. (2018). dmstudio. https://github.com/seanhoran/dmstudio
-
Abrory, A. N. (2026). dmstudio-rm. https://github.com/nazabrory/dmstudio-rm