存储scipy网格数据使用的权重以供重用 [英] storing the weights used by scipy griddata for re-use

查看:176
本文介绍了存储scipy网格数据使用的权重以供重用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据从非结构化网格 M1 插值到另一个非结构化网格 M2 .为此,scipy.interpolate.griddata似乎不错.

但是,我需要多次从 M1 插值到 M2 ,仅更改数据而不更改网格.我猜想,在内部,当从 M1 插值到 M2 时,scipy.interpolate.griddata定义了一些权重系数,这可能是计算中昂贵的部分之一.

因此,我想避免每次都重新计算这些权重.有没有办法做到这一点?即,从一个非结构化网格多次插值到另一个非结构化网格,两者均保持不变,以避免重新计算scipy.interpolate.griddata(或等效值)的内部?

解决方案

一种解决方案是使用 可用于非线性插值. griddata使用LinearNDInterpolatorCloughTocher2DInterpolator.

I am trying to interpolate data from an unstructured mesh M1 to another unstructured mesh M2. For this, scipy.interpolate.griddata seems good.

However, I will need to interpolate many times from M1 to M2, changing only the data not the meshes. I guess that, internally, the scipy.interpolate.griddata defines some weight coefficients when interpolating from M1 to M2 and that this may be one of the expensive parts of the computation.

Therefore, I would like to avoid re-compute these weigths each time. Is there a way to do this? I.e., interpolating many times from one unstructured mesh to another unstructured mesh, both kept constant, avoiding to re-compute the internals of scipy.interpolate.griddata (or equivalent)?

解决方案

A solution is to use the LinearNDInterpolator Scipy function with a pre-computed Delaunay triangulation:

from scipy.spatial import Delaunay
from scipy.interpolate import LinearNDInterpolator

tri = Delaunay(mesh1)  # Compute the triangulation

# Perform the interpolation with the given values:
interpolator = LinearNDInterpolator(tri, values_mesh1)
values_mesh2 = interpolator(mesh2)

mesh1 is a (number of points * dim) array.

Note: CloughTocher2DInterpolator could be used for non-linear interpolation. griddata uses either LinearNDInterpolator or CloughTocher2DInterpolator.

这篇关于存储scipy网格数据使用的权重以供重用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