예제 #1
0
    def plot(self):

        if self.startingpoint.description == None:
            location_text = ""
        else:
            location_text = self.startingpoint.description + " "

        # Gets the better CVM description if it exists.
        try:
            cvmdesc = UCVM_CVMS[self.cvm]
        except:
            cvmdesc = self.cvm

        if 'title' in self.meta:
            title = self.meta['title']
        else:
            title = "%s%s Elevation Profile From %sm To %sm at (%.2f,%.2f)" % (
                location_text, cvmdesc, self.startelevation, self.toelevation,
                self.startingpoint.longitude, self.startingpoint.latitude)

        # Call the plot object.
        p = Plot(title, "Units (see legend)", "Elevation (m)", None, 7, 10)

        # Add to plot.
        self.addtoplot(p)

        if self.filename == None:
            plt.show()
        else:
            plt.savefig(self.filename)
예제 #2
0
    def plot(self, properties, filename=None):

        if self.startingpoint.description == None:
            location_text = ""
        else:
            location_text = self.startingpoint.description + " "

        # Gets the better CVM description if it exists.
        try:
            cvmdesc = UCVM_CVMS[self.cvm]
        except:
            cvmdesc = self.cvm

        # Call the plot object.
        p = Plot("%s%s Depth Profile From %sm To %sm" % (location_text, cvmdesc, self.startingpoint.depth, self.todepth), \
                 "Units (see legend)", "Depth (m)", None, 7, 10)

        # Add to plot.
        self.addtoplot(p, properties)

        if filename == None:
            plt.show()
        else:
            plt.savefig(filename)
