Ejemplo n.º 1
0
    def compute_ipo(sst_anoms, years_pass=11, N=2.0):
        high = np.int(years_pass * 12.)
        B, A = signal.butter(N, N / high, btype='lowpass', output='ba')

        def filter_SST(x):
            if any(np.isnan(x)):
                z = x
            else:
                z = signal.filtfilt(B, A, x)
            return z

        sst_anoms['sst_filtered'] = (('time', 'lat', 'lon'),
                                     np.apply_along_axis(
                                         filter_SST, 0,
                                         sst_anoms['sst_masked'].data))

        lat = sst_anoms['lat'].values
        lon = sst_anoms['lon'].values
        lons, lats = np.meshgrid(lon, lat)
        coslat = np.cos(np.deg2rad(lat))
        wgts = np.sqrt(coslat)[..., np.newaxis]
        sst_anoms.load()
        X = sst_anoms['sst_filtered'].data
        solver = Eof(X, weights=wgts)
        eofs = solver.eofsAsCorrelation(neofs=5)
        pcs = solver.pcs(npcs=5, pcscaling=1)
        PCs = pd.DataFrame(pcs, index=sst_anoms['time'].to_index())
        PCs_monthly = solver.projectField(sst_anoms['sst_masked'].data, 5)
        PCs_monthly = pd.DataFrame(PCs_monthly,
                                   index=sst_anoms['time'].to_index())
        return eofs, PCs, lons, lats, PCs_monthly