Exemple #1
0
def create_inmodel_dictionary_from_file(input_file,
                                        x,y,
                                        working_directory = None):
    """
    update inmodel dictionary to get elevation details from file
    
    ------------------------------Parameters-----------------------------------    
    **input_file** full path to a csv file containing list of following parameters:
    elevation filename,offset,resmin,resmax,strike
    where:
    elevation filename = Full path to x y z file containing elevations of the 
                         constraining layer to put into the inversions, put
                         none if providing a constant elevation.
                         Numbers are converted to absolute values internally.
    offset = Constant depth of constraining layer, if provided in addition to
             elevation filename the offset is added/subtracted from depth 
             from file, positive down.
    resmin, resmax, strike = minimum and maximum resistivity values and strike 
                             of minimum resistivity for constraining layer
    **x** x position of station in same coordinate system as elevation file
    **y** y position of station in same coordinate system as elevation file
   
    """
 
    inmodel_dict = {}
    inmodel_list = []

    if working_directory is None:
        working_directory = os.path.abspath('.')
    
    for line in open(input_file).readlines()[1:]:
        line = line.strip().split(',')
        if str.lower(line[0]) != 'none':
            elevfn = os.path.join(working_directory,line[0])
    #        print "elevfn",elevfn
            try:
                elev = np.abs(mted.get_elevation(x,y,elevfn)/1000.)
            except IOError:
                print "File not found, set elevation to zero instead"
                elev = 0.0
        else:
            elev = 0.0
        params = [float(pp) for pp in line[1:]]
   #     print elev,params
        inmodel_list.append([round(elev+params[0],2),params[1:]])
    print x,y,"inmodel_list",inmodel_list,
    i = 0
    while i < len(inmodel_list) - 1:
        print i,
        if inmodel_list[i][0] > inmodel_list[i+1][0]:
            print "remove"
            inmodel_list.remove(inmodel_list[i])
        i += 1
    print "inmodel_list",inmodel_list,
    for item in inmodel_list:
        try:
            print "item[0],item[1]",item[0],item[1],
            inmodel_dict[item[0]] = item[1]
        except:
            print "couldn't assign value to dictionary"
    
    #print "inmodel_dict",inmodel_dict
    return inmodel_dict
Exemple #2
0
    def plot_parameter(self,#parameter,
                       twiny_offset=0.35,
                       plot_inmodel=True,
                       additional_data = None):
        
        parameter = self.parameters

        try:
            # initialise a list containing a model to plot  
            models_to_plot = [self.Model.models[self.modelno-1]]
            # append inmodel to list if needed
            if plot_inmodel:
                if self.Inmodel is not None:
                    models_to_plot.append(self.Inmodel.inmodel)

            axes = []
            twin = False
            c = 0
            nlc = len(self.linedict['colour'])
            ls,lw = self.linedict['style'],self.linedict['width']       
            
            if 'minmax' in parameter:
                twin = True
                for model in models_to_plot:
#                    print c,nlc
                    plt.plot(model[:,3],model[:,1],
                             self.linedict['colour'][c%nlc],ls=ls,lw=lw)
                    p, = plt.plot(model[:,2],model[:,1],
                                  self.linedict['colour'][(c+1)%nlc],ls=ls,lw=lw)
                    plt.xscale('log')   
                c += 2
                ax = plt.gca()
                ax = self._set_axis_params(ax,'minmax')
                axes.append([ax,p])
                
            if 'aniso' in parameter:
                if twin:
                    ax = make_twiny(twiny_offset)
                for modelvals in models_to_plot:           
                    p, = plt.plot(modelvals[:,3]/modelvals[:,2],modelvals[:,1],
                                  self.linedict['colour'][c%nlc],ls=ls,lw=lw)
                    plt.xscale('log')
