analysis.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:AdK_analysis 作者: orbeckst 项目源码 文件源码
def interpolationFunction(self,data=None,spline_order=3,cval=None):
        """Returns a function F(x,y) that interpolates any values of the 2D observable.

        F = interpolationFunction(self,data=None,spline_order=3,cval=None)

        cval is set to data.mean() by default. cval cannot be chosen too large
        or too small or NaN because otherwise the spline interpolation breaks
        down near the region and produces wild oscillations.
        """
        # see http://www.scipy.org/Cookbook/Interpolation
        from scipy import ndimage

        if data is None:
            data = self.observable

        if cval is None:
            cval = data.mean()
        _data = data.filled(cval)   # fill with moderate value, not 1000 to keep spline happy

        coeffs = ndimage.spline_filter(_data,order=spline_order)
        x0,y0 = self.mNMP[0], self.mLID[0]
        dx,dy = self.mNMP[1] - x0, self.mLID[1] - y0
        def _transform(cnew, c0, dc):
            return (numpy.atleast_1d(cnew) - c0)/dc
        def interpolatedF(NMP,LID):
            """B-spline function over the 2D observable, F(NMP,LID).

            Example usage:
            >>> XX,YY = numpy.mgrid[40:75:0.5,96:150:0.5]
            >>> FF = Observable.F(XX,YY)
            >>> contourf(XX,YY,FF, numpy.linspace(-3,11,100),extend='both')
            """
            return ndimage.map_coordinates(coeffs,
                                           numpy.array([_transform(NMP,x0,dx),_transform(LID,y0,dy)]),
                                           prefilter=False,mode='constant',cval=cval)
        return interpolatedF
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号