def getplotvals(self, datafile=None): # How many y and x values will we need? ## The plot width - needs to be stored as property for the plot function to work. self.plot_width = self.bottomrightpoint.longitude - self.upperleftpoint.longitude ## The plot height - needs to be stored as a property for the plot function to work. self.plot_height = self.upperleftpoint.latitude - self.bottomrightpoint.latitude ## The number of x points we retrieved. Stored as a property for the plot function to work. if (self.xsteps): self.num_x = int(self.xsteps) else: self.num_x = int(math.ceil(self.plot_width / self.spacing)) + 1 ## The number of y points we retrieved. Stored as a property for the plot function to work. if (self.ysteps): self.num_y = int(self.ysteps) else: self.num_y = int(math.ceil(self.plot_height / self.spacing)) + 1 ## The 2D array of retrieved material properties self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] u = UCVM() # Generate a list of points to pass to UCVM. ucvmpoints = [] for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): ucvmpoints.append(Point(self.upperleftpoint.longitude + x * self.spacing, \ self.bottomrightpoint.latitude + y * self.spacing, \ self.upperleftpoint.depth)) self.ucvm_query_results = u.map_grid(ucvmpoints, self.cvm)
def getplotvals(self, mproperty="vs"): # How many y and x values will we need? ## The plot width - needs to be stored as property for the plot function to work. self.plot_width = self.bottomrightpoint.longitude - self.upperleftpoint.longitude ## The plot height - needs to be stored as a property for the plot function to work. self.plot_height = self.upperleftpoint.latitude - self.bottomrightpoint.latitude ## The number of x points we retrieved. Stored as a property for the plot function to work. if (self.xsteps is not None): self.num_x = int(self.xsteps) else: self.num_x = int(math.ceil(self.plot_width / self.spacing)) + 1 ## The number of y points we retrieved. Stored as a property for the plot function to work. if (self.ysteps is not None): self.num_y = int(self.ysteps) else: self.num_y = int(math.ceil(self.plot_height / self.spacing)) + 1 ## Maximum depth encountered. self.max_val = 0 ## Minimum depth (always 0). self.min_val = 0 ## The 2D array of retrieved Vs30 values. self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] u = UCVM(install_dir=self.installdir, config_file=self.configfile) ### MEI if (self.datafile != None): # print "\nUsing --> "+datafile data = u.import_binary(self.datafile, self.num_x, self.num_y) # print "Total points imported is ", len(data), "for ", self.num_x, " and ", self.num_y else: # Generate a list of points to pass to UCVM. ucvmpoints = [] for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): ucvmpoints.append(Point(self.upperleftpoint.longitude + x * self.spacing, \ self.bottomrightpoint.latitude + y * self.spacing, \ self.upperleftpoint.depth)) # print "Total points extracted is ", len(ucvmpoints), "for ", self.num_x, " and ", self.num_y data = u.basin_depth(ucvmpoints, self.cvm, self.vs_threshold) i = 0 j = 0 for matprop in data: self.materialproperties[i][j].vs = matprop if matprop > self.max_val: self.max_val = matprop j = j + 1 if j >= self.num_x: j = 0 i = i + 1
def getplotvals(self, mproperty="vs"): # How many y and x values will we need? ## The plot width - needs to be stored as property for the plot function to work. self.plot_width = self.bottomrightpoint.longitude - self.upperleftpoint.longitude ## The plot height - needs to be stored as a property for the plot function to work. self.plot_height = self.upperleftpoint.latitude - self.bottomrightpoint.latitude ## The number of x points we retrieved. Stored as a property for the plot function to work. if (self.xsteps): self.num_x = int(self.xsteps) else: self.num_x = int(math.ceil(self.plot_width / self.spacing)) + 1 ## The number of y points we retrieved. Stored as a property for the plot function to work. if (self.ysteps): self.num_y = int(self.ysteps) else: self.num_y = int(math.ceil(self.plot_height / self.spacing)) + 1 ## The 2D array of retrieved material properties. self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] u = UCVM(install_dir=self.installdir, config_file=self.configfile) ### MEI if (self.datafile != None): data = u.import_binary(self.datafile, self.num_x, self.num_y) print "\nUsing --> " + self.datafile print "expecting x ", self.num_x, " y ", self.num_y else: # Generate a list of points to pass to UCVM. ucvmpoints = [] for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): ucvmpoints.append(Point(self.upperleftpoint.longitude + x * self.spacing, \ self.bottomrightpoint.latitude + y * self.spacing, \ self.upperleftpoint.depth)) data = u.query(ucvmpoints, self.cvm) i = 0 j = 0 isfloat = 0 if (self.datafile != None): isfloat = 1 for matprop in data: if isfloat: self.materialproperties[i][j].setProperty(mproperty, matprop) else: self.materialproperties[i][j] = matprop j = j + 1 if j >= self.num_x: j = 0 i = i + 1
def getplotvals(self): point_list = [] # Generate the list of points. toto = self.toelevation if (toto <= 0): toto = toto - 1 else: toto = toto + 1 for i in np.arange(self.startelevation, toto, self.spacing): point_list.append( Point(self.startingpoint.longitude, self.startingpoint.latitude, elevation=i)) u = UCVM(install_dir=self.installdir, config_file=self.configfile, z_range=self.z_range) ###MEI if (self.datafile != None): print "\nUsing --> " + self.datafile data = u.import_matprops(self.datafile) if len(data) == 0: print "ERROR: no matprops plot data." exit(1) else: data = u.query(point_list, self.cvm, elevation=1) tmp = [] for matprop in data: self.vplist.append(matprop.vp) self.vslist.append(matprop.vs) self.rholist.append(matprop.density) ## create the blob if (self.datafile == None): ## save an external copy of matprops b = { 'vp': float(matprop.vp), 'vs': float(matprop.vs), 'density': float(matprop.density) } tmp.append(b) if (self.datafile == None): blob = {'matprops': tmp} u.export_matprops(blob, self.filename) u.export_metadata(self.meta, self.filename)
def getplotvals(self): # How many y and x values will we need? ## The plot width - needs to be stored as property for the plot function to work. self.plot_width = self.bottomrightpoint.longitude - self.upperleftpoint.longitude ## The plot height - needs to be stored as a property for the plot function to work. self.plot_height = self.upperleftpoint.latitude - self.bottomrightpoint.latitude ## The number of x points we retrieved. Stored as a property for the plot function to work. self.num_x = int(math.ceil(self.plot_width / self.spacing)) + 1 ## The number of y points we retrieved. Stored as a property for the plot function to work. self.num_y = int(math.ceil(self.plot_height / self.spacing)) + 1 ## Maximum depth encountered. self.max_val = 0 ## Minimum depth (always 0). self.min_val = 0 # Generate a list of points to pass to UCVM. ucvmpoints = [] for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): ucvmpoints.append(Point(self.upperleftpoint.longitude + x * self.spacing, \ self.bottomrightpoint.latitude + y * self.spacing, \ self.upperleftpoint.depth)) ## The 2D array of retrieved Vs30 values. self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] u = UCVM() data = u.basin_depth(ucvmpoints, self.cvm, self.vs_threshold) i = 0 j = 0 for matprop in data: self.materialproperties[i][j].vs = matprop if matprop > self.max_val: self.max_val = matprop j = j + 1 if j >= self.num_x: j = 0 i = i + 1
def getplotvals(self): point_list = [] # Generate the list of points. for i in xrange(self.startingpoint.depth, self.todepth + 1, self.spacing): point_list.append( Point(self.startingpoint.longitude, self.startingpoint.latitude, i)) u = UCVM() data = u.query(point_list, self.cvm) for matprop in data: self.vplist.append(float(matprop.vp) / 1000) self.vslist.append(float(matprop.vs) / 1000) self.rholist.append(float(matprop.density) / 1000)
def getplotvals(self): point_list = [] # Generate the list of points. # for i in xrange(int(self.startingpoint.depth), int(self.todepth + 1), int(self.spacing)): self.meta['depth'] = [] for i in np.arange(self.startingpoint.depth, self.todepth + 1, self.spacing): point_list.append( Point(self.startingpoint.longitude, self.startingpoint.latitude, i)) self.meta['depth'].append(i) u = UCVM(install_dir=self.installdir, config_file=self.configfile) if (self.datafile != None): print "\nUsing --> " + self.datafile data = u.import_matprops(self.datafile) if len(data) == 0: print "ERROR: no matprops plot data." exit(1) else: data = u.query(point_list, self.cvm) # print "NUMBER of data found ", len(data) tmp = [] for matprop in data: self.vplist.append(matprop.vp) self.vslist.append(matprop.vs) self.rholist.append(matprop.density) ## create the blob if (self.datafile == None): ## save an external copy of matprops b = { 'vp': float(matprop.vp), 'vs': float(matprop.vs), 'density': float(matprop.density) } tmp.append(b) if (self.datafile == None): blob = {'matprops': tmp} u.export_matprops(blob, self.filename) u.export_metadata(self.meta, self.filename)
def getplotvals(self): point_list = [] proj = pyproj.Proj(proj='utm', zone=11, ellps='WGS84') x1, y1 = proj(self.startingpoint.longitude, self.startingpoint.latitude) x2, y2 = proj(self.endingpoint.longitude, self.endingpoint.latitude) num_prof = int(math.sqrt((x2-x1)*(x2-x1) + \ (y2-y1)*(y2-y1))/self.hspacing) for j in xrange(int(self.startingpoint.depth), int(self.todepth) + 1, int(self.vspacing)): for i in xrange(0, num_prof + 1): x = x1 + i * (x2 - x1) / float(num_prof) y = y1 + i * (y2 - y1) / float(num_prof) lon, lat = proj(x, y, inverse=True) point_list.append(Point(lon, lat, j)) u = UCVM() data = u.query(point_list, self.cvm) ## Private number of x points. self.num_x = num_prof + 1 ## Private number of y points. self.num_y = (int(self.todepth) - int(self.startingpoint.depth)) / int( self.vspacing) + 1 ## The 2D array of retrieved material properties. self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): self.materialproperties[y][x] = data[y * self.num_x + x]
def getplotvals(self, mproperty='vs'): point_list = [] lon_list = [] lat_list = [] depth_list = [] proj = pyproj.Proj(proj='utm', zone=11, ellps='WGS84') x1, y1 = proj(self.startingpoint.longitude, self.startingpoint.latitude) x2, y2 = proj(self.endingpoint.longitude, self.endingpoint.latitude) num_prof = int(math.sqrt((x2-x1)*(x2-x1) + \ (y2-y1)*(y2-y1))/self.hspacing) # cnt=0 jstart = self.startingdepth for j in xrange(int(self.startingdepth), int(self.todepth) + 1, int(self.vspacing)): depth_list.append(round(j, 3)) for i in xrange(0, num_prof + 1): x = x1 + i * (x2 - x1) / float(num_prof) y = y1 + i * (y2 - y1) / float(num_prof) lon, lat = proj(x, y, inverse=True) point_list.append(Point(lon, lat, j)) if (j == jstart): lon_list.append(round(lon, 5)) lat_list.append(round(lat, 5)) # if(cnt < 10) : # print("point.. lon ",lon, " lat ",lat," j ",j) # cnt += 1 self.lon_list = lon_list self.lat_list = lat_list self.depth_list = depth_list # print("total points generated..", len(point_list)) # print("total lon..", len(lon_list)) # print("total lat..", len(lat_list)) # print("total lat..", len(depth_list)) u = UCVM(install_dir=self.installdir, config_file=self.configfile) ### MEI -- TODO, need to have separate routine that generates cross section datafile if (self.datafile != None): ## Private number of x points. self.num_x = num_prof + 1 ## Private number of y points. self.num_y = (int(self.todepth) - int(self.startingdepth)) / int( self.vspacing) + 1 print "\nUsing -->" + self.datafile print "expecting x ", self.num_x, " y ", self.num_y data = u.import_binary(self.datafile, self.num_x, self.num_y) ## this set of data is only for --datatype: either 'vs', 'vp', 'rho', or 'poisson' ## The 2D array of retrieved material properties. self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] datapoints = data.reshape(self.num_y, self.num_x) for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): tmp = datapoints[y][x] if (mproperty == 'vp'): self.materialproperties[y][x].setProperty('Vp', tmp) if (mproperty == 'density'): self.materialproperties[y][x].setProperty( 'Density', tmp) if (mproperty == 'poisson'): self.materialproperties[y][x].setProperty( 'Poisson', tmp) if (mproperty == 'vs'): self.materialproperties[y][x].setProperty('Vs', tmp) else: data = u.query(point_list, self.cvm) ## Private number of x points. self.num_x = num_prof + 1 ## Private number of y points. self.num_y = (int(self.todepth) - int(self.startingdepth)) / int( self.vspacing) + 1 ## The 2D array of retrieved material properties. self.materialproperties = [[ MaterialProperties(-1, -1, -1) for x in xrange(self.num_x) ] for x in xrange(self.num_y)] for y in xrange(0, self.num_y): for x in xrange(0, self.num_x): self.materialproperties[y][x] = data[y * self.num_x + x]
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()
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()
def __init__(self, startingpoint, meta={}): self.meta = meta if 'installdir' in self.meta: self.installdir = self.meta['installdir'] else: self.installdir = None if 'configfile' in self.meta: self.configfile = self.meta['configfile'] else: self.configfile = None self.metadata = None if 'metadata' in self.meta: f = self.meta['metadata'] u = UCVM(install_dir=self.installdir, config_file=self.configfile) self.metadata = u.import_metadata(f) if not isinstance(startingpoint, Point): raise TypeError("The starting point must be an instance of Point.") else: ## Defines the @link common.Point starting point @endlink for the depth profile. self.startingpoint = startingpoint ## The discretization of the plot, in meters. if self.metadata != None and "vertical_spacing" in self.metadata: self.spacing = float(self.metadata['vertical_spacing']) elif 'vertical_spacing' in self.meta: self.spacing = float(self.meta['vertical_spacing']) else: self.spacing = -1 if self.metadata != None and 'ending_depth' in self.metadata: self.todepth = float(self.metadata['ending_depth']) elif 'ending_depth' in self.meta: self.todepth = float(self.meta['ending_depth']) else: self.todepth = 50000 if (self.todepth - self.startingpoint.depth) % self.spacing != 0: raise ValueError("%s\n%s\n%s" % ("The spacing value does not divide evenly into the requested depth. ", \ "Please make sure that the depth (%.2f - %.2f) divided by the spacing " % (todepth, startingpoint.depth), \ "%.2f has no remainder" % (spacing))) else: if self.metadata != None and "starting_depth" in self.metadata: self.startingdepth = float(self.metadata['starting_depth']) ## Defines the depth to which the plot should go in meters. else: self.startingdepth = self.startingpoint.depth ## The CVM to use (must be installed with UCVM). if 'cvm' in self.meta: self.cvm = self.meta['cvm'] self.datafile = None if 'datafile' in self.meta: self.datafile = self.meta['datafile'] self.filename = None if 'outfile' in self.meta: self.filename = self.meta['outfile'] self.properties = "vs" if 'data_type' in self.meta: self.properties = self.meta['data_type'] ## Private holding place for returned Vp data. self.vplist = [] ## Private holding place for returned Vs data. self.vslist = [] ## Private holding place for returned density data. self.rholist = [] ## Private holding place for depth data. self.depthlist = [] ## Default threshold in simplified units if 'vs_threshold' in self.meta: self.threshold = self.meta['vs_threshold'] else: self.threshold = None