#                    if not twin:
                    ax = plt.gca()
                    twin = True
                    ax = self._set_axis_params(ax,'aniso')
                c += 1
                axes.append([ax,p])
                
            if 'strike' in parameter:

                if twin:
                    ax = make_twiny(twiny_offset)
                for modelvals in models_to_plot:
                    strike = modelvals[:,4]%180 + self.rotation_angle 
    #                if self.xlim['strike'][-1] == 180:
                    strike[strike < self.xlim['strike'][0]-45] += 180
                    p, = plt.plot(strike,modelvals[:,1],self.linedict['colour'][c%nlc],ls=ls,lw=lw)
                    ax = plt.gca()
                    twin = True
                    ax = self._set_axis_params(ax,'strike')
                axes.append([ax,p])

            if self.horizon_list is not None:
                c = 0
                for h in self.horizon_list:
                    elev = ed.get_elevation(self.Model.x,self.Model.y,h)
                    elev = update_scale(elev,self.horizon_zscale)
                    plt.plot(plt.xlim(),[elev]*2,
                             self.horizon_linedict['colour'][c],
                             lw=self.horizon_linedict['width'])
                    c += 1
#
#            if additional_data is not None:
#                print "plotting additional data"
#                plt.plot(additional_data[:,0],additional_data[:,1],lw=0.1)

            return axes
        except IndexError:
            print "station omitted"
Exemple #3
0
    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"
Exemple #4
0
    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_parameter(
            self,  #parameter,
            twiny_offset=0.35,
            plot_inmodel=True,
            additional_data=None):

        parameter = self.parameters

        try:
            # initialise a list containing a model to plot
            models_to_plot = [self.Model.models[self.modelno - 1]]
            # append inmodel to list if needed
            if plot_inmodel:
                if self.Inmodel is not None:
                    models_to_plot.append(self.Inmodel.inmodel)

            axes = []
            twin = False
            c = 0
            nlc = len(self.linedict['colour'])
            ls, lw = self.linedict['style'], self.linedict['width']

            if 'minmax' in parameter:
                twin = True
                for model in models_to_plot:
                    #                    print c,nlc
                    plt.plot(model[:, 3],
                             model[:, 1],
                             self.linedict['colour'][c % nlc],
                             ls=ls,
                             lw=lw)
                    p, = plt.plot(model[:, 2],
                                  model[:, 1],
                                  self.linedict['colour'][(c + 1) % nlc],
                                  ls=ls,
                                  lw=lw)
                    plt.xscale('log')
                c += 2
                ax = plt.gca()
                ax = self._set_axis_params(ax, 'minmax')
                axes.append([ax, p])

            if 'aniso' in parameter:
                if twin:
                    ax = make_twiny(twiny_offset)
                for modelvals in models_to_plot:
                    p, = plt.plot(modelvals[:, 3] / modelvals[:, 2],
                                  modelvals[:, 1],
                                  self.linedict['colour'][c % nlc],
                                  ls=ls,
                                  lw=lw)
                    plt.xscale('log')
                    #                    if not twin:
                    ax = plt.gca()
                    twin = True
                    ax = self._set_axis_params(ax, 'aniso')
                c += 1
                axes.append([ax, p])

            if 'strike' in parameter:

                if twin:
                    ax = make_twiny(twiny_offset)
                for modelvals in models_to_plot:
                    strike = modelvals[:, 4] % 180 + self.rotation_angle
                    #                if self.xlim['strike'][-1] == 180:
                    strike[strike < self.xlim['strike'][0] - 45] += 180
                    p, = plt.plot(strike,
                                  modelvals[:, 1],
                                  self.linedict['colour'][c % nlc],
                                  ls=ls,
                                  lw=lw)
                    ax = plt.gca()
                    twin = True
                    ax = self._set_axis_params(ax, 'strike')
                axes.append([ax, p])

            if self.horizon_list is not None:
                c = 0
                for h in self.horizon_list:
                    elev = ed.get_elevation(self.Model.x, self.Model.y, h)
                    elev = update_scale(elev, self.horizon_zscale)
                    plt.plot(plt.xlim(), [elev] * 2,
                             self.horizon_linedict['colour'][c],
                             lw=self.horizon_linedict['width'])
                    c += 1


#
#            if additional_data is not None:
#                print "plotting additional data"
#                plt.plot(additional_data[:,0],additional_data[:,1],lw=0.1)

            return axes
        except IndexError:
            print "station omitted"