Package: orchid-python-api
IntroductionThis project defines the implementation of the Python API for Orchid*.Specifically, theorchidpackage makes Orchid features available to Python applications and to the
Python REPL.(* Orchid is a mark of Reveal Energy Services, Inc.)A Reading SuggestionThis document is one of several documents you may want to read:README- This file.README-dev.md- A similar file targeting for package developers.ReleaseNotes.md- The release notes for this project.Additionally, as part of the 2022.4 release, we upgradedpythonnet, the package we use to expose .NET to the Python
runtime, from version 2.5.2 to version 3.0.0.post1. This upgrade is a breaking upgrade. The document,README-pythonnet3.md, describes the changes that we needed to make to the Orchid Python API to
repair failing internal tests. The document,README-pythonnet3-low.md, describes the
changes that we needed to make to the Orchid Python API to repair failing low-level examples.Although one can read this document in any text editor since it is simply a text file, consider installing
thePython grip utility. This application allows one to "render local readme
files before sending off to GitHub". Although you need not send any of these file toGitHub, by usinggripto render the file, you can much more easily navigate the document links.ExamplesHigh-level examplesThis project includes eight scripts and six notebooks in theexamplesdirectory of theorchid-python-apipackage:NameDemonstrates...completion_analysis.ipynbA detailed analysis of the completion performed on two different wells in a projectplot_trajectories.ipynbPlotting the well trajectories for a projectplot_time_series.ipynbPlotting the monitor curves for a projectplot_treatment.ipynbPlotting the treatment curves for a specific stage of a well in a projectsearch_data_frames.ipynbSearching object collections and our data frame accessvolume_2_first_response.ipynbUsing derivatives to calculate the fluid volume pumped before the first responseSix of the eight scripts contain the same code as the notebooks but run either at the command line or in a REPL. The
last three scripts:NameDemonstrates using the high-level Python API to...stage_qc_results.pyRead and write QC results for a stage. (Replaces low-levelstage_qc_status.py)change_stage_times.pyChange the start and stop times (the time range) of a stageadd_stages.pyAdd one or more stages to a well. (Improvement overadd_stages_low.py)Low-level examplesIn addition, this project includes five scripts and a notebook in theexamples/low_leveldirectory of theorchid-python-apipackage:NameDemonstrates...auto_pick.pyAutomatically pick observations and save them to an .ifrac fileauto_pick_and_create_stage_attribute.pyCreate and save stage attributesauto_pick_iterate_example.pyUse iteration to find visible stages instead of .NET methodmonitor_time_series.pyFind high-level time series from a low-level monitor time seriesadd_stages_low.pyAdds newly created stages to a well of a projectmulti_picking_events.pyCreates and adds a number of multi-picking eventsThe notebook,auto_pick.ipynbcontain the same code as the script,auto_pick.py, but runs in a Jupyter
notebook.To use these examples:You may need toconfigure the Orchid Python API to find the Orchid installationYoumustconfigure the Orchid Python API to find the Orchid training dataYou may need toview the Orchid API configuration detailsYou may want to invoke the command,copy_orchid_examplesThis command copies the example files into an optionally specified (virtual environment) directory. (The
default destination is your current working directory.) Note that this command is a command-line script
that runs in a console or terminal. Additionally, this command supports a help flag,-hor--help, to
provide you with help on running this command.More detailed instructions for running the examples can be found at:Run Orchid high-level examples.TutorialsAdditionally, this project includes one notebook and one script in thetutorialsdirectory of theorchid-python-apipackage:dom_navigation_tutorial.ipynbdom_navigation_tutorial.pyThe notebook,dom_navigation_tutorial.ipynb, demonstrates using the Orchid Python API class,SearchableProjectObjects, to navigate a project. TheSearchableProjectObjectsprovides:Three query methods:all_names()all_display_names()all_object_ids()Three specific search methods:find_by_name()find_by_display_name()find_by_object_id()A general search method:find()- This method expects a predicate to identify project objects of interestTwo general iteration methods:all_objects()SearchableProjectObjectsis aniteratorThe script contains code similar to the notebook but runs either at the command line or in a REPL.To use these tutorials:You may need toconfigure the Orchid Python API to find the Orchid installationYoumustconfigure the Orchid Python API to find the Orchid training dataYou may need toview the Orchid API configuration detailsYou may want to invoke the command,copy_orchid_tutorialsThis command copies the tutorial files into an optionally specified (virtual environment) directory. (The
default destination is your current working directory.) Note that this command is a command-line script
that runs in a console or terminal. Additionally, this command supports a help flag,-hor--help, to
provide you with help on running this command.More detailed instructions for running the tutorials can be found at:Run Orchid tutorials.Getting StartedVirtual environmentsWe recommend the use of virtual environments to use the Orchid Python API. This choice avoids putting
Orchid-specific packages in your system Python environment.You have several options to create and manage virtual environments:venv,pipenv,poetry, andconda.
Thevenvis available as a standard Python package and is a spartan tool to manage environments.poetryis a tool targeting developers but can be used by end-users. Our recommended tool ispipenv. It provides a
good balance betweenvenvandpoetry. Remember, bothpipenvandpoetrymust be installed in your
Python environment separately from Python itself, but can be installed usingpip. Finally,condais an open source package management system and environment management system that runs on Windows, macOS
and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates,
saves, loads and switches between environments on your local computer. It was created for Python programs,
but it can package and distribute software for any language.We recommend the use ofpipenv. This environment hides a number of details involved in managing a virtual
environment and yet provides a fairly simple interface. We will assume in this document that you are usingpipenv.Although we recommendpipenv, because we understand many of our users useconda(either Anaconda or
Miniconda), we have asectionfor installing theorchid-python-apiin acondavirtual environment.Using any ofpipenv,venvorpoetry, your first step is to create a directory foryourproject.
Then, change into that project directory.Step-by-step pipenv installInstall python 3.10 by followingthese installation instructions. To
ensure access from the command line, be sure to select the "Add Python 3.x to PATH" option on theinstaller start page.Open a console using eitherpowershellor the Windows console.Create a directory for the virtual environment. We will symbolically call it/path/to/orchid-virtualenv.Change the current working directory by executing,chdir /path/to/orchid-virtualenv.Create an empty virtual environment by runningpipenv install.Activate the virtual environment by runningpipenv shellInstall Orchid by runningpip install orchid-python-api.Step-by-step conda installInstallAnacondaorMinicondafollowing the corresponding instructions for
your operating system.If installing on Windows, the installer will presentthis screen. We have seen no need to install
Anaconda / Miniconda on yourPATH. Although we do not
disagree with option to register the Anaconda / Miniconda version of Python as your default Python
executable, in some situations, accepting this choice can cause problems.Since we will be usingbothconda installandpip installto install packages, read the article,Using Pip in a Conda Environment. Our
subsequent instructions assume you have read this article and have chosen how you wish to manage these
two package installers together.The following instructions assume that you will use the simple (put perhaps not scalable) process of creating
thecondavirtual environment with all packages you want to use available in the Anaconda/Miniconda
ecosystem and, within that virtual environment, usepipto installorchid-python-api.Open an Anaconda Powershell console.Optionally create a directory for your work.We symbolically call it/path/to/orchid-virtualenv.Change to the current working directory by executingchdir /path/to/orchid-virtualenv.Create an empty virtual environment by runningconda create --name <your-virtualenv-name> python=3.10.Activate the virtual environment by runningconda activate <your-virtualenv_name>Install Orchid by runningpip install orchid-python-api.Using a requirements fileAn alternative method used by customers uses a requirements file,requirements.txt, that we create as part of our
release process butdo notinclude in our distribution.This fileis available
from our GitHub repository. Forpipenv, usethese import instructions. Forconda, read the accepted answer to thisStack Overflow postfor the correct command and additional options you may need to consider.Configure the Orchid Python APIThe Orchid Python API requires a licensed Orchid installation on your workstation. Depending on the details of
the installation, you may need to configure the Orchid Python API to refer to different locations.Using the fallback configurationIf you installed the latest version Orchid using the installation defaults, and you installed theorchid-python-apiusing thepipenv installation instructionsor
theconda installation instructions, you need to takenoadditional
steps to configure the Orchid Python API to find this installation. For your information, the default
installation location is,%ProgramFiles%\Reveal Energy Services\Orchid. The Orchid Python API uses the API
version to find and use the corresponding version of Orchid.Using an environment variableThis mechanism is perhaps the easiest procedure to create an Orchid Python API configuration that changes
rarely and is available to all your tools. It works best with a system restart. (Environment variables can be
made available for a narrow set of tools on your system or available to all your tools depending on arcane
technical rules that you need not understand.)To use environment variables to configure the Orchid Python API, you will need to create the environment
variableORCHID_ROOTand set its value to the path of thePythonApiLibsdirectory beneath the Orchid
installation directory. (For your information, thePythonApiLibsdirectory containing the version-specific
Orchid binary and configuration files should be in a subdirectory likeORCHID_ROOT/Orchid-2020.4.232/PythonApiLibswhen you accept the installation defaults.)This section assumes you want to create a long-term configuration that survives a system restart and is
available to all your tools. Symbolically, this document will refer to the directory containing the binaries
required by the Orchid Python API as/path-to/orchid/version/python-api-libs.To create the required environment variable, enter the search term "environment variables" in the Windows-10
search box and select the item named, "Edit environment variables for your account." The system will then
present you with the "Environment Variables" dialog. Under the section named "User variables for
<your.username>", click the "New" button. In the "Variable name" text box, enter "ORCHID_ROOT". (These two
words are separated by the underscore symbol.)Navigate to the "Variable Value" text box. Click the "Browse Directory" button to select the directory into
which Orchid is installed,/path-to/orchid/version/python-api-libs. This action pastes the directory
name into the "Variable Value" text box. Verify that the directory is correct, and then click "OK". Verify
that you see the nameORCHID_ROOTwith the correct value in the "User variables for <your.username>" list.
Finally, click "OK" to dismiss the "Environment Variables" dialog.Although you have created theORCHID_ROOTenvironment variable with the appropriate value, only "new" opened
tools can use that variable. However, the details of "new" is technical and may not correspond to what you
expect. If you understand these details, you can jump toVerify Installation. If you are not confident of these details, restart
your system before proceeding toVerify Installation.Using a configuration fileAnother option to configure the Orchid Python API is by creating a configuration file. A configuration file is
easier to change than an environment variable and does not require a system restart to work best. However, it
requires more knowledge and work on your part. In general, a configuration file is better if your requirements
change "often". For example, if you are working with multiple, side-by-side Orchid versions and Orchid Python
API versions, you may find it faster and easier to create a configuration file once and change it as you
change Orchid / Orchid Python API versions.To use a file to configure the Orchid Python API, you will need to create a configuration file namedpython_api.yamland set the value of theorchid>rootkey to the path of thePythonApiLibsdirectory
beneath the Orchid installation directory. (For your information, thePythonApiLibsdirectory containing the
version-specific Orchid binary and configuration files should be in a subdirectory likeORCHID_ROOT/Orchid-2020.4.232/PythonApiLibswhen you accept the installation defaults.)Symbolically, this document will refer to the directory containing the binaries required by the
Orchid Python API as/path-to/orchid/version/python-api-libs.To create a configuration file used by the Orchid Python API, you must:Create the directory,/path/to/home-directory/.orchid, where/path/to/home-directoryis a symbolic
reference to your home directory.Create the file,python_api.yamlin/path/to/home-directory/.orchid.Technically, the format of the file isYAML("YAML Ain't Markup Language"), a "human friendly data
serialization standard". (For technical details, visitthe website. For a gentler
introduction, visitthe Wikipedia entryor read / watch one of the manyYAMLintroductions / tutorials.)Because these articles describeYAMLgenerally, theydo notdescribe the details of theYAMLdocument
expected by the Orchid Python API. We, however, distribute an example file namepython_api.yaml.examplein
each installedorchid-python-apipackage. Assuming you created a virtual environment as described in
the step-by-steppipenv installation instructionsor
theconda installation instructionssection, you can find this example file,python_api.yaml.example, in the directory,/path/to/orchid-virtualenv/Lib/site-packages/orchid_python_api/examples.To use this configuration file as an example:Copy the file to the expected location. For example, assuming the symbolic names referenced above, execute:copy /path/to/orchid-virtualenv/Lib/site-packages/orchid_python_api/examples/python_api.yaml.example /path/to/home-directory/.orchid/python_api.yamlEdit the copied file,/path/to/home-directory/.orchid/python_api.yaml, using your favoritetexteditor.The example file, contains comments, introduced by a leading octothorpe character (#, number sign, or hash),
that describe the information expected by the Orchid Python API. In summary, you'll need to provide a value
for theorchid>rootkey that contains (symbolically),/path-to/orchid/version/python-api-libs.If you want to ensure your configuration is correct,view the Orchid API configuration details.Configure the Orchid training dataUsing the Orchid Python APIrequiresa licensed Orchid installation on your workstation. However,
to use the example Jupyter notebooks or scripts, youmustconfigure the Orchid Python API to find the
Orchid training data.Using an environment variableThis mechanism is perhaps the easiest procedure to create an Orchid Python API configuration that changes
rarely and is available to all your tools. It works best with a system restart. (Environment variables can be
made available for a narrow set of tools on your system or available to all your tools depending on arcane
technical rules that you need not understand.)To use environment variables to configure the Orchid Python API to find the Orchid training data, you will
need to create the environment variableORCHID_TRAINING_DATAand set its value to the location of the Orchid
training data.This document assumes you want to create a long-term configuration that survives a system restart and is
available to all your tools. Symbolically, this document will refer to the Orchid training data location as/path-to/orchid/training-data.To create the required environment variable, enter the search term "environment variables" in the Windows-10
search box and select the item named, "Edit environment variables for your account." The system will then
present your with the "Environment Variables" dialog. Under the section named "User variables for
<your.username>", click the "New" button. In the "Variable name" text box, enter "ORCHID_TRAINING_DATA".
(These three words are separated by the underscore symbol.)Navigate to the "Variable Value" text box. Click the "Browse Directory" button to select the directory
containing the Orchid training data,/path-to/orchid/training-data. This action pastes the directory name
into the "Variable Value" text box. Verify that the directory is correct, and then click "OK". Verify that
you see the nameORCHID_TRAINING_DATAwith the correct value in the "User variables for <your.username>"
list. Finally, click "OK" to dismiss the "Environment Variables" dialog.Although you have now created theORCHID_TRAINING_DATAenvironment variable with the appropriate value,
only "new" tools can now use that variable. However, the details of "new" is technical and may not correspond
to your what you expect. If you understand these details, you can jump toVerify Installation. If you are not confident of these details, restart
your system before proceeding toVerify Installation.Using a configuration fileAnother option to configure the Orchid Python API to find the Orchid training data is by creating a
configuration file. A configuration file is easier to change than an environment variable and does not require
a system restart to work best. However, it requires more knowledge and work on your part. In general, a
configuration file is better if your requirements change "often". For example, if you are working with
multiple, side-by-side Orchid versions and Orchid Python API versions, you may find it faster and easier to
create a configuration file once and change it as you change Orchid / Orchid Python API versions or training
data locations.To create a configuration file used by the Orchid Python API, you create a file namedpython_api.yamland put it in the directory,/path/to/home-directory/.orchid, where/path/to/home-directoryis a
symbolic reference to your home directory. Technically, the format of the file isYAML("YAML Ain't Markup
Language"), a "human friendly data serialization standard". (For technical details, visitthe website. For a gentler introduction, visitthe Wikipedia entryor read / watch on of the manyYAMLintroductions / tutorials.)Because these articles describeYAMLgenerally, theydo notdescribe the details of theYAMLdocument
expected by the Orchid Python API. We, however, distribute an example file namepython_api.yaml.examplein
each installedorchid-python-apipackage. Assuming you created a virtual environment as described in
the step-by-steppipenv installation instructionsor theconda installation instructions, you can find this example file,python_api.yaml.example, in the directory,/path/to/orchid-virtualenv/Lib/site-packages/orchid_python_api/examples.To use this configuration file as an example:Copy the file to the expected location. For example, assuming the symbolic names referenced above, execute
the commandcopy /path/to/orchid-virtualenv/Lib/site-packages/orchid_python_api/examples/python_api.yaml.example /path/to/home-directory/.orchid/python_api.yamlEdit the copied file,/path/to/home-directory/.orchid/python_api.yaml, using your favoritetexteditor.The example file, contains comments, introduced by a leading octothorpe character (#, number sign, or hash),
that describe the information expected by the Orchid Python API. In summary, you'll need to provide a value
for the 'orchid' > 'training_data' key that contains the pathname of the directory containing the Orchid
training data files.If you want to ensure your configuration is correct,view the Orchid API configuration details.Verify installationJupyter labIn your activated virtual environment, runjupyter labto open a browser tab.In the first cell, enterimport orchid.Run the cell.Wait patiently.The import should complete with no errors.Python REPLIn your activated virtual environment, run eitherpythonoripythonto open a REPL.Enterimport orchid.Wait patiently.The import should complete with no errors.Run Orchid high-level examplesIf you have not already done so,configure the Orchid Python API to find the Orchid installationYoumustconfigure the Orchid Python API to find the Orchid training dataNavigate to the directory associated with the virtual environmentIf necessary, activate the virtual environment by executing eitherpipenv shellorconda activate <your-virtualenv_name>.Runcopy_orchid_examplesIf the script reports that it skipped notebooks or scripts, repeat the command with an additional argument:copy_orchid_examples --overwriteVerify that the current directory has six example notebooks:completion_analysis.ipynbplot_time_series.ipynbplot_trajectories.ipynbplot_treatment.ipynbsearch_data_frames.ipynbvolume_2_first_response.ipynbVerify that the current directory has nine example scripts:completion_analysis.pyplot_time_series.pyplot_trajectories.pyplot_treatment.pysearch_data_frames.pyvolume_2_first_response.pystage_qc_results.pychange_stage_times.pyadd_stages.pyRun high-level example scriptsRun the first scriptExecute the commandpython plot_trajectories.pyWait patiently for thematplotlibplot window to appear.Ensure the plot is correct.Dismiss thematplotlibwindow.Repeat for these scripts:plot_treatment.pyplot_time_series.pycompletion_analysis.py(This script prints multiple messages and presentsmultipleplots.
You must dismiss each plot to continue.)volume_2_first_response.pysearch_data_frames.pyRun thestage_qc_results.pyscript.Run thechange_stage_times.pyscript.Run theadd_stages.pyscript.The scripts,stage_qc_results.py,change_stage_times.py, andadd_stages.py, differ from the other scripts. These
scripts require a number of command line arguments to run correctly.For example, to see an explanation of these arguments, execute any of this scripts with the--helpoption.
The most typical arguments are described in the following paragraphs.To both read and write stage QC results, run the command:python stage_qc_results.py -v2 /path/to/orchid-traing-data/frankNstein_Bakken_UTM13_FEET.v11.ifracTo only read the existing stage QC data, run the commandpython stage_qc_results.py -v2 --read-only /path/to/orchid-traing-data/frankNstein_Bakken_UTM13_FEET.ifracTo change the stage start and stop times (the time range), run the commandpython change_stage_times.py -v2 /path/to/orchid-traing-data/frankNstein_Bakken_UTM13_FEET.ifracTo add stages to a well, run the commandpython add_stages.py -v2 /path/to/orchid-traing-data/frankNstein_Bakken_UTM13_FEET.v11.ifracRun high-level example notebooksOpen Jupyter by runningjupyter labin the shellWithin Jupyter,Successfully run notebook,plot_trajectories.ipynbOpen notebookRun all cells of notebookWait patientlyVerify that no exceptions occurredRepeat for remaining notebooks:plot_time_series.ipynbplot_treatment.ipynbcompletion_analysis.ipynbvolume_2_first_response.ipynbsearch_data_frames.ipynbRun Orchid tutorialsIf you have not already done so,configure the Orchid Python API to find the Orchid installationYoumustconfigure the Orchid Python API to find the Orchid training dataNavigate to the directory associated with the virtual environmentIf necessary, activate the virtual environment by executing eitherpipenv shellorconda activate <your-virtualenv_name>.Runcopy_orchid_tutorials.exeIf the script reports that it skipped notebooks or scripts, repeat the command with an additional argument:python </path/to/virtualenv/Lib/site-packages/copy_orchid_tutorials.py --overwriteVerify that the current directory has one tutorial notebooks:dom_navigation_tutorial.ipynbVerify that the current directory has five example scripts:dom_navigation_tutorial.pyRun tutorial scriptRun thedom_navigation_tutorial.pyscriptExecute the commandpython dom_navigation_tutorial.pyFollow the on-screen messages to advance through the tutorialRun tutorial notebookOpen Jupyter by runningjupyter labin the shellWithin Jupyter,Run the notebook,dom_navigation_tutorial.ipynbOpen the notebook injupyterRun each cell of the notebook. Typically, this process involvesRead the instructions or comments preceding the code cell(s)Observe the result of executing the codeView Orchid Configuration DetailsTo "debug" the Orchid Python API configuration, perform the following steps:Change to the directory associated with your Python virtual environment.If necessary, activate the virtual environment.Within that virtual environment, invoke Python. It is important to create a new REPL so that you start with
a "clean" environment.Within the Python REPL, execute the following commands.import logging
logging.basicConfig(level=logging.DEBUG)
import orchidEnabling loggingbeforeimporting is critical. If you have already importedorchid, the simplest
solution is to close this REPL and create another, "clean" REPL.You should see output like the following:DEBUG:orchid.configuration:fallback configuration={'orchid': {'root': 'C:\\Program Files\\Reveal Energy Services\\Orchid\\Orchid-2020.4.361'}}
DEBUG:orchid.configuration:file configuration={'orchid': {'root': 'c:\\path-to\\bin\\x64\\Debug\\net48', 'training_data ': 'c:\\path-to\\installed-training-data'}}
DEBUG:orchid.configuration:environment configuration = {'orchid': {'root': 'c:\\another\\path-to\bin\\x64\\Debug\\net48'}}
DEBUG:orchid.configuration:result configuration={'orchid': {'root': 'c:\\another\\path-to\bin\\x64\\Debug\\net48'}}This output describes four details of the configuration.ConfigurationExplanationfallbackThe always available configuration (may be empty)fileThe configuration specified in your configuration file (may be empty)environmentThe configuration specified using environment variables (may be empty)resultThe configuration used by the Orchid Python API (should not be empty)