예제 #3
0
    def plot(self):

        self.installdir = None
        if 'installdir' in self.meta:
            self.installdir = self.meta['installdir']

        self.configfile = None
        if 'configfile' in self.meta:
            self.configfile = self.meta['configfile']

        if 'color' in self.meta:
            color_scale = self.meta['color']

        if 'gate' in self.meta:
            scale_gate = int(self.meta['gate'])
        else:
            scale_gate = None

        if color_scale == "b" and scale_gate is None:
            scale_gate = 2.5

        if self.startingpoint.description == None:
            location_text = ""
        else:
            location_text = self.startingpoint.description + " "

        if 'data_type' in self.meta:
            mproperty = self.meta['data_type']
        else:
            mproperty = "vs"

        # Gets the better CVM description if it exists.
        try:
            cvmdesc = UCVM_CVMS[self.cvm]
        except:
            cvmdesc = self.cvm

        if 'title' in self.meta:
            title = self.meta['title']
        else:
            title = "%s%s Cross Section from (%.2f, %.2f) to (%.2f, %.2f)" % (location_text, cvmdesc, self.startingpoint.longitude, \
                        self.startingpoint.latitude, self.endingpoint.longitude, self.endingpoint.latitude)
            self.meta['title'] = title

        self.getplotvals(mproperty)

        # Call the plot object.
        p = Plot(None, None, None, None, 10, 10)

        plt.axes([0.1, 0.7, 0.8, 0.25])

        # Figure out which is upper-right and bottom-left.
        ur_lat = self.startingpoint.latitude if self.startingpoint.latitude > self.endingpoint.latitude else self.endingpoint.latitude
        ur_lon = self.startingpoint.longitude if self.startingpoint.longitude > self.endingpoint.longitude else self.endingpoint.longitude
        ll_lat = self.startingpoint.latitude if self.startingpoint.latitude < self.endingpoint.latitude else self.endingpoint.latitude
        ll_lon = self.startingpoint.longitude if self.startingpoint.longitude < self.endingpoint.longitude else self.endingpoint.longitude

        # Add 1% to each for good measure.
        ur_lat = ur_lat + 0.03 * ur_lat
        ur_lon = ur_lon - 0.015 * ur_lon
        ll_lat = ll_lat - 0.03 * ll_lat
        ll_lon = ll_lon + 0.015 * ll_lon

        # Plot map up top.
        m = basemap.Basemap(projection='cyl', llcrnrlat=ll_lat, urcrnrlat=ur_lat, \
                            llcrnrlon=ll_lon, urcrnrlon=ur_lon, \
                            resolution='f', anchor='C')

        lat_ticks = np.arange(ll_lat, ur_lat + 0.1, (ur_lat - ll_lat))
        lon_ticks = np.arange(ll_lon, ur_lon + 0.1, (ur_lon - ll_lon))

        m.drawparallels(lat_ticks, linewidth=1.0, labels=[1, 0, 0, 0])
        m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0, 0, 0, 1])
        m.drawstates()
        m.drawcountries()

        m.drawcoastlines()
        m.drawmapboundary(fill_color='aqua')
        m.fillcontinents(color='brown', lake_color='aqua')

        m.plot([self.startingpoint.longitude, self.endingpoint.longitude],
               [self.startingpoint.latitude, self.endingpoint.latitude])

        valign1 = "top"
        valign2 = "bottom"
        if self.endingpoint.latitude < self.startingpoint.latitude:
            valign1 = "bottom"
            valign2 = "top"

        plt.text(self.startingpoint.longitude, self.startingpoint.latitude, \
                 '[S] %.1f, %.1f' % (self.startingpoint.longitude, self.startingpoint.latitude), \
                 color='k', horizontalalignment="center", verticalalignment=valign1)

        plt.text(self.endingpoint.longitude, self.endingpoint.latitude, \
                 '[E] %.1f, %.1f' % (self.endingpoint.longitude, self.endingpoint.latitude), \
                 color='k', horizontalalignment="center", verticalalignment=valign2)

        plt.axes([0.05, 0.18, 0.9, 0.54])

        datapoints = np.arange(self.num_x * self.num_y,
                               dtype=np.float32).reshape(
                                   self.num_y, self.num_x)

        for y in xrange(0, self.num_y):
            for x in xrange(0, self.num_x):
                if self.datafile != None:
                    datapoints[y][x] = self.materialproperties[y][
                        x].getProperty(mproperty)
                elif mproperty != "poisson":
                    datapoints[y][x] = self.materialproperties[y][
                        x].getProperty(mproperty)
                else:
                    if self.materialproperties[y][
                            x].vp == 0 or self.materialproperties[y][
                                x].vs == 0.0:
                        datapoints[y][x] = 0.0
                    else:
                        datapoints[y][x] = self.materialproperties[y][
                            x].getProperty("vp") / self.materialproperties[y][
                                x].getProperty("vs")

        u = UCVM(install_dir=self.installdir, config_file=self.configfile)

        myInt = 1000
        newdatapoints = datapoints / myInt

        self.max_val = np.nanmax(newdatapoints)
        self.min_val = np.nanmin(newdatapoints)
        self.mean_val = np.mean(newdatapoints)

        BOUNDS = u.makebounds()
        TICKS = u.maketicks()

        if mproperty == "vp":
            BOUNDS = [bound * 1.7 for bound in BOUNDS]
            TICKS = [tick * 1.7 for tick in TICKS]

        # Set default colormap and range
        colormap = basemap.cm.GMT_seis
        norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)

        umax = round(self.max_val)
        if (umax < 5):
            umax = 5
        umin = round(self.min_val)

        if color_scale == "s":
            colormap = basemap.cm.GMT_seis
            norm = mcolors.Normalize(vmin=0, vmax=umax)
        elif color_scale == "s_r":
            colormap = basemap.cm.GMT_seis_r
            norm = mcolors.Normalize(vmin=0, vmax=umax)
        elif color_scale == "sd":
            BOUNDS = u.makebounds(self.min_val,
                                  self.max_val,
                                  5,
                                  self.mean_val,
                                  substep=5)
            colormap = basemap.cm.GMT_seis
            TICKS = u.maketicks(self.min_val, self.max_val, 5)
            norm = mcolors.Normalize(vmin=self.min_val, vmax=self.max_val)
        elif color_scale == "b":
            C = []
            for bound in BOUNDS:
                if bound < scale_gate:
                    C.append("grey")
                else:
                    C.append("red")
            colormap = mcolors.ListedColormap(C)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        elif color_scale == 'd':
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        elif color_scale == 'd_r':
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis_r,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        elif color_scale == 'dd':
            BOUNDS = u.makebounds(self.min_val,
                                  self.max_val,
                                  5,
                                  self.mean_val,
                                  substep=5)
            TICKS = u.maketicks(self.min_val, self.max_val, 5)
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        else:
            print "ERROR: unknown option for colorscale."

