示例#1
0
    def calc_n34(self):

        #print('got to function')
        vtsub, nyrs = basic_functions.time_subset(self.var, self.time0,
                                                  self.tim1, self.tim2)

        # Compute monthly climatology
        sst_clim = np.zeros(
            [12, len(self.dimdict['lat']),
             len(self.dimdict['lon'])])
        for i in range(12):
            j = np.arange(i, nyrs * 12, 12)
            sst_clim[i, :, :] = np.mean(vtsub[j, :, :], axis=0)

        # Compute anomaly
        sst_anom = np.zeros([vtsub.shape[0], vtsub.shape[1], vtsub.shape[2]])
        for i in range(vtsub.shape[0]):
            j = i % 12
            print(j)
            sst_anom[i, :, :] = vtsub[i, :, :] - sst_clim[j, :, :]

        # Area mean
        illat = np.where(self.dimdict['lat'] >= -5)[0][0]
        iulat = np.where(self.dimdict['lat'] >= 5)[0][0] + 1
        illon = np.where(self.dimdict['lon'] >= -170)[0][0]
        iulon = np.where(self.dimdict['lon'] >= -120)[0][0] + 1

        sst_anom_nino34 = np.mean(sst_anom[:, illat:iulat, illon:iulon],
                                  axis=(1, 2))  # should weight latitude

        # 5-month running mean
        smooth_length = 5
        x = (smooth_length - 1) / 2
        nino34 = np.zeros([sst_anom_nino34.shape[0] - smooth_length + 1])
        #time = range(nyrs*12)
        t = []
        for i in range(sst_anom_nino34.shape[0] - smooth_length + 1):
            nino34[i] = np.mean(sst_anom_nino34[i:i + smooth_length])
            t.append(x + i)
            #years.append(self.tim1+x+i)

        fig, ax = plt.subplots()
        plt.plot(t, nino34, color='k')
        ax.grid()

        plt.axhline(y=0, color='k')

        plt.fill_between(t, y1=0, y2=nino34, where=nino34 > 0, color='r')
        plt.fill_between(t, y1=0, y2=nino34, where=nino34 < 0, color='b')

        plt.savefig('nino34_numpy.png')
        '''
示例#2
0
    def climatology_lon_lat(self, time_mean):

        # seasonal mean then average over climatological time period
        clim_var = np.zeros(
            [len(self.dimdict['lat']),
             len(self.dimdict['lon'])])
        for ilat in range(len(self.dimdict['lat'])):
            for ilon in range(len(self.dimdict['lon'])):
                var_tsub, nsubyrs = basic_functions.time_subset(
                    self.var[:, ilat, ilon], self.time0, self.tim1, self.tim2)
                var_seas = basic_functions.seasonal_mean(
                    var_tsub, nsubyrs, time_mean)
                var_clim_seas = np.mean(var_seas, axis=0)
                clim_var[ilat, ilon] = var_clim_seas

        return clim_var
示例#3
0
    def climatology_shgt_slat(self, selhgt, sellat, time_mean):

        shgt = np.where(self.dimdict['hgt'] >= selhgt)[0][0]
        slat = np.where(self.dimdict['lat'] >= sellat)[0][0]

        # select variable at height and latitude
        var = self.var[:, shgt, slat]

        # climatological monthly mean
        var_tsub, nsubyrs = basic_functions.time_subset(
            var, self.time0, self.tim1, self.tim2)
        var_seas = basic_functions.seasonal_mean(var_tsub, nsubyrs, time_mean)
        var_clim_seas = var_seas.mean()
        print var_clim_seas.shape

        return var_clim_seas
示例#4
0
    def climatology_polar_hgt_mon(self):

        # polar cap mean (70-90N)
        var_amean = np.zeros(
            [len(self.dimdict['tim']),
             len(self.dimdict['hgt'])])
        for itim in range(len(self.dimdict['tim'])):
            for ihgt in range(len(self.dimdict['hgt'])):
                var_amean[itim, ihgt] = basic_functions.latitude_mean(
                    self.var[itim, ihgt, :], self.dimdict['lat'], 70, 90)

        # climatological monthly mean
        clim_var = np.zeros([12, len(self.dimdict['hgt'])])
        for ihgt in range(len(self.dimdict['hgt'])):
            var_tsub, nsubyrs = basic_functions.time_subset(
                var_amean[:, ihgt], self.time0, self.tim1, self.tim2)
            var_seas = basic_functions.seasonal_mean(var_tsub, nsubyrs,
                                                     'clim_monthly')
            clim_var[:, ihgt] = var_seas

        return clim_var