0

サブパッケージの関数のこの例を使用して、緯度と経度を度単位で表した配列と、グリッド上の各座標の補間データ値を使用した配列を逆算したいと思います。RectSphereBivariateSplinescipy.interpolate

内挿されたデータオブジェクトRectSphereBivariateSplineが作成するのは、データ値のuおよびvコンポーネントであり、グリッドの次数の変化ごとに1つの値があります(この例では、緯度=180および経度=360)。

そうですか?

プロットするために、緯度、経度、およびそれぞれのデータ値を逆算するにはどうすればよいですか?

import numpy as np
from scipy.interpolate import RectSphereBivariateSpline

def geo_interp(lats,lons,data,grid_size_deg):
        '''We want to interpolate it to a global one-degree grid'''
        deg2rad = np.pi/180.
        new_lats = np.linspace(grid_size_deg, 180, 180) * deg2rad
        new_lons = np.linspace(grid_size_deg, 360, 360) * deg2rad
        new_lats, new_lons = np.meshgrid(new_lats, new_lons)

        '''We need to set up the interpolator object'''
        lut = RectSphereBivariateSpline(lats*deg2rad, lons*deg2rad, data)

        '''Finally we interpolate the data. The RectSphereBivariateSpline 
        object only takes 1-D arrays as input, therefore we need to do some reshaping.'''
        data_interp = lut.ev(new_lats.ravel(),
                        new_lons.ravel()).reshape((360, 180)).T
        return data_interp

if __name__ == '__main__':
        import matplotlib.pyplot as plt

        '''Suppose we have global data on a coarse grid'''
        lats = np.linspace(10, 170, 9) # in degrees
        lons = np.linspace(0, 350, 18) # in degrees
        data = np.dot(np.atleast_2d(90. - np.linspace(-80., 80., 18)).T,
                        np.atleast_2d(180. - np.abs(np.linspace(0., 350., 9)))).T

        '''Interpolate data to 1 degree grid'''
        data_interp = geo_interp(lats,lons,data,1)

        '''Looking at the original and the interpolated data, 
        one can see that the interpolant reproduces the original data very well'''
        fig = plt.figure()
        ax1 = fig.add_subplot(211)
        ax1.imshow(data, interpolation='nearest')
        ax2 = fig.add_subplot(212)
        ax2.imshow(data_interp, interpolation='nearest')
        plt.show()

ベクトル加算(つまり、ピタゴラス定理)を使用する可能性があると思いましたが、次数の変化ごとに1つの値しかなく、ポイントではないため、これは機能しません。

pow((pow(data_interp[0,:],2.0)+pow(data_interp[:,0],2.0)),1/2.0)
4

1 に答える 1

1

プロットに使用できる緯度と経度のベクトルは、「geo_interp」関数(「net_lats」と「new_lons」)で生成されているようです。メインプログラムでこれらが必要な場合は、関数の外部でこれらのベクトルを宣言するか、メインプログラムで使用するために生成されたこれらのベクトルを関数に返す必要があります。

お役に立てれば。

于 2013-12-22T09:14:36.767 に答える