## MEI, TODO this is a temporary way to generate an output of a cross_section input file
        if (self.datafile == None):
            self.meta['num_x'] = self.num_x
            self.meta['num_y'] = self.num_y
            self.meta['datapoints'] = datapoints.size
            self.meta['max'] = np.asscalar(self.max_val)
            self.meta['min'] = np.asscalar(self.min_val)
            self.meta['mean'] = np.asscalar(self.mean_val)
            self.meta['lon_list'] = self.lon_list
            self.meta['lat_list'] = self.lat_list
            self.meta['depth_list'] = self.depth_list
            if self.filename:
                u.export_metadata(self.meta, self.filename)
                u.export_binary(datapoints, self.filename)
            else:
                #https://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python
                rnd = ''.join(
                    random.SystemRandom().choice(string.ascii_uppercase +
                                                 string.digits)
                    for _ in range(6))
                f = "cross_section" + rnd
                u.export_metadata(self.meta, f)
                u.export_binary(datapoints, f)

        img = plt.imshow(newdatapoints, cmap=colormap, norm=norm)
        plt.xticks([0,self.num_x/2,self.num_x], ["[S] %.3f" % self.startingpoint.longitude, \
                                                 "%.3f" % ((float(self.endingpoint.longitude) + float(self.startingpoint.longitude)) / 2), \
                                                 "[E] %.3f" % self.endingpoint.longitude])
        plt.yticks([0,self.num_y/2,self.num_y], ["%.2f" % (self.startingdepth/1000), \
                                                 "%.2f" % (self.startingdepth+ ((self.todepth-self.startingdepth)/2)/1000), \
                                                 "%.2f" % (self.todepth / 1000)])

        plt.title(title)

        cax = plt.axes([0.1, 0.1, 0.8, 0.02])
        cbar = plt.colorbar(img,
                            cax=cax,
                            orientation='horizontal',
                            ticks=TICKS,
                            spacing='regular')
        if mproperty != "poisson":
            cbar.set_label(mproperty.title() + " (km/s)")
        else:
            cbar.set_label("Vp/Vs")

        if self.filename:
            plt.savefig(self.filename)
        else:
            plt.show()
