def pr_sowfa(dir, trs_para, varD): """ extract horizontal average of velocity at various times and heights """ # coordinate transmation O = trs_para[0] alpha = trs_para[1] fr = open(dir + '/data/' + 'aveData', 'rb') aveData = pickle.load(fr) fr.close() zSeq = aveData['H'] zNum = zSeq.size tSeq = aveData['time'] tNum = tSeq.size tDelta = tSeq[1] - tSeq[0] uSeq = aveData['U_mean'] vSeq = aveData['V_mean'] wSeq = aveData['W_mean'] varSeq = np.zeros((tNum, zNum)) for zInd in range(zNum): tmp = np.concatenate( (uSeq[:, zInd].reshape(tNum, 1), vSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp = np.concatenate((tmp, wSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp_ = funcs.trs(tmp, O, alpha) varSeq[:, zInd] = tmp_[:, varD] return tSeq, zSeq, varSeq
def getData_sowfa(dir, prbg, trs_para, var, varD): """ extract velocity data of specified probe groups """ # coordinate transmation O = trs_para[0] alpha = trs_para[1] # read data readDir = dir + '/data/' readName = prbg fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() coors = data_org['coors'] # coordinate transformation prbNum = coors.shape[0] for p in range(prbNum): tmp = data_org[var][p] data_org[var][p] = funcs.trs(tmp, O, alpha) xSeq = np.array(data_org['info'][2]) ySeq = np.array(data_org['info'][3]) zSeq = np.array(data_org['info'][4]) xNum = xSeq.size yNum = ySeq.size zNum = zSeq.size varSeq = data_org[var][:, :, varD] tSeq = data_org['time'] tNum = tSeq.size return tSeq, xSeq, ySeq, zSeq, varSeq, coors
def getSliceData_Ny_sowfa(dir, jobName, slice, var, varD, trs_para, tInd, xInd, zInd): """ extract velocity data of specified slice_Nz """ readDir = dir + '/data/' readName = slice fr = open(readDir + readName, 'rb') data = pickle.load(fr) fr.close() slc = sdc.Slice(data, 1) del data # 2 means z-axis tSeq = slc.data['time'] tSeq = tSeq[tInd[0]:tInd[1]] Y = slc.N_location # height of this plane O, alpha = trs_para[0], trs_para[1] varSeq = [] for t_ind in range(tInd[0], tInd[1]): print('processing: ' + str(t_ind) + ' ...') tmp = slc.data[var][t_ind] tmp = funcs.trs(tmp, O, alpha) tmp1 = slc.meshITP_Ny(xInd, zInd, tmp[:, varD], 0, method_='linear') xSeq, zSeq, varSeq_ = tmp1[0], tmp1[1], tmp1[2] varSeq.append(varSeq_) varSeq = np.array(varSeq) return tSeq, xSeq, zSeq, Y, varSeq
def uwflux_sowfa(ppDir, trs_para, varD): O = trs_para[0] alpha = trs_para[1] # ave_itv = t_para[0] # tplot = t_para[1] fr = open(ppDir + '/data/' + 'aveData', 'rb') aveData = pickle.load(fr) fr.close() zSeq = aveData['H'] zNum = zSeq.size tSeq = aveData['time'] tNum = tSeq.size tDelta = tSeq[1] - tSeq[0] uwSeq = aveData['uw_mean'] vwSeq = aveData['vw_mean'] wwSeq = aveData['ww_mean'] R13Seq = aveData['R13_mean'] R23Seq = aveData['R23_mean'] R33Seq = aveData['R33_mean'] rsvSeq = np.zeros((tNum, zNum)) sgsSeq = np.zeros((tNum, zNum)) for zInd in range(zNum): tmp = np.concatenate( (uwSeq[:, zInd].reshape(tNum, 1), vwSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp = np.concatenate((tmp, wwSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp_ = funcs.trs(tmp, O, alpha) rsvSeq[:, zInd] = tmp_[:, varD] tmp = np.concatenate( (R13Seq[:, zInd].reshape(tNum, 1), R23Seq[:, zInd].reshape( tNum, 1)), axis=1) tmp = np.concatenate((tmp, R33Seq[:, zInd].reshape(tNum, 1)), axis=1) tmp_ = funcs.trs(tmp, O, alpha) sgsSeq[:, zInd] = tmp_[:, varD] totSeq = rsvSeq + sgsSeq return tSeq, zSeq, rsvSeq, sgsSeq, totSeq
def PSD_data_sowfa(jobDir, prbg, trs_para, var, varD): """ Extract velocity data of specified probe groups INPUT jobDir: job directory, e.g. '/scratch/sowfadata/pp/tutorials/example_nbl' prbg: name of the probe group, e.g. 'prbg0' trs_para: coordinate transform parameters, e.g. ((0,0,0),30.0), the origin and the conterclockwise rotation degree var: name of the target variable, e.g. 'U' varD: the dimension of which the target vector variable will be outputted OUTPUT tSeq: 1D array of times xSeq: 1D array of x positions ySeq: 1D array of y positions zSeq: 1D array of heights varSeq: 2D array of the target variable, 1st dim point ID, 2nd dim time coors: 2D array of coordinates of the probes, 1st dim point ID, 2nd dim x, y, z """ # coordinate transmation O = trs_para[0] alpha = trs_para[1] # read data readDir = jobDir + '/data/' readName = prbg fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() coors = data_org['coors'] # coordinate transformation prbNum = coors.shape[0] for p in range(prbNum): tmp = data_org[var][p] data_org[var][p] = funcs.trs(tmp, O, alpha) xSeq = np.array(data_org['info'][2]) ySeq = np.array(data_org['info'][3]) zSeq = np.array(data_org['info'][4]) xNum = xSeq.size yNum = ySeq.size zNum = zSeq.size varSeq = data_org[var][:, :, varD] tSeq = data_org['time'] tNum = tSeq.size return tSeq, xSeq, ySeq, zSeq, varSeq, coors
def getSliceData_Nz_sowfa(jobDir, slice, var, varD, trs_para, tInd, xcoor, ycoor): """ Extract data from specified slice_Nz INPUT jobDir: job directory, e.g. '/scratch/sowfadata/pp/tutorials/example_nbl' slice: the name of the slice, e.g. 'Nz2' var: name of the target variable, e.g. 'U' varD: the dimension of which the target vector variable will be outputted trs_para: coordinate transform parameters, e.g. ((0,0,0),30.0), the origin and the conterclockwise rotation degree tInd: a tuple containing the start time index and end time index of the output data (not including the end tInd) xcoor: a tuple containing the start x, end x and x.size of the output data ycoor: a tuple containing the start y, end y and y.size of the output data OUTPUT tSeq: 1D array of times ySeq: 1D array of y positions xSeq: 1D array of x positions H: the height of the slice varSeq: 3D array of the target variable, 1st dim time, 2nd dim y, 3rd x """ readDir = jobDir + '/data/' readName = slice fr = open(readDir + readName, 'rb') data = pickle.load(fr) fr.close() slc = sdc.Slice(data, 2) del data # 2 means z-axis tSeq = slc.data['time'] tSeq = tSeq[tInd[0]:tInd[1]] H = slc.N_location # height of this plane O, alpha = trs_para[0], trs_para[1] varSeq = [] for t_ind in range(tInd[0], tInd[1]): print('processing: ' + str(t_ind) + ' ...') tmp = slc.data[var][t_ind] tmp = funcs.trs(tmp, O, alpha) tmp1 = slc.meshITP_Nz(xcoor, ycoor, tmp[:, varD], method_='linear') xSeq, ySeq, varSeq_ = tmp1[0], tmp1[1], tmp1[2] varSeq.append(varSeq_) varSeq = np.array(varSeq) return tSeq, xSeq, ySeq, H, varSeq
def velo_pr_sowfa(jobDir, trs_para, varD): """ Extract horizontal average of velocity at various times and heights based on aveData from SOWFA INPUT jobDir: job directory, e.g. '/scratch/sowfadata/pp/tutorials/example_nbl' trs_para: coordinate transform parameters, e.g. ((0,0,0),30.0), the origin and the conterclockwise rotation degree varD: the dimension of which the target vector variable will be outputted OUTPUT: tSeq: 1D array of times zSeq: 1D array of heights varSeq: 2D array of time and horizontal average variables, 1st dim time, 2nd dim height """ # coordinate transmation O = trs_para[0] alpha = trs_para[1] fr = open(jobDir + '/data/' + 'aveData', 'rb') aveData = pickle.load(fr) fr.close() zSeq = aveData['H'] zNum = zSeq.size tSeq = aveData['time'] tNum = tSeq.size tDelta = tSeq[1] - tSeq[0] uSeq = aveData['U_mean'] vSeq = aveData['V_mean'] wSeq = aveData['W_mean'] varSeq = np.zeros((tNum, zNum)) for zInd in range(zNum): tmp = np.concatenate( (uSeq[:, zInd].reshape(tNum, 1), vSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp = np.concatenate((tmp, wSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp_ = funcs.trs(tmp, O, alpha) varSeq[:, zInd] = tmp_[:, varD] return tSeq, zSeq, varSeq
plotDataList = [] HList = [] for slice in sliceList: readDir = ppDir + '/data/' readName = slice fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() slc = sdc.Slice(data_org, 2) H = slc.N_location # height of this plane HList.append(H) tmp = slc.data[var][tInd][:] tmp = funcs.trs(tmp, O, alpha) slcData = slc.meshITP_Nz((0, 2000, 100), (0, 2000, 100), tmp[:, varD], method_='linear') ySeq = slcData[1] yNum = slcData[1].size xNum = slcData[0].size PSD_list = [] for xInd in range(xNum): # detrend by deg_ order plynomial fit deg_ = 1 polyFunc = np.poly1d(np.polyfit(ySeq, slcData[2][xInd], deg=deg_)) tmp = slcData[2][xInd] - polyFunc(ySeq) tmp = tmp - tmp.mean()
plotDataList = [] HList = [] for slice in sliceList: readDir = ppDir + '/data/' readName = slice fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() slc = sdc.Slice(data_org, 2) H = slc.N_location # height of this plane HList.append(H) var_av = slc.get_ave(var) var_av = funcs.trs(var_av, O, alpha) xcoor, ycoor, u_seq = slc.meshITP_Nz((0, 2000, 100), (0, 2000, 100), var_av[:, varD], method_='linear') plotData = (xcoor, ycoor, u_seq) plotDataList.append(plotData) ### group plot rNum, cNum = (4, 2) fig, axs = plt.subplots(rNum, cNum, constrained_layout=True) fig.set_figwidth(8) fig.set_figheight(12)
uwSeq = aveData['uw_mean'] vwSeq = aveData['vw_mean'] wwSeq = aveData['ww_mean'] R13Seq = aveData['R13_mean'] R23Seq = aveData['R23_mean'] R33Seq = aveData['R33_mean'] rsvSeq = np.zeros((tNum, zNum)) sgsSeq = np.zeros((tNum, zNum)) for zInd in range(zNum): tmp = np.concatenate( (uwSeq[:, zInd].reshape(tNum, 1), vwSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp = np.concatenate((tmp, wwSeq[:, zInd].reshape(tNum, 1)), axis=1) tmp_ = funcs.trs(tmp, O, alpha) rsvSeq[:, zInd] = tmp_[:, varD] tmp = np.concatenate( (R13Seq[:, zInd].reshape(tNum, 1), R23Seq[:, zInd].reshape(tNum, 1)), axis=1) tmp = np.concatenate((tmp, R33Seq[:, zInd].reshape(tNum, 1)), axis=1) tmp_ = funcs.trs(tmp, O, alpha) sgsSeq[:, zInd] = tmp_[:, varD] ### plot ave_itv = 3600.0 # by default, the averaging interval is 3600s tplot = 72000.0 rsvplot = np.zeros(zNum) sgsplot = np.zeros(zNum)
fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() slc = sdc.Slice(data_org, 2) H = slc.N_location # height of this plane HList.append(H) pNum = slc.data['pNo'].size autocorr_list = [] for pInd in range(pNum): print(pInd) # coordinate transformation U_ = slc.data[var][:, pInd] U_ = funcs.trs(U_, O, alpha) # interpolate vSeq = U_[:, varD] f = interp1d(tSeq, vSeq, fill_value='extrapolate') v_seq = f(t_seq) # detrend v_seq = funcs.detrend(t_seq, v_seq) tau_seq, tmp = funcs.corr(t_seq, v_seq, v_seq) autocorr_list.append(tmp) autocorr_seq = np.average(np.array(autocorr_list), axis=0) plotDataList.append((tau_seq, autocorr_seq)) zNum = len(HList) # plot fig, ax = plt.subplots(figsize=(6, 6))
xNum = int((xMax - xMin) / dx + 1) x = np.linspace(xMin, xMax, xNum) f = open("/scratch/ppcode/sowfa/tmp/probesNx", "w") for zInd in range(zNum): z = zList[zInd] coors = np.zeros((xNum, 3)) for i in range(xNum): coors[i][0], coors[i][1], coors[i][2] = x[i], y, z # probes's coordinate transmation O = ((xMin + xMax) / 2, y, z) coors_ = funcs.trs(coors, O, alpha) for r in range(xNum): coors_[r] += O f.write('\n') f.write(' ' + 'probeNx' + str(zInd) + '\n') f.write(' {' + '\n') f.write(' type probes;' + '\n') f.write(' functionObjectLibs ("libsampling.so");' + '\n') f.write(' outputControl runTime;' + '\n') f.write(' writeInterval 0.1;' + '\n') f.write(' timeStart 0.0;' + '\n') f.write(' fields' + '\n') f.write(' (' + '\n') f.write(' U' + '\n') f.write(' );' + '\n')
""" wind direction profile of stationary flow (sowfa vs palm) """ fig, ax = plt.subplots(figsi""" animation for deepwind_gs10 (SOWFA) """ prjDir = '/scratch/sowfadata/JOBS' prjName = 'deepwind' jobName = 'gs10' ppDir = '/scratch/sowfadata/pp/' + prjName + '/' + jobName tSeq, xSeq, ySeq, H, varSeq = getSliceData_Nz_sowfa(ppDir, jobName, 'Nz0', 'U', 0, ((0,0,0),30), (0,150), (0,2560,256), (0,2560,256)) t0 = tSeq[0] vMin, vMax, vDelta = (-2, 2, 0.4) cbreso = 100 # resolution of colorbar levels = np.linspace(vMin, vMax, cbreso + 1) # transform coors of prbg prbg0 = np.vstack((780 + 20*np.arange(0,51), np.array([1280 for i in range(51)]), np.array([0 for i in range(51)]))) prbg0 = funcs.trs(prbg0.T, (1280,1280,0), -30); prbg0[:,0] += 1280; prbg0[:,1] += 1280; prbg1 = np.vstack((np.array([1280 for i in range(51)]), 780 + 20*np.arange(0,51), np.array([0 for i in range(51)]))) prbg1 = funcs.trs(prbg1.T, (1280,1280,0), -30); prbg1[:,0] += 1280; prbg1[:,1] += 1280; for tInd in range(0,150,100): fig, axs = plt.subplots(figsize=(8,8), constrained_layout=False) x_ = xSeq y_ = ySeq v_ = varSeq[tInd] v_ -= v_.mean() v_[np.where(v_ < vMin)] = vMin v_[np.where(v_ > vMax)] = vMax CS = axs.contourf(x_, y_, v_, cbreso, levels=levels, cmap='jet', vmin=vMin, vmax=vMax) plt.scatter(prbg0[:,0], prbg0[:,1], 1, marker='o', color='k') plt.scatter(prbg1[:,0], prbg1[:,1], 1, marker='o', color='k')
readName = slice fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() slc = sdc.Slice(data_org, 2) H = slc.N_location # height of this plane tIndList = list(range(0, 600, 10)) tNum = len(tIndList) for tInd in tIndList: print(tInd) tmp = slc.data[var][tInd] tmp = funcs.trs(tmp, O, alpha) # coordinate transformation plotData = slc.meshITP_Nz((0, 2000, 100), (0, 2000, 100), slc.data[var][tInd][:, varD], method_='linear') plotDataList.append(plotData) vMin, vMax, vDelta = (-1.8, 1.8, 0.4) cbreso = 100 # resolution of colorbar levels = np.linspace(vMin, vMax, cbreso + 1) for tIndInd in range(tNum): fig, axs = plt.subplots(figsize=(8, 8), constrained_layout=True) x_ = plotDataList[tIndInd][0] y_ = plotDataList[tIndInd][1] v_ = plotDataList[tIndInd][2]
ppDir = '/scratch/sowfadata/pp/' + prjName + '/' + jobName tSeq, xSeq, ySeq, H, varSeq = getSliceData_Nz_sowfa(ppDir, jobName, 'Nz2', 'U', 0, ((0, 0, 0), 30), (0, 30), (680, 1880, 240), (680, 1880, 240)) t0 = tSeq[0] vMin, vMax, vDelta = (-2, 2, 0.4) cbreso = 100 # resolution of colorbar levels = np.linspace(vMin, vMax, cbreso + 1) # transform coors of prbg prbg0 = np.vstack( (780 + 20 * np.arange(0, 51), np.array([1280 for i in range(51)]), np.array([0 for i in range(51)]))) prbg0 = funcs.trs(prbg0.T, (1280, 1280, 0), -30) prbg0[:, 0] += 1280 prbg0[:, 1] += 1280 prbg1 = np.vstack( (np.array([1280 for i in range(51)]), 780 + 20 * np.arange(0, 51), np.array([0 for i in range(51)]))) prbg1 = funcs.trs(prbg1.T, (1280, 1280, 0), -30) prbg1[:, 0] += 1280 prbg1[:, 1] += 1280 for tInd in range(0, 30, 1): fig, axs = plt.subplots(figsize=(4.5, 3.8), constrained_layout=False) x_ = xSeq y_ = ySeq v_ = varSeq[tInd] v_ -= v_.mean()
varName = 'Su' varUnit = r'$\mathrm{m^2/s}$' varName_save = 'Su' # read data readDir = ppDir + '/data/' readName = prbg fr = open(readDir + readName, 'rb') data_org = pickle.load(fr) fr.close() # coordinate transformation prbNum = data_org['coors'].shape[0] for p in range(prbNum): tmp = data_org[var][p] data_org[var][p] = funcs.trs(tmp, O, alpha) # choose the probegroup to be used in plotting xSeq = np.array(data_org['info'][2]) ySeq = np.array(data_org['info'][3]) zSeq = np.array(data_org['info'][4]) xNum = xSeq.size yNum = ySeq.size zNum = zSeq.size t_start = 432000.0 t_end = 434400.0 t_delta = 0.1 fs = 1 / t_delta # sampling frequency t_num = int((t_end - t_start) / t_delta + 1) t_seq = np.linspace(t_start, t_end, t_num)
K = 1 else: K = len(zList) ''' save (I,J,K) into a binary file with pickle ''' f = open(jobDir + '/data/' + prbgName + '_info', 'wb') pickle.dump([O, alpha, xList, yList, zList], f) f.close() coorList = [] for k in range(K): for j in range(J): for i in range(I): coorList.append((xList[i], yList[j], zList[k])) coors = np.array(coorList) coors = funcs.trs(coors, O, alpha) for p in range(I * J * K): coors[p] += O f = open(jobDir + '/data/' + prbgName + '_dict', "w") f.write('\n') f.write(' ' + prbgName + '\n') f.write(' {' + '\n') f.write(' type probes;' + '\n') f.write(' functionObjectLibs ("libsampling.so");' + '\n') f.write(' interpolationScheme cellPointFace;' + '\n') f.write(' outputControl runTime;' + '\n') f.write(' writeInterval 0.5;' + '\n') f.write(' timeStart 0.0;' + '\n') f.write(' fields' + '\n') f.write(' (' + '\n')