Example #1
0
    def _get_polygon_data(self):
        """
        Method that gets the polygondict, cdict and extent of all the borehole points and store them in lines and colors
        """

        self.borehole_tube = []
        self.colors_bh = []
        self.faults_bh = []
        self.faults_color_bh = []
        _ = self.geo_model.set_section_grid(self.model_sections_dict)
        _ = gempy.compute_model(self.geo_model, compute_mesh=False)
        faults = list(self.geo_model.surfaces.df.loc[self.geo_model.surfaces.df['isFault']]['surface'])
        for name in self.borehole_dict.keys():
            polygondict, cdict, extent = section_utils.get_polygon_dictionary(self.geo_model,
                                                                              section_name=name)
            plt.close()  # avoid inline display

            # To get the top point of the model
            x, y = self.borehole_dict[name][0][0], self.borehole_dict[name][0][1]
            _ = self.grid.scale_frame(self.frame[int(y/self._pixel_scale[1]), int(x/self._pixel_scale[0])])
            z = numpy.asarray([_, _])
            color = numpy.asarray([None])
            fault_point = numpy.asarray([])
            fault_color = numpy.asarray([])
            for formation in list(self.geo_model.surfaces.df['surface']):
                 for path in polygondict.get(formation):
                     if path != []:
                        vertices = path.vertices
                        _idx = (numpy.abs(vertices[:, 0] - extent[1]/2)).argmin()
                        _compare = vertices[:, 0][_idx]
                        _mask = numpy.where(vertices[:, 0] == _compare)
                        extremes = vertices[_mask]
                        z_val = extremes[:, 1]
                        if formation in faults:
                            # fault_point = numpy.append(fault_point, z_val)
                            # fault_color = numpy.append(fault_color, cdict.get(formation))
                            self.faults_bh.append(numpy.asarray([x, y, z_val[0]]))
                            self.faults_color_bh.append(cdict.get(formation))
                        else:
                            z = numpy.vstack((z, z_val))
                            color = numpy.append(color, cdict.get(formation))

            mask1 = z[:, 0].argsort()
            mask2 = z[:, 0][mask1] <= z[0, 0]  # This is the first value added to start counting

            z_final = z[:, 0][mask1][mask2]
            color_final = color[mask1][mask2]
            # color_final[-1] = color[mask1][mask2 == False][0] Not needed to replace the color since is already none

            x_final = numpy.ones(len(z_final)) * x
            y_final = numpy.ones(len(z_final)) * y

            borehole_points = numpy.vstack((x_final, y_final, z_final)).T

            line = self._lines_from_points(borehole_points)
            line["scalars"] = numpy.arange(len(color_final))

            # For a single borehole
            self.borehole_tube.append(line.tube(radius=self._radius_borehole))
            self.colors_bh.append(color_final)
def plot_pathdict(geo_model, section_name):
    from gempy.core.grid_modules import section_utils
    pathdict, cdict, extent = section_utils.get_polygon_dictionary(
        geo_model, section_name)
    import matplotlib.path
    import matplotlib.patches as patches
    surfaces = list(geo_model.surfaces.df['surface'])[:-1][::-1]
    fig, ax = plt.subplots()
    for formation in surfaces:
        for path in pathdict.get(formation):
            if path != []:
                if type(path) == matplotlib.path.Path:
                    patch = patches.PathPatch(path,
                                              fill=False,
                                              lw=1,
                                              edgecolor=cdict.get(
                                                  formation, 'k'))
                    ax.add_patch(patch)
                elif type(path) == list:
                    for subpath in path:
                        assert type(subpath == matplotlib.path.Path)
                        patch = patches.PathPatch(subpath,
                                                  fill=False,
                                                  lw=1,
                                                  edgecolor=cdict.get(
                                                      formation, 'k'))
                        ax.add_patch(patch)
    ax.set_ylim(extent[2:4])
    ax.set_xlim(extent[:2])
    plt.show()
Example #3
0
def _extract_control_points_from_cross_section(geo_model, section_name:str):
    #TODO: ask miguel for an easier way of doing this
    import scipy
    grids = geo_model.get_active_grids()
    extent = geo_model.grid.regular_grid.extent
    if 'sections' not in grids:
        section_dict = {'section1': ([extent[0], extent[3]/2], [extent[1], extent[3]/2], [50, 50])}
        geo_model.set_section_grid(section_dict)
        import gempy as gp
        sol = gp.compute_model(geo_model)
        section_name = 'section1'

    from gempy.core.grid_modules import section_utils
    polygondict, cdict, extent = section_utils.get_polygon_dictionary(geo_model, section_name)

    surfaces = list(geo_model.surfaces.df['surface'])[:-1][::-1]
    control_points=[]
    for formation in surfaces:
        for polygon in polygondict.get(formation):
            if polygon != []:
                vertices = polygondict[formation][0].vertices
                df = pd.DataFrame({'col1': vertices[:, 0],
                                   'col2': vertices[:, 1],
                                  #'codes': polygondict[formation][0].codes
                                    })

                #df = df.sort_values(['col2'], ignore_index=True, ascending=False )
                #df = df.sort_values(['col1'], ignore_index=True)#, ascending=False)
                df = df.sort_values(['col1','col2'], ignore_index=True, ascending=True)

                df = df.drop_duplicates(subset=['col1'], keep='first', ignore_index=True )
                mat = scipy.spatial.distance.cdist(df[['col1', 'col2']],
                                                   df[['col1', 'col2']], metric='euclidean')

                new_df = pd.DataFrame(mat)
                closest = np.where(new_df.eq(new_df[new_df != 0].min(), 0), new_df.columns, False)
                df['close'] = [i[i.astype(bool)].tolist() for i in closest]
                cp=[]
                #max_count = df.shape[0]
                for count, position in enumerate(df.to_numpy()):
                    #if count + 1 ==
                    #print(count)
                    if position[-1]!=[]:
                        if position[-1][0] >= count+1:
                            cp.append(position[:2])
                control_points.append(np.asarray(cp))

    return control_points
Example #4
0
# sphinx_gallery_thumbnail_number = 4
gp.plot_2d(geo_model,
           section_names=['section1', 'section2', 'section3', 'topography'],
           show_topography=True)
plt.show()

# %%
# Get polygons of formations in sections
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

# %%
from gempy.core.grid_modules import section_utils

# %%
polygondict, cdict, extent = section_utils.get_polygon_dictionary(
    geo_model, 'section1')

# %%
# this stores the xy points in the sections for every surface.
polygondict

# %%
# Look at resulting polygons:
# '''''''''''''''''''''''''''
#

# %%
import matplotlib.path
import matplotlib.patches as patches