savepath='figures/png/' + grid + '_' + '/eluv_for_ttide_at_element/' if not os.path.exists(savepath): os.makedirs(savepath) base_dir = os.path.dirname(__file__) cons=np.array([['M2 '],['M4 ']]) for i in range(0,len(elements)): j=elements[i] print 'Element: ' +("%d"%j) f,ax=plt.subplots(nrows=3,ncols=1,sharex=True) [nameu, freq, tidecon_uv, xout]=t_tide(data['ua'][starttime:,j]+1j*data['va'][starttime:,j],stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_uv) [nameu, freq, tidecon_uv2, xout]=t_tide(data2['ua'][starttime:,j]+1j*data2['va'][starttime:,j],stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre2=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_uv2) uvel1=(data['zeta'][starttime:,data['nv'][j,0]] + data['zeta'][starttime:,data['nv'][j,1]] + data['zeta'][starttime:,data['nv'][j,2]]) / 3.0 [nameu, freq, tidecon_el, xout]=t_tide(uvel1,stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre_el=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_el) uvel2=(data['zeta'][starttime:,data['nv'][j,0]] + data['zeta'][starttime:,data['nv'][j,1]] + data['zeta'][starttime:,data['nv'][j,2]]) / 3.0 [nameu, freq, tidecon_el2, xout]=t_tide(uvel2,stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre_el2=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_el2)
f.savefig(savepath + grid +'_'+regionname+ '_ebb_vectors_at_' + ("%04d" %(starttime+offset+ebb)) + '.png',dpi=600) plt.close(f) resu=np.empty((len(eidx),len(data['time'][starttime:]))) resv=np.empty((len(eidx),len(data['time'][starttime:]))) resu2=np.empty((len(eidx),len(data['time'][starttime:]))) resv2=np.empty((len(eidx),len(data['time'][starttime:]))) for j in range(0,len(eidx)): print j i=eidx[j] [nameu, freq, tidecon_uv, xout]=t_tide(data['ua'][starttime:,i]+1j*data['va'][starttime:,i],stime=data['time'][starttime],lat=data['uvnodell'][i,1],output=False,constitnames=np.array([['M2 '],['N2 '],['S2 '],['K1 '],['O1 ']])) resu[j,:]=data['ua'][starttime:,i]-np.real(t_predic(data['time'][starttime:],nameu,freq,tidecon_uv)).flatten() resv[j,:]=data['va'][starttime:,i]-np.imag(t_predic(data['time'][starttime:],nameu,freq,tidecon_uv)).flatten() [nameu, freq, tidecon_uv, xout]=t_tide(data2['ua'][starttime:,i]+1j*data2['va'][starttime:,i],stime=data['time'][starttime],lat=data['uvnodell'][i,1],output=False,constitnames=np.array([['M2 '],['N2 '],['S2 '],['K1 '],['O1 ']])) resu2[j,:]=data2['ua'][(starttime+offset):,i]-np.real(t_predic(data2['time'][(starttime+offset):],nameu,freq,tidecon_uv)).flatten() resv2[j,:]=data2['va'][(starttime+offset):,i]-np.imag(t_predic(data2['time'][(starttime+offset):],nameu,freq,tidecon_uv)).flatten() f=plt.figure() ax_res=f.add_axes([.125,.1,.8,.775]) ax_res.triplot(data['trigrid'],lw=.5) axsub1lw=1 for i in cages: tnodes=data['nv'][i,:] ax_res.plot(data['nodell'][tnodes[[0,1]],0],data['nodell'][tnodes[[0,1]],1],cagecolor,lw=axsub1lw,label='Drag')
savepath='figures/png/' + grid + '_' + datatype + '/eluv_for_ttide_at_element/' if not os.path.exists(savepath): os.makedirs(savepath) base_dir = os.path.dirname(__file__) cons=np.array([['M2 '],['M4 ']]) for i in range(0,len(elements)): j=elements[i] print 'Element: ' +("%d"%j) f,ax=plt.subplots(nrows=3,ncols=1,sharex=True) [nameu, freq, tidecon_uv, xout]=t_tide(data['ua'][starttime:,j]+1j*data['va'][starttime:,j],stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_uv) [nameu, freq, tidecon_uv2, xout]=t_tide(data2['ua'][starttime:,j]+1j*data2['va'][starttime:,j],stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre2=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_uv2) uvel1=(data['zeta'][starttime:,data['nv'][j,0]] + data['zeta'][starttime:,data['nv'][j,1]] + data['zeta'][starttime:,data['nv'][j,2]]) / 3.0 [nameu, freq, tidecon_el, xout]=t_tide(uvel1,stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre_el=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_el) uvel2=(data['zeta'][starttime:,data['nv'][j,0]] + data['zeta'][starttime:,data['nv'][j,1]] + data['zeta'][starttime:,data['nv'][j,2]]) / 3.0 [nameu, freq, tidecon_el2, xout]=t_tide(uvel2,stime=data['time'][starttime],lat=data['uvnodell'][j,1],output=False,constitnames=cons) tpre_el2=t_predic(data['time'][starttime:(starttime+plotlength)],nameu,freq,tidecon_el2)
region = regions(regionname) savepath = 'figures/png/' + grid + '_' + '/ellipses/' + name + '_' + regionname + '/' if not os.path.exists(savepath): os.makedirs(savepath) idx = equal_vectors(data, region, spacing) tidecon_uv = np.empty([len(idx), 5, 8]) print len(idx) for i in range(0, len(idx)): j = idx[i] [nameu, freq, tidecon_uv[i, ], xout] = t_tide(data['ua'][starttime:, j] + 1j * data['va'][starttime:, j], stime=data['time'][starttime], lat=data['uvnodell'][j, 1], output=False, constitnames=np.array([['M2 '], ['N2 '], ['S2 '], ['K1 '], ['O1 ']])) print('T_tide Finished') idxl = np.where(tidecon_uv[:, 3, 2] >= 0)[0] idxr = np.where(tidecon_uv[:, 3, 2] < 0)[0] ellsleft = [ Ellipse(xy=(data['uvnodell'][idx[idxl[i]], 0], data['uvnodell'][idx[idxl[i]], 1]), width=np.fabs(tidecon_uv[idxl[i], 3, 2]) / divider, height=tidecon_uv[idxl[i], 3, 0] / divider, angle=tidecon_uv[idxl[i], 3, 4] + 90, fc='None',
#[nameu, fu, tidecon, xout]=tt.t_tide(data['zeta'][199:-1,118836],dt=1.555) print print '/\ Scalar test (errcalc=linear)' print #[nameu, fu, tidecon, xout]=tt.t_tide(data['ua'][199:-1,149999]+1j*data['va'][199:-1,149999],errcalc='linear') print print '/\ Complex test (errcalc=linear)' print #kill [nameu, fu, tidecon, xout]=tt.t_tide(data['zeta'][199:-1,118836],errcalc='wboot') print print '/\ Scalar test (errcalc=wboot)' print [nameu, fu, tidecon, xout]=tt.t_tide(data['ua'][199:-1,149999]+1j*data['va'][199:-1,149999],errcalc='wboot') print print '/\ Complex test (errcalc=wboot)' print [nameu, fu, tidecon, xout]=tt.t_tide(data['zeta'][199:-1,118836],stime=data['time'][0],lat=data['nodell'][118836,1],constitnames=np.array([['M2 ']])) print print '/\ Scalar test (stime,lat,con=m2)' print [nameu, fu, tidecon, xout]=tt.t_tide(data['ua'][199:-1,149999]+1j*data['va'][199:-1,149999],stime=data['time'][0],lat=data['uvnodell'][149999,1],constitnames=np.array([['M2 ']]))
print('done load') data = ncdatasort(data,trifinder=True) print('done sort') savepath='figures/png/' + grid + '_' + datatype + '/misc/' if not os.path.exists(savepath): os.makedirs(savepath) loc=[-58.9161,44.1942] ua=interpE_at_loc(data,'ua',loc) va=interpE_at_loc(data,'va',loc) [nameu, freq, tidecon_uv, xout]=t_tide(ua[starttime:endtime]+1j*va[starttime:endtime],stime=data['time'][starttime],lat=loc[1],output=True,constitnames=['M2','S2','N2','K1','O1'],dt=np.diff(data['time'])[0]*24) dist=np.sqrt(ua**2+va**2) f=plt.figure() ax=f.add_axes([.125,.1,.775,.8]) scb=ax.scatter(ua,va,s=25,c=dist,edgecolors='None') cb=plt.colorbar(scb) ax.set_xlabel(r'depth averaged u-velocity (m/s)') ax.set_ylabel(r'depth averaged v-velocity (m/s)') cb.set_label(r'depth averaged speed (m/s)') f.savefig(savepath + grid + '_' +name+ '_john_scatter.png',dpi=600) plt.close(f)
endtime=2785 ### load the .nc file ##### data = loadnc('runs/'+grid+'/'+name+'/output/',singlename=grid + '_0001.nc') print('done load') data = ncdatasort(data) print('done sort') dt=np.diff(data['time'])[0]*24 tidecon_uv=np.empty([len(data['uvnodell'][:,0]),29,8]) for i in range(0,len(data['uvnodell'][:,0])): print(i) [nameu, freq, tidecon_uv[i,], xout]=t_tide(data['ua'][starttime:endtime,i]+1j*data['va'][starttime:endtime,i],stime=data['time'][starttime],lat=data['uvnodell'][i,1],output=False,synth=-1,dt=dt) tidesave={} tidesave['nameu']=nameu tidesave['freq']=freq tidesave['tidecon']=tidecon_uv np.save('data/ttide/'+grid+'_'+name+'_'+datatype+'_uv_all.npy',tidesave) tidecon_el=np.empty([len(data['nodell'][:,0]),29,4]) for j in range(0,len(data['nodell'][:,0])): print(j) [nameu, freq, tidecon_el[j,], xout]=t_tide(data['zeta'][starttime:endtime,j],stime=data['time'][starttime],lat=data['nodell'][j,1],synth=-1,output=False,dt=dt) tidesave={} tidesave['nameu']=nameu
# Build an M2 tidal series with 5m elevation ein = 5*np.cos(((2*np.pi/12.42))*np.arange(1001)) # Build an M2 tidal series for current # Use to 2m/s horizontal currents and .5m/s vertical currents uin = 2*np.cos(((2*np.pi/12.42))*np.arange(1001)) vin = 0.5*np.cos(((2*np.pi/12.42))*np.arange(1001)) uvin = uin+1j*vin ######################################################################## # Elevation Test Cases ######################################################################## # Basic test case [nameu, freq, tidecon, xout] = t_tide(ein) print() print('*' * 80) print() # No output test case [nameu, freq, tidecon, xout] = t_tide(ein, output=False) print() print('*' * 80) print() # Pandas output case [nameu, freq, tidecon, xout] = t_tide(ein, out_style='pandas')
#testel=np.genfromtxt('kiti_118836.csv', dtype=None, delimiter=',') #print np.absolute(data['zeta'][199:-1,118836]-testel).min() #print np.absolute(data['zeta'][199:-1,118836]-testel).max() #[nameu, fu, tidecon, xout]=tt.t_tide(data['zeta'][199:-1,118836],dt=1.555) print print '/\ Scalar test (errcalc=linear)' print #[nameu, fu, tidecon, xout]=tt.t_tide(data['ua'][199:-1,149999]+1j*data['va'][199:-1,149999],errcalc='linear') print print '/\ Complex test (errcalc=linear)' print #kill [nameu, fu, tidecon, xout] = tt.t_tide(data['zeta'][199:-1, 118836], errcalc='wboot') print print '/\ Scalar test (errcalc=wboot)' print [nameu, fu, tidecon, xout ] = tt.t_tide(data['ua'][199:-1, 149999] + 1j * data['va'][199:-1, 149999], errcalc='wboot') print print '/\ Complex test (errcalc=wboot)' print [nameu, fu, tidecon, xout] = tt.t_tide(data['zeta'][199:-1, 118836], stime=data['time'][0], lat=data['nodell'][118836, 1], constitnames=np.array([['M2 ']])) print
print('done load') data = ncdatasort(data, trifinder=True) print('done sort') savepath = 'figures/png/' + grid + '_' + datatype + '/misc/' if not os.path.exists(savepath): os.makedirs(savepath) loc = [-58.9161, 44.1942] ua = ipt.interpE_at_loc(data, 'ua', loc) va = ipt.interpE_at_loc(data, 'va', loc) [nameu, freq, tidecon_uv, xout] = t_tide(ua[starttime:endtime] + 1j * va[starttime:endtime], stime=data['time'][starttime], lat=loc[1], output=True, constitnames=['M2', 'S2', 'N2', 'K1', 'O1'], dt=np.diff(data['time'])[0] * 24) dist = np.sqrt(ua**2 + va**2) f = plt.figure() ax = f.add_axes([.125, .1, .775, .8]) scb = ax.scatter(ua, va, s=25, c=dist, edgecolors='None') cb = plt.colorbar(scb) ax.set_xlabel(r'depth averaged u-velocity (m/s)') ax.set_ylabel(r'depth averaged v-velocity (m/s)') cb.set_label(r'depth averaged speed (m/s)') f.savefig(savepath + grid + '_' + name + '_john_scatter.png', dpi=600) plt.close(f)