def plot_events(events, map_object, beachball_size=0.02, project=None): """ """ for event in events: # Add beachball plot. x, y = map_object(event["longitude"], event["latitude"]) focmec = [event["m_rr"], event["m_tt"], event["m_pp"], event["m_rt"], event["m_rp"], event["m_tp"]] # Attempt to calculate the best beachball size. width = max((map_object.xmax - map_object.xmin, map_object.ymax - map_object.ymin)) * beachball_size b = Beach(focmec, xy=(x, y), width=width, linewidth=1, facecolor="red") b.set_picker(True) b._project = project b._event_name = os.path.splitext( os.path.basename(event["filename"]))[0] b.detailed_event_description = ( "Event %.1f %s\n" "Lat: %.1f, Lng: %.1f, Depth: %.1f km\n" "Time: %s\n" "%s" ) % (event["magnitude"], event["magnitude_type"], event["latitude"], event["longitude"], event["depth_in_km"], event["origin_time"], event["event_name"]) b.set_zorder(200000000) plt.gca().add_collection(b) _set_global_pick_handler()
def plot_events(events, map_object, beachball_size=0.02): """ """ beachballs = [] for event in events: # Add beachball plot. x, y = map_object(event["longitude"], event["latitude"]) focmec = [ event["m_rr"], event["m_tt"], event["m_pp"], event["m_rt"], event["m_rp"], event["m_tp"] ] # Attempt to calculate the best beachball size. width = max((map_object.xmax - map_object.xmin, map_object.ymax - map_object.ymin)) * beachball_size b = Beach(focmec, xy=(x, y), width=width, linewidth=1, facecolor="red") b.set_zorder(200000000) map_object.ax.add_collection(b) beachballs.append(b) return beachballs
def mt_plot(): """ Return a moment tensor image. """ formats = {"png": "image/png", "svg": "image/svg+xml"} args = flask.request.args m_rr = float(args["m_rr"]) m_tt = float(args["m_tt"]) m_pp = float(args["m_pp"]) m_rt = float(args["m_rt"]) m_rp = float(args["m_rp"]) m_tp = float(args["m_tp"]) focmec = (m_rr, m_tt, m_pp, m_rt, m_rp, m_tp) # Allow hexcolors. color = args.get("color", "red") try: hexcolor = "#" + color hex2color(hexcolor) color = hexcolor except ValueError: pass size = int(args.get("size", 32)) lw = float(args.get("lw", 1)) format = args.get("format", "png") if format not in formats.keys(): flask.abort(500) dpi = 100 fig = plt.figure(figsize=(float(size) / float(dpi), float(size) / float(dpi)), dpi=dpi) ax = plt.Axes(fig, [0., 0., 1., 1.]) ax.set_axis_off() fig.add_axes(ax) bb = Beach(focmec, xy=(0, 0), width=200, linewidth=lw, facecolor=color) ax.add_collection(bb) ax.set_xlim(-105, 105) ax.set_ylim(-105, 105) temp = io.BytesIO() plt.savefig(temp, format=format, dpi=dpi, transparent=True) plt.close(fig) plt.close("all") temp.seek(0, 0) return flask.send_file(temp, mimetype=formats[format], add_etags=False, attachment_filename="mt.%s" % format)
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)
i=where(slab[:,2]>-60)[0] x=distance[i] y=slab[i,2] z=marker_color[i] im=ax.scatter(x,y,marker='o',lw=0,c=z,s=90,vmin=0,vmax=8,cmap=cm) # ADD MTs for k in range(len(MTs)): mt=MTs[k,3:9] #MT=analysis.MT(mt[0],mt[1],mt[2],mt[3],mt[4],mt[5],1,1,1) #MT.get_nodal_planes() MT=mopad.MomentTensor(mt,system='USE') np1,np2=MT.get_fps() #Thrust if (np1[2]>45 and np1[2]<135) or (np2[2]>45 and np2[2]<135): print k beach=Beach(np1, xy=(distance_MTs[k], depth_MTs[k]), width=6,linewidth=0.5,facecolor='r') print 'Thrust: '+str(np1)+' , '+str(np2) #Normal elif (np1[2]>-135 and np1[2]<-45) or (np2[2]>-135 and np2[2]<-45): print k beach=Beach(np1, xy=(distance_MTs[k], depth_MTs[k]), width=6,linewidth=0.5,facecolor='b') print 'Normal: '+str(np1)+' , '+str(np2) #Oblique else: print k beach=Beach(np1, xy=(distance_MTs[k], depth_MTs[k]), width=6,linewidth=0.5,facecolor='g') print 'Oblique: '+str(np1)+' , '+str(np2) ax.add_collection(beach) #plt.colorbar() ax.plot(distance_topo,topo,lw=2) ax.yaxis.tick_left()