IN_VAR = InFile[Vname][T1:T2 + 1, ...] VarNt = len(IN_VAR) if (Vname == "/pcprr"): IN_VAR = IN_VAR * 24 # convert mm/h to mm/day VARS[isim, 0:VarNt] = IN_VAR InFile.close() print("") # Make the plot Fig = plt.figure() Ax = Fig.add_axes([0.1, 0.1, 0.7, 0.8]) Xaxis = plu.AxisConfig('x', Xlims, Xlabel) Xaxis.fontsize = 12 Yaxis = plu.AxisConfig('y', Ylims, Ylabel) Yaxis.fontsize = 12 Ptitle = plu.TitleConfig('', Pname) Ptitle.fontsize = 24 Legend = plu.LegendConfig(SimLegText, 'upper left') Legend.bbox = [1.02, 1.0] Legend.fontsize = 9 Legend.ncol = 1 plu.PlotLine(Ax, T, VARS.transpose(), Ptitle, Xaxis, Yaxis, Legend, SimColors)
def CreateFig(self): # get labels for sims and factors LabelScheme = conf.SetLabelScheme() # Collect input data in a 3D array: (x,z,sim) SimTitles = [] for i in range(self.Nsims): Sim = self.SimList[i] InFname = self.InFname.replace("<SIM>", Sim) InVname = self.InVname print("Reading {0:s} ({1:s})".format(InFname, InVname)) InFile = h5py.File(InFname, mode='r') # grab the coordinate values, and initialize the input array if (i == 0): print("Reading {0:s} ({1:s})".format(InFname, self.XcoordName)) X = InFile[self.XcoordName][:] * self.XcoordScale + self.XcoordOffset print("Reading {0:s} ({1:s})".format(InFname, self.YcoordName)) Y = InFile[self.YcoordName][:] * self.YcoordScale + self.YcoordOffset Nx = len(X) Ny = len(Y) InVar = np.zeros( [ Ny, Nx, self.Nsims ], dtype=np.float_) InVar[ :, :, i ] = InFile[InVname][:,:] * self.InScale + self.InOffset InFile.close() SimTitles.append(r'${0:s}\ ({1:s})$'.format(self.Title, LabelScheme[Sim])) # Build the factors from the input cross sections # The third dimension in InVar is the sim which # is mapped as: # # index sim # 0 NSND # 1 SND # 2 NSD # 3 SD # # Factors are in this order: # # index factor formula # 0 FAC_SAL SND - NSND # 1 FAC_DUST NSD - NSND # 2 FAC_INT SD - (SND + NSD) + NSND FacTitles = [ ] FacVar = np.zeros( [ Ny, Nx, self.Nfacs ], dtype=np.float_) for i in range(self.Nfacs): Factor = self.FacList[i] if (Factor == 'FAC_SAL'): # SND - NSND FacVar[:,:,i] = InVar[:,:,1] - InVar[:,:,0] elif (Factor == 'FAC_DUST'): # NSD - NSND FacVar[:,:,i] = InVar[:,:,2] - InVar[:,:,0] elif (Factor == 'FAC_INT'): # SD - (SND + NSD) + NSND FacVar[:,:,i] = InVar[:,:,3] - (InVar[:,:,1] + InVar[:,:,2]) + InVar[:,:,0] else: print("ERROR: PlotXsection: Attempted to calculate too many factors") print("ERROR: PlotXsection: Stopping!") sys.exit(1) FacTitles.append(r'${0:s}\ ({1:s})$'.format(self.Title, LabelScheme[Factor])) # 7 panel plot # Sims on the left side, 4 panels # Factors on right side, 3 panels self.Fig = plt.figure() # Place axes for all panels AxW = 0.40 AxH = 0.16 AxLeftLlx = 0.07 AxRightLlx = 0.53 AxLly = [ 0.10, 0.32, 0.54, 0.76 ] self.SimAx.append(self.Fig.add_axes([ AxLeftLlx, AxLly[3], AxW, AxH ])) self.SimAx.append(self.Fig.add_axes([ AxLeftLlx, AxLly[2], AxW, AxH ])) self.SimAx.append(self.Fig.add_axes([ AxLeftLlx, AxLly[1], AxW, AxH ])) self.SimAx.append(self.Fig.add_axes([ AxLeftLlx, AxLly[0], AxW, AxH ])) self.FacAx.append(self.Fig.add_axes([ AxRightLlx, AxLly[2], AxW, AxH ])) self.FacAx.append(self.Fig.add_axes([ AxRightLlx, AxLly[1], AxW, AxH ])) self.FacAx.append(self.Fig.add_axes([ AxRightLlx, AxLly[0], AxW, AxH ])) # for placing text in upper right (blank) space # create axes, turn off the axes, then place the text in that axes TxtAx = self.Fig.add_axes([ AxRightLlx, AxLly[3], AxW, AxH ]) TxtAx.set_axis_off() # create axes and contour specs objects Xaxis = plu.AxisConfig('x', [ self.Xmin, self.Xmax ], self.Xlabel) Xaxis.fontsize = self.AxFsize if self.Xticks: Xaxis.ticks = self.Xticks if self.XtickLabels: Xaxis.ticklabels = self.XtickLabels Yaxis = plu.AxisConfig('y', [ self.Ymin, self.Ymax ], self.Ylabel) Yaxis.fontsize = self.AxFsize if self.Yticks: Yaxis.ticks = self.Yticks if self.YtickLabels: Yaxis.ticklabels = self.YtickLabels SimCspecs = plu.ContourConfig(self.SimCmin, self.SimCmax, self.SimCnum, self.SimCmap, self.Cfilled, self.SimCtype) FacCspecs = plu.ContourConfig(self.FacCmin, self.FacCmax, self.FacCnum, self.FacCmap, self.Cfilled, self.FacCtype) # Sim cross sections for i in range(self.Nsims): Ptitle = plu.TitleConfig(self.SimPmarkers[i], SimTitles[i]) Ptitle.fontsize = self.TitleFsize Xaxis.show = self.SimXshow[i] Yaxis.show = self.SimYshow[i] plu.PlotContour(self.SimAx[i], X, Y, InVar[:,:,i], Ptitle, Xaxis, Yaxis, SimCspecs) # factor cross sections for i in range(self.Nfacs): Ptitle = plu.TitleConfig(self.FacPmarkers[i], FacTitles[i]) Ptitle.fontsize = self.TitleFsize Xaxis.show = self.FacXshow[i] Yaxis.show = self.FacYshow[i] plu.PlotContour(self.FacAx[i], X, Y, FacVar[:,:,i], Ptitle, Xaxis, Yaxis, FacCspecs) # Place a tag (text) in the empty panel if requested. # transAxes says to use the Axes coordinates which always run from 0 to 1 if (self.Tag): TxtAx.text(1, 1, self.Tag, transform=TxtAx.transAxes, fontsize=20, horizontalalignment='right', verticalalignment='bottom') # If doing a track (PTRACK or STRACK), place labels on x-axis if (hasattr(self, "tracktype")): if (self.tracktype == 'ptrack'): self.SimAx[3].text(0, -0.1, 'C', transform=self.SimAx[3].transAxes, fontsize=14, color='blue', horizontalalignment='left', verticalalignment='top') self.SimAx[3].text(1, -0.1, 'D', transform=self.SimAx[3].transAxes, fontsize=14, color='blue', horizontalalignment='right', verticalalignment='top') self.FacAx[2].text(0, -0.1, 'C', transform=self.FacAx[2].transAxes, fontsize=14, color='blue', horizontalalignment='left', verticalalignment='top') self.FacAx[2].text(1, -0.1, 'D', transform=self.FacAx[2].transAxes, fontsize=14, color='blue', horizontalalignment='right', verticalalignment='top') elif (self.tracktype == 'strack'): self.SimAx[3].text(0, -0.1, 'A', transform=self.SimAx[3].transAxes, fontsize=14, color='red', horizontalalignment='left', verticalalignment='top') self.SimAx[3].text(1, -0.1, 'B', transform=self.SimAx[3].transAxes, fontsize=14, color='red', horizontalalignment='right', verticalalignment='top') self.FacAx[2].text(0, -0.1, 'A', transform=self.FacAx[2].transAxes, fontsize=14, color='red', horizontalalignment='left', verticalalignment='top') self.FacAx[2].text(1, -0.1, 'B', transform=self.FacAx[2].transAxes, fontsize=14, color='red', horizontalalignment='right', verticalalignment='top') # If doing a plan view with storm location, mark the storm location with # a large white 'X'. if (hasattr(self, "StormX") and hasattr(self, "StormY")): for i in range(4): self.SimAx[i].plot(self.StormX, self.StormY, 'wo') for i in range(3): self.FacAx[i].plot(self.StormX, self.StormY, 'co') print("Writing: {0:s}".format(self.OutFname)) self.Fig.savefig(self.OutFname) plt.close() print("")
FacColors.append(Color) # Create 2 panel plot # top half: Tgrad # bottom half: Tgrad factors Pdir = 'Plots.py' Ylim = [-0.8, 2.5] YmarkerPos = Ylim[0] - 0.5 Fig = plt.figure() AxSims = Fig.add_axes([0.1, 0.6, 0.7, 0.3]) AxFactors = Fig.add_axes([0.1, 0.1, 0.7, 0.3]) # Vt max time series, top half Xaxis = plu.AxisConfig('x', [0, 1800], 'Linear Distance (km)') Xaxis.ticks = [500, 1000, 1500] Xaxis.fontsize = 12 Yaxis = plu.AxisConfig('y', Ylim, r'${\nabla}\overline{T}\ (10^{-6}\ K\ m^{-1})$') Yaxis.fontsize = 12 Ptitle = plu.TitleConfig('a', r'$PSAP:\ {\nabla}\overline{T}:\ Sims$') Ptitle.fontsize = 24 Legend = plu.LegendConfig(SimLegText, 'upper left') Legend.bbox = [1.02, 1.0] Legend.fontsize = 12 Legend.ncol = 1
print(" Writing {0:d} frames into: {1:s}".format(OutNt, OutDir)) Count = 0 for it in range(0, Nt, FrameInc): Count = Count + 1 SimTime = T[it] / 86400.0 # convert to days # read in the variable, it will keep track of the frame increment VAR = InFile[InVname][it, ...] OutFname = "{0:s}/{1:s}_{2:s}_{3:04d}.png".format( OutDir, OutVname, Sim, Count) print(" {0:s}".format(OutFname)) Fig = plt.figure() Xaxis = plu.AxisConfig('x', [X[0], X[-1]], "Longitude") Xaxis.fontsize = 14 Yaxis = plu.AxisConfig('y', [Y[0], Y[-1]], "Latitude") Yaxis.fontsize = 14 Cspecs = plu.ContourConfig(Cmin, Cmax, Cnum, Cmap, Cfilled, Ctype) TitleString = "{0:s}: {1:s}, SimTime: {2:7.2f} (d)".format( Sim, OutVname, SimTime) Ptitle = plu.TitleConfig("", TitleString) Ptitle.fontsize = 20 plu.PlotContour(Fig.gca(), X, Y, VAR, Ptitle, Xaxis, Yaxis, Cspecs) # For the channel RCE sims Fig.gca().set_aspect(4.0)
# top half: Vt max time series # lower left quarter: PSAP bar graph # lower right quarter: SAP bar graph Pdir = 'Plots.py' Nbars = SalWindH1.size Xbars = np.arange(1, Nbars + 1) # x values for bar graphs: 1 through Nbars Fig = plt.figure() AxVt = Fig.add_axes([0.10, 0.60, 0.70, 0.30]) AxPsap = Fig.add_axes([0.10, 0.10, 0.35, 0.30]) AxSap = Fig.add_axes([0.60, 0.10, 0.35, 0.30]) # Vt max time series, top half Xaxis = plu.AxisConfig('x', [0, 62], '') Xaxis.ticks = [6, 18, 30, 42, 54] Xaxis.ticklabels = [ "12Z\n22Aug", "0Z\n23Aug", "12Z\n23Aug", "0Z\n24Aug", "12Z\n23Aug" ] Xaxis.fontsize = 14 Yaxis = plu.AxisConfig('y', [5, 23], r'$Speed (ms^{-1})$') Yaxis.fontsize = 14 Ptitle = plu.TitleConfig('a', r'$V_t (max)$') Ptitle.fontsize = 24 Legend = plu.LegendConfig(LegText, 'upper left') Legend.bbox = [1.02, 1.0] Legend.fontsize = 12
def CreateFig(self): # get labels and colors for sims and factors LabelScheme = conf.SetLabelScheme() ColorScheme = conf.SetColorScheme() # Collect input data in an array: (y,sim) # Create factors on the y values, assume all sims have identical x values # and all sims have identical length y values SimLabels = [] SimColors = [] for i in range(self.Nsims): Sim = self.SimList[i] SimLabels.append(LabelScheme[Sim]) SimColors.append(ColorScheme[Sim]) InFname = self.InFname.replace("<SIM>", Sim) Xname = self.Xname Yname = self.Yname print("Reading {0:s} ({1:s})".format(InFname, Xname)) print("Reading {0:s} ({1:s})".format(InFname, Yname)) InFile = h5py.File(InFname, mode='r') X = InFile[Xname][...] * self.Xscale + self.Xoffset Y = InFile[Yname][...] * self.Yscale + self.Yoffset if (i == 0): Nx = len(X) Ny = len(Y) Yvals = np.zeros([ Ny, self.Nsims ], dtype=np.float_) Yvals[:,i] = Y InFile.close() print("") # Build the factors from the input cross sections # The second dimension in Yvals is the sim which # is mapped as: # # index sim # 0 NSND # 1 SND # 2 NSD # 3 SD # # Factors are in this order: # # index factor formula # 0 FAC_SAL SND - NSND # 1 FAC_DUST NSD - NSND # 2 FAC_INT SD - (SND + NSD) + NSND FacLabels = [] FacColors = [] FacVals = np.zeros( [ Ny, self.Nfacs ], dtype=np.float_) for i in range(self.Nfacs): Factor = self.FacList[i] FacLabels.append(LabelScheme[Factor]) FacColors.append(ColorScheme[Factor]) if (Factor == 'FAC_SAL'): # SND - NSND FacVals[:,i] = Yvals[:,1] - Yvals[:,0] elif (Factor == 'FAC_DUST'): # NSD - NSND FacVals[:,i] = Yvals[:,2] - Yvals[:,0] elif (Factor == 'FAC_INT'): # SD - (SND + NSD) + NSND FacVals[:,i] = Yvals[:,3] - (Yvals[:,1] + Yvals[:,2]) + Yvals[:,0] else: print("ERROR: PlotXsection: Attempted to calculate too many factors") print("ERROR: PlotXsection: Stopping!") sys.exit(1) # 2 panel plot # Sims on top # Factors on bottom self.Fig = plt.figure() # legeng specs LegBbox = [ 1.02, 1.0 ] LegFsize = 12 LegNcol = 1 # Place axes for all panels AxW = 0.70 AxH = 0.35 AxLlx = 0.10 AxLly = [ 0.10, 0.55 ] self.SimAx.append(self.Fig.add_axes([ AxLlx, AxLly[1], AxW, AxH ])) self.FacAx.append(self.Fig.add_axes([ AxLlx, AxLly[0], AxW, AxH ])) # create axes Xaxis = plu.AxisConfig('x', [ self.Xmin, self.Xmax ], self.Xlabel) Xaxis.fontsize = self.AxFsize if self.Xticks: Xaxis.ticks = self.Xticks if self.XtickLabels: Xaxis.ticklabels = self.XtickLabels Yaxis = plu.AxisConfig('y', [ self.Ymin, self.Ymax ], self.Ylabel) Yaxis.fontsize = self.AxFsize if self.Yticks: Yaxis.ticks = self.Yticks if self.YtickLabels: Yaxis.ticklabels = self.YtickLabels # Sim lines Ptitle = plu.TitleConfig(self.SimPmarkers[0], "SIMS: {0:s}".format(self.Title)) Ptitle.fontsize = self.TitleFsize Legend = plu.LegendConfig(SimLabels, 'upper left') Legend.bbox = LegBbox Legend.fontsize = LegFsize Legend.ncol = LegNcol Xaxis.show = self.SimXshow[0] Yaxis.show = self.SimYshow[0] Yaxis.lim = self.SimLimits plu.PlotLine(self.SimAx[0], X, Yvals, Ptitle, Xaxis, Yaxis, Legend, SimColors) # Factor lines Ptitle = plu.TitleConfig(self.FacPmarkers[0], "FACTORS: {0:s}".format(self.Title)) Ptitle.fontsize = self.TitleFsize Legend = plu.LegendConfig(FacLabels, 'upper left') Legend.bbox = LegBbox Legend.fontsize = LegFsize Legend.ncol = LegNcol Xaxis.show = self.FacXshow[0] Yaxis.show = self.FacYshow[0] Yaxis.lim = self.FacLimits plu.PlotLine(self.FacAx[0], X, FacVals, Ptitle, Xaxis, Yaxis, Legend, FacColors) print("Writing: {0:s}".format(self.OutFname)) self.Fig.savefig(self.OutFname) plt.close() print("")
FacAxSap = [] FacAxSap.append(FigSap.add_axes([AxRightLlx, AxLly[2], AxW, AxH])) FacAxSap.append(FigSap.add_axes([AxRightLlx, AxLly[1], AxW, AxH])) FacAxSap.append(FigSap.add_axes([AxRightLlx, AxLly[0], AxW, AxH])) # for placing text in upper right (blank) space # create axes, turn off the axes, then place the text in that axes TxtAxPsap = FigPsap.add_axes([AxRightLlx, AxLly[3], AxW, AxH]) TxtAxPsap.set_axis_off() TxtAxSap = FigSap.add_axes([AxRightLlx, AxLly[3], AxW, AxH]) TxtAxSap.set_axis_off() Cfilled = 1 # 0 - no fill, 1 - fill Xaxis = plu.AxisConfig('x', [0, 500], "Radius (km)") Xaxis.fontsize = 12 Yaxis = plu.AxisConfig('y', [0, 6], "Z (km)") Yaxis.ticks = [0, 2, 4, 6] Yaxis.fontsize = 12 # Vt cross sections Cmap = 'nipy_spectral' Cmin = 0 Cmax = 20 Cnum = 21 Clim = [Cmin, Cmax] Clevs = np.linspace(Cmin, Cmax, num=Cnum) Xshow = [0, 0, 0, 1] Yshow = [1, 1, 1, 1]
SimColors.append(ColorScheme[Case]) SimLegText.append(LabelScheme[Case]) FacColors = [] FacLegText = [] for Case in FacsList: FacColors.append(ColorScheme[Case]) FacLegText.append(LabelScheme[Case]) Fig = plt.figure() AxSims = Fig.add_axes([0.1, 0.6, 0.7, 0.3]) AxFactors = Fig.add_axes([0.1, 0.1, 0.7, 0.3]) # Vt max time series, top half Xaxis = plu.AxisConfig('x', [0, 62], '') Xaxis.ticks = [6, 18, 30, 42, 54] Xaxis.ticklabels = [ "12Z\n22Aug", "0Z\n23Aug", "12Z\n23Aug", "0Z\n24Aug", "12Z\n23Aug" ] Xaxis.fontsize = 14 Yaxis = plu.AxisConfig('y', [5, 23], r'$Speed (ms^{-1})$') Yaxis.fontsize = 14 Ptitle = plu.TitleConfig('a', r'$V_t (max): Sims$') Ptitle.fontsize = 24 Legend = plu.LegendConfig(SimLegText, 'upper left') Legend.bbox = [1.02, 1.0] Legend.fontsize = 12
FacColors.append(Color) # Wind shear plot # top half: Sims # bottom half: Factors Pdir = 'Plots.py' YlimSims = [4, 10] YlimFacs = [-1.5, 1.5] Fig = plt.figure() AxSims = Fig.add_axes([0.1, 0.6, 0.7, 0.3]) AxFactors = Fig.add_axes([0.1, 0.1, 0.7, 0.3]) # Simulations, top half Xaxis = plu.AxisConfig('x', [0, 62], '') Xaxis.ticks = [6, 18, 30, 42, 54] Xaxis.ticklabels = [ "12Z\n22Aug", "0Z\n23Aug", "12Z\n23Aug", "0Z\n24Aug", "12Z\n24Aug" ] Xaxis.fontsize = 12 Yaxis = plu.AxisConfig('y', YlimSims, r'Shear') Yaxis.fontsize = 12 Ptitle = plu.TitleConfig('a', r'$Wind\ Shear:\ Sims$') Ptitle.fontsize = 24 Legend = plu.LegendConfig(SimLegText, 'upper left') Legend.bbox = [1.02, 1.0] Legend.fontsize = 12