Skip to content

Commit

Permalink
Test python doc
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Aug 28, 2020
1 parent 1adb236 commit 667b6ba
Show file tree
Hide file tree
Showing 79 changed files with 13,748 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__
build
_build
.vscode
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ResInsight Scripting API - rips

## Please note
The folder **rips** is a local copy for testing purposes. We need to be able to communicate the generated files to readthedocs in some way.

## How to generate documentation locally
- Install Python 3.x
- Install dependencies for rips `pip install grpcio grpcio-tools protobuf`
- Install the documentation system `pip install sphinx`
- Install dependencies for sphinx `pip install m2r sphinx_rtd_theme`
- Open command line in folder **docs**
- Execute `make html`
- Open the generated documentation in a browser `build/html/index.html`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
36 changes: 36 additions & 0 deletions docs/rips/PythonExamples/all_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
###################################################################################
# This example will connect to ResInsight, retrieve a list of cases and print info
#
###################################################################################

# Import the ResInsight Processing Server Module
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all cases
cases = resinsight.project.cases()

print ("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case id: " + str(case.id))
print("Case name: " + case.name)
print("Case type: " + case.__class__.__name__)
print("Case file name: " + case.file_path)
print("Case reservoir bounding box:", case.reservoir_boundingbox())

timesteps = case.time_steps()
for t in timesteps:
print("Year: " + str(t.year))
print("Month: " + str(t.month))

if isinstance(case, rips.EclipseCase):
print ("Getting coarsening info for case: ", case.name, case.id)
coarsening_info = case.coarsening_info()
if coarsening_info:
print("Coarsening information:")

for c in coarsening_info:
print("[{}, {}, {}] - [{}, {}, {}]".format(c.min.x, c.min.y, c.min.z,
c.max.x, c.max.y, c.max.z))
27 changes: 27 additions & 0 deletions docs/rips/PythonExamples/all_simulation_wells.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
###################################################################################
# This example will connect to ResInsight, retrieve a list of
# simulation wells and print info
###################################################################################

# Import the ResInsight Processing Server Module
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
cases = resinsight.project.cases()

for case in cases:
print("Case id: " + str(case.id))
print("Case name: " + case.name)

timesteps = case.time_steps()
sim_wells = case.simulation_wells()
for sim_well in sim_wells:
print("Simulation well: " + sim_well.name)

for (tidx, timestep) in enumerate(timesteps):
status = sim_well.status(tidx)
cells = sim_well.cells(tidx)
print("timestep: " + str(tidx) + " type: " + status.well_type + " open: " + str(status.is_open) + " cells:" + str(len(cells)))
17 changes: 17 additions & 0 deletions docs/rips/PythonExamples/all_wells.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
###################################################################################
# This example will connect to ResInsight, retrieve a list of wells and print info
#
###################################################################################

# Import the ResInsight Processing Server Module
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
wells = resinsight.project.well_paths()

print ("Got " + str(len(wells)) + " wells: ")
for well in wells:
print("Well name: " + well.name)
28 changes: 28 additions & 0 deletions docs/rips/PythonExamples/alter_wbs_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Load ResInsight Processing Server Client Library
import rips

# Connect to ResInsight instance
resinsight = rips.Instance.find()

# Get the project
project = resinsight.project

# Find all the well bore stability plots in the project
wbsplots = project.descendants(rips.WellBoreStabilityPlot)

# Chose a sensible output folder
dirname = "C:/temp"

# Loop through all Well Bore Stability plots
for wbsplot in wbsplots:
# Set depth type a parameter and export snapshot
wbsplot.depth_type = "TRUE_VERTICAL_DEPTH_RKB"

# Example of setting parameters for existing plots
params = wbsplot.parameters()
params.user_poisson_ratio = 0.12345
params.update()
wbsplot.update()
wbsplot.export_snapshot(export_folder=dirname)


27 changes: 27 additions & 0 deletions docs/rips/PythonExamples/case_grid_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import rips

resinsight = rips.Instance.find()

case_paths = []
case_paths.append("C:/Users/lindk/source/repos/ResInsight/TestModels/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID")
case_paths.append("C:/Users/lindk/source/repos/ResInsight/TestModels/Case_with_10_timesteps/Real10/BRUGGE_0010.EGRID")
for case_path in case_paths:
assert os.path.exists(case_path), "You need to set valid case paths for this script to work"

case_group = resinsight.project.create_grid_case_group(case_paths=case_paths)

case_group.print_object_info()

