bp / bp/resqpy

Question: How to add a fault in Resqml model with grid.

Open
#808 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
67
Forks
18
Avg merge
2h 26m
Merged PRs (30d)
1

Description

Hello, I'm trying to add a fault epc model with grid and one single. Here is my code:
def save_grid_to_resqml(x, y, z, properties, fault_data, resqml_file_path):
"""
Saves a grid with fault and additional properties to RESQML format using resqpy.
"""
model = rq.Model(epc_file=resqml_file_path, new_epc=True, create_basics=True, create_hdf5_ext=True)

crs = rqc.Crs(model)
crs.create_xml()

x_unique = np.unique(x)
y_unique = np.unique(y)
z_unique = -np.unique(z)

extent_kji = (len(z_unique), len(y_unique), len(x_unique))
dxyz = (x_unique[1] - x_unique[0], y_unique[1] - y_unique[0], z_unique[1] - z_unique[0])
origin = (x_unique[0], y_unique[0], z_unique[0])
#print(f"{origin =}")

grid = grr.RegularGrid(model, extent_kji=extent_kji, dxyz=dxyz, origin=origin, crs_uuid=crs.uuid, as_irregular_grid=True)

grid.make_regular_points_cached()

grid.write_hdf5()
grid.create_xml(write_geometry=True)

grid_x, grid_y, grid_z = np.meshgrid(x_unique, y_unique, -z_unique, indexing='ij')
points = np.vstack((x, y, z)).T
grid_points = np.vstack((grid_x.flatten(), grid_y.flatten(), grid_z.flatten())).T
values = np.array(properties, dtype=np.float64)
prop_array = griddata(points, values, grid_points, method='linear').reshape(grid_x.shape)

nan_mask = np.isnan(prop_array)
if np.any(nan_mask):
nearest_values = griddata(points, values, grid_points, method='nearest').reshape(grid_x.shape)
prop_array[nan_mask] = nearest_values[nan_mask]

prop_array = prop_array.transpose(2, 1, 0)

single_property = rqp.Property.from_array(
parent_model=model,
cached_array=prop_array.astype(float),
source_info='Generated by script',
keyword='Struct',
support_uuid=grid.uuid,
property_kind='Structural',
indexable_element='cells',
uom='m'
)

# Handling fault data
fault_indices = np.where(fault_data['Fault'].values == 1)[0]
fault_points = fault_data[['X', 'Y', 'Z']].values[fault_indices]
point_set = rqs.PointSet(model, points_array=fault_points, crs_uuid=crs.uuid)
point_set.write_hdf5()
point_set.create_xml()

fault_surface = rqs.Surface(model, crs_uuid=crs.uuid)
fault_surface.set_from_point_set(point_set)
fault_surface.write_hdf5()
fault_surface.create_xml(add_as_part=True, add_relationships=True, title="Fault Surface")

fault_feature = rqo.TectonicBoundaryFeature(model, kind='fault', feature_name='Fault1')
fault_feature.create_xml()
fault_interp = rqo.FaultInterpretation(model, tectonic_boundary_feature=fault_feature, is_normal=True)
fault_interp.create_xml(add_as_part=True, add_relationships=True)

if fault_interp.uuid is None:
fault_interp.uuid = bu.new_uuid()
if fault_surface.uuid is None:
fault_surface.uuid = bu.new_uuid()

# Create reciprocal relationship
model.create_reciprocal_relationship(fault_interp, 'destinationObject', fault_surface, 'sourceObject')

model.store_epc()

return model, grid

I have a problem with create_reciprocal_relationship: PS C:\Users\ABerete\Documents\code\3DGeoContext.Computation.Utils> & c:/Users/ABerete/Documents/code/3DGeoContext.Computation.Utils/.venv/Scripts/python.exe c:/Users/ABerete/Documents/code/3DGeoContext.Computation.Utils/mss3_utils/scripting/adding_fault_resqml_.py
Traceback (most recent call last):
File "c:\Users\ABerete\Documents\code\3DGeoContext.Computation.Utils\mss3_utils\scripting\adding_fault_resqml_.py", line 142, in
main(input_file_path, fault_file_path, resqml_file_path)
File "c:\Users\ABerete\Documents\code\3DGeoContext.Computation.Utils\mss3_utils\scripting\adding_fault_resqml_.py", line 135, in main
model, grid = save_grid_to_resqml(x, y, z, properties, fault_data, resqml_file_path)
File "c:\Users\ABerete\Documents\code\3DGeoContext.Computation.Utils\mss3_utils\scripting\adding_fault_resqml_.py", line 121, in save_grid_to_resqml
model.create_reciprocal_relationship(fault_interp, 'destinationObject', fault_surface, 'sourceObject')
File "C:\Users\ABerete\Documents\code\3DGeoContext.Computation.Utils\.venv\lib\site-packages\resqpy\model\_model.py", line 1867, in create_reciprocal_relationship
return m_x._create_reciprocal_relationship(self,
File "C:\Users\ABerete\Documents\code\3DGeoContext.Computation.Utils\.venv\lib\site-packages\resqpy\model\_xml.py", line 555, in _create_reciprocal_relationship
uuid_a = node_a.attrib['uuid']
AttributeError: 'FaultInterpretation' object has no attribute 'attrib'

Contributor guide

Open the contributing guide

Research direction

Start at Model.create_reciprocal_relationship and follow the traceback into _create_reciprocal_relationship, using the fault construction code in the issue as the reproduction. Determine the supported relationship inputs and verify the resulting RESQML model can be stored with the fault surface and interpretation linked.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.