Skip to content

Commit

Permalink
Update after Python black has been used for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed May 4, 2021
1 parent 50c1f01 commit c70367a
Show file tree
Hide file tree
Showing 75 changed files with 1,575 additions and 1,994 deletions.
13 changes: 8 additions & 5 deletions docs/rips/PythonExamples/all_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()
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: ")
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case id: " + str(case.id))
print("Case name: " + case.name)
Expand All @@ -26,11 +26,14 @@
print("Month: " + str(t.month))

if isinstance(case, rips.EclipseCase):
print ("Getting coarsening info for case: ", case.name, case.id)
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))
print(
"[{}, {}, {}] - [{}, {}, {}]".format(
c.min.x, c.min.y, c.min.z, c.max.x, c.max.y, c.max.z
)
)
13 changes: 11 additions & 2 deletions docs/rips/PythonExamples/all_simulation_wells.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all wells
cases = resinsight.project.cases()
Expand All @@ -24,4 +24,13 @@
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)))
print(
"timestep: "
+ str(tidx)
+ " type: "
+ status.well_type
+ " open: "
+ str(status.is_open)
+ " cells:"
+ str(len(cells))
)
4 changes: 2 additions & 2 deletions docs/rips/PythonExamples/all_wells.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import rips

# Connect to ResInsight
resinsight = rips.Instance.find()
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: ")
print("Got " + str(len(wells)) + " wells: ")
for well in wells:
print("Well name: " + well.name)
4 changes: 1 addition & 3 deletions docs/rips/PythonExamples/alter_wbs_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@
params = wbsplot.parameters()
params.user_poisson_ratio = 0.12345
params.update()
wbsplot.update()
wbsplot.update()
wbsplot.export_snapshot(export_folder=dirname)


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

resinsight = rips.Instance.find()
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")
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"
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_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)

Expand All @@ -24,4 +30,3 @@
view = case_group.views()[0]
cell_result = view.cell_result()
cell_result.set_result_variable("PRESSURE_DEV")

4 changes: 2 additions & 2 deletions docs/rips/PythonExamples/case_info_streaming_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import rips

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

# Get the first case. This will fail if you haven't loaded any cases
case = resinsight.project.cases()[0]
Expand All @@ -20,7 +20,7 @@
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))
assert cell_counts.active_cell_count == len(active_cell_infos)

# Print information for the first active cell
print("First active cell: ")
Expand Down
6 changes: 2 additions & 4 deletions docs/rips/PythonExamples/cell_result_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
######################################################################
import rips

resinsight = rips.Instance.find()
resinsight = rips.Instance.find()

view = resinsight.project.views()[0]
results = view.cell_result_data()
print ("Number of result values: ", len(results))
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)


19 changes: 9 additions & 10 deletions docs/rips/PythonExamples/command_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
view1.set_time_step(time_step=2)

# Set cell result to SOIL
view1.apply_cell_result(result_type='DYNAMIC_NATIVE', result_variable='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)
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)

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

# Export properties in the view
view1.export_property()

Expand All @@ -53,5 +53,4 @@
# Print contents of temporary folder
print(os.listdir(tmpdirname))

assert(os.path.exists(full_path))

assert os.path.exists(full_path)
60 changes: 0 additions & 60 deletions docs/rips/PythonExamples/create_and_export_fracture_model.py

This file was deleted.

54 changes: 33 additions & 21 deletions docs/rips/PythonExamples/create_and_export_stim_plan_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@
facies_properties_file_path = (Path(home_dir) / "facies_id.roff").as_posix()
print("Facies properties file path:", facies_properties_file_path)

# Find a case
cases = resinsight.project.cases()
case = cases[1]

# Use the last time step
time_steps = case.time_steps()
time_step = time_steps[len(time_steps) - 1]


# Create stim plan model template
fmt_collection = project.descendants(rips.StimPlanModelTemplateCollection)[0]
stim_plan_model_template = fmt_collection.new_stim_plan_model_template(elastic_properties_file_path=elastic_properties_file_path,
facies_properties_file_path=facies_properties_file_path)
stim_plan_model_template = fmt_collection.new_stim_plan_model_template(
eclipse_case=case,
time_step=time_step,
elastic_properties_file_path=elastic_properties_file_path,
facies_properties_file_path=facies_properties_file_path,
)
stim_plan_model_template.overburden_formation = "Garn"
stim_plan_model_template.overburden_facies = "Shale"
stim_plan_model_template.underburden_formation = "Garn"
Expand Down Expand Up @@ -49,7 +62,9 @@

# Add some scaling factors
elastic_properties = stim_plan_model_template.elastic_properties()
elastic_properties.add_property_scaling(formation="Garn", facies="Calcite", property="YOUNGS_MODULUS", scale=1.44)
elastic_properties.add_property_scaling(
formation="Garn", facies="Calcite", property="YOUNGS_MODULUS", scale=1.44
)


well_name = "B-2 H"
Expand All @@ -59,34 +74,28 @@
print("well path:", well_path)
stim_plan_model_collection = project.descendants(rips.StimPlanModelCollection)[0]

# Find a case
cases = resinsight.project.cases()
case = cases[0]

# Use the last time step
time_steps = case.time_steps()
time_step = time_steps[len(time_steps) - 1]


export_folder = tempfile.gettempdir()

stim_plan_models = []

# Create and export a StimPlan model for each depth
measured_depths = [ 3200.0, 3400.0, 3600.0 ]
measured_depths = [3200.0, 3400.0, 3600.0]
for measured_depth in measured_depths:

# Create stim plan model at a give measured depth
stim_plan_model = stim_plan_model_collection.new_stim_plan_model(eclipse_case=case,
time_step=time_step,
well_path=well_path,
measured_depth=measured_depth,
stim_plan_model_template=stim_plan_model_template)
stim_plan_model = stim_plan_model_collection.new_stim_plan_model(
well_path=well_path,
measured_depth=measured_depth,
stim_plan_model_template=stim_plan_model_template,
)
stim_plan_models.append(stim_plan_model)

# Make the well name safer to use as a directory path
well_name_part = well_name.replace(" ", "_")
directory_path = Path(export_folder) / '{}_{}'.format(well_name_part, int(measured_depth))
directory_path = Path(export_folder) / "{}_{}".format(
well_name_part, int(measured_depth)
)

# Create the folder
directory_path.mkdir(parents=True, exist_ok=True)
Expand All @@ -95,14 +104,17 @@
stim_plan_model.export_to_file(directory_path=directory_path.as_posix())

# Create a fracture mode plot
stim_plan_model_plot_collection = project.descendants(rips.StimPlanModelPlotCollection)[0]
stim_plan_model_plot = stim_plan_model_plot_collection.new_stim_plan_model_plot(stim_plan_model=stim_plan_model)
stim_plan_model_plot_collection = project.descendants(
rips.StimPlanModelPlotCollection
)[0]
stim_plan_model_plot = stim_plan_model_plot_collection.new_stim_plan_model_plot(
stim_plan_model=stim_plan_model
)

print("Exporting fracture model plot to: ", directory_path)
stim_plan_model_plot.export_snapshot(export_folder=directory_path.as_posix())



print("Setting measured depth and perforation length.")
stim_plan_models[0].measured_depth = 3300.0
stim_plan_models[0].perforation_length = 123.445
Expand Down

0 comments on commit c70367a

Please sign in to comment.