#stat_cases = caseGroup.statistics_cases()
#case_ids = []
#for stat_case in stat_cases:
# stat_case.set_dynamic_properties_to_calculate(["SWAT"])
# case_ids.append(stat_case.id)

case_group.compute_statistics()

view = case_group.views()[0]
cell_result = view.cell_result()
cell_result.set_result_variable("PRESSURE_DEV")

27 changes: 27 additions & 0 deletions docs/rips/PythonExamples/case_info_streaming_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
###############################################################################
# This example will get the cell info for the active cells for the first case
###############################################################################

# Import the ResInsight Processing Server Module
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()

# Get the first case. This will fail if you haven't loaded any cases
case = resinsight.project.cases()[0]

# Get the cell count object
cell_counts = case.cell_count()
print("Number of active cells: " + str(cell_counts.active_cell_count))
print("Total number of reservoir cells: " + str(cell_counts.reservoir_cell_count))

# Get information for all active cells
active_cell_infos = case.cell_info_for_active_cells()

# A simple check on the size of the cell info
assert(cell_counts.active_cell_count == len(active_cell_infos))

# Print information for the first active cell
print("First active cell: ")
print(active_cell_infos[0])
17 changes: 17 additions & 0 deletions docs/rips/PythonExamples/cell_result_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
######################################################################
# This script retrieves cell result data and alters it
######################################################################
import rips

resinsight = rips.Instance.find()

view = resinsight.project.views()[0]
results = view.cell_result_data()
print ("Number of result values: ", len(results))

newresults = []
for i in range(0, len(results)):
newresults.append(results[i] * -1.0)
view.set_cell_result_data(newresults)


57 changes: 57 additions & 0 deletions docs/rips/PythonExamples/command_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
###############################################################################
# This example will show setting time step, window size and export snapshots and properties
###############################################################################
import os
import tempfile
import rips

# Load instance
resinsight = rips.Instance.find()

# Set window sizes
resinsight.set_main_window_size(width=800, height=500)
resinsight.set_plot_window_size(width=1000, height=1000)


# Retrieve first case
case = resinsight.project.cases()[0]

# Get a view
view1 = case.views()[0]

# Clone the view
view2 = view1.clone()

# Set the time step for view1 only
view1.set_time_step(time_step=2)

# Set cell result to SOIL
view1.apply_cell_result(result_type='DYNAMIC_NATIVE', result_variable='SOIL')


# Create a temporary directory which will disappear at the end of this script
# If you want to keep the files, provide a good path name instead of tmpdirname
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
print("Temporary folder: ", tmpdirname)

# Set export folder for snapshots and properties
resinsight.set_export_folder(export_type='SNAPSHOTS', path=tmpdirname)
resinsight.set_export_folder(export_type='PROPERTIES', path=tmpdirname)

# Export all snapshots
resinsight.project.export_snapshots()

assert(len(os.listdir(tmpdirname)) > 0)

# Export properties in the view
view1.export_property()

# Check that the exported file exists
expected_file_name = case.name + "-" + str("3D_View") + "-" + "T2" + "-SOIL"
full_path = tmpdirname + "/" + expected_file_name

# Print contents of temporary folder
print(os.listdir(tmpdirname))

assert(os.path.exists(full_path))

43 changes: 43 additions & 0 deletions docs/rips/PythonExamples/create_wbs_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import grpc

# Load ResInsight Processing Server Client Library
import rips
# Connect to ResInsight instance
resInsight = rips.Instance.find()

# Get all GeoMech cases
cases = resInsight.project.descendants(rips.GeoMechCase)

# Get all well paths
well_paths = resInsight.project.well_paths()

# Ensure there's at least one well path
if len(well_paths) < 1:
print("No well paths in project")
exit(1)

# Create a set of WbsParameters
params = rips.WbsParameters()
params.user_poisson_ratio = 0.23456
params.user_ucs = 123

# Loop through all cases
for case in cases:
assert(isinstance(case, rips.GeoMechCase))
min_res_depth, max_res_depth = case.reservoir_depth_range()

# Find a good output path
case_path = case.file_path
folder_name = os.path.dirname(case_path)

# Import formation names
case.import_formation_names(formation_files=['D:/Projects/ResInsight-regression-test/ModelData/norne/Norne_ATW2013.lyr'])

# create a folder to hold the snapshots
dirname = os.path.join(folder_name, 'snapshots')
print("Exporting to: " + dirname)

for well_path in well_paths[0:4]: # Loop through the first five well paths
# Create plot with parameters
wbsplot = case.create_well_bore_stability_plot(well_path=well_path.name, time_step=0, parameters=params)

0 comments on commit 667b6ba

Please sign in to comment.