df1 = df_1.loc[i1] if switch == 0: phi0 = df0.azim.unique() phi1 = df1.azim.unique() r0 = df0.range_gate.iloc[0].values r1 = df1.range_gate.iloc[0].values r_0, phi_0 = np.meshgrid(r0, np.pi - np.radians(phi0)) # meshgrid r_1, phi_1 = np.meshgrid(r0, np.pi - np.radians(phi1)) # meshgrid tree, tri, w0, neigh0, index0, w1, neigh1, index1 = wr.grid_over2( (r_0, phi_0), (r_1, phi_1), -d) switch = 1 u, v, grd, s = wr.direct_wf_rec(df0.astype(np.float32), df1.astype(np.float32), tri, d, N_grid=512) U_out.append(u), V_out.append(v), su.append(s) U_out = [item for sublist in U_out for item in sublist] V_out = [item for sublist in V_out for item in sublist] su = [item for sublist in su for item in sublist] #filename = file_out_path_u_field+'/U_rec_'+dy+'.pkl' #joblib.dump((U_out, V_out, grd, su), filename) # #with open(file_out_path_u_field+'/U_rec_'+dy+'.pkl', 'wb') as field: # pickle.dump((U_out, V_out, grd, su),field) #### Vorticity
indt0 = [x for x in indt0 if np.sum(x) > 0] indt1 = [x for x in indt1 if np.sum(x) > 0] if (len(indt0)>0)&(len(indt1)>0): for i0,i1 in zip(indt0,indt1): df0 = df_0.loc[i0] df1 = df_1.loc[i1] if switch == 0: phi0 = df0.azim.unique() phi1 = df1.azim.unique() r0 = df0.range_gate.iloc[0].values r1 = df1.range_gate.iloc[0].values r_0, phi_0 = np.meshgrid(r0, np.pi/2-np.radians(phi0)) # meshgrid r_1, phi_1 = np.meshgrid(r0, np.pi/2-np.radians(phi1)) # meshgrid tree,tri, w0, neigh0, index0, w1, neigh1, index1 = wr.grid_over2((r_0, phi_0),(r_1,phi_1), -d) switch = 1 uo, vo, grdu, so = wr.direct_wf_rec(df0.astype(np.float32), df1.astype(np.float32), tri, d, N_grid = chunk) ulist.append(uo) vlist.append(vo) ulist = [item for sublist in ulist for item in sublist] vlist = [item for sublist in vlist for item in sublist] dr0 = np.array(np.r_[-d/2,np.ones(1)]).T dr1 = np.array(np.r_[d/2,np.ones(1)]).T fig0, ax0 = plt.subplots(figsize=(8, 8)) ax0.set_aspect('equal') ax0.use_sticky_edges = False ax0.margins(0.07) for j in range(len(ulist)):
areatriangles(tri_t1)) + 2 * np.std(areatriangles(tri_t1)) mask1 = maskt | maska tri_t1.set_mask(mask1) pts_in_1 = tri_t1.get_trifinder()(x_i, y_i) != -1 tri_t1.set_mask(None) ################## start = 8500 end = 8750 ind0 = (df_0.scan >= start) & (df_0.scan <= end) ind1 = (df_1.scan >= start) & (df_1.scan <= end) U_out, V_out, grd, _ = wf.direct_wf_rec(df_0.loc[ind0], df_1.loc[ind1], tri, d, N_grid=512) x = grd[0][0, :] y = grd[1][:, 0] k_1_r = [] k_2_r = [] Su_u_r = [] Sv_v_r = [] Su_v_r = [] for scan_i in range(len(U_out)): print(scan_i) ku, kv, Su, Sv, Suv = sc.spatial_spec_sq(x,
times_scan0 = scan_init_0 + times0 times_scan1 = scan_init_1 + times1 if len(times0) <= len(times0): times = times0 else: times = times1 UV = pd.DataFrame() for i in range(len(times) - 1): print(times[i], times[i + 1]) loc0 = (chunk0.scan >= times[i]) & (chunk0.scan < times[i + 1]) loc1 = (chunk1.scan >= times[i]) & (chunk1.scan < times[i + 1]) U_out, V_out, grd, _ = wr.direct_wf_rec( chunk0.loc[loc0].astype(np.float32), chunk1.loc[loc1].astype(np.float32), tri, d, N_grid=512) init = scan_init_0 + times[i] end = scan_init_0 + times[i + 1] scan = np.arange(init, end) time = np.array([ str(date + timedelta(seconds=chunk0.loc[loc0].loc[ chunk0.loc[loc0].scan == s].stop_time.min()))[:-7] for s in chunk0.loc[loc0].scan.unique() ]) vel = np.vstack([ np.c_[grd[0][~np.isnan(u)], grd[1][~np.isnan(u)], u[~np.isnan(u)], v[~np.isnan(u)], np.asarray(~np.isnan(u)).nonzero()[0], np.asarray(~np.isnan(u)).nonzero()[1],
rel = np.c_[s_syn[:,0],t0,rel0,s_syn[:,1],t1,rel1,rel] ############################################################################### loc0 = np.array([0,6322832.3]) loc1 = np.array([0,6327082.4]) d = loc1-loc0 phi0 = df0.azim.unique() phi1 = df1.azim.unique() r0 = df0.range_gate.iloc[0].values r1 = df1.range_gate.iloc[0].values r_0, phi_0 = np.meshgrid(r0, np.pi/2-np.radians(phi0)) # meshgrid r_1, phi_1 = np.meshgrid(r0, np.pi/2-np.radians(phi1)) # meshgrid tree,tri, w0, neigh0, index0, w1, neigh1, index1 = wr.grid_over2((r_0, phi_0),(r_1,phi_1), -d) chunk = 256 _, _, grdu, so = wr.direct_wf_rec((df0.loc[df0.scan == s_syn[0,0]]).astype(np.float32), (df1.loc[df1.scan == s_syn[0,1]]).astype(np.float32), tri, d, N_grid = chunk) find = np.reshape(tri.get_trifinder()(grdu[0].flatten(), grdu[1].flatten()),grdu[0].shape) c = len(grdu[0].flatten())/np.sum(find!=-1) ################## 10min periods and averages ############################# for i in range(len(t_arrayhms)-1): hms1 = t_arrayhms[i] hms2 = t_arrayhms[i+1] L_scan = pd.read_hdf(file_name,where = 'name == name_id & hms >= hms1 & hms < hms2', key='L') if L_scan.empty: print('empty df') else: ind_rel = np.isin(pd.to_datetime(rel[:,1]),L_scan.time.values) L_scan['relscan'] = rel[ind_rel,-1] L_scan['area_frac'] = L_scan['area_frac'].values*c
if switch == 0: phi0 = df0.azim.unique() phi1 = df1.azim.unique() r0 = df0.range_gate.iloc[0].values r1 = df1.range_gate.iloc[0].values r_0, phi_0 = np.meshgrid(r0, np.pi / 2 - np.radians(phi0)) # meshgrid r_1, phi_1 = np.meshgrid(r0, np.pi / 2 - np.radians(phi1)) # meshgrid tree, tri, w0, neigh0, index0, w1, neigh1, index1 = wr.grid_over2( (r_0, phi_0), (r_1, phi_1), -d) switch = 1 print(t_scan[0]) uo, vo, grdu, so, r_i_0, phi_i_0, r_i_1, phi_i_1, mask = wr.direct_wf_rec( df0.astype(np.float32), df1.astype(np.float32), tri, d, N_grid=chunk) r_i = np.sqrt(grdu[0]**2 + grdu[1]**2) phi_i = np.arctan2(grdu[1], grdu[0]) ind = tri.get_trifinder()(grdu[0].flatten(), grdu[1].flatten()) != -1 r_i_0, phi_i_0 = wr.translationpolargrid((r_i, phi_i), -d / 2) phi_i_0 = np.pi * 0.5 - phi_i_0 phi_i_0 = np.where(phi_i_0 < 0, 2 * np.pi + phi_i_0, phi_i_0) r_i_1, phi_i_1 = wr.translationpolargrid((r_i, phi_i), d / 2) phi_i_1 = np.pi * 0.5 - phi_i_1 phi_i_1 = np.where(phi_i_1 < 0, 2 * np.pi + phi_i_1, phi_i_1) plt.figure()
df = None df_0.drop(columns = labels_CNR,inplace=True) df_1.drop(columns = labels_CNR,inplace=True) df_0.columns = labels_short df_1.columns = labels_short if switch == 0: phi0 = df_0.azim.unique() phi1 = df_1.azim.unique() r0 = np.array(df_0.iloc[(df_0.azim==min(phi0)).nonzero()[0][0]].range_gate) r1 = np.array(df_1.iloc[(df_1.azim==min(phi0)).nonzero()[0][0]].range_gate) r_0, phi_0 = np.meshgrid(r0, np.pi-np.radians(phi0)) # meshgrid r_1, phi_1 = np.meshgrid(r1, np.pi-np.radians(phi1)) # meshgrid tree,tri, w0, neigh0, index0, w1, neigh1, index1 = wr.grid_over2((r_0, phi_0),(r_1,phi_1),-d) switch = 1 U_out, V_out, grd, _ = wr.direct_wf_rec(df_0.astype(np.float32), df_1.astype(np.float32), tri, d,N_grid = 512) U_mean = np.nanmean(np.array(U_out)) V_mean = np.nanmean(np.array(V_out)) gamma = np.arctan2(V_mean,U_mean) tau_out = [] eta_out = [] r_u_out = [] r_v_out = [] r_uv_out = [] if len(U_out)>0: for U,V in zip(U_out, V_out): tau,eta,r_u,r_v,r_uv,_,_,_ = sc.spatial_autocorr_sq(grd,U,V, gamma=gamma, transform = False, transform_r = True,e_lim=.1,refine=32) tau_out.append(tau.astype(np.float32)) eta_out.append(eta.astype(np.float32))