def plot_interface(self, x, y, z, scale='km'): """ take xyz data, create a grid and make a contour plot """ import pek1dplotting as p1dp z = p1dp.update_scale(z, scale) xi = np.array( np.meshgrid( np.linspace( min(x), max(x), 20), np.linspace( min(y), max(y), 50))).T zi = si.griddata(np.vstack([x, y]).T, z, xi, method=self.imethod) cmap = plt.get_cmap(self.cmap) if self.levels is None: plt1 = plt.contourf(xi[:, :, 0], xi[:, :, 1], zi, cmap=cmap) self.levels = plt1.levels else: plt1 = plt.contourf(xi[:, :, 0], xi[:, :, 1], zi, levels=self.levels, cmap=cmap) ax = plt.gca() ax.set_aspect('equal') if self.plot_cbar: self.add_cbar() if self.xlim is not None: plt.xlim(self.xlim) if self.ylim is not None: plt.ylim(self.ylim)
def plot_interface(self,x,y,z,scale='km'): """ take xyz data, create a grid and make a contour plot """ import pek1dplotting as p1dp z = p1dp.update_scale(z,scale) xi = np.array(np.meshgrid(np.linspace(min(x),max(x),20),np.linspace(min(y),max(y),50))).T zi = si.griddata(np.vstack([x,y]).T, z, xi, method=self.imethod) cmap = plt.get_cmap(self.cmap) if self.levels is None: plt1 = plt.contourf(xi[:,:,0],xi[:,:,1],zi,cmap=cmap) self.levels = plt1.levels else: plt1 = plt.contourf(xi[:,:,0],xi[:,:,1],zi, levels=self.levels,cmap=cmap) ax = plt.gca() ax.set_aspect('equal') if self.plot_cbar: self.add_cbar() if self.xlim is not None: plt.xlim(self.xlim) if self.ylim is not None: plt.ylim(self.ylim)
def plot_aniso_and_interfaces(self,plot_aniso=True): """ plot a set of models and up to three interfaces for comparison. """ import pek1dplotting as p1dp if type(self.xyzfiles) == str: self.xyzfiles = [self.xyzfiles] if self.subplot_layout == 'vertical': s1,s2 = len(self.xyzfiles)+1,1 sp_labels = ['y']*(len(self.xyzfiles)-1)+['xy'] ad_labels = 'y' if not plot_aniso: s1 -= 1 elif self.subplot_layout == 'horizontal': s2,s1 = len(self.xyzfiles)+1,1 sp_labels = ['x']*(len(self.xyzfiles)) ad_labels = 'xy' if not plot_aniso: s2 -= 1 sp_labels[0] += 'y' # elif self.subplot_layout == 'grid': # s1 = int(np.ceil((len(self.xyzfiles)+1)**0.5)) # s2 = s1 # sp_labels = ['','xy','x'] # ad_labels = 'y' # set self.cmap false for the time being, until all individual plots are done cbar = self.plot_cbar self.plot_cbar = False header_rows,scale = [[d[at] for d in [self.aniso_depth_file_dict, self.xyzfiles_dict]] for at in ['header_rows','scale']] self.depth = p1dp.update_scale(self.depth,scale[0]) zmin,zmax = np.amin(self.depth),np.amax(self.depth) for f in self.xyzfiles: z = p1dp.update_scale(np.loadtxt(f,skiprows=header_rows[1])[:,2], scale[1]) if np.amin(z) < zmin: zmin = np.amin(z) if np.amax(z) > zmax: zmax = np.amax(z) self.levels = np.linspace(zmin,zmax,self.n_levels) x,y = self.x,self.y # if self.figsize is None: # ar = ((float(s1)/float(s2))*((np.amax(y) - np.amin(y))/(np.amax(x) - np.amin(x))))**0.9 # self.figsize=(10,10*ar) plt.figure(figsize=self.figsize) plt.subplot(s1,s2,1) if plot_aniso: sp = range(2,len(self.xyzfiles)+2) self.plot_aniso_depth_map() title = "Magnitude and depth of anisotropy\nfrom 1D anisotropic inversions" self._update_axis_params(title,ad_labels) else: sp = range(1,len(self.xyzfiles)+1) # plt.gca().set_xticklabels([]) for s,ss in enumerate(sp): ax = plt.subplot(s1,s2,ss) # print self.xyzfiles[s] xyz = np.loadtxt(self.xyzfiles[s],skiprows=header_rows[1]) x,y,z = [xyz[:,i] for i in range(3)] self.plot_interface(x,y,z, scale=scale[1]) self.add_xy_data(ss) self.add_ax_text(ss) self._update_axis_params(title=self.xyzfile_titles[s], labels=sp_labels[s]) if 'x' not in sp_labels[s]: ax.set_xticklabels([]) plt.xlabel('') if 'y' not in sp_labels[s]: ax.set_yticklabels([]) plt.ylabel('') self.plot_cbar = cbar bottom = self.cbar_ax[1]+self.cbar_ax[3]+0.05 plt.subplots_adjust(wspace=self.wspace, hspace=self.hspace, bottom=bottom) if self.plot_cbar: self.add_cbar()
def plot_parameter(self,parameter, ylim=[6,0], horizon_list = None, horizon_zscale = 'km', new_figure = True, plot_inmodel=True, additional_data = None): """ parameter = 'anisotropy', 'minmax', or 'strike' or list containing several of these additional_data - additional data (e.g. resistivity logs) to plot on the figure. Provide as a list of 2D numpy arrays [depth, param] """ import pek1dplotting as p1dp # self.get_station_distance() # # # define some initial locations to put the plots corresponding to distance along profile # profile_x = (self.station_distances - np.amin(self.station_distances)) # # # normalise so max distance is at 1 # profile_x /= (np.amax(self.station_distances)-np.amin(self.station_distances)) # # # make an empty array to put buffered distances # profile_x_buf = np.zeros_like(profile_x) # modelno = self.Model_suite.modelno # ## print profile_x px = self.ax_width dx = self.plot_spacing nx = len(self.Model_suite.model_list) profile_x = np.linspace(0.,px*nx+dx*(nx-1),nx) + px/2. profile_x = np.linspace(0.,1.-2.5*px-dx,nx) + px + dx # print profile_x,px,dx,nx # # # # # shift each station along the profile so that they don't overlap each other # for i in range(len(profile_x)): # if i == 0: # profile_x_buf[i] = profile_x[i] # else: # profile_x_buf[i] = max(profile_x[i],profile_x_buf[i-1]+px+self.plot_spacing) # # renormalise so that end station is still within the plot bounds # profile_x_buf /= np.amax(profile_x_buf)/(self.fig_width-2.*px) # profile_x_buf += px/2 # # if new_figure: # plt.figure(figsize=(len(profile_x),5*self.ax_height)) for i in range(len(self.Model_suite.model_list)): data_list = [] try: Model = self.Model_suite.model_list[i] data_list.append(Model.models[modelno-1]) if plot_inmodel: if len(self.Model_suite.inmodel_list) > 0: Inmodel = self.Model_suite.inmodel_list[i] data_list.append(Inmodel.inmodel) # ax = plt.subplot(1,len(self.Model_suite.model_list),i+1) ax = plt.axes([profile_x[i],self.ax_bottom,px,self.ax_height]) axes = [] twin = False if 'minmax' in parameter: ls,lw = '-',1 twin = True for modelvals in data_list: plt.plot(modelvals[:,3],modelvals[:,1],'0.5',ls=ls,lw=lw) p, = plt.plot(modelvals[:,2],modelvals[:,1],'k',ls=ls,lw=lw) plt.xscale('log') lw*=0.5 ax = self._set_axis_params(ax,'minmax') axes.append([ax,p]) if 'aniso' in parameter: ls,lw = '-',1 color = 'k' if twin: ax = make_twiny() color = 'b' twin = True for modelvals in data_list: p, = plt.plot(modelvals[:,3]/modelvals[:,2],modelvals[:,1], 'k-',ls=ls,lw=lw) plt.xscale('log') lw *= 0.5 ax = self._set_axis_params(ax,'aniso') axes.append([ax,p]) if 'strike' in parameter: color,lw = 'k',1 ls = '-' if twin: ax=make_twiny() color,lw = 'b',0.5 twin = True for modelvals in data_list: p, = plt.plot(modelvals[:,4]%180,modelvals[:,1],color,ls=ls,lw=lw) lw *= 0.5 ax = self._set_axis_params(ax,'strike') axes.append([ax,p]) if horizon_list is not None: for h in horizon_list: elev = ed.get_elevation(Model.x,Model.y,h) elev = p1dp.update_scale(elev,horizon_zscale) plt.plot(plt.xlim(),[elev]*2) if additional_data is not None: print "plotting additional data" plt.plot(additional_data[i][:,0],additional_data[i][:,1],lw=0.1) if i != 0: ax.set_yticklabels([]) for ax,p in axes: ax.xaxis.label.set_color(p.get_color()) ax.tick_params(axis='x', colors=p.get_color()) ax.spines['bottom'].set_color(p.get_color()) if i == 0: for label in ax.get_yticklabels(): label.set_fontproperties(self.font) label.set_fontsize(self.label_fontsize) ylab = plt.ylabel('Depth, km') ylab.set_fontproperties(self.font) if self.title_type == 'single': if i == 0: if type(parameter) == list: titlestring = ' and '.join([self.titles[p] for p in parameter]) else: titlestring = self.titles[parameter] title = plt.title(titlestring,ha='left') title.set_fontproperties(self.font) title.set_fontsize(self.title_fontsize) elif self.title_type == 'multiple': title = plt.title(self.titles[i]) elif self.title_type == 'station': title = plt.title(self.Model_suite.model_list[i].station) title.set_fontproperties(self.font) title.set_fontsize(self.title_fontsize) except IndexError: print "station omitted"
def plot_aniso_and_interfaces(self): """ plot a set of models and up to three interfaces for comparison. """ import pek1dplotting as p1dp if type(self.xyzfiles) == str: self.xyzfiles = [self.xyzfiles] if len(self.xyzfiles) == 1: s1,s2 = 2,1 sp = [2] sp_labels = ['y'] ad_labels = 'xy' elif len(self.xyzfiles) == 2: s1,s2 = 3,1 sp = [2,3] sp_labels = ['y','xy'] ad_labels = 'y' # if more than 3 interfaces provided, plot the first 3 elif len(self.xyzfiles) >= 3: s1,s2 = 2,2 sp = [2,3,4] sp_labels = ['','xy','x'] ad_labels = 'y' # set self.cmap false for the time being, until all individual plots are done cbar = self.cbar self.cbar = False header_rows,scale = [[d[at] for d in [self.aniso_depth_file_dict, self.xyzfiles_dict]] for at in ['header_rows','scale']] self.z = p1dp.update_scale(self.z,scale[0]) zmin,zmax = np.amin(self.z),np.amax(self.z) for f in self.xyzfiles: z = p1dp.update_scale(np.loadtxt(f,skiprows=header_rows[1])[:,2], scale[1]) if np.amin(z) < zmin: zmin = np.amin(z) if np.amax(z) > zmax: zmax = np.amax(z) self.levels = np.linspace(zmin,zmax,self.n_levels) x,y = self.x,self.y ar = ((float(s1)/float(s2))*((np.amax(y) - np.amin(y))/(np.amax(x) - np.amin(x))))**0.9 plt.figure(figsize=(self.figsize,self.figsize*ar)) plt.subplot(s1,s2,1) self.plot_aniso_depth_map() title = "Magnitude and depth of anisotropy\nfrom 1D anisotropic inversions" self._update_axis_params(title,ad_labels) plt.gca().set_xticklabels([]) for s,ss in enumerate(sp): ax = plt.subplot(s1,s2,ss) print self.xyzfiles[s] xyz = np.loadtxt(self.xyzfiles[s],skiprows=header_rows[1]) x,y,z = [xyz[:,i] for i in range(3)] self.plot_interface(x,y,z, scale=scale[1]) self._update_axis_params(title=self.xyzfile_titles[s], labels=sp_labels[s]) if 'x' not in sp_labels[s]: ax.set_xticklabels([]) plt.xlabel('') if 'y' not in sp_labels[s]: ax.set_yticklabels([]) plt.ylabel('') self.cbar = cbar plt.subplots_adjust(wspace=0.0) ax = plt.axes([0.88,0.1,0.08,0.8]) ax.set_visible(False) if self.cbar: cbar = plt.colorbar(fraction=0.8) cbar.set_label("Depth, km") cticks = range(int(self.levels[0]),int(self.levels[-1]+1)) cbar.set_ticks(cticks)
def plot_parameter(self, parameter, ylim=[6, 0], horizon_list=None, horizon_zscale='km', new_figure=True, plot_inmodel=True, additional_data=None): """ parameter = 'anisotropy', 'minmax', or 'strike' or list containing several of these additional_data - additional data (e.g. resistivity logs) to plot on the figure. Provide as a list of 2D numpy arrays [depth, param] """ import pek1dplotting as p1dp # self.get_station_distance() # # # define some initial locations to put the plots corresponding to distance along profile # profile_x = (self.station_distances - np.amin(self.station_distances)) # # # normalise so max distance is at 1 # profile_x /= (np.amax(self.station_distances)-np.amin(self.station_distances)) # # # make an empty array to put buffered distances # profile_x_buf = np.zeros_like(profile_x) # modelno = self.Model_suite.modelno # ## print profile_x px = self.ax_width dx = self.plot_spacing nx = len(self.Model_suite.model_list) profile_x = np.linspace(0., px * nx + dx * (nx - 1), nx) + px / 2. profile_x = np.linspace(0., 1. - 2.5 * px - dx, nx) + px + dx # print profile_x,px,dx,nx # # # # # shift each station along the profile so that they don't overlap each other # for i in range(len(profile_x)): # if i == 0: # profile_x_buf[i] = profile_x[i] # else: # profile_x_buf[i] = max(profile_x[i],profile_x_buf[i-1]+px+self.plot_spacing) # # renormalise so that end station is still within the plot bounds # profile_x_buf /= np.amax(profile_x_buf)/(self.fig_width-2.*px) # profile_x_buf += px/2 # # if new_figure: # plt.figure(figsize=(len(profile_x),5*self.ax_height)) for i in range(len(self.Model_suite.model_list)): data_list = [] try: Model = self.Model_suite.model_list[i] data_list.append(Model.models[modelno - 1]) if plot_inmodel: if len(self.Model_suite.inmodel_list) > 0: Inmodel = self.Model_suite.inmodel_list[i] data_list.append(Inmodel.inmodel) # ax = plt.subplot(1,len(self.Model_suite.model_list),i+1) ax = plt.axes( [profile_x[i], self.ax_bottom, px, self.ax_height]) axes = [] twin = False if 'minmax' in parameter: ls, lw = '-', 1 twin = True for modelvals in data_list: plt.plot(modelvals[:, 3], modelvals[:, 1], '0.5', ls=ls, lw=lw) p, = plt.plot(modelvals[:, 2], modelvals[:, 1], 'k', ls=ls, lw=lw) plt.xscale('log') lw *= 0.5 ax = self._set_axis_params(ax, 'minmax') axes.append([ax, p]) if 'aniso' in parameter: ls, lw = '-', 1 color = 'k' if twin: ax = make_twiny() color = 'b' twin = True for modelvals in data_list: p, = plt.plot(modelvals[:, 3] / modelvals[:, 2], modelvals[:, 1], 'k-', ls=ls, lw=lw) plt.xscale('log') lw *= 0.5 ax = self._set_axis_params(ax, 'aniso') axes.append([ax, p]) if 'strike' in parameter: color, lw = 'k', 1 ls = '-' if twin: ax = make_twiny() color, lw = 'b', 0.5 twin = True for modelvals in data_list: p, = plt.plot(modelvals[:, 4] % 180, modelvals[:, 1], color, ls=ls, lw=lw) lw *= 0.5 ax = self._set_axis_params(ax, 'strike') axes.append([ax, p]) if horizon_list is not None: for h in horizon_list: elev = ed.get_elevation(Model.x, Model.y, h) elev = p1dp.update_scale(elev, horizon_zscale) plt.plot(plt.xlim(), [elev] * 2) if additional_data is not None: print "plotting additional data" plt.plot(additional_data[i][:, 0], additional_data[i][:, 1], lw=0.1) if i != 0: ax.set_yticklabels([]) for ax, p in axes: ax.xaxis.label.set_color(p.get_color()) ax.tick_params(axis='x', colors=p.get_color()) ax.spines['bottom'].set_color(p.get_color()) if i == 0: for label in ax.get_yticklabels(): label.set_fontproperties(self.font) label.set_fontsize(self.label_fontsize) ylab = plt.ylabel('Depth, km') ylab.set_fontproperties(self.font) if self.title_type == 'single': if i == 0: if type(parameter) == list: titlestring = ' and '.join( [self.titles[p] for p in parameter]) else: titlestring = self.titles[parameter] title = plt.title(titlestring, ha='left') title.set_fontproperties(self.font) title.set_fontsize(self.title_fontsize) elif self.title_type == 'multiple': title = plt.title(self.titles[i]) elif self.title_type == 'station': title = plt.title( self.Model_suite.model_list[i].station) title.set_fontproperties(self.font) title.set_fontsize(self.title_fontsize) except IndexError: print "station omitted"
def plot_aniso_and_interfaces(self): """ plot a set of models and up to three interfaces for comparison. """ import pek1dplotting as p1dp if type(self.xyzfiles) == str: self.xyzfiles = [self.xyzfiles] if len(self.xyzfiles) == 1: s1, s2 = 2, 1 sp = [2] sp_labels = ['y'] ad_labels = 'xy' elif len(self.xyzfiles) == 2: s1, s2 = 3, 1 sp = [2, 3] sp_labels = ['y', 'xy'] ad_labels = 'y' # if more than 3 interfaces provided, plot the first 3 elif len(self.xyzfiles) >= 3: s1, s2 = 2, 2 sp = [2, 3, 4] sp_labels = ['', 'xy', 'x'] ad_labels = 'y' # set self.cmap false for the time being, until all individual plots are done cbar = self.cbar self.cbar = False header_rows, scale = [[ d[at] for d in [self.aniso_depth_file_dict, self.xyzfiles_dict] ] for at in ['header_rows', 'scale']] self.z = p1dp.update_scale(self.z, scale[0]) zmin, zmax = np.amin(self.z), np.amax(self.z) for f in self.xyzfiles: z = p1dp.update_scale( np.loadtxt(f, skiprows=header_rows[1])[:, 2], scale[1]) if np.amin(z) < zmin: zmin = np.amin(z) if np.amax(z) > zmax: zmax = np.amax(z) self.levels = np.linspace(zmin, zmax, self.n_levels) x, y = self.x, self.y ar = ((float(s1) / float(s2)) * ((np.amax(y) - np.amin(y)) / (np.amax(x) - np.amin(x))))**0.9 plt.figure(figsize=(self.figsize, self.figsize * ar)) plt.subplot(s1, s2, 1) self.plot_aniso_depth_map() title = "Magnitude and depth of anisotropy\nfrom 1D anisotropic inversions" self._update_axis_params(title, ad_labels) plt.gca().set_xticklabels([]) for s, ss in enumerate(sp): ax = plt.subplot(s1, s2, ss) print self.xyzfiles[s] xyz = np.loadtxt(self.xyzfiles[s], skiprows=header_rows[1]) x, y, z = [xyz[:, i] for i in range(3)] self.plot_interface(x, y, z, scale=scale[1]) self._update_axis_params(title=self.xyzfile_titles[s], labels=sp_labels[s]) if 'x' not in sp_labels[s]: ax.set_xticklabels([]) plt.xlabel('') if 'y' not in sp_labels[s]: ax.set_yticklabels([]) plt.ylabel('') self.cbar = cbar plt.subplots_adjust(wspace=0.0) ax = plt.axes([0.88, 0.1, 0.08, 0.8]) ax.set_visible(False) if self.cbar: cbar = plt.colorbar(fraction=0.8) cbar.set_label("Depth, km") cticks = range(int(self.levels[0]), int(self.levels[-1] + 1)) cbar.set_ticks(cticks)
def plot_aniso_and_interfaces(self, plot_aniso=True): """ plot a set of models and up to three interfaces for comparison. """ import pek1dplotting as p1dp if type(self.xyzfiles) == str: self.xyzfiles = [self.xyzfiles] if self.subplot_layout == 'vertical': s1, s2 = len(self.xyzfiles) + 1, 1 sp_labels = ['y'] * (len(self.xyzfiles) - 1) + ['xy'] ad_labels = 'y' if not plot_aniso: s1 -= 1 elif self.subplot_layout == 'horizontal': s2, s1 = len(self.xyzfiles) + 1, 1 sp_labels = ['x'] * (len(self.xyzfiles)) ad_labels = 'xy' if not plot_aniso: s2 -= 1 sp_labels[0] += 'y' # elif self.subplot_layout == 'grid': # s1 = int(np.ceil((len(self.xyzfiles)+1)**0.5)) # s2 = s1 # sp_labels = ['','xy','x'] # ad_labels = 'y' # set self.cmap false for the time being, until all individual plots are done cbar = self.plot_cbar self.plot_cbar = False header_rows, scale = [[ d[at] for d in [self.aniso_depth_file_dict, self.xyzfiles_dict] ] for at in ['header_rows', 'scale']] self.depth = p1dp.update_scale(self.depth, scale[0]) zmin, zmax = np.amin(self.depth), np.amax(self.depth) for f in self.xyzfiles: z = p1dp.update_scale( np.loadtxt(f, skiprows=header_rows[1])[:, 2], scale[1]) if np.amin(z) < zmin: zmin = np.amin(z) if np.amax(z) > zmax: zmax = np.amax(z) self.levels = np.linspace(zmin, zmax, self.n_levels) x, y = self.x, self.y # if self.figsize is None: # ar = ((float(s1)/float(s2))*((np.amax(y) - np.amin(y))/(np.amax(x) - np.amin(x))))**0.9 # self.figsize=(10,10*ar) plt.figure(figsize=self.figsize) plt.subplot(s1, s2, 1) if plot_aniso: sp = range(2, len(self.xyzfiles) + 2) self.plot_aniso_depth_map() title = "Magnitude and depth of anisotropy\nfrom 1D anisotropic inversions" self._update_axis_params(title, ad_labels) else: sp = range(1, len(self.xyzfiles) + 1) # plt.gca().set_xticklabels([]) for s, ss in enumerate(sp): ax = plt.subplot(s1, s2, ss) # print self.xyzfiles[s] xyz = np.loadtxt(self.xyzfiles[s], skiprows=header_rows[1]) x, y, z = [xyz[:, i] for i in range(3)] self.plot_interface(x, y, z, scale=scale[1]) self.add_xy_data(ss) self.add_ax_text(ss) self._update_axis_params(title=self.xyzfile_titles[s], labels=sp_labels[s]) if 'x' not in sp_labels[s]: ax.set_xticklabels([]) plt.xlabel('') if 'y' not in sp_labels[s]: ax.set_yticklabels([]) plt.ylabel('') self.plot_cbar = cbar bottom = self.cbar_ax[1] + self.cbar_ax[3] + 0.05 plt.subplots_adjust(wspace=self.wspace, hspace=self.hspace, bottom=bottom) if self.plot_cbar: self.add_cbar()