예제 #4
0
    def plot(self, property, filename = None, title = None):
        
        if self.plot_type == "HorizontalSlice":

            if title == None:
                title = "Horizontal Slice Difference Plot"

            # Call the plot object.
            p = Plot(title, "", "", None, 10, 10)
            
            colormap = basemap.cm.GMT_seis
        
            m = basemap.Basemap(projection='cyl', llcrnrlat=self.plot_specs.bottomrightpoint.latitude, \
                                urcrnrlat=self.plot_specs.upperleftpoint.latitude, \
                                llcrnrlon=self.plot_specs.upperleftpoint.longitude, \
                                urcrnrlon=self.plot_specs.bottomrightpoint.longitude, \
                                resolution='f', anchor='C')
        
            lat_ticks = np.arange(self.plot_specs.bottomrightpoint.latitude, \
                                  self.plot_specs.upperleftpoint.latitude + 0.1, \
                                  self.plot_specs.plot_height / 2)
            lon_ticks = np.arange(self.plot_specs.upperleftpoint.longitude, \
                                  self.plot_specs.bottomrightpoint.longitude + 0.1, \
                                  self.plot_specs.plot_width / 2)
    
            m.drawparallels(lat_ticks, linewidth=1.0, labels=[1,0,0,0])
            m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0,0,0,1])
            m.drawstates()
            m.drawcountries()
    
            lons = np.arange(self.plot_specs.upperleftpoint.longitude, \
                             self.plot_specs.bottomrightpoint.longitude, \
                             self.plot_specs.spacing)
            lats = np.arange(self.plot_specs.bottomrightpoint.latitude, \
                             self.plot_specs.upperleftpoint.latitude, \
                             self.plot_specs.spacing)
    
            # Get the properties.
            datapoints = np.arange(self.plot_specs.num_x * self.plot_specs.num_y, \
                                   dtype=float).reshape(self.plot_specs.num_y, self.plot_specs.num_x)
        
            for i in xrange(0, self.plot_specs.num_y):
                for j in xrange(0, self.plot_specs.num_x):
                    datapoints[i][j] = self.difference_values[i][j].getProperty(property) / 1000.0
                    
            t = m.transform_scalar(datapoints, lons, lats, len(lons), len(lats))
            img = m.imshow(t, cmap=colormap)
    
            m.drawcoastlines()
    
            cax = plt.axes([0.125, 0.05, 0.775, 0.02])
            cbar = plt.colorbar(img, cax=cax, orientation='horizontal')
            cbar.set_label(property.title() + " (km/s)")
        
        elif self.plot_type == "CrossSection":
            
            if title == None:
                title = "Horizontal Slice Difference Plot"
                
            # Call the plot object.
            p = Plot(None, None, None, None, 10, 10)

            colormap = basemap.cm.GMT_seis

            plt.axes([0.1,0.7,0.8,0.25])

            # Figure out which is upper-right and bottom-left.
            ur_lat = self.plot_specs.startingpoint.latitude if self.plot_specs.startingpoint.latitude > self.plot_specs.endingpoint.latitude else self.plot_specs.endingpoint.latitude
            ur_lon = self.plot_specs.startingpoint.longitude if self.plot_specs.startingpoint.longitude > self.plot_specs.endingpoint.longitude else self.plot_specs.endingpoint.longitude
            ll_lat = self.plot_specs.startingpoint.latitude if self.plot_specs.startingpoint.latitude < self.plot_specs.endingpoint.latitude else self.plot_specs.endingpoint.latitude
            ll_lon = self.plot_specs.startingpoint.longitude if self.plot_specs.startingpoint.longitude < self.plot_specs.endingpoint.longitude else self.plot_specs.endingpoint.longitude
    
            # Add 1% to each for good measure.
            ur_lat = ur_lat + 0.03 * ur_lat
            ur_lon = ur_lon - 0.015 * ur_lon
            ll_lat = ll_lat - 0.03 * ll_lat
            ll_lon = ll_lon + 0.015 * ll_lon
    
            # Plot map up top.
            m = basemap.Basemap(projection='cyl', llcrnrlat=ll_lat, urcrnrlat=ur_lat, \
                                llcrnrlon=ll_lon, urcrnrlon=ur_lon, \
                                resolution='f', anchor='C')
    
            lat_ticks = np.arange(ll_lat, ur_lat + 0.1, (ur_lat - ll_lat))
            lon_ticks = np.arange(ll_lon, ur_lon + 0.1, (ur_lon - ll_lon))
    
            m.drawparallels(lat_ticks, linewidth=1.0, labels=[1,0,0,0])
            m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0,0,0,1])
            m.drawstates()
            m.drawcountries()
    
            m.drawcoastlines()
            m.drawmapboundary(fill_color='aqua')
            m.fillcontinents(color='brown',lake_color='aqua')
    
            m.plot([self.plot_specs.startingpoint.longitude,self.plot_specs.endingpoint.longitude], [self.plot_specs.startingpoint.latitude,self.plot_specs.endingpoint.latitude])
            m.plot([self.plot_specs_2.startingpoint.longitude,self.plot_specs_2.endingpoint.longitude], [self.plot_specs_2.startingpoint.latitude,self.plot_specs_2.endingpoint.latitude])
    
            valign1 = "top"
            valign2 = "bottom"
            if self.plot_specs.endingpoint.latitude < self.plot_specs.startingpoint.latitude:
                valign1 = "bottom"
                valign2 = "top"
    
            plt.text(self.plot_specs.startingpoint.longitude, self.plot_specs.startingpoint.latitude, \
                     '[S] %.1f, %.1f' % (self.plot_specs.startingpoint.longitude, self.plot_specs.startingpoint.latitude), \
                     color='k', horizontalalignment="center", verticalalignment=valign1)
    
            plt.text(self.plot_specs.endingpoint.longitude, self.plot_specs.endingpoint.latitude, \
                     '[E] %.1f, %.1f' % (self.plot_specs.endingpoint.longitude, self.plot_specs.endingpoint.latitude), \
                     color='k', horizontalalignment="center", verticalalignment=valign2)
    
            plt.axes([0.05,0.18,0.9,0.54])
    
            datapoints = np.arange(self.plot_specs.num_x * self.plot_specs.num_y,dtype=float).reshape(self.plot_specs.num_y, self.plot_specs.num_x)
            
            for i in xrange(0, self.plot_specs.num_y):
                for j in xrange(0, self.plot_specs.num_x):   
                    datapoints[i][j] = self.difference_values[i][j].getProperty(property) / 1000          
    
            img = plt.imshow(datapoints, cmap=colormap)
            
            if self.plot_specs.startingpoint.longitude != self.plot_specs.endingpoint.longitude:
                plt.xticks([0,self.plot_specs.num_x/2,self.plot_specs.num_x], ["[S] %.2f" % self.plot_specs.startingpoint.longitude, \
                            "%.2f" % ((float(self.plot_specs.endingpoint.longitude) + float(self.plot_specs.startingpoint.longitude)) / 2), \
                            "[E] %.2f" % self.plot_specs.endingpoint.longitude])
            else:
                plt.xticks([0,self.plot_specs.num_x/2,self.plot_specs.num_x], ["[S] %.2f" % self.plot_specs.startingpoint.latitude, \
                            "%.2f" % ((float(self.plot_specs.endingpoint.latitude) + float(self.plot_specs.startingpoint.latitude)) / 2), \
                            "[E] %.2f" % self.plot_specs.endingpoint.latitude])                
                
            plt.yticks([0,self.plot_specs.num_y/2,self.plot_specs.num_y], ["%.0f" % self.plot_specs.startingpoint.depth, \
                        "%.0f" % (self.plot_specs.todepth / 2000), \
                        "%.0f" % (self.plot_specs.todepth / 1000)])
    
            plt.title(title)
    
            cax = plt.axes([0.1, 0.1, 0.8, 0.02])
            cbar = plt.colorbar(img, cax=cax, orientation='horizontal')
            cbar.set_label(property.title() + " (km/s)")  
        
        if filename:
            plt.savefig(filename)
        else:
            plt.show()
