def _plot_beachball(ax2d, rtp_mt): """ Private function that plots a beachball into a 2d matplotlib :class:`~matplotlib.axes.Axes`. :type ax2d: :class:`matplotlib.axes.Axes` :param ax2d: 2d matplotlib Axes :param ax2d: matplotlib Axes3D object :param rtp_mt: moment tensor in RTP convention """ import matplotlib.pyplot as plt norm = plt.Normalize(-1., 1.) cmap = get_cmap('bwr') bball = beach(rtp_mt, xy=(0, 0), width=50, facecolor=cmap(norm(0.7)), bgcolor=cmap(norm(-0.7))) ax2d.add_collection(bball) ax2d.set(xlim=(-50, 50), ylim=(-50, 50), xticks=(-40, 40), yticks=(-40, 40), xticklabels=('West', 'East'), yticklabels=('South', 'North'), title='lower hemisphere stereographical projection')
def plot_misfit_depth_focal(misfit_array,depth_array,m_inverse_list,misfit_init,m_initial): ax = plt.gca() plt.plot(depth_array,misfit_array*200,'black') for _i in np.arange(0,depth_array.shape[0],1): #focmecs.append(m_inverse_list[_i]) print(depth_array[_i],misfit_array[_i],m_inverse_list[_i]) b = beach(m_inverse_list[_i], xy=(depth_array[_i],misfit_array[_i]*200),width=3,linewidth=0.2,facecolor='b') #b.set_zorder(10) ax.add_collection(b) ax.set_aspect("equal") b = beach(m_initial, xy=(0,misfit_init*200),width=3,linewidth=0.2,facecolor='r') ax.add_collection(b) ax.set_xlim((-35, 25)) ax.set_ylim((220, 290)) #xlabel= ax.grid() ax.set_ylabel('Misfit') ax.set_xlabel('Depth Perturpation(km)') plt.savefig(dir_output+'misfit_depth.ps',format='ps') plt.close()
def test_collection(self): """ Tests to plot mopad beachballs as collection into an existing axis object. The moment tensor values are taken form the test_Beachball unit test. See that test for more information about the parameters. """ mt = [[0.91, -0.89, -0.02, 1.78, -1.55, 0.47], [274, 13, 55], [130, 79, 98], [264.98, 45.00, -159.99], [160.55, 76.00, -46.78], [1.45, -6.60, 5.14, -2.67, -3.16, 1.36], [235, 80, 35], [138, 56, 168], [1, 1, 1, 0, 0, 0], [-1, -1, -1, 0, 0, 0], [1, -2, 1, 0, 0, 0], [1, -1, 0, 0, 0, 0], [1, -1, 0, 0, 0, -1], [179, 55, -78], [10, 42.5, 90], [10, 42.5, 92], [150, 87, 1], [0.99, -2.00, 1.01, 0.92, 0.48, 0.15], [5.24, -6.77, 1.53, 0.81, 1.49, -0.05], [16.578, -7.987, -8.592, -5.515, -29.732, 7.517], [-2.39, 1.04, 1.35, 0.57, -2.94, -0.94], [150, 87, 1]] with ImageComparison(self.path, 'mopad_collection.png') as ic: # Initialize figure fig = plt.figure(figsize=(6, 6), dpi=300) ax = fig.add_subplot(111, aspect='equal') # Plot the stations or borders ax.plot([-100, -100, 100, 100], [-100, 100, -100, 100], 'rv') x = -100 y = -100 for i, t in enumerate(mt): # add the beachball (a collection of two patches) to the axis ax.add_collection(beach(t, width=30, xy=(x, y), linewidth=.6)) x += 50 if (i + 1) % 5 == 0: x = -100 y += 50 # set the x and y limits ax.axis([-120, 120, -120, 120]) # create and compare image fig.savefig(ic.name)
def _draw_mt_finite(self): if not hasattr(self, "mpl_mt_finite_ax"): return try: self.bb_finite.remove() except: pass self.bb_finite = beach(self.finite_source.CMT.tensor / 1e16, xy=(0, 0), width=200, linewidth=1, facecolor="red") self.mpl_mt_finite_ax.add_collection(self.bb_finite) self.mpl_mt_finite_ax.set_xlim(-105, 105) self.mpl_mt_finite_ax.set_ylim(-105, 105) self.mpl_mt_finite_figure.canvas.draw()
def _draw_mt(self): if not hasattr(self, "mpl_mt_ax"): return try: self.bb.remove() except Exception: pass fm = self.focmec fm = [_i / 1e16 for _i in fm] self.bb = beach(fm, xy=(0, 0), width=200, linewidth=1, facecolor="red") self.mpl_mt_ax.add_collection(self.bb) self.mpl_mt_ax.set_xlim(-105, 105) self.mpl_mt_ax.set_ylim(-105, 105) self.mpl_mt_figure.canvas.draw()
def _draw_mt(self): if not hasattr(self, "mpl_mt_ax"): return try: self.bb.remove() except: pass fm = self.focmec fm = [_i / 1e16 for _i in fm] self.bb = beach(fm, xy=(0, 0), width=200, linewidth=1, facecolor="red") self.mpl_mt_ax.add_collection(self.bb) self.mpl_mt_ax.set_xlim(-105, 105) self.mpl_mt_ax.set_ylim(-105, 105) self.mpl_mt_figure.canvas.draw()
def _draw_mt_finite(self): if not hasattr(self, "mpl_mt_finite_ax"): return try: self.bb_finite.remove() except Exception: pass self.bb_finite = beach(self.finite_source.CMT.tensor / 1e16, xy=(0, 0), width=200, linewidth=1, facecolor="red") self.mpl_mt_finite_ax.add_collection(self.bb_finite) self.mpl_mt_finite_ax.set_xlim(-105, 105) self.mpl_mt_finite_ax.set_ylim(-105, 105) self.mpl_mt_finite_figure.canvas.draw()
def plot_SSRT_map(self, lat_array, lon_array, intersting_satellites, dphi, dlambda): # Set map boundaries south, north = -62, -52 west, east = -48.5, -24 center = [(east+west)/2, (north+south)/2] m = Basemap(llcrnrlon=west, llcrnrlat=south, urcrnrlon=east, urcrnrlat=north, resolution='h', area_thresh = 0.1, projection='tmerc', lat_ts=0, lon_0=center[0], lat_0=center[1]) # Plot features m.drawcoastlines() m.drawparallels(np.arange(-81., 81., 2),labels=[1,0,0,0], linewidth=0.0) m.drawmeridians(np.arange(-180., 181., 4),labels=[0,0,0,1], linewidth=0.0) m.shadedrelief() if 'iMac' in self.pathList: m.readshapefile(r'<your_path>', name='PB2002_plates', drawbounds=False, color='r') else: m.readshapefile(r'<your_path>', name='PB2002_plates', drawbounds=False, color='r') plate_names = [] for plate_dict in m.PB2002_plates_info: plate_names.append(plate_dict['PlateName']) plates_of_interest = ['Scotia', 'Sandwich', 'Antarctica'] #South America #Antartica for info, shape in zip(m.PB2002_plates_info, m.PB2002_plates): if info['PlateName'] in plates_of_interest: x, y = zip(*shape) m.plot(x, y, marker=None, color='sandybrown') m.drawmapscale(-42.0, -61.5, center[0], center[1], 500, barstyle='fancy', fontcolor='whitesmoke', fillcolor1='whitesmoke', fillcolor2='silver') earthquake_index_original = 3841 # SSRT EQ at 9:04 UT # Plot ground tracks eq_longitude_values = [] eq_latitude_values = [] satellite_list = [] start = [0, 0, 0] end = [14400, 9720, 14400] for i in range(len(intersting_satellites)): spec_sv_lam = lon_array[: ,i] spec_sv_phi = lat_array[: ,i] #Code added here to splice arrays depending on when the satellites were tracked. Use VTEC plots (time axes) for reference spec_sv_lam = spec_sv_lam[start[i]:end[i]] spec_sv_phi = spec_sv_phi[start[i]:end[i]] # Find index of EQ once the splice has happened: earthquake_index = earthquake_index_original - start[i] #earthquake_index = 973 track_len = len(spec_sv_lam) earthquake_long = spec_sv_lam[earthquake_index] earthquake_lat = spec_sv_phi[earthquake_index] longitude_values = [] latitude_values = [] for j in range(track_len): latitude = spec_sv_phi[j] longitude = spec_sv_lam[j] latitude_values.append(latitude) longitude_values.append(longitude) # Convert latitude and longitude to coordinates X and Y x, y = m(longitude_values, latitude_values) x_eq, y_eq = m(earthquake_long, earthquake_lat) eq_longitude_values.append(x_eq) eq_latitude_values.append(y_eq) d = intersting_satellites[i] +1 d_replace = str(d).zfill(2) prn = 'G%s' % d_replace satellite_list.append(prn) # Plot the points on the map plt.plot(x,y,'-', color='b', zorder=7) #burlywood print "plot_SSRT_map: Track plotted for PRN{0}".format(intersting_satellites[i]+1) #Plotting exact points on the ground track where earthquake occurs m.scatter(eq_longitude_values, eq_latitude_values, s=40, marker='*', color='r', zorder=10) for i, (x, y) in enumerate(zip(eq_longitude_values, eq_latitude_values), start=0): plt.annotate(str(satellite_list[i]), (x,y), xytext=(2, 2), textcoords='offset points', color='k', fontsize=9, zorder=9) # Plot points and text lons, lats = [-46.401, dlambda, -44., -32.0, -29, -29.5, -32.7], [-60.274, dphi, -57., -61.5, -54.5, -56.2, -58.0] x, y = m(lons, lats) x_offsets = [26000, 20000] y_offsets = [-25000, 12000] m.scatter(x[1], y[1], s=100, marker='^', color='k') plt.text(x[2], y[2], 'Scotia Sea', style='italic', fontsize=17) plt.text(x[1] +x_offsets[1], y[1] +y_offsets[1], 'krsa', style='italic', color='k', fontsize=15) plt.text(x[3], y[3], 'Antarctic\n Plate', fontsize=11) plt.text(x[4], y[4], 'South America\n Plate', fontsize=11) plt.text(x[5], y[5], 'Sandwich\n Plate', fontsize=11) plt.text(x[6], y[6], 'Scotia\n Plate', fontsize=11) ax = plt.gca() b = beach([190, 89, -140], facecolor='orange', xy=(x[0], y[0]), width=70000, linewidth=1, alpha=0.85) b.set_zorder(10) ax.add_collection(b) #plt.show() if 'iMac' in self.pathList: plt.savefig(r'<your_path>', bbox_inches="tight") else: plt.savefig(r'<your_path>', bbox_inches="tight") plt.close() print "SSRT map created."
def ploteventstation(dir_observe,list_input): m = Basemap(projection='merc', lon_0=13, lat_0=48, resolution="h",llcrnrlon=-78, llcrnrlat=-36, urcrnrlon=-61, urcrnrlat=-12) # create grids and compute map projection coordinates for lon/lat grid #x, y = m(*np.meshgrid(lons, lats)) # Make contour plot #cs = m.contourf(x, y, srtm,30,cmap=plt.cm.jet) m.drawcountries(color="blue", linewidth=0.1) m.shadedrelief() m.drawcoastlines(linewidth=0.5) m.drawcountries(linewidth=0.2) parallels = np.arange(-81,0,4.) m.drawparallels(parallels,linewidth=0,labels=[1,0,1,1]) meridians = np.arange(10.,351.,4.) m.drawmeridians(meridians,linewidth=0,labels=[1,1,0,1]) focmecs=[] lats=[] lons=[] stalons=np.array([]) stalats=np.array([]) files = glob.glob(dir_observe) #files = glob.glob('*.h5') for f in files: ####### here implement the for circyle ds = pyasdf.ASDFDataSet(f) print(ds) event=ds.events[0] event_id=event.resource_id.id.split('=')[-1] magnitude=event.magnitudes[0].mag; Mtype=event.magnitudes[0].magnitude_type otime=event.origins[0].time evlo=event.origins[0].longitude; evla=event.origins[0].latitude; evdp=event.origins[0].depth/1000. #print(evlo) #print(evla) values=np.array([]) valuetype='depth' mtensor=event.focal_mechanisms[0].moment_tensor.tensor mt=[mtensor.m_rr, mtensor.m_tt, mtensor.m_pp, mtensor.m_rt, mtensor.m_rp, mtensor.m_tp] focmecs.append(mt) lats.append(evla) lons.append(evlo) #print(focmecs) #print(lats,lons) x, y = m(lons, lats) #print(x,y) staLst=ds.waveforms.list() stalons=np.array([]); stalats=np.array([]) for staid in list_input: stla, stlo,evz =ds.waveforms[staid].coordinates.values() print(stlo,stla) stalons=np.append(stalons, stlo) stalats=np.append(stalats, stla) #ax.add_collection(b) stax, stay=m(stalons, stalats) m.plot(stax, stay, '^', markersize=3) #m=self._get_basemap(projection=projection, geopolygons=geopolygons, blon=blon, blat=blat) #m.etopo() # m.shadedrelief() #stax, stay=m(stalons, stalats) #m.plot(stax, stay, '^', markersize=3) # plt.title(str(self.period)+' sec', fontsize=20) ax = plt.gca() # Two focal mechanisms for beachball routine, specified as [strike, dip, rake] for i in range(len(focmecs)): b = beach(focmecs[i], xy=(x[i], y[i]), width=100000, linewidth=0.2) b.set_zorder(10) ax.add_collection(b) #################################################################### plt.savefig('test.ps',format='ps') plt.close()
def plot_Japan_map(self, lat_array, lon_array, intersting_satellites, dphi, dlambda): #Japan boundary south, north = 32, 45 west, east = 132.5, 151 center = [(east+west)/2, (north+south)/2] m = Basemap(llcrnrlon=west, llcrnrlat=south, urcrnrlon=east, urcrnrlat=north, resolution='h', area_thresh = 0.1, projection='tmerc', lat_ts=0, lon_0=center[0], lat_0=center[1]) # Plot features m.drawcoastlines() m.drawparallels(np.arange(-81., 81., 2),labels=[1,0,0,0], linewidth=0.0) #-81., 81., 4 m.drawmeridians(np.arange(-180., 181., 4),labels=[0,0,0,1], linewidth=0.0) #-180., 181., 10 m.shadedrelief() if 'iDerry_iMac' in self.pathList: m.readshapefile(r'<your_path>', name='PB2002_plates', drawbounds=False, color='r') else: m.readshapefile(r'<your_path>', name='PB2002_plates', drawbounds=False, color='orange') plate_names = [] for plate_dict in m.PB2002_plates_info: plate_names.append(plate_dict['PlateName']) plates_of_interest = ['Okhotsk', 'Philippine Sea', 'Pacific', 'Eurasia', 'North America'] #Kermadec #Pacific #Australia for info, shape in zip(m.PB2002_plates_info, m.PB2002_plates): if info['PlateName'] in plates_of_interest: x, y = zip(*shape) m.plot(x, y, marker=None, color='sandybrown') m.drawmapscale(146.3, 33.2, 145, 40, 500, barstyle='fancy', fontcolor='whitesmoke', fillcolor1='whitesmoke', fillcolor2='silver') earthquake_index_original = 973 # Japan MIZU=973/2772 eq_longitude_values = [] eq_latitude_values = [] satellite_list = [] start = [0, 0, 0, 0, 0, 0, 0, 0] end = [6480, 10800, 10800, 10800, 10080, 9360, 10800, 7200] for i in range(len(intersting_satellites)): spec_sv_lam = lon_array[: ,i] spec_sv_phi = lat_array[: ,i] #Code added here to splice arrays depending on when the satellites were tracked. Use VTEC plots (time axes) for reference spec_sv_lam = spec_sv_lam[start[i]:end[i]] spec_sv_phi = spec_sv_phi[start[i]:end[i]] # Find index of EQ once the splice has happened: earthquake_index = earthquake_index_original - start[i] #earthquake_index = 973 track_len = len(spec_sv_lam) earthquake_long = spec_sv_lam[earthquake_index] earthquake_lat = spec_sv_phi[earthquake_index] longitude_values = [] latitude_values = [] for j in range(track_len): latitude = spec_sv_phi[j] longitude = spec_sv_lam[j] latitude_values.append(latitude) longitude_values.append(longitude) # Convert latitude and longitude to coordinates X and Y x, y = m(longitude_values, latitude_values) x_eq, y_eq = m(earthquake_long, earthquake_lat) eq_longitude_values.append(x_eq) eq_latitude_values.append(y_eq) d = intersting_satellites[i] +1 d_replace = str(d).zfill(2) prn = 'G%s' % d_replace satellite_list.append(prn) # Plot the points on the map plt.plot(x,y,'-', color='blue', zorder=7) print "plot_Japan_map: Track plotted for PRN{0}".format(intersting_satellites[i]+1) #Plotting exact points on the ground track where earthquake occurs m.scatter(eq_longitude_values, eq_latitude_values, s=40, marker='*', color='r', zorder=10) for i, (x, y) in enumerate(zip(eq_longitude_values, eq_latitude_values), start=0): plt.annotate(str(satellite_list[i]), (x,y), xytext=(2, 2), textcoords='offset points', color='k', fontsize=9, zorder=9) # Plot points and text lons, lats = [142.372, 139.840, dlambda, 145.5, 133, 136.2, 138.9, 146.1, 139.0], [38.297, 35.653, dphi, 36.0, 39, 42, 43.5, 41.1, 33.3] x, y = m(lons, lats) x_offsets = [26000, 20000] y_offsets = [-25000, 12000] m.scatter(x[1], y[1], s=60, marker='s', color='k') #For the capital square symbol for Tokyo m.scatter(x[2], y[2], s=100, marker='^', color='k') plt.text(x[2] +x_offsets[1], y[2] +y_offsets[1], 'mizu', style='italic', color='k', fontsize=15) plt.text(x[1] +x_offsets[1], y[1] +y_offsets[1], 'Tokyo', color='k', fontsize=15, zorder=3) plt.text(x[3], y[3], 'Pacific\n Ocean', style='italic', color='dodgerblue', fontsize=17, zorder=8) plt.text(x[4], y[4], 'Sea of\nJapan', style='italic', color='dodgerblue', fontsize=17, zorder=8) plt.text(x[5], y[5], 'Eurasian\n Plate', fontsize=11) plt.text(x[6], y[6], 'North\nAmerican\nPlate', fontsize=11) plt.text(x[7], y[7], 'Pacific\n Plate', fontsize=11) plt.text(x[8], y[8], 'Philippine\n Sea Plate', fontsize=10) #Beachball plotting ax = plt.gca() b = beach([193, 9, 78], facecolor='red', xy=(x[0], y[0]), width=70000, linewidth=1, alpha=0.85) b.set_zorder(10) ax.add_collection(b) if 'iMac' in self.pathList: plt.savefig(r'<your_path>', bbox_inches="tight") else: plt.savefig(r'<your_path>', bbox_inches="tight") plt.close() print "Japan Map generated"