Running ROOT under Linux / as CLI or Python module

I am exploring a way to run the Restoration Opportunities Optimization Tool under Debian Linux as a command line tool or as a Python library , and somehow I am having difficulties setting up all dependencies. I took the application from ROOT | Natural Capital Project , unpacked it using pyextractor and uncompiled it using uncompyle6 so that I could get the source .py files , but was not able to run python “root_parameters.py” due to various errors (the last one being StopIteration in preprocessing.py). Windows packaged exe file runs OK though.

I wonder whether it would be possible to get Python code for ROOT as well as system configuration / dependencies information. I would highly appreciate any other hints and ideas on how to run ROOT as a command line tool or Python module under Linux.

Thank you very much in advance for your response.

To add more details: apparently there is a problem with marginal_tables/marginals.csv file generation: under Windows it is a larger file with a lot of columns, while under Linux when I rtry to run Root with the same input files and parameters it only contains a partial header, and no values:

SDU_ID,pixel_count,area_ha,maskpixct,maskpixha

Hi @olessko , that’s neat that you went through all the trouble of decompiling the binaries! It’ll be way easier for you to just clone and run the source code from the root repository, though :slight_smile:

The thing about package versions is that the debian:stable repos are typically pretty far behind the latest package versions, so the easiest way to get a functional environment up and running would be to use conda. I use miniconda myself (download page).

Assuming you have miniconda all set up and on your PATH, here’s what you’ll want to do to get a local version of ROOT up and running:

sudo apt-get install build-essential
git clone https://github.com/natcap/root.git
cd root
conda env create -p ./root-env -f environment.yml
conda activate ./root-env
python setup.py install
python natcap/root/root.py

Let us know how this goes!
James

1 Like

Hi James,

Thank you very much for the advice and for the link to git repository. Somehow I could not find it, and thought that decompiling ROOT would be the only option :slight_smile:

Anaconda-based install worked reasonably well (had to install GDAL and natcap.invest manually before that), but I am still not able to run ROOT properly, as a Python command line tool without GUI. I removed natcap.gui sections and try to call ROOT with python root_parameters.py script that works fine with an older ROOT version, but
a) ROOT does not generate output/sdu_value_tables/baseline.csv table but fails:
File "/home/admin/root/natcap/root/root.py", line 535, in validate_objectives_and_constraints_tables with open(baseline_sdu_stats_file) as f: FileNotFoundError: [Errno 2] No such file or directory: '/home/admin/data/output/sdu_value_tables/baseline.csv'

b) when I copy the baseline.csv table from a successful ROOT GUI run under Windows I get an error message
File "/home/admin/root/natcap/root/root.py", line 552, invalidate_objectives_and_constraints_tables raise RootInputError(msg) root.RootInputError: Error in Objectives table. The following factors were not found in the sdu value tables: ['weight', 'objective', 'minmax']

It looks like the headers structure in the config csv files were changed between ROOT versions, and I have a functioning project that works fine with an older ROOT version under Windows.

Would you be able to share a functioning set of input files and parameters so that I could identify and fix the differences between an older ROOT version and the one from the repository?

Thanks a lot in advance!

Oles