예제 #1
0
파일: main.py 프로젝트: nishadhka/WEM
    def frontogenesis(self,
                      time,
                      level,
                      wrf_sd=0,
                      out_sd=0,
                      dom=1,
                      clvs=0,
                      no_title=1):
        """
        Compute and plot (Miller?) frontogenesis as d/dt of theta gradient.
        
        Use a centred-in-time derivative; hence, if
        time index is start or end of wrfout file, skip the plot.
        """

        outpath = self.get_outpath(out_sd)
        self.W = self.get_wrfout(wrf_sd, dom=dom)
        tstr = utils.string_from_time('output', time)

        Front = self.W.compute_frontogenesis(time, level)

        if isinstance(Front, N.ndarray):
            F = BirdsEye(self.C, self.W)
            fname = 'frontogen_{0}.png'.format(tstr)
            F.plot_data(Front,
                        'contourf',
                        outpath,
                        fname,
                        time,
                        clvs=clvs,
                        no_title=no_title)
        else:
            print("Skipping this time; at start or end of run.")
예제 #2
0
파일: main.py 프로젝트: nishadhka/WEM
    def std(self, t, lv, va, wrf_sds, out_sd, dom=1, clvs=0):
        """Compute standard deviation of all members
        for given variable.
        
        Inputs:
        t       :   time
        lv      :   level
        va      :   variable
        wrf_sds :   list of wrf subdirs to loop over

        Optional
        out_sd  :   directory in which to save image
        clvs    :   user-set contour levels
        """

        outpath = self.get_outpath(out_sd)

        ncfiles = self.list_ncfiles(wrf_sds)

        # Use first wrfout to initialise grid, get indices
        self.W = self.get_wrfout(wrf_sds[0], dom=dom)

        tidx = self.W.get_time_idx(t)

        if lv == 2000:
            # lvidx = None
            lvidx = 0
        else:
            print("Only support surface right now")
            raise Exception

        std_data = stats.std(ncfiles, va, tidx, lvidx)

        F = BirdsEye(self.C, self.W)
        t_name = utils.string_from_time('output', t)
        fname_t = 'std_{0}_{1}'.format(va, t_name)

        # pdb.set_trace()
        plotkwargs = {}
        plotkwargs['no_title'] = 1
        if isinstance(clvs, N.ndarray):
            plotkwargs['clvs'] = clvs
        F.plot_data(std_data, 'contourf', outpath, fname_t, t, **plotkwargs)
        print("Plotting std dev for {0} at time {1}".format(va, t_name))
예제 #3
0
파일: main.py 프로젝트: nishadhka/WEM
    def upperlevel_W(self,
                     time,
                     level,
                     wrf_sd=0,
                     out_sd=0,
                     dom=1,
                     clvs=0,
                     no_title=1):
        # import pdb; pdb.set_trace()
        outpath = self.get_outpath(out_sd)
        self.W = self.get_wrfout(wrf_sd, dom=dom)

        data = self.W.isosurface_p('W', time, level)
        F = BirdsEye(self.C, self.W)
        tstr = utils.string_from_time('output', time)
        fname = 'W_{0}_{1}.png'.format(level, tstr)
        F.plot_data(data,
                    'contourf',
                    outpath,
                    fname,
                    time,
                    clvs=clvs,
                    no_title=no_title)
예제 #4
0
파일: main.py 프로젝트: nishadhka/WEM
    def plot_diff_energy(self,
                         ptype,
                         energy,
                         time,
                         folder,
                         fname,
                         p2p,
                         plotname,
                         V,
                         no_title=0,
                         ax=0):
        """
        
        folder  :   directory holding computed data
        fname   :   naming scheme of required files
        p2p     :   root directory for plots
        V       :   constant values to contour at
        """
        sw = 0

        DATA = self.load_data(folder, fname, format='pickle')

        if isinstance(time, collections.Sequence):
            time = calendar.timegm(time)

        #for n,t in enumerate(times):

        for pn, perm in enumerate(DATA):
            f1 = DATA[perm]['file1']
            f2 = DATA[perm]['file2']
            if sw == 0:
                # Get times and info about nc files
                # First time to save power
                W1 = WRFOut(f1)
                permtimes = DATA[perm]['times']
                sw = 1

            # Find array for required time
            x = N.where(N.array(permtimes) == time)[0][0]
            data = DATA[perm]['values'][x][0]
            if not pn:
                stack = data
            else:
                stack = N.dstack((data, stack))
                stack_average = N.average(stack, axis=2)

        if ax:
            kwargs1 = {'ax': ax}
            kwargs2 = {'save': 0}
        #birdseye plot with basemap of DKE/DTE
        F = BirdsEye(self.C, W1, **kwargs1)  # 2D figure class
        #F.plot2D(va,t,en,lv,da,na)  # Plot/save figure
        tstr = utils.string_from_time('output', time)
        fname_t = ''.join((plotname, '_{0}'.format(tstr)))
        # fpath = os.path.join(p2p,fname_t)
        fig_obj = F.plot_data(stack_average,
                              'contourf',
                              p2p,
                              fname_t,
                              time,
                              V,
                              no_title=no_title,
                              **kwargs2)

        if ax:
            return fig_obj
