Example #1
0
    def thetaeq(self, filled=True, cmap=None, **kwargs):
        self.initialize_plot()
        self.level = kwargs['level']*100
        clevels = kwargs['clevels']
        t_arrays = read_files(self, 'temperature')  # [C]
        q_arrays = read_files(self, 'sphum')  # [kg/kg]
        rh_arrays = read_files(self, 'relhumid')
        press = np.zeros(rh_arrays[0].shape)+kwargs['level']  # [hPa]
        X, Y = np.meshgrid(self.lons, self.lats)
        self.series['thetaeq'] = []
        for i in range(len(self.dates)):
            mixr = thermo.mixing_ratio(specific_humidity=q_arrays[i])
            theta = thermo.theta_equiv2(C=t_arrays[i], hPa=press,
                                        mixing_ratio=mixr, relh=rh_arrays[i])
            val = get_value_at(-123., 38.5, theta, self)  # closest to BBY
            self.series['thetaeq'].append(val)
            if filled:
                cf = self.axes[i].contourf(X, Y, theta, clevels, cmap=cmap)
                try:
                    self.axes[i].cax.colorbar(cf, ticks=clevels[::4])
                except AttributeError:
                    add_colorbar(self.axes[i], cf)
            else:
                cs = self.axes[i].contour(X, Y, theta, clevels, colors='r',
                                          linewidths=0.6)
                clabels = self.axes[i].clabel(cs, clevels[::5],
                                              fontweight='bold',
                                              fontsize=10,
                                              fmt='%1.0f')
                [txt.set_color('r') for txt in clabels]

            set_limits(self, i)
            self.add_date(i)
        txt = 'Equivalent Potential Temperature [K] at {} hPa\n'
        self.title += txt.format(str(self.level/100))
Example #2
0
    def theta(self, **kwargs):
        self.initialize_plot()
        self.level = kwargs['level']*100
        cmap = kwargs['cmap']
        t_arrays = read_files(self, 'temperature')  # [C]
        q_arrays = read_files(self, 'sphum')  # [kg/kg]
        X, Y = np.meshgrid(self.lons, self.lats)
        clevels = kwargs['clevels']
        self.series['theta'] = []
        for i in range(len(self.dates)):
            mixr = thermo.mixing_ratio(specific_humidity=q_arrays[i])
            press = np.zeros(mixr.shape)+kwargs['level']  # [hPa]
            theta = thermo.theta2(C=t_arrays[i], hPa=press, mixing_ratio=mixr)
            val = get_value_at(-123., 38.5, theta, self)  # closest to BBY
            self.series['theta'].append(val)
            cf = self.axes[i].contourf(X, Y, theta, clevels, cmap=cmap)
            self.axes[i].cax.colorbar(cf, ticks=clevels[::4])
            set_limits(self, i)
            self.add_date(i)

        self.l1 = 'Potential Temperature [K] at ' + \
            str(self.level/100) + ' hPa'
