def get_buoy(f=None, target_index=None): buoy = mf.parse_buoy(f) bucomp = -buoy.SPD * np.sin(np.radians(buoy.DIR)) bvcomp = -buoy.SPD * np.cos(np.radians(buoy.DIR)) buoy['U'] = bucomp buoy['V'] = bvcomp buoy.drop(buoy.columns[[0, 1, 2, 3, 4]], axis=1, inplace=True) buoy = buoy.loc[target_index] return buoy
def make_quiver(ax): """ make quiver plot for each file """ for i, f in enumerate(buoyfiles): df = mf.parse_buoy(f) df2 = df[st:en] time = df2.index[::2] wspd = df2.SPD[::2] wdir = df2.DIR[::2] X = np.asarray(range(len(wspd))) Y = np.zeros(len(wspd)) U = np.asarray(-wspd*np.sin(wdir*np.pi/180.)) V = np.asarray(-wspd*np.cos(wdir*np.pi/180.)) if len(time) > 0: ntime = len(time) xticks = range(0, ntime, 18) xticklabels = time[xticks] date_fmt = '%d\n%H' xtlabels = [t.strftime(date_fmt) for t in xticklabels] Q = ax[i].quiver( X, Y, U, V, width=0.002, facecolor='b', edgecolor='k', headwidth=3) if i == 0: ax[i].quiverkey(Q, 0.9, 0.1, 10, r'$10 \frac{m}{s}$', fontproperties={'weight': 'bold', 'size': 14}) ax[i].set_xticks(xticks) ax[i].set_xticklabels(xtlabels) ax[i].invert_xaxis() ax[i].set_xlim([ntime+5, -5]) ax[i].set_ylim([-0.02, 0.02]) filename = os.path.basename(f) buoyname = 'B'+filename[3:5] degree_sign = u'\N{DEGREE SIGN}' atext = buoyname+' - '+buoylats[buoyname]+degree_sign+'N' ax[i].text(0.05, 0.1, atext, transform=ax[i].transAxes, fontsize=14, verticalalignment='bottom') else: ax[i].text( 0.5, 0.5, 'NO DATA', weight='bold', transform=ax[i].transAxes) filename = os.path.basename(f) buoyname = 'B'+filename[3:5] atext = buoyname+' - '+buoylats[buoyname]+degree_sign+'N' ax[i].text(0.05, 0.1, atext, transform=ax[i].transAxes, fontsize=14, verticalalignment='bottom') ax[i].set_yticklabels(['']) plt.draw()