예제 #5
0
파일: main.py 프로젝트: nishadhka/WEM
    def cold_pool_strength(self,
                           time,
                           wrf_sd=0,
                           wrf_nc=0,
                           out_sd=0,
                           swath_width=100,
                           dom=1,
                           twoplot=0,
                           fig=0,
                           axes=0,
                           dz=0):
        """
        Pick A, B points on sim ref overlay
        This sets the angle between north and line AB
        Also sets the length in along-line direction
        For every gridpt along line AB:
            Locate gust front via shear
            Starting at front, do 3-grid-pt-average in line-normal
            direction
            
        time    :   time (tuple or datenum) to plot
        wrf_sd  :   string - subdirectory of wrfout file
        wrf_nc  :   filename of wrf file requested.
                            If no wrfout file is explicitly specified, the
                            netCDF file in that folder is chosen if unambiguous.
        out_sd      :   subdirectory of output .png.
        swath_width :   length in gridpoints in cross-section-normal direction
        dom     :   domain number
        return2 :   return two figures. cold pool strength and cref/cross-section.
        axes    :   if two-length tuple, this is the first and second axes for
                    cross-section/cref and cold pool strength, respectively
        dz      :   plot height of cold pool only.
        
        """
        # Initialise
        self.W = self.get_wrfout(wrf_sd, wrf_nc, dom=dom)
        outpath = self.get_outpath(out_sd)

        # keyword arguments for plots
        line_kwargs = {}
        cps_kwargs = {}
        # Create two-panel figure
        if twoplot:
            P2 = Figure(self.C, self.W, plotn=(1, 2))
            line_kwargs['ax'] = P2.ax.flat[0]
            line_kwargs['fig'] = P2.fig
            P2.ax.flat[0].set_size_inches(3, 3)

            cps_kwargs['ax'] = P2.ax.flat[1]
            cps_kwargs['fig'] = P2.fig
            P2.ax.flat[1].set_size_inches(6, 6)

        elif isinstance(axes, tuple) and len(axes) == 2:
            line_kwargs['ax'] = axes[0]
            line_kwargs['fig'] = fig

            cps_kwargs['ax'] = axes[1]
            cps_kwargs['fig'] = fig

            return_ax = 1

        # Plot sim ref, send basemap axis to clicker function
        F = BirdsEye(self.C, self.W)
        self.data = F.plot2D('cref',
                             time,
                             2000,
                             dom,
                             outpath,
                             save=0,
                             return_data=1)

        C = Clicker(self.C, self.W, data=self.data, **line_kwargs)
        # C.fig.tight_layout()

        # Line from front to back of system
        C.draw_line()
        # C.draw_box()
        lon0, lat0 = C.bmap(C.x0, C.y0, inverse=True)
        lon1, lat1 = C.bmap(C.x1, C.y1, inverse=True)

        # Pick location for environmental dpt
        # C.click_x_y()
        # Here, it is the end of the cross-section
        lon_env, lat_env = C.bmap(C.x1, C.y1, inverse=True)
        y_env, x_env, exactlat, exactlon = utils.getXY(self.W.lats1D,
                                                       self.W.lons1D, lat_env,
                                                       lon_env)
        # Create the cross-section object
        X = CrossSection(self.C, self.W, lat0, lon0, lat1, lon1)

        # Ask user the line-normal box width (self.km)
        #C.set_box_width(X)

        # Compute the grid (DX x DY)
        cps = self.W.cold_pool_strength(X,
                                        time,
                                        swath_width=swath_width,
                                        env=(x_env, y_env),
                                        dz=dz)
        # import pdb; pdb.set_trace()

        # Plot this array
        CPfig = BirdsEye(self.C, self.W, **cps_kwargs)
        tstr = utils.string_from_time('output', time)
        if dz:
            fprefix = 'ColdPoolDepth_'
        else:
            fprefix = 'ColdPoolStrength_'
        fname = fprefix + tstr

        pdb.set_trace()
        # imfig,imax = plt.subplots(1)
        # imax.imshow(cps)
        # plt.show(imfig)
        # CPfig.plot_data(cps,'contourf',outpath,fname,time,V=N.arange(5,105,5))
        mplcommand = 'contour'
        plotkwargs = {}
        if dz:
            clvs = N.arange(100, 5100, 100)
        else:
            clvs = N.arange(10, 85, 2.5)
        if mplcommand[:7] == 'contour':
            plotkwargs['levels'] = clvs
            plotkwargs['cmap'] = plt.cm.ocean_r
        cf2 = CPfig.plot_data(cps, mplcommand, outpath, fname, time,
                              **plotkwargs)
        # CPfig.fig.tight_layout()

        plt.close(fig)

        if twoplot:
            P2.save(outpath, fname + "_twopanel")

        if return_ax:
            return C.cf, cf2