예제 #5
0
    def plot(self, horizontal_label=None):

        if self.upperleftpoint.description == None:
            location_text = ""
        else:
            location_text = self.upperleftpoint.description + " "

        if 'data_type' in self.meta:
            mproperty = self.meta['data_type']
        else:
            mproperty = "vs"

        scale_gate = None
        if 'color' in self.meta:
            color_scale = self.meta['color']

        if 'gate' in self.meta:
            scale_gate = float(self.meta['gate'])

        if color_scale == "b" and scale_gate is None:
            scale_gate = 2.5

        # Gets the better CVM description if it exists.
        try:
            cvmdesc = UCVM_CVMS[self.cvm]
        except:
            cvmdesc = self.cvm

        if 'title' in self.meta:
            title = self.meta['title']
        else:
            title = "%s%s Horizontal Slice at %.0fm" % (
                location_text, cvmdesc, self.upperleftpoint.depth)
            self.meta['title'] = title

        self.getplotvals(mproperty)

        # Call the plot object.
        p = Plot(title, "", "", None, 10, 10)

        u = UCVM(install_dir=self.installdir, config_file=self.configfile)

        BOUNDS = u.makebounds()
        TICKS = u.maketicks()

        m = basemap.Basemap(projection='cyl', llcrnrlat=self.bottomrightpoint.latitude, \
                            urcrnrlat=self.upperleftpoint.latitude, \
                            llcrnrlon=self.upperleftpoint.longitude, \
                            urcrnrlon=self.bottomrightpoint.longitude, \
                            resolution='f', anchor='C')

        lat_ticks = np.arange(self.bottomrightpoint.latitude,
                              self.upperleftpoint.latitude + 0.1,
                              self.plot_height / 2)
        lon_ticks = np.arange(self.upperleftpoint.longitude,
                              self.bottomrightpoint.longitude + 0.1,
                              self.plot_width / 2)

        m.drawparallels(lat_ticks, linewidth=1.0, labels=[1, 0, 0, 0])
        m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0, 0, 0, 1])
        m.drawstates()
        m.drawcountries()

        alons = np.arange(self.upperleftpoint.longitude,
                          self.bottomrightpoint.longitude, self.spacing)
        alats = np.arange(self.bottomrightpoint.latitude,
                          self.upperleftpoint.latitude, self.spacing)
        lons = np.linspace(self.upperleftpoint.longitude,
                           self.bottomrightpoint.longitude - self.spacing,
                           self.num_x - 1)
        lats = np.linspace(self.bottomrightpoint.latitude,
                           self.upperleftpoint.latitude - self.spacing,
                           self.num_y - 1)

        # Get the properties.
        datapoints = np.arange(self.num_x * self.num_y,
                               dtype=np.float32).reshape(
                                   self.num_y, self.num_x)

        nancnt = 0
        zerocnt = 0
        negcnt = 0
        print("total cnt is ", self.num_x * self.num_y)
        for i in xrange(0, self.num_y):
            for j in xrange(0, self.num_x):
                if (self.datafile != None):
                    datapoints[i][j] = self.materialproperties[i][
                        j].getProperty(mproperty)
                elif mproperty != "poisson":
                    if color_scale == "sd" or color_scale == "sd_r":
                        datapoints[i][j] = self.materialproperties[i][
                            j].getProperty(mproperty)
                        if (datapoints[i][j] == -1):
                            datapoints[i][j] = np.nan
                            nancnt = nancnt + 1
##to have blank background
##                        if (datapoints[i][j] == 0) :
##                            datapoints[i][j]=np.nan
##                            zerocnt=zerocnt+1
##
                    else:
                        datapoints[i][j] = self.materialproperties[i][
                            j].getProperty(mproperty)
                        if (datapoints[i][j] == 0):
                            # KEEP 0 as 0                           datapoints[i][j]=np.nan
                            zerocnt = zerocnt + 1
                        if (datapoints[i][j] < 0):
                            negcnt = negcnt + 1
                        if (datapoints[i][j] == -1):
                            datapoints[i][j] = np.nan
                            nancnt = nancnt + 1
                else:
                    datapoints[i][j] = u.poisson(
                        self.materialproperties[i][j].vs,
                        self.materialproperties[i][j].vp)

