def Ttime_plot_contourf(self, Ttimes, plotBranch=True, write2shp=False): """ function Ttime_plot_contourf is different from function Ttime_plot This function creates a collection of lines like contourf lines, so that we can import the contourf lines to ArcGIS for visualization """ #### call segment class for plotting Bthfile = '%s\\%s' % (self.workdir, 'Bth_WB1.npt') WS = W2_Segmentation(Bthfile) WS.VisSeg2() nt = [] for l in Ttimes: nt.append(len(l))
def travel_time(self, Np, Nt, InitialSeg, starttime, branchID, location_x, write2shp, density, excelfile): """ calculate travel time based on the particle tracking """ if branchID == 1: #### read segment information WB = W2_Bathymetry(self.Bthfile) pat = WB.VisBranch2(branchID) #### create empty array for travel time Ttime = np.zeros([Np, WB.X.shape[0]]) #### calculate travel time for i in range(Np): for tstep in range(Nt): location_x_tem = location_x[i, tstep] ind = self.Xsearch(location_x_tem, WB.X) if tstep == 0: Ttime[i, InitialSeg - 1:ind + 1] = tstep + 1 ind_tem = ind else: ind_nonzero = np.nonzero(Ttime[i, :])[0].max( ) ## only add travel time to zero elements if ind > max(ind_tem, ind_nonzero): Ttime[i, max(ind_tem + 1, ind_nonzero + 1):ind + 1] = tstep + 1 print(Ttime[i, :]) ind_tem = ind #### calculate the average among particles #### be careful about this average among particles #Ttime = np.mean(Ttime, axis=0, dtype=np.int) #### simply average may yield smaller travel time at the downstream end #### because some particle may not travel to the last segment, which has zero travel time there #### so only average among non-zero values. Ttime_avg = np.zeros([WB.X.shape[0]]) for i in range(WB.X.shape[0]): if i >= InitialSeg - 1: Ttime_avg[i] = np.median(Ttime[:, i][np.nonzero(Ttime[:, i])]) #pdb.set_trace() Ttime_avg = Ttime_avg[1:-1] ## calculate concentrate/water_level based on the travel time concentrate, water_level = self.Concentrate_branch1( Nt, starttime, Ttime_avg) ## calculate distance to WTP gate dist = self.dist2WTP_branch1(Ttime_avg) ## calculate particle percentage percentage = self.Percentage_branch1(Np, Nt, starttime, location_x, Ttime_avg) Ttime_avg[ Ttime_avg != 0] = Ttime_avg[-1] - Ttime_avg[Ttime_avg != 0] #### call segment class for segment information WS = W2_Segmentation(self.Bthfile) WS.VisSeg2() #### save travel time data to txt file #### #self.savetxt_Traveltime_branch1(WS, Ttime_avg, density, self.flows[self.flow_condition], txtfile) save_excel_Traveltime_branch1(WS, Ttime_avg, density, self.solubility, self.flows[self.flow_condition], \ concentrate, water_level, dist, excelfile) if write2shp: from myshapefile import writeShpLines_one_branch writeShpLines_one_branch( WS, Ttime_avg, shpname='particle_surface_traveltime_branch1') if branchID == 5: """ Under development """ #### read segment information for branch 5 WB = W2_Bathymetry(self.Bthfile) pat = WB.VisBranch2(branchID) x_branch5 = WB.X #### segment x coordinates for branch 5 #### read segment information for branch 1 WB = W2_Bathymetry(self.Bthfile) pat = WB.VisBranch2(branchID=1) x_branch1 = WB.X #### create empty array for travel time #### should not include the inactive cell at the end of branch5 when combining # x_combined = x_branch5.tolist()[0:-1] + \ # (x_branch1[self.DHS5-1:] - x_branch1[self.DHS5-1] + x_branch5[-2]).tolist() x_combined = x_branch5.tolist()[0:-1] + \ (x_branch1[self.DHS5-1:] - x_branch1[self.DHS5-1] + x_branch5[-2]).tolist()[1:] x_combined = np.asarray(x_combined) Ttime = np.zeros([Np, x_combined.shape[0]]) #### calculate travel time for i in range(Np): for tstep in range(Nt): location_x_tem = location_x[i, tstep] ind = self.Xsearch(location_x_tem, x_combined) if tstep == 0: Ttime[i, InitialSeg - 1:ind + 1] = tstep + 1 ind_tem = ind else: ind_nonzero = np.nonzero(Ttime[i, :])[0].max( ) ## only add travel time to zero elements if ind > max(ind_tem, ind_nonzero): Ttime[i, max(ind_tem + 1, ind_nonzero + 1):ind + 1] = tstep + 1 print(Ttime[i, :]) ind_tem = ind #### separate the travel time to branch 1 segments and branch 5 segments Ttime5 = Ttime[:, 0:len(x_branch5[0:-1]) + 1] Ttime1 = np.zeros([Np, len(x_branch1)]) #Ttime1[:, self.DHS5:] = Ttime[:, len(x_branch5[0:-1])+1:] Ttime1[:, self.DHS5:-1] = Ttime[:, len(x_branch5[0:-1]) + 1:] #pdb.set_trace() #### calculate the average among particles Ttime_avg1 = np.zeros([Ttime1.shape[1]]) for i in range(Ttime1.shape[1]): if i >= self.DHS5 and len(Ttime1[:, i].nonzero()[0]) != 0: Ttime_avg1[i] = np.median(Ttime1[:, i][np.nonzero(Ttime1[:, i])]) Ttime_avg5 = np.zeros([Ttime5.shape[1]]) for i in range(Ttime5.shape[1]): if i >= InitialSeg - 1: Ttime_avg5[i] = np.median(Ttime5[:, i][np.nonzero(Ttime5[:, i])]) Ttime_avg1 = Ttime_avg1[1:-1] Ttime_avg5 = Ttime_avg5[1:-1] Ttimes_avg = [Ttime_avg1, Ttime_avg5] ## calculate concentrate/water level based on the travel time concentrates, water_levels = self.Concentrate_branch5( Nt, starttime, Ttimes_avg) ## calculate distance to WTP gate dists = self.dist2WTP_branch5(Ttimes_avg) ## calculate particle percentage percentages = self.Percentage_branch5(Np, Nt, starttime, location_x, x_combined, Ttimes_avg) MaxTime = Ttimes_avg[0][-1] for Ttime in Ttimes_avg: Ttime[Ttime != 0] = MaxTime - Ttime[Ttime != 0] #### call segment class for segment information WS = W2_Segmentation(self.Bthfile) WS.VisSeg2() #### save travel time data to txt file #### #self.savetxt_Traveltime_branch5(WS, Ttimes_avg, density, self.flows[self.flow_condition], txtfile) save_excel_Traveltime_branch5(WS, Ttimes_avg, density, self.solubility, self.flows[self.flow_condition], \ concentrates, water_levels, dists, excelfile) if write2shp: from myshapefile import writeShpLines writeShpLines(WS, Ttimes_avg, shpname='particle_bottom_traveltime_branch5')
def Ttime_plot(self, Ttimes, plotBranch=True, write2shp=False): """ Visualize the travel time on W2 segments multiple lines' color changing the values corresponding to gradient color: https://stackoverflow.com/questions/55587674/how-to-make-multiple-lines-color-changing-with-values-corresponding-to-gradient Matplotlib - add colorbar to a sequence of line plots: https://stackoverflow.com/questions/8342549/matplotlib-add-colorbar-to-a-sequence-of-line-plots """ #### call segment class for plotting WS = W2_Segmentation(self.Bthfile) WS.VisSeg2() if self.initialBranch == 1: ## branch 1 MaxTime = Ttimes[0][-1] Ttime = Ttimes[0] ## conversion to zero travel time at donwstream gate (only on nonzero values) Ttime[Ttime!=0] = Ttime[-1] - Ttime[Ttime!=0] #### write to ArcGIS if write2shp: self.writeShpLines_one_branch(WS, Ttime, shpname='traveltime_branch1') #### line color zz = np.asarray(Ttime) r = (zz.astype(np.float)-zz.min())/(zz.max()-zz.min()) g = np.zeros_like(r) b = 1 - r colorlist = [] for i in range(len(zz)): colorlist.append((r[i], g[i], b[i])) #### gray color for zero travel time for i in range(len(zz)): if zz[i] == 0: colorlist[i] = 'gray' colorlist = [] for i in range(len(zz)): colorlist.append((r[i], g[i], b[i])) #### gray color for zero travel time for i in range(len(zz)): if zz[i] == 0: colorlist[i] = 'gray' #### colorbar: Setting up a colormap that's a simple transtion mymap = mpl.colors.LinearSegmentedColormap.from_list('mycolors',['blue','red']) # Using contourf to provide my colorbar info, then clearing the figure ss = 1 levels = np.arange(zz.min(),zz.max(),ss) CS3 = plt.contourf([[0,0],[0,0]], levels, cmap=mymap) plt.clf() #### matplotlib plotting plt.rcParams.update({'font.size': 14}) fig = plt.figure(figsize=(10,12)) ax = fig.add_subplot(111) if plotBranch: ax.plot(WS.Pnts1[:,0], WS.Pnts1[:,1], '.-', markersize=2, color='0.5') #### Plot segments for i in range(len(WS.westPnts1)): ax.plot([WS.westPnts1[i,0], WS.eastPnts1[i,0]], [WS.westPnts1[i,1], WS.eastPnts1[i,1]], '-', color=colorlist[i]) for i in range(len(WS.segs1)): if Ttimes[0][i] != 0: ax.annotate('%s'%str(int(Ttimes[0][i])), (WS.Pnts1[i,0], WS.Pnts1[i,1]), color=colorlist[i], fontsize=8) elif self.initialBranch == 5: ## branch 5 nt = [] for l in Ttimes: nt.append(len(l)) MaxTime = Ttimes[0][-1] for Ttime in Ttimes: Ttime[Ttime!=0] = MaxTime - Ttime[Ttime!=0] #### write to ArcGIS if write2shp: self.writeShpLines(WS, Ttimes, shpname='traveltime_branch5') #### line color zz = np.asarray(Ttimes[0].tolist() + Ttimes[1].tolist()) r = (zz.astype(np.float)-zz.min())/(zz.max()-zz.min()) g = np.zeros_like(r) b = 1 - r colorlist = [] for i in range(len(zz)): colorlist.append((r[i], g[i], b[i])) #### gray color for zero travel time for i in range(len(zz)): if zz[i] == 0: colorlist[i] = 'gray' #### colorbar: Setting up a colormap that's a simple transtion mymap = mpl.colors.LinearSegmentedColormap.from_list('mycolors',['blue','red']) # Using contourf to provide my colorbar info, then clearing the figure ss = 1 levels = np.arange(zz.min(),zz.max(),ss) CS3 = plt.contourf([[0,0],[0,0]], levels, cmap=mymap) plt.clf() #### matplotlib plotting plt.rcParams.update({'font.size': 14}) fig = plt.figure(figsize=(10,12)) ax = fig.add_subplot(111) if plotBranch: ax.plot(WS.Pnts1[:,0], WS.Pnts1[:,1], '.-', markersize=2, color='0.5') ax.plot(WS.Pnts5[:,0], WS.Pnts5[:,1], '.-', markersize=2, color='0.5') for i in range(len(WS.westPnts1)): ax.plot([WS.westPnts1[i,0], WS.eastPnts1[i,0]], [WS.westPnts1[i,1], WS.eastPnts1[i,1]], '-', color=colorlist[i]) for i in range(len(WS.westPnts5)): ax.plot([WS.westPnts5[i,0], WS.eastPnts5[i,0]], [WS.westPnts5[i,1], WS.eastPnts5[i,1]], '-', color=colorlist[i+nt[0]]) #### Plot segments for i in range(len(WS.segs1)): if Ttimes[0][i] != 0: ax.annotate('%s'%str(int(Ttimes[0][i])), (WS.Pnts1[i,0], WS.Pnts1[i,1]), color=colorlist[i], fontsize=8) for i in range(len(WS.segs5)): if Ttimes[1][::-1][i] != 0: ax.annotate('%s'%str(int(Ttimes[1][::-1][i])), (WS.Pnts5[i,0], WS.Pnts5[i,1]), color=colorlist[sum(nt[:])-i-1], fontsize=8) ax.set_xlabel('Easting [m]') ax.set_ylabel('Northing [m]') fig.colorbar(CS3) ax.set_aspect(True) fig.tight_layout() plt.show()
def travel_time_full_branch(self, starttime, initialBranch=1, initialSeg=1, flow_condition='high', write2shp=False, write2txt=True): """ call travel time function, and calculate the travel time for all branches: 1 to 5 """ self.initialBranch = initialBranch self.initialSeg = initialSeg #### read conservative tracer file for all branches, so don't need to read the file multiple times self.Readcpl() #starttime = 0 #endtime = 149 starttime = starttime endtime = starttime + 300 #### calculate the travel time for all branches Ttime1 = self.travel_time(starttime=starttime, endtime=endtime, branchID=1) #Ttime2 = self.travel_time(endtime=endtime, branchID=2) #Ttime3 = self.travel_time(endtime=endtime, branchID=3) #Ttime4 = self.travel_time(endtime=endtime, branchID=4) Ttime5 = self.travel_time(starttime=starttime, endtime=endtime, branchID=5) if self.initialBranch == 5: print ('Spill released at branch 5 \n') #Ttime1[self.DHS5-2:] += Ttime5[-1] #### because branch 1 and branch 5 are calculated separate if Ttime1[self.DHS5] < Ttime5[-2]: dt_tem = Ttime1[self.DHS5+1] - Ttime1[self.DHS5] Ttime1[self.DHS5] = Ttime5[-2] + 1 Ttime1[self.DHS5+1] = Ttime1[self.DHS5] + dt_tem elif self.initialBranch == 1: print ('Spill released at branch 1 \n') ## delete inactive segments Ttime1 = Ttime1[1:-1] #Ttime2 = Ttime2[1:-1] #Ttime3 = Ttime3[1:-1] #Ttime4 = Ttime4[1:-1] Ttime5 = Ttime5[1:-1] ## branch 2, 3, 4, 5, adding time from the main branch #Ttime2[Ttime2!=0] = Ttime2[Ttime2!=0] - Ttime2[-1] + Ttime1[self.DHS2-2] #Ttime3[Ttime3!=0] = Ttime3[Ttime3!=0] - Ttime3[-1] + Ttime1[self.DHS3-2] #Ttime4[Ttime4!=0] = Ttime4[Ttime4!=0] - Ttime4[-1] + Ttime1[self.DHS4-2] #Ttime5[Ttime5!=0] = Ttime5[Ttime5!=0] - Ttime5[-1] + Ttime1[self.DHS5-2] ## also remember to remove inactivate segments from Ttimes Ttimes = [Ttime1, Ttime5] ## save to txt file if write2txt: #### call segment class for segment information WS = W2_Segmentation(self.Bthfile) WS.VisSeg2() #### save travel time data to txt file #### if self.initialBranch == 1: ## calculate tracer concentrate based on the travel time concentrate, water_level = self.Concentrate_branch1(starttime, endtime, Ttimes[0]) ## calculate distance to WTP gate dist = self.dist2WTP_branch1(Ttimes[0]) ## conversion to zero travel time at donwstream gate (only on nonzero values) Ttime = Ttimes[0] Ttime[Ttime!=0] = Ttime[-1] - Ttime[Ttime!=0] ## save txt density = 9 ## density information not useful for non-soluble contanminants #txtfile=r'txt\tracer_branch%s_%s.txt'%(str(self.initialBranch), flow_condition) #self.savetxt_Traveltime_branch1(WS, Ttime, density, self.flows[flow_condition], concentrate, txtfile) excelfile=r'excel\tracer_branch%s_%s.xlsx'%(str(self.initialBranch), flow_condition) save_excel_Traveltime_branch1(WS, Ttime, density, self.solubility, self.flows[flow_condition], concentrate, water_level, dist, excelfile) elif self.initialBranch == 5: ## calculate tracer concentrate based on the travel time concentrates, water_levels = self.Concentrate_branch5(starttime, endtime, Ttimes) ## calculate distance to WTP gate dists = self.dist2WTP_branch5(Ttimes) ## conversion to zero travel time at donwstream gate (only on nonzero values) MaxTime = Ttimes[0][-1] for Ttime in Ttimes: Ttime[Ttime!=0] = MaxTime - Ttime[Ttime!=0] ## save txt density = 9 #txtfile=r'txt\tracer_branch%s_%s.txt'%(str(self.initialBranch), flow_condition) #self.savetxt_Traveltime_branch5(WS, Ttimes, density, self.flows[flow_condition], concentrates, txtfile) excelfile=r'excel\tracer_branch%s_%s.xlsx'%(str(self.initialBranch), flow_condition) save_excel_Traveltime_branch5(WS, Ttimes, density, self.solubility, self.flows[flow_condition], concentrates, water_levels, dists, excelfile) self.Ttime_plot(Ttimes, plotBranch=True, write2shp=write2shp)
def Ttime_plot(self, Ttimes, plotBranch=True, write2shp=False): """ Visualize the travel time on W2 segments multiple lines' color changing the values corresponding to gradient color: https://stackoverflow.com/questions/55587674/how-to-make-multiple-lines-color-changing-with-values-corresponding-to-gradient Matplotlib - add colorbar to a sequence of line plots: https://stackoverflow.com/questions/8342549/matplotlib-add-colorbar-to-a-sequence-of-line-plots """ #### calculate travel time first #self.travel_time(endtime=1460, branchID=1) #### call segment class for plotting Bthfile = '%s\\%s' % (self.workdir, 'Bth_WB1.npt') WS = W2_Segmentation(Bthfile) WS.VisSeg2() #### create shapefile to integrate with ArcGIS if write2shp: self.writeShpLines(WS, Ttimes) pdb.set_trace() nt = [] for l in Ttimes: nt.append(len(l)) #### line color zz = Ttimes[0].tolist() + Ttimes[1].tolist() + Ttimes[2].tolist( ) + Ttimes[3].tolist() + Ttimes[4].tolist() zz = np.asarray(zz) r = (zz.astype(np.float) - zz.min()) / (zz.max() - zz.min()) g = np.zeros_like(r) b = 1 - r colorlist = [] for i in range(len(zz)): colorlist.append((r[i], g[i], b[i])) # #### black color for zero travel time for i in range(len(zz)): if zz[i] == 0: colorlist[i] = 'gray' #### colorbar # Setting up a colormap that's a simple transtion mymap = mpl.colors.LinearSegmentedColormap.from_list( 'mycolors', ['blue', 'red']) # Using contourf to provide my colorbar info, then clearing the figure ss = 1 levels = np.arange(zz.min(), zz.max(), ss) CS3 = plt.contourf([[0, 0], [0, 0]], levels, cmap=mymap) plt.clf() plt.rcParams.update({'font.size': 14}) fig = plt.figure(figsize=(10, 12)) ax = fig.add_subplot(111) if plotBranch: ax.plot(WS.Pnts1[:, 0], WS.Pnts1[:, 1], '.-', markersize=2, color='0.5') ax.plot(WS.Pnts2[:, 0], WS.Pnts2[:, 1], '.-', markersize=2, color='0.5') ax.plot(WS.Pnts3[:, 0], WS.Pnts3[:, 1], '.-', markersize=2, color='0.5') ax.plot(WS.Pnts4[:, 0], WS.Pnts4[:, 1], '.-', markersize=2, color='0.5') ax.plot(WS.Pnts5[:, 0], WS.Pnts5[:, 1], '.-', markersize=2, color='0.5') #### Plot segments for i in range(len(WS.westPnts1)): ax.plot([WS.westPnts1[i, 0], WS.eastPnts1[i, 0]], [WS.westPnts1[i, 1], WS.eastPnts1[i, 1]], '-', color=colorlist[i]) for i in range(len(WS.westPnts2)): ax.plot([WS.westPnts2[i, 0], WS.eastPnts2[i, 0]], [WS.westPnts2[i, 1], WS.eastPnts2[i, 1]], '-', color=colorlist[i + sum(nt[:1])]) for i in range(len(WS.westPnts3)): ax.plot([WS.westPnts3[i, 0], WS.eastPnts3[i, 0]], [WS.westPnts3[i, 1], WS.eastPnts3[i, 1]], '-', color=colorlist[i + sum(nt[:2])]) for i in range(len(WS.westPnts4)): ax.plot([WS.westPnts4[i, 0], WS.eastPnts4[i, 0]], [WS.westPnts4[i, 1], WS.eastPnts4[i, 1]], '-', color=colorlist[i + sum(nt[:3])]) for i in range(len(WS.westPnts5)): ax.plot([WS.westPnts5[i, 0], WS.eastPnts5[i, 0]], [WS.westPnts5[i, 1], WS.eastPnts5[i, 1]], '-', color=colorlist[i + sum(nt[:4])]) #### len(WS.segs1) = 44, segments 2-45 # for i in range(len(WS.segs1)): # ax.annotate('%s:%s'%(str(WS.segs1[i]),str(int(Ttimes[0][i]))), (WS.Pnts1[i,0], WS.Pnts1[i,1]), color=(r[i],g, b[i]), fontsize=8) # #ax.annotate('Seg %s, Time=%s'%(str(WS.segs1[i]),str(int(self.Ttime[i+1]))), (WS.Pnts1[i,0], WS.Pnts1[i,1]), color=(r[i],g, b[i]), fontsize=18) ## for zoom plot only # for i in range(len(WS.segs2)): # ax.annotate('%s:%s'%(str(WS.segs2[i]),str(int(Ttimes[1][::-1][i]))), (WS.Pnts2[i,0], WS.Pnts2[i,1]), color=(r[i],g, b[i]), fontsize=8) # for i in range(len(WS.segs3)): # ax.annotate('%s:%s'%(str(WS.segs3[i]),str(int(Ttimes[2][::-1][i]))), (WS.Pnts3[i,0], WS.Pnts3[i,1]), color=(r[i],g, b[i]), fontsize=8) # for i in range(len(WS.segs4)): # ax.annotate('%s:%s'%(str(WS.segs4[i]),str(int(Ttimes[3][::-1][i]))), (WS.Pnts4[i,0], WS.Pnts4[i,1]), color=(r[i],g, b[i]), fontsize=8) # for i in range(len(WS.segs5)): # ax.annotate('%s:%s'%(str(WS.segs5[i]),str(int(Ttimes[4][::-1][i]))), (WS.Pnts5[i,0], WS.Pnts5[i,1]), color=(r[i],g, b[i]), fontsize=8) #### label segment without the segment ID for i in range(len(WS.segs1)): if Ttimes[0][i] != 0: ax.annotate('%s' % str(int(Ttimes[0][i])), (WS.Pnts1[i, 0], WS.Pnts1[i, 1]), color=colorlist[i], fontsize=8) #ax.annotate('Seg %s, Time=%s'%(str(WS.segs1[i]),str(int(self.Ttime[i+1]))), (WS.Pnts1[i,0], WS.Pnts1[i,1]), color=(r[i],g, b[i]), fontsize=18) ## for zoom plot only for i in range(len(WS.segs2)): if Ttimes[1][::-1][i] != 0: ax.annotate('%s' % str(int(Ttimes[1][::-1][i])), (WS.Pnts2[i, 0], WS.Pnts2[i, 1]), color=colorlist[sum(nt[:2]) - i - 1], fontsize=8) for i in range(len(WS.segs3)): if Ttimes[2][::-1][i] != 0: ax.annotate('%s' % str(int(Ttimes[2][::-1][i])), (WS.Pnts3[i, 0], WS.Pnts3[i, 1]), color=colorlist[sum(nt[:3]) - i - 1], fontsize=8) for i in range(len(WS.segs4)): if Ttimes[3][::-1][i] != 0: ax.annotate('%s' % str(int(Ttimes[3][::-1][i])), (WS.Pnts4[i, 0], WS.Pnts4[i, 1]), color=colorlist[sum(nt[:4]) - i - 1], fontsize=8) for i in range(len(WS.segs5)): if Ttimes[4][::-1][i] != 0: ax.annotate('%s' % str(int(Ttimes[4][::-1][i])), (WS.Pnts5[i, 0], WS.Pnts5[i, 1]), color=colorlist[sum(nt[:]) - i - 1], fontsize=8) #pdb.set_trace() ax.set_xlabel('Easting [m]') ax.set_ylabel('Northing [m]') fig.colorbar(CS3) ax.set_aspect(True) fig.tight_layout() plt.show()
def VisFinal(self, PlotGrid=True, saveshp=True): """ visualize the particle trajectories at a given time step set PlotTemp == False for now, need to figure out how to contour plot 1D array """ self.ReadFinalcsv() ## call the segmentation class to get some information filename = r'M:\Projects\0326\099-09\2-0 Wrk Prod\Dongyu_work\spill_modeling\particle_tracking_test\20191111_baseline4\Bth_WB1.npt' WB = W2_Segmentation(filename) WB.readBathymetry() x = [] y = [] for i in range(len(self.Part)): #for i in [0,1,2,3,4,5]: ## for a specific particle particleID = self.Part[i] segID = self.Seg[i] branchID = self.Branch[i] layerID = self.Layer[i] laterDist = self.LaterDist[i] print "Reading particle %s ... \n"%str(particleID) ## search the corresponding seg info segs = WB.lyrs_segID[WB.lyrs_branchID==branchID] seg_length = np.asarray(WB.seg_length)[WB.lyrs_branchID==branchID] seg_ori = np.asarray(WB.seg_ori)[WB.lyrs_branchID==branchID] lyrs = WB.lyrs[WB.lyrs_branchID==branchID] ## truncate boundary cells segs = segs[1:-1] seg_length = seg_length[1:-1] seg_ori = seg_ori[1:-1] lyrs = lyrs[1:-1] ## read corresponding seg points info segs, Pnts= WB.BranchPnt(branchID=branchID) ## goes longitudinal direction xtem = Pnts[segID-2][0] - self.Xlocation[i]*np.sin(seg_ori[segID-2]) ytem = Pnts[segID-2][1] - self.Xlocation[i]*np.cos(seg_ori[segID-2]) ## goes Lateral direction starting from left bank, the left is determined facing downstream, manual page 309 #x.append( xtem + lyrs[segID-2][layerID]/2.*np.cos(np.pi*2-seg_ori[segID-2]) ) #y.append( ytem + lyrs[segID-2][layerID]/2.*np.sin(np.pi*2-seg_ori[segID-2]) ) ## This is the left facing upstream #x.append( xtem - lyrs[segID-2][layerID]/2.*np.cos(np.pi*2-seg_ori[segID-2]) + laterDist*np.cos(np.pi*2-seg_ori[segID-2]) ) #y.append( ytem - lyrs[segID-2][layerID]/2.*np.sin(np.pi*2-seg_ori[segID-2]) + laterDist*np.sin(np.pi*2-seg_ori[segID-2]) ) ## This is the left facing downstream x.append( xtem + lyrs[segID-2][layerID-1]/2.*np.cos(np.pi*2-seg_ori[segID-2]) - laterDist*np.cos(np.pi*2-seg_ori[segID-2]) ) y.append( ytem + lyrs[segID-2][layerID-1]/2.*np.sin(np.pi*2-seg_ori[segID-2]) - laterDist*np.sin(np.pi*2-seg_ori[segID-2]) ) #pdb.set_trace() if saveshp == True: self.writeShp(x, y) plt.rcParams.update({'font.size': 18}) #fig = plt.figure(figsize=(11.5,10)) fig = plt.figure(figsize=(11.5,8)) ax = fig.add_subplot(111) ax.plot(x, y, '.', color = 'r', markersize=8) if PlotGrid==True: WB.VisSeg2() ax.plot(WB.Pnts1[:,0], WB.Pnts1[:,1], '.-k') ax.plot(WB.Pnts2[:,0], WB.Pnts2[:,1], '.-b') ax.plot(WB.Pnts3[:,0], WB.Pnts3[:,1], '.-b') ax.plot(WB.Pnts4[:,0], WB.Pnts4[:,1], '.-b') ax.plot(WB.Pnts5[:,0], WB.Pnts5[:,1], '.-b') for i in range(len(WB.westPnts1)): ax.plot([WB.westPnts1[i,0], WB.eastPnts1[i,0]], [WB.westPnts1[i,1], WB.eastPnts1[i,1]], '-k') for i in range(len(WB.westPnts2)): ax.plot([WB.westPnts2[i,0], WB.eastPnts2[i,0]], [WB.westPnts2[i,1], WB.eastPnts2[i,1]], '-k') for i in range(len(WB.westPnts3)): ax.plot([WB.westPnts3[i,0], WB.eastPnts3[i,0]], [WB.westPnts3[i,1], WB.eastPnts3[i,1]], '-k') for i in range(len(WB.westPnts4)): ax.plot([WB.westPnts4[i,0], WB.eastPnts4[i,0]], [WB.westPnts4[i,1], WB.eastPnts4[i,1]], '-k') for i in range(len(WB.westPnts5)): ax.plot([WB.westPnts5[i,0], WB.eastPnts5[i,0]], [WB.westPnts5[i,1], WB.eastPnts5[i,1]], '-k') for i in range(len(WB.segs1)): ax.annotate('%s'%str(WB.segs1[i]), (WB.Pnts1[i,0], WB.Pnts1[i,1]), color='b', fontsize=8) for i in range(len(WB.segs2)): ax.annotate('%s'%str(WB.segs2[i]), (WB.Pnts2[i,0], WB.Pnts2[i,1]), color='b', fontsize=8) for i in range(len(WB.segs3)): ax.annotate('%s'%str(WB.segs3[i]), (WB.Pnts3[i,0], WB.Pnts3[i,1]), color='b', fontsize=8) for i in range(len(WB.segs4)): ax.annotate('%s'%str(WB.segs4[i]), (WB.Pnts4[i,0], WB.Pnts4[i,1]), color='b', fontsize=8) for i in range(len(WB.segs5)): ax.annotate('%s'%str(WB.segs5[i]), (WB.Pnts5[i,0], WB.Pnts5[i,1]), color='b', fontsize=8) #ax.set_xlim([-20000,10000]) ax.set_xlabel('Easting [m]') ax.set_ylabel('Northing [m]') ax.set_aspect(True) plt.show()