From 18215d3869a5e397f52c6f2e680597fa1ed8be80 Mon Sep 17 00:00:00 2001 From: Niederau Date: Fri, 11 Aug 2023 17:44:34 +0200 Subject: [PATCH] [BUG] surface points added to wrong surface --- gempy/core/data_modules/geometric_data.py | 4 ++-- test/test_core/test_data_mutation.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gempy/core/data_modules/geometric_data.py b/gempy/core/data_modules/geometric_data.py index fb9182a5..33ccc5e7 100644 --- a/gempy/core/data_modules/geometric_data.py +++ b/gempy/core/data_modules/geometric_data.py @@ -162,7 +162,7 @@ def map_data_from_surfaces(self, surfaces, attribute: str, idx=None): def _add_surface_to_list_from_new_surface_points_or_orientations(self, idx, surface: list | str): if type(surface) is str: surface = [surface] - # Check is self.df['surface'] is a category + # Check if self.df['surface'] is a category if not isinstance(self.df['surface'].dtype, pd.CategoricalDtype): self.df['surface'] = self.df['surface'].astype('category', copy=True) self.df['surface'] = self.df['surface'].cat.set_categories(self.surfaces.df['surface'].values) @@ -172,7 +172,7 @@ def _add_surface_to_list_from_new_surface_points_or_orientations(self, idx, surf # if s not in self.df['surface'].cat.categories: # self.df['surface'] = self.df['surface'].cat.add_categories(s) - if type(idx) is int: + if isinstance(idx, (np.int64, int)): self.df.loc[idx, 'surface'] = surface[0] elif type(idx) is list: self.df.loc[idx, 'surface'] = surface diff --git a/test/test_core/test_data_mutation.py b/test/test_core/test_data_mutation.py index a859bd59..53957971 100644 --- a/test/test_core/test_data_mutation.py +++ b/test/test_core/test_data_mutation.py @@ -6,6 +6,7 @@ import numpy as np import pytest import os +import matplotlib.pyplot as plt mm = gp.ImplicitCoKriging() mm.add_surfaces(['surface1', 'foo1', 'foo2', 'foo3']) @@ -93,4 +94,20 @@ def test_read_data(): model.read_data(path_i=data_path + "/data/input_data/tut_chapter1/simple_fault_model_points.csv", path_o=data_path + "/data/input_data/tut_chapter1/simple_fault_model_orientations.csv") - assert model._surface_points.df.shape[0] == 57 \ No newline at end of file + assert model._surface_points.df.shape[0] == 57 + +def test_add_surface_points_to_model(): + geo_model = gp.create_model('TestModel1') + gp.init_data(geo_model, extent=[0, 800, 0, 200, -600, 0], resolution=[100, 100, 100]) + geo_model.set_default_surfaces() + + geo_model.add_surface_points(X=223, Y=0.01, Z=-94, surface='surface1') + geo_model.add_surface_points(X=458, Y=0, Z=-107, surface='surface1') + geo_model.add_surface_points(X=612, Y=0, Z=-14, surface='surface1') + geo_model.add_orientations(X=350, Y=0, Z=-300, surface='surface1', pole_vector=(0, 0, 1)) + + geo_model.add_surface_points(X=225, Y=1, Z=-269, surface='surface2') + geo_model.add_surface_points(X=459, Y=1, Z=-279, surface='surface2') + + #gp.plot_2d(geo_model, cell_number=5, legend='force') + #plt.show()