#        print (" total number of nancnt is ", nancnt)
#        print (" total number of zerocnt is ", zerocnt)
#        print (" total number of negcnt is ", negcnt)

        myInt = 1000
        if mproperty == "poisson":  ## no need to reduce.. should also be using sd or dd
            myInt = 1
            if color_scale == "s":
                color_scale = "sd"
            elif color_scale == "d":
                color_scale = "dd"

        newdatapoints = datapoints / myInt

        newmax_val = np.nanmax(newdatapoints)
        newmin_val = np.nanmin(newdatapoints)
        newmean_val = np.mean(newdatapoints)

        self.max_val = np.nanmax(datapoints)
        self.min_val = np.nanmin(datapoints)
        self.mean_val = np.mean(datapoints)

        if color_scale == "s":
            colormap = basemap.cm.GMT_seis
            norm = mcolors.Normalize(vmin=BOUNDS[0],
                                     vmax=BOUNDS[len(BOUNDS) - 1])
        elif color_scale == "s_r":
            colormap = basemap.cm.GMT_seis_r
            norm = mcolors.Normalize(vmin=BOUNDS[0],
                                     vmax=BOUNDS[len(BOUNDS) - 1])
        elif color_scale == "sd":
            BOUNDS = u.makebounds(newmin_val,
                                  newmax_val,
                                  5,
                                  newmean_val,
                                  substep=5)
            #            colormap = basemap.cm.GMT_globe
            colormap = basemap.cm.GMT_seis
            TICKS = u.maketicks(newmin_val, newmax_val, 5)
            norm = mcolors.Normalize(vmin=BOUNDS[0],
                                     vmax=BOUNDS[len(BOUNDS) - 1])
        elif color_scale == "b":
            C = []
            for bound in BOUNDS:
                if bound < scale_gate:
                    C.append("grey")
                else:
                    C.append("red")
            colormap = mcolors.ListedColormap(C)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        elif color_scale == "d":
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        elif color_scale == "d_r":
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis_r,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        elif color_scale == 'dd':
            BOUNDS = u.makebounds(newmin_val,
                                  newmax_val,
                                  5,
                                  newmean_val,
                                  substep=5,
                                  all=True)
            TICKS = u.maketicks(newmin_val, newmax_val, 5)
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis,
                                            len(BOUNDS) - 1)
            #            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_globe, len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        else:
            print "ERROR: unknown option for colorscale."

        if (self.datafile == None):
            self.meta['num_x'] = self.num_x
            self.meta['num_y'] = self.num_y
            self.meta['datapoints'] = datapoints.size
            self.meta['max'] = np.asscalar(self.max_val)
            self.meta['min'] = np.asscalar(self.min_val)
            self.meta['mean'] = np.asscalar(self.mean_val)
            self.meta['lon_list'] = lons.tolist()
            self.meta['lat_list'] = lats.tolist()
            if self.filename:
                u.export_metadata(self.meta, self.filename)
                u.export_binary(datapoints, self.filename)

        ## reduce the datapoints before passing in..

        t = m.transform_scalar(newdatapoints, lons, lats, len(lons), len(lats))
        img = m.imshow(t, cmap=colormap, norm=norm)

        #        print "MIN is ", np.nanmin(datapoints)
        #        print "MAX is ", np.nanmax(datapoints)
        #        img=m.scatter(xlist, ylist, c=dlist, cmap=colormap, norm=norm, s=1, edgecolor='',marker='o')
        #        img=m.scatter(xcoords, ycoords, c=datapoints, cmap=colormap, norm=norm, s=1, edgecolor='',marker='o')

        m.drawcoastlines()

        cax = plt.axes([0.125, 0.05, 0.775, 0.02])
        cbar = plt.colorbar(img,
                            cax=cax,
                            orientation='horizontal',
                            spacing='proportional',
                            ticks=TICKS)
        if mproperty != "poisson":
            if horizontal_label == None:
                cbar.set_label(mproperty.title() + " (km/s)")
            else:
                cbar.set_label(horizontal_label)
        else:
            cbar.set_label("Poisson(Vs,Vp)")

        if self.filename:
            plt.savefig(self.filename)
## MEI, TODO p.savehtml("show.html")
        else:
            plt.show()
