def plot_map(self, solution: Solution = None, contour_lines=False, show_faults=True, show_data=True, show_all_data=False, figsize=(12,12)): if solution is None: solution = self.model.solutions assert solution.geological_map is not None, 'Geological map not computed. Activate the topography grid.' try: geomap = solution.geological_map.reshape(self.model.grid.topography.values_3D[:, :, 2].shape) except AttributeError: warnings.warn('Geological map not computed. Activate the topography grid.') if show_data: self.plot_data(direction='z', at='topography', show_all_data=show_all_data) else: fig, ax = plt.subplots(figsize=figsize) im = plt.imshow(geomap, origin='lower', extent=self.model.grid.topography.extent, cmap=self._cmap, norm=self._norm, zorder=-100) if contour_lines == True and show_data == False: CS = ax.contour(self.model.grid.topography.values_3D[:, :, 2], cmap='Greys', linestyles='solid', extent=self.model.grid.topography.extent) ax.clabel(CS, inline=1, fontsize=10, fmt='%d') plothelp.add_colorbar(im=im, label='elevation [m]', cs=CS, aspect=35) if show_faults == True: self.extract_section_fault_lines('topography', faults_only=True) plt.title("Geological map", fontsize=15) plt.xlabel('X') plt.ylabel('Y')
def plot_map(self, solution: Solution = None, contour_lines=True, show_faults=True, show_data=False): if solution is not None: assert solution.geological_map is not None, 'Geological map not computed. Activate the topography grid.' else: solution = self.model.solutions geomap = solution.geological_map.reshape( self.model.grid.topography.values_3D[:, :, 2].shape) if show_data: self.plot_data(direction='z') else: fig, ax = plt.subplots(figsize=(6, 6)) im = plt.imshow(geomap, origin='lower', extent=self.model.grid.topography.extent, cmap=self._cmap, norm=self._norm) if contour_lines == True and show_data == False: CS = ax.contour(self.model.grid.topography.values_3D[:, :, 2], cmap='Greys', linestyles='solid', extent=self.model.grid.topography.extent) ax.clabel(CS, inline=1, fontsize=10, fmt='%d') plothelp.add_colorbar(im=im, label='elevation [m]', cs=CS, aspect=35) if show_faults == True: self.extract_section_fault_lines('topography') plt.title("Geological map", fontsize=15) plt.xlabel('X') plt.ylabel('Y')
def show(self): from gempy.plot.helpers import add_colorbar if self.type == 'artificial': fig, ax = plt.subplots() CS= ax.contour(self.values_3D[:, :, 2], extent=(self.extent[:4]), colors='k', linestyles='solid') ax.clabel(CS, inline=1, fontsize=10, fmt='%d') CS2 = ax.contourf(self.values_3D[:, :, 2], extent=(self.extent[:4]), cmap='terrain') add_colorbar(axes=ax, label='elevation [m]', cs=CS2) else: im = plt.imshow(np.flipud(self.values_3D[:,:,2]), extent=(self.extent[:4])) add_colorbar(im=im, label='elevation [m]') plt.axis('scaled') plt.xlabel('X') plt.ylabel('Y') plt.title('Model topography')
def plot_probabilities(plot, block, shape, T=False, extent=None): fig, ax = plt.subplots(int(np.ceil(block.shape[0] / 2)), 2, figsize=(16, 8)) ax = ax.flatten() print(int(np.ceil(block.shape[0] / 2))) print(block.shape) for i in range(block.shape[0]): allcolors = list(plot._color_lot.values())[plot.model.faults.n_faults:] formnames = list(plot._color_lot.keys())[plot.model.faults.n_faults:] c2 = allcolors[i] title = formnames[i] cmap = mcolors.LinearSegmentedColormap.from_list('c', ['#FFFFFF', c2]) if T: plotblock = block[i].reshape(shape).T else: plotblock = block[i].reshape(shape) im = ax[i].imshow(plotblock, origin='lower', cmap=cmap, extent=extent) ax[i].set_title(title) helpers.add_colorbar(im, label='probability')
def plot_topography(ax, geo_model, extent_val, **kwargs): """ Args: ax: geo_model: extent_val: **kwargs: Returns: """ hillshade = kwargs.pop('show_hillshade', True) contour = kwargs.pop('show_contour', False) fill_contour = kwargs.pop('show_fill_contour', False) azdeg = kwargs.pop('azdeg', 0) altdeg = kwargs.pop('altdeg', 0) cmap = kwargs.pop('cmap', 'terrain') super = kwargs.pop('super_res', False) colorbar = kwargs.pop("show_colorbar", False) topo = geo_model._grid.topography if super: import skimage topo_super_res = skimage.transform.resize(topo.values_2d, (1600, 1600), order=3, mode='edge', anti_aliasing=True, preserve_range=False) values = topo_super_res[..., 2] else: values = topo.values_2d[..., 2] if contour is True: CS = ax.contour(values, extent=extent_val, colors='k', linestyles='solid', origin='lower') ax.clabel(CS, inline=1, fontsize=10, fmt='%d') if fill_contour is True: CS2 = ax.contourf(values, extent=extent_val, cmap=cmap) if colorbar: from gempy.plot.helpers import add_colorbar add_colorbar(axes=ax, label='elevation [m]', cs=CS2) if hillshade is True: from matplotlib.colors import LightSource # Note: 180 degrees are subtracted because visualization in Sandbox is upside-down ls = LightSource(azdeg=azdeg - 180, altdeg=altdeg) # TODO: Is is better to use ls.hillshade or ls.shade?? hillshade_topography = ls.hillshade(values) # vert_exag=0.3, # blend_mode='overlay') global hill hill = ax.imshow(hillshade_topography, cmap=plt.cm.gray, origin='lower', extent=extent_val, alpha=0.4, zorder=11, aspect='auto')
def plot_mapview( self, show_lith: bool = True, # show_boundary: bool = True, show_hillshade: bool = True, show_contour: bool = False, show_only_faults: bool = False, **kwargs): cmap_type = kwargs.pop('cmap', 'YlOrRd') if 'ax' in kwargs: # append plot to existing axis ax = kwargs.pop('ax') else: figsize = kwargs.pop("figsize", (10, 6)) fig, ax = plt.subplots(figsize=figsize) if show_lith: image = self.vertices_mapview[:, 2].reshape(self.model_resolution[:2]) self.lith = ax.imshow( image, origin='lower', zorder=-10, extent=self.model_extent[:4], cmap=cmap_type, #norm=norm, aspect='auto') fill_contour = kwargs.pop('show_fill_contour', False) azdeg = kwargs.pop('azdeg', 0) altdeg = kwargs.pop('altdeg', 0) super = kwargs.pop('super_res', False) colorbar = kwargs.pop("show_colorbar", False) topo = self.grid.depth_grid[:, 2].reshape(self.model_resolution[:2]) #if super: # import skimage # topo_super_res = skimage.transform.resize( # topo, # (1600, 1600), # order=3, # mode='edge', # anti_aliasing=True, preserve_range=False) # values = topo_super_res[..., 2] #else: # values = topo.values_2d[..., 2] if show_contour is True: CS = ax.contour(topo, extent=self.model_extent[:4], colors='k', linestyles='solid', origin='lower') ax.clabel(CS, inline=1, fontsize=10, fmt='%d') if fill_contour is True: CS2 = ax.contourf(topo, extent=self.model_extent[:4], cmap=cmap) if colorbar: from gempy.plot.helpers import add_colorbar add_colorbar(axes=ax, label='elevation [m]', cs=CS2) if show_hillshade: from matplotlib.colors import LightSource # Note: 180 degrees are subtracted because visualization in Sandbox is upside-down ls = LightSource(azdeg=azdeg - 180, altdeg=altdeg) # TODO: Is it better to use ls.hillshade or ls.shade?? hillshade_topography = ls.hillshade(topo) # vert_exag=0.3, # blend_mode='overlay') self.hill = ax.imshow(hillshade_topography, cmap=plt.cm.gray, origin='lower', extent=self.model_extent[:4], alpha=0.4, zorder=11, aspect='auto')
def plot_results(self, geo_data, prop='val', direction='y', cell_number=0, contour=False, cmap='viridis', alpha=0, legend=False, interpolation='nearest', show_data=True): """ TODO WRITE DOCSTRING Args: geo_data: prop: property that should be plotted - "val", "var" or "both" direction: x, y or z cell_number: contour: cmap: alpha: legend: Returns: """ a = np.full_like(self.mask, np.nan, dtype=np.double) #array like lith_block but with nan if outside domain est_vals = self.results_df['est_value'].values est_var = self.results_df['est_variance'].values # set values if prop == 'val': a[np.where(self.mask == True)] = est_vals elif prop == 'var': a[np.where(self.mask == True)] = est_var elif prop == 'both': a[np.where(self.mask == True)] = est_vals b = np.full_like(self.mask, np.nan, dtype=np.double) b[np.where(self.mask == True)] = est_var else: print('prop must be val var or both') #create plot object p = visualization_2d.PlotSolution(geo_data) _a, _b, _c, extent_val, x, y = p._slice(direction, cell_number)[:-2] #colors cmap = cm.get_cmap(cmap) cmap.set_bad(color='w', alpha=alpha) #define color and alpha for nan values # plot if prop is not 'both': if show_data: plt.scatter(self.data_df[x].values, self.data_df[y].values, marker='*', s=9, c='k') plot.plot_section(geo_data, direction=direction, cell_number=cell_number) if contour == True: im = plt.contourf(a.reshape(self.sol.grid.regular_grid.resolution)[_a, _b, _c].T, cmap=cmap, origin='lower', levels=25, extent=extent_val, interpolation=interpolation) if legend: ax = plt.gca() helpers.add_colorbar(axes=ax, label='prop', cs=im) else: im = plt.imshow(a.reshape(self.sol.grid.regular_grid.resolution)[_a, _b, _c].T, cmap=cmap, origin='lower', extent=extent_val, interpolation=interpolation) if legend: helpers.add_colorbar(im, label='pups', location='right') else: f, ax = plt.subplots(1, 2, sharex=True, sharey=True) ax[0].title.set_text('Estimated value') im1 = ax[0].imshow(a.reshape(self.sol.grid.regular_grid.resolution)[_a, _b, _c].T, cmap=cmap, origin='lower', interpolation=interpolation, extent=self.sol.grid.regular_grid.extent[[0, 1, 4, 5]]) helpers.add_colorbar(im1, label='unit') ax[1].title.set_text('Variance') im2 = ax[1].imshow(b.reshape(self.sol.grid.regular_grid.resolution)[_a, _b, _c].T, cmap=cmap, origin='lower', interpolation=interpolation, extent=self.sol.grid.regular_grid.extent[[0, 1, 4, 5]]) helpers.add_colorbar(im2, label='unit') plt.tight_layout()
def plot_topography(self, ax, fill_contour=False, contour=True, section_name=None, cell_number=None, direction='y', block=None, **kwargs): hillshade = kwargs.get('hillshade', True) azdeg = kwargs.get('azdeg', 0) altdeg = kwargs.get('altdeg', 0) cmap = kwargs.get('cmap', 'terrain') self.update_colot_lot() section_name, cell_number, direction = self._check_default_section(ax, section_name, cell_number, direction) if section_name is not None and section_name != 'topography': p1 = self.model._grid.sections.df.loc[section_name, 'start'] p2 = self.model._grid.sections.df.loc[section_name, 'stop'] x, y, z = self._slice_topo_4_sections(p1, p2, self.model._grid.topography.resolution[0]) pseudo_x = np.linspace(0, self.model._grid.sections.df.loc[section_name, 'dist'], z.shape[0]) a = np.vstack((pseudo_x, z)).T xy = np.append(a, ([self.model._grid.sections.df.loc[section_name, 'dist'], a[:, 1][-1]], [self.model._grid.sections.df.loc[section_name, 'dist'], self.model._grid.regular_grid.extent[5]], [0, self.model._grid.regular_grid.extent[5]], [0, a[:, 1][0]])).reshape(-1, 2) ax.fill(xy[:, 0], xy[:, 1], 'k', zorder=10) elif section_name == 'topography': import skimage from gempy.plot.helpers import add_colorbar topo = self.model._grid.topography topo_super_res = skimage.transform.resize( topo.values_2d, (1600, 1600), order=3, mode='edge', anti_aliasing=True, preserve_range=False) values = topo_super_res[:, :, 2].T if contour is True: CS = ax.contour(values, extent=(topo.extent[:4]), colors='k', linestyles='solid', origin='lower') ax.clabel(CS, inline=1, fontsize=10, fmt='%d') if fill_contour is True: CS2 = ax.contourf(values, extent=(topo.extent[:4]), cmap=cmap) add_colorbar(axes=ax, label='elevation [m]', cs=CS2) if hillshade is True: from matplotlib.colors import LightSource ls = LightSource(azdeg=azdeg, altdeg=altdeg) hillshade_topography = ls.hillshade(values) ax.imshow(hillshade_topography, origin='lower', extent=topo.extent[:4], alpha=0.5, zorder=11, cmap='gray') elif cell_number is not None or block is not None: p1, p2 = self.calculate_p1p2(direction, cell_number) resx = self.model._grid.regular_grid.resolution[0] resy = self.model._grid.regular_grid.resolution[1] x, y, z = self._slice_topo_4_sections(p1, p2, resx) if direction == 'x': a = np.vstack((y, z)).T ext = self.model._grid.regular_grid.extent[[2, 3]] elif direction == 'y': a = np.vstack((x, z)).T ext = self.model._grid.regular_grid.extent[[0, 1]] else: raise NotImplementedError a = np.append(a, ([ext[1], a[:, 1][-1]], [ext[1], self.model._grid.regular_grid.extent[5]], [ext[0], self.model._grid.regular_grid.extent[5]], [ext[0], a[:, 1][0]])) line = a.reshape(-1, 2) ax.fill(line[:, 0], line[:, 1], color='k')