Example #3
0
    def cross_section(self, **kwargs):

        field = kwargs['field']
        clevels = kwargs['clevels']
        cmap = kwargs['cmap']
        self.orientation = kwargs['orientation']

        self.initialize_plot()
        self.horizontal = False
        t_arrays = read_files(self, 'temperature')  # [C]
        q_arrays = read_files(self, 'sphum')  # [kg/kg]
        rh_arrays = read_files(self, 'relhumid')

        isob = get_vertical_array(self)/100.  # to [hPa]
        z, n = t_arrays[0].shape
        press = np.tile(np.array([isob]).transpose(), (1, n))

        X, Y = np.meshgrid(range(len(self.lons)), range(len(isob)))

        if len(clevels) == 2:
            foo = clevels[0]
            boundsc = clevels[1]
            clevels = foo

        ''' make a color map of fixed colors '''
        vmin = min(clevels)
        vmax = max(clevels)
        bounds = clevels
        snsmap = sns.color_palette(cmap, n_colors=len(bounds))
        cmap = colors.ListedColormap(snsmap)
        norm = colors.BoundaryNorm(bounds, cmap.N)

        plot_field = []
        if field == 'thetaeq':
            for i in range(6):
                mixr = thermo.mixing_ratio(specific_humidity=q_arrays[i])
                theta = thermo.theta_equiv2(
                    C=t_arrays[i], hPa=press,
                    mixing_ratio=mixr, relh=rh_arrays[i])
                theta[theta > 320] = np.nan
                plot_field.append(theta)
            plot_fieldc = plot_field
            cboundaries = bounds
            cticks = bounds
            boundsc = bounds
            ti = ' - Equivalent potential temperature [K]'
        elif field == 'q':
            for i in range(6):
                q = q_arrays[i]
                plot_field.append(q*1000.)  # [g kg-1]
            plot_fieldc = plot_field
            cboundaries = bounds
            cticks = bounds
            boundsc = bounds
            ti = ' - Specific humidity [g kg-1]'
        elif field == 'U':
            plot_field = read_files(self, 'u')
            plot_fieldc = plot_field
            cboundaries = bounds
            cticks = bounds
            boundsc = bounds
            ti = ' - Wind speed zonal component [m s-1]'
        elif field == 'V':
            plot_field = read_files(self, 'v')
            plot_fieldc = plot_field
            cboundaries = bounds
            cticks = bounds
            boundsc = bounds
            ti = ' - Wind speed meridional component [m s-1]'
        elif field == 'thetaeq+U':
            for i in range(6):
                mixr = thermo.mixing_ratio(specific_humidity=q_arrays[i])
                theta = thermo.theta_equiv2(
                    C=t_arrays[i], hPa=press,
                    mixing_ratio=mixr, relh=rh_arrays[i])
                theta[theta > 320] = np.nan
                plot_field.append(theta)
            plot_fieldc = read_files(self, 'u')
            cboundaries = bounds
            cticks = bounds
            t0 = '\nEquivalent potential temperature [K] (color coded)'
            t1 = '\nWind speed zonal component [m s-1] (contour lines)'
            ti = t0+t1
        elif field == 'thetaeq+V':
            for i in range(6):
                mixr = thermo.mixing_ratio(specific_humidity=q_arrays[i])
                theta = thermo.theta_equiv2(
                    C=t_arrays[i], hPa=press,
                    mixing_ratio=mixr, relh=rh_arrays[i])
                theta[theta > 320] = np.nan
                plot_field.append(theta)
            plot_fieldc = read_files(self, 'v')
            cboundaries = bounds
            cticks = bounds
            t0 = '\nEquivalent potential temperature [K] (color coded)'
            t1 = '\nWind speed meridional component [m s-1] (contour lines)'
            ti = t0+t1

        for i in range(6):
            im = self.axes[i].imshow(plot_field[i],
                                     interpolation='none',
                                     vmin=vmin,
                                     vmax=vmax,
                                     cmap=cmap,
                                     norm=norm)
            self.axes[i].cax.colorbar(im,
                                      cmap=cmap, norm=norm,
                                      boundaries=cboundaries,
                                      ticks=cticks[::4])
            xticks = self.lons[::10]
            xticklabs = [str(x) for x in xticks]
            xticklabs.reverse()
            xticklabs.append(' ')
            xticklabs.reverse()
            self.axes[i].set_xticklabels(xticklabs)
            yidx = np.where(isob == self.zboundary)[0]
            self.axes[i].set_ylim([36, yidx])
            yticks = self.axes[i].get_yticks()
            isob_yticks = [isob[y] for y in yticks]
            if i == 0:
                yticklabs = [str(x) for x in isob_yticks]
            else:
                yticklabs = [' ' for x in isob_yticks]
            self.axes[i].set_yticklabels(yticklabs)

            ''' add contour lines '''
            cs = self.axes[i].contour(X, Y, plot_fieldc[i],
                                      origin='lower', levels=boundsc,
                                      colors='k', linewidths=0.5)
            if field in ['thetaeq+U', 'thetaeq+V']:
                self.axes[i].clabel(cs, boundsc,
                                    fmt='%1.0f',
                                        fontsize=10)
            self.axes[i].set_ylim([36, yidx])

            ''' add vertical line '''
            xidx = np.where(self.lons == -123.0)
            self.axes[i].axvline(xidx, color='k', linestyle=':')

            ''' add date to subplot '''
            self.add_date(i)

            ''' add axis label '''
            self.axes[i].set_xlabel('Longitude [deg]')
            if i == 0:
                self.axes[i].set_ylabel('Pressure level [hPa]')

        t1 = 'Climate Forecast System Reanalysis'+ti
        if self.orientation[0] == 'zonal':
            t2 = '\nLatitude: ' + str(self.orientation[1])
        elif self.orientation[0] == 'meridional':
            t2 = '\nLongitude: ' + str(self.orientation[1])
        plt.suptitle(t1+t2)