예제 #6
0
    def plot(self,
             property,
             filename=None,
             title=None,
             horizontal_label=None,
             color_scale="d"):

        if self.upperleftpoint.description == None:
            location_text = ""
        else:
            location_text = self.upperleftpoint.description + " "

        # Gets the better CVM description if it exists.
        try:
            cvmdesc = UCVM_CVMS[self.cvm]
        except:
            cvmdesc = self.cvm

        if title == None:
            title = "%s%s Horizontal Slice at %.0fm" % (
                location_text, cvmdesc, self.upperleftpoint.depth)

        self.getplotvals()

        # Call the plot object.
        p = Plot(title, "", "", None, 10, 10)

        BOUNDS = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
        TICKS = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]

        if property == "vp":
            BOUNDS = [bound * 1.7 for bound in BOUNDS]
            TICKS = [tick * 1.7 for tick in TICKS]

        if color_scale == "s":
            colormap = basemap.cm.GMT_seis
            norm = mcolors.Normalize(vmin=BOUNDS[0],
                                     vmax=BOUNDS[len(BOUNDS) - 1])
        elif color_scale == "sd":
            colormap = basemap.cm.GMT_seis
            norm = mcolors.Normalize(vmin=self.min_val, vmax=self.max_val)
            TICKS = [
                self.min_val, (self.min_val + self.max_val) / 2, self.max_val
            ]
        else:
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)

        m = basemap.Basemap(projection='cyl', llcrnrlat=self.bottomrightpoint.latitude, \
                            urcrnrlat=self.upperleftpoint.latitude, \
                            llcrnrlon=self.upperleftpoint.longitude, \
                            urcrnrlon=self.bottomrightpoint.longitude, \
                            resolution='f', anchor='C')

        lat_ticks = np.arange(self.bottomrightpoint.latitude,
                              self.upperleftpoint.latitude + 0.1,
                              self.plot_height / 2)
        lon_ticks = np.arange(self.upperleftpoint.longitude,
                              self.bottomrightpoint.longitude + 0.1,
                              self.plot_width / 2)

        m.drawparallels(lat_ticks, linewidth=1.0, labels=[1, 0, 0, 0])
        m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0, 0, 0, 1])
        m.drawstates()
        m.drawcountries()

        lons = np.arange(self.upperleftpoint.longitude,
                         self.bottomrightpoint.longitude, self.spacing)
        lats = np.arange(self.bottomrightpoint.latitude,
                         self.upperleftpoint.latitude, self.spacing)

        # Get the properties.
        datapoints = np.arange(self.num_x * self.num_y,
                               dtype=float).reshape(self.num_y, self.num_x)

        for i in xrange(0, self.num_y):
            for j in xrange(0, self.num_x):
                if property != "poisson":
                    if color_scale == "sd":
                        datapoints[i][j] = self.materialproperties[i][
                            j].getProperty(property)
                    else:
                        datapoints[i][j] = self.materialproperties[i][
                            j].getProperty(property) / 1000.0
                else:
                    datapoints[i][j] = self.materialproperties[i][
                        j].vp / self.materialproperties[i][j].vs

        t = m.transform_scalar(datapoints, lons, lats, len(lons), len(lats))
        img = m.imshow(t, cmap=colormap, norm=norm)

        m.drawcoastlines()

        cax = plt.axes([0.125, 0.05, 0.775, 0.02])
        cbar = plt.colorbar(img,
                            cax=cax,
                            orientation='horizontal',
                            ticks=TICKS)
        if property != "poisson":
            if horizontal_label == None:
                cbar.set_label(property.title() + " (km/s)")
            else:
                cbar.set_label(horizontal_label)
        else:
            cbar.set_label("Vp/Vs")

        if filename:
            plt.savefig(filename)
        else:
            plt.show()
