From ec69bda6f42fcbc93b6325d399e0b940ec4e2ced Mon Sep 17 00:00:00 2001 From: gbene Date: Fri, 27 Jan 2023 11:26:09 +0100 Subject: [PATCH] general fixes --- pzero/entities_factory.py | 37 +++++++++++--------- pzero/project_window.py | 2 +- pzero/well2vtk.py | 71 ++++++++++++++++++++------------------- pzero/windows_factory.py | 69 +++++++++++++++++++++++++++---------- 4 files changed, 110 insertions(+), 69 deletions(-) diff --git a/pzero/entities_factory.py b/pzero/entities_factory.py index 7b70048..95a81e2 100644 --- a/pzero/entities_factory.py +++ b/pzero/entities_factory.py @@ -2343,7 +2343,7 @@ def create_trace(self,xyz_trace,name=None): lines = Spline(xyz_trace) lines.rename_array('arc_length','MD') # lines = lines.compute_arc_length() - lines.field_data['name'] = [name] + lines.field_data['pname'] = [name] lines.field_data['MD'] = lines['MD'] self.ShallowCopy(lines) @@ -2389,22 +2389,27 @@ def plot_along_trace(self,prop=None,method='trace',camera=None): return actor def plot_tube(self,prop): - - prop_trace = self.get_field_data(f'p{prop}').reshape(-1,3) - prop_data = self.get_field_data(prop).reshape(-1,3) - # temp = pv_helpers.lines_from_points(prop_trace) - temp = Spline(prop_trace) - temp[prop] = prop_data - - filter = vtkTubeFilter() - filter.SetInputData(temp) - filter.SetRadius(1) - filter.SetNumberOfSides(10) - filter.Update() - out = filter.GetOutput() - del temp - return out + try: + prop_trace = self.get_field_data(f'p{prop}').reshape(-1,3) + except AttributeError: + print('Data not available') + return None + else: + prop_data = self.get_field_data(prop).reshape(-1,3) + + # temp = pv_helpers.lines_from_points(prop_trace) + temp = Spline(prop_trace) + temp[prop] = prop_data + + filter = vtkTubeFilter() + filter.SetInputData(temp) + filter.SetRadius(1) + filter.SetNumberOfSides(10) + filter.Update() + out = filter.GetOutput() + del temp + return out def plot_markers(self,prop): print(self.get_field_data_keys()) diff --git a/pzero/project_window.py b/pzero/project_window.py index 683465f..57fd52a 100644 --- a/pzero/project_window.py +++ b/pzero/project_window.py @@ -1062,7 +1062,7 @@ def open_project(self): """Read name of last revision in project file. This opens the last revision. To open a different one, edit the project file.""" # _________________________________________________________________________ IN THE FUTURE an option to open a specific revision could be added fin = open(in_file_name, 'rt') - rev_name = fin.readlines()[2] + rev_name = fin.readlines()[2].strip() fin.close() in_dir_name = in_file_name[:-3] + '_p0/' + rev_name self.TextTerminal.appendPlainText(("Opening project/revision : " + in_file_name + "/" + rev_name + "\n")) diff --git a/pzero/well2vtk.py b/pzero/well2vtk.py index 6e1ea59..fa8f92f 100644 --- a/pzero/well2vtk.py +++ b/pzero/well2vtk.py @@ -45,8 +45,7 @@ def well2vtk(self,path=None): # Get and set well trace data trace_data = data['GEOMETRY'] - - print(xyz_head[0]) + x = xyz_head[0,0]-trace_data['DX'] y = xyz_head[0,1]-trace_data['DY'] z = xyz_head[0,2]-trace_data['DZ'] @@ -75,39 +74,41 @@ def well2vtk(self,path=None): if key == 'LITHOLOGY' or key == 'GEOLOGY': tr_data = np_full(shape=(points,3),fill_value=np_nan) - color_dict = {k: np_random.rand(3) for k in pd.unique(prop[key])} - for row,(start,end,value) in prop.iterrows(): - start_idx = np_argmin(np_abs(arr - start)) - end_idx = np_argmin(np_abs(arr - end)) - # print(key) - # print(len(curve_copy.points[start_idx:end_idx])) - - if key == "GEOLOGY": - marker_pos = well_obj.trace.points[start_idx,:].reshape(-1,3) - marker_obj = VertexSet() - marker_obj.points = marker_pos - marker_obj.auto_cells() - - marker_obj_dict = deepcopy(GeologicalCollection.geological_entity_dict) - marker_obj_dict["topological_type"] = "VertexSet" - marker_obj_dict['uid'] = str(uuid4()) - marker_obj_dict['name'] = f'marker_{value}' - marker_obj_dict['geological_type'] = 'top' - marker_obj_dict['geological_feature'] = value - marker_obj_dict['x_section'] = well_uid - marker_obj_dict['vtk_obj'] = marker_obj - self.geol_coll.add_entity_from_dict(marker_obj_dict) - color_R = self.geol_coll.get_uid_legend(uid=marker_obj_dict['uid'])['color_R']/255 - color_G = self.geol_coll.get_uid_legend(uid=marker_obj_dict['uid'])['color_G']/255 - color_B = self.geol_coll.get_uid_legend(uid=marker_obj_dict['uid'])['color_B']/255 - color_dict[value] = np_array([color_R,color_G,color_B]) - del marker_obj_dict - color_val = color_dict[value] - - tr_data[start_idx:end_idx] = color_val - - - + try: + color_dict = {k: np_random.rand(3) for k in pd.unique(prop[key])} + except: + print('No key found') + else: + for row,(start,end,value) in prop.iterrows(): + start_idx = np_argmin(np_abs(arr - start)) + end_idx = np_argmin(np_abs(arr - end)) + # print(key) + # print(len(curve_copy.points[start_idx:end_idx])) + + if key == "GEOLOGY": + marker_pos = well_obj.trace.points[start_idx,:].reshape(-1,3) + marker_obj = VertexSet() + marker_obj.points = marker_pos + marker_obj.auto_cells() + + marker_obj_dict = deepcopy(GeologicalCollection.geological_entity_dict) + marker_obj_dict["topological_type"] = "VertexSet" + marker_obj_dict['uid'] = str(uuid4()) + marker_obj_dict['name'] = f'marker_{value}' + marker_obj_dict['geological_type'] = 'top' + marker_obj_dict['geological_feature'] = value + marker_obj_dict['x_section'] = well_uid + marker_obj_dict['vtk_obj'] = marker_obj + self.geol_coll.add_entity_from_dict(marker_obj_dict) + color_R = self.geol_coll.get_uid_legend(uid=marker_obj_dict['uid'])['color_R']/255 + color_G = self.geol_coll.get_uid_legend(uid=marker_obj_dict['uid'])['color_G']/255 + color_B = self.geol_coll.get_uid_legend(uid=marker_obj_dict['uid'])['color_B']/255 + color_dict[value] = np_array([color_R,color_G,color_B]) + del marker_obj_dict + color_val = color_dict[value] + + tr_data[start_idx:end_idx] = color_val + else: tr_data = np_zeros(shape=points) for row,(start,end,value) in prop.iterrows(): diff --git a/pzero/windows_factory.py b/pzero/windows_factory.py index 35db504..b466b32 100644 --- a/pzero/windows_factory.py +++ b/pzero/windows_factory.py @@ -1236,7 +1236,7 @@ def create_well_tree(self): property_combo = QComboBox() property_combo.uid = uid - property_combo.name = 'General' + property_combo.name = 'Annotations' property_combo.addItem("none") property_combo.addItem("name") self.WellsTreeWidget.setItemWidget(tlevel_1, 2, property_combo) @@ -1256,8 +1256,13 @@ def create_well_tree(self): property_combo.addItem("Y") property_combo.addItem("Z") for prop in self.parent.well_coll.get_uid_properties_names(uid): - if prop!= ('LITHOLOGY' or 'GEOLOGY'): + if prop == 'LITHOLOGY': + pass + elif prop == 'GEOLOGY': + pass + else: property_combo.addItem(prop) + self.WellsTreeWidget.setItemWidget(tlevel_2_trace, 2, property_combo) @@ -1327,12 +1332,17 @@ def update_well_tree_added(self, new_list=None): property_combo = QComboBox() property_combo.uid = uid + property_combo.name = 'Trace' property_combo.addItem("none") property_combo.addItem("X") property_combo.addItem("Y") property_combo.addItem("Z") for prop in self.parent.well_coll.get_uid_properties_names(uid): - if prop != 'GEOLOGY': + if prop == 'LITHOLOGY': + pass + elif prop == 'GEOLOGY': + pass + else: property_combo.addItem(prop) self.WellsTreeWidget.setItemWidget(glevel_2, 2, property_combo) @@ -1346,28 +1356,47 @@ def update_well_tree_added(self, new_list=None): break else: """Different geological type, geological feature and scenario""" - glevel_1 = QTreeWidgetItem(self.WellsTreeWidget, [self.parent.well_coll.get_uid_well_locid(uid)]) - glevel_1.setFlags(glevel_1.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable) - self.WellsTreeWidget.insertTopLevelItem(0, glevel_1) + tlevel_1 = QTreeWidgetItem(self.WellsTreeWidget, [self.parent.well_coll.get_uid_well_locid(uid)]) # self.GeologyTreeWidget as parent -> top level + tlevel_1.setFlags(tlevel_1.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable) property_combo = QComboBox() property_combo.uid = uid + property_combo.name = 'Annotations' + property_combo.addItem("none") + property_combo.addItem("name") + self.WellsTreeWidget.setItemWidget(tlevel_1, 2, property_combo) + property_combo.currentIndexChanged.connect(lambda: self.toggle_property()) + + + # ======================================= TRACE ======================================= + + tlevel_2_trace = QTreeWidgetItem(tlevel_1, ['Trace', uid]) # tlevel_1 as parent -> middle level + tlevel_2_trace.setFlags(tlevel_2_trace.flags() | Qt.ItemIsTristate | Qt.ItemIsUserCheckable) + + property_combo = QComboBox() + property_combo.uid = uid + property_combo.name = 'Trace' property_combo.addItem("none") property_combo.addItem("X") property_combo.addItem("Y") property_combo.addItem("Z") for prop in self.parent.well_coll.get_uid_properties_names(uid): - property_combo.addItem(prop) + if prop == 'LITHOLOGY': + pass + elif prop == 'GEOLOGY': + pass + else: + property_combo.addItem(prop) + + - glevel_2 = QTreeWidgetItem(glevel_1, ['Trace', uid]) - self.WellsTreeWidget.setItemWidget(glevel_2, 2, property_combo) + self.WellsTreeWidget.setItemWidget(tlevel_2_trace, 2, property_combo) property_combo.currentIndexChanged.connect(lambda: self.toggle_property()) - glevel_2.setFlags(glevel_2.flags() | Qt.ItemIsUserCheckable) + tlevel_2_trace.setFlags(tlevel_2_trace.flags() | Qt.ItemIsUserCheckable) if self.actors_df.loc[self.actors_df['uid'] == uid, 'show'].values[0]: - glevel_2.setCheckState(0, Qt.Checked) + tlevel_2_trace.setCheckState(0, Qt.Checked) elif not self.actors_df.loc[self.actors_df['uid'] == uid, 'show'].values[0]: - glevel_2.setCheckState(0, Qt.Unchecked) - self.WellsTreeWidget.insertTopLevelItem(0, glevel_2) + tlevel_2_trace.setCheckState(0, Qt.Unchecked) break self.WellsTreeWidget.itemChanged.connect(self.toggle_well_visibility) @@ -3311,7 +3340,11 @@ def save_home_view(self): self.default_view = self.plotter.camera_position def zoom_home_view(self): - self.plotter.camera_position = self.default_view + try: + self.plotter.camera_position = self.default_view + except AttributeError: + print('No default view set') + def zoom_active(self): self.plotter.reset_camera() @@ -3978,7 +4011,7 @@ def show_labels(self,uid=None,collection=None,show_property=None): elif collection == 'well_coll': plot_entity = self.parent.well_coll.get_uid_vtk_obj(uid) point = plot_entity.points[0].reshape(-1,3) - name_value = self.parent.well_coll.get_uid_well_locid(uid) + name_value = [self.parent.well_coll.get_uid_well_locid(uid)] elif collection == 'fluids_coll': plot_entity = self.parent.fluids_coll.get_uid_vtk_obj(uid) point = plot_entity.GetCenter() @@ -4152,7 +4185,8 @@ def change_bore_vis(self,method): elif self.toggle_bore_geo == -1: self.plotter.remove_actor(f'{uid}_litho') geo = plot_entity.plot_tube('GEOLOGY') - self.plotter.add_mesh(geo,name=f'{uid}_geo',rgb=True) + if geo != None: + self.plotter.add_mesh(geo,name=f'{uid}_geo',rgb=True) self.toggle_bore_geo *= -1 elif method == 'litho': @@ -4166,7 +4200,8 @@ def change_bore_vis(self,method): elif self.toggle_bore_litho == -1: self.plotter.remove_actor(f'{uid}_geo') litho = plot_entity.plot_tube('LITHOLOGY') - self.plotter.add_mesh(litho,name=f'{uid}_litho',rgb=True) + if litho != None: + self.plotter.add_mesh(litho,name=f'{uid}_litho',rgb=True) self.toggle_bore_litho *= -1 '''[Gabriele] PC Filters ----------------------------------------------------'''