예제 #1
0
    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("")
예제 #2
0
            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)

            Fig.savefig(OutFname)
            plt.close()

        InFile.close()