예제 #7
0
    def plot(self, property, filename=None, title=None, color_scale="d"):

        if self.startingpoint.description == None:
            location_text = ""
        else:
            location_text = self.startingpoint.description + " "

        # Gets the better CVM description if it exists.
        try:
            cvmdesc = UCVM_CVMS[self.cvm]
        except:
            cvmdesc = self.cvm

        if title == None:
            title = "%s%s Cross Section from (%.2f, %.2f) to (%.2f, %.2f)" % (location_text, cvmdesc, self.startingpoint.longitude, \
                        self.startingpoint.latitude, self.endingpoint.longitude, self.endingpoint.latitude)

        self.getplotvals()

        # Call the plot object.
        p = Plot(None, None, None, None, 10, 10)

        BOUNDS = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
        TICKS = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]

        if property == "vp":
            BOUNDS = [bound * 1.7 for bound in BOUNDS]
            TICKS = [tick * 1.7 for tick in TICKS]

        # Set default colormap and range
        colormap = basemap.cm.GMT_seis
        norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)
        try:
            if color_scale == "s":
                colormap = basemap.cm.GMT_seis
                norm = mcolors.Normalize(vmin=0, vmax=self.max_val)
        except:
            colormap = pycvm_cmapDiscretize(basemap.cm.GMT_seis,
                                            len(BOUNDS) - 1)
            norm = mcolors.BoundaryNorm(BOUNDS, colormap.N)

        plt.axes([0.1, 0.7, 0.8, 0.25])

        # Figure out which is upper-right and bottom-left.
        ur_lat = self.startingpoint.latitude if self.startingpoint.latitude > self.endingpoint.latitude else self.endingpoint.latitude
        ur_lon = self.startingpoint.longitude if self.startingpoint.longitude > self.endingpoint.longitude else self.endingpoint.longitude
        ll_lat = self.startingpoint.latitude if self.startingpoint.latitude < self.endingpoint.latitude else self.endingpoint.latitude
        ll_lon = self.startingpoint.longitude if self.startingpoint.longitude < self.endingpoint.longitude else self.endingpoint.longitude

        # Add 1% to each for good measure.
        ur_lat = ur_lat + 0.03 * ur_lat
        ur_lon = ur_lon - 0.015 * ur_lon
        ll_lat = ll_lat - 0.03 * ll_lat
        ll_lon = ll_lon + 0.015 * ll_lon

        # Plot map up top.
        m = basemap.Basemap(projection='cyl', llcrnrlat=ll_lat, urcrnrlat=ur_lat, \
                            llcrnrlon=ll_lon, urcrnrlon=ur_lon, \
                            resolution='f', anchor='C')

        lat_ticks = np.arange(ll_lat, ur_lat + 0.1, (ur_lat - ll_lat))
        lon_ticks = np.arange(ll_lon, ur_lon + 0.1, (ur_lon - ll_lon))

        m.drawparallels(lat_ticks, linewidth=1.0, labels=[1, 0, 0, 0])
        m.drawmeridians(lon_ticks, linewidth=1.0, labels=[0, 0, 0, 1])
        m.drawstates()
        m.drawcountries()

        m.drawcoastlines()
        m.drawmapboundary(fill_color='aqua')
        m.fillcontinents(color='brown', lake_color='aqua')

        m.plot([self.startingpoint.longitude, self.endingpoint.longitude],
               [self.startingpoint.latitude, self.endingpoint.latitude])

        valign1 = "top"
        valign2 = "bottom"
        if self.endingpoint.latitude < self.startingpoint.latitude:
            valign1 = "bottom"
            valign2 = "top"

        plt.text(self.startingpoint.longitude, self.startingpoint.latitude, \
                 '[S] %.1f, %.1f' % (self.startingpoint.longitude, self.startingpoint.latitude), \
                 color='k', horizontalalignment="center", verticalalignment=valign1)

        plt.text(self.endingpoint.longitude, self.endingpoint.latitude, \
                 '[E] %.1f, %.1f' % (self.endingpoint.longitude, self.endingpoint.latitude), \
                 color='k', horizontalalignment="center", verticalalignment=valign2)

        plt.axes([0.05, 0.18, 0.9, 0.54])

        datapoints = np.arange(self.num_x * self.num_y,
                               dtype=float).reshape(self.num_y, self.num_x)

        for y in xrange(0, self.num_y):
            for x in xrange(0, self.num_x):
                datapoints[y][x] = self.materialproperties[y][x].getProperty(
                    property) / 1000

        img = plt.imshow(datapoints, cmap=colormap, norm=norm)
        plt.xticks([0,self.num_x/2,self.num_x], ["[S] %.2f" % self.startingpoint.longitude, \
                                                 "%.2f" % ((float(self.endingpoint.longitude) + float(self.startingpoint.longitude)) / 2), \
                                                 "[E] %.2f" % self.endingpoint.longitude])
        plt.yticks([0,self.num_y/2,self.num_y], ["%.0f" % self.startingpoint.depth, \
                                                 "%.0f" % (self.todepth / 2000), \
                                                 "%.0f" % (self.todepth / 1000)])

        plt.title(title)

        cax = plt.axes([0.1, 0.1, 0.8, 0.02])
        cbar = plt.colorbar(img,
                            cax=cax,
                            orientation='horizontal',
                            ticks=TICKS)
        if property != "poisson":
            cbar.set_label(property.title() + " (km/s)")
        else:
            cbar.set_label("Vp/Vs")

        if filename:
            plt.savefig(filename)
        else:
            plt.show()