将网格从中心坐标重新采样到外部(即角)坐标 [英] Resample grid from center coordinates to external (i.e. corner) coordinates

查看:256
本文介绍了将网格从中心坐标重新采样到外部(即角)坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一种从网格中心位置(红色点)外推网格角位置(蓝色点)的简便方法?

Is there a readily available method for extrapolating the grid corner positions (blue dots) from grid center positions (red dots)?

我正在使用的网格不是矩形的,因此常规的双线性插值似乎不是最好的方法;不过,这只是为了让我在我的图表中使用pyplot.pcolormesh()数据,所以也许这无关紧要.

The grid I am working with is not rectangular, so regular bi-linear interpolation doesn't seem like it would be the best way; though, this is just so that I my plot my data use pyplot.pcolormesh(), so perhaps that doesn't matter so much.

示例网格数据:

import numpy as np

lons = np.array([[ 109.93299681,  109.08091365,  108.18301276,  107.23602539],
                 [ 108.47911382,  107.60397996,  106.68325946,  105.71386119],
                 [ 107.06790187,  106.17259769,  105.23214707,  104.2436463 ],
                 [ 105.69908292,  104.78633156,  103.82905363,  102.82453812]])

lats = np.array([[ 83.6484245 ,  83.81088466,  83.97177823,  84.13098916],
                 [ 83.55459198,  83.71460466,  83.87294803,  84.02950188],
                 [ 83.4569054 ,  83.61444708,  83.77022192,  83.92410637],
                 [ 83.35554612,  83.51060313,  83.6638013 ,  83.81501464]])

推荐答案

我不知道有什么健壮的matplotlib技术可以满足您的要求,但我可能有不同的解决方案.我经常不得不填充/外推到我缺少信息的网格区域.为此,我使用了一个Fortran程序,该程序是使用F2PY(与numpy一起提供)编译的,该程序将其创建到python模块中.假设您具有Intel Fortran编译器,则可以使用以下命令对其进行编译:f2py --verbose --fcompiler=intelem -c -m extrapolate fill.f90.您可以使用以下命令从python调用程序(有关完整示例,请参见此处) :

I am not aware of any robust matplotlib technique for doing what you are asking, but I may have a different solution. I often have to fill/extrapolate to areas of a grid where I am missing information. To do this I use a Fortran program that I compile using F2PY (that ships with numpy), which creates it into a python module. Assuming you have the Intel Fortran compiler you compile it with the following command: f2py --verbose --fcompiler=intelem -c -m extrapolate fill.f90. You can call the program from python with (see here for full example):

    import extrapolate as ex
    undef=2.0e+35
    tx=0.9*undef
    critx=0.01
    cor=1.6
    mxs=100

    field = Zg
    field=np.where(abs(field) > 50 ,undef,field)

    field=ex.extrapolate.fill(int(1),int(grdROMS.xi_rho),
                            int(1),int(grdROMS.eta_rho),
                            float(tx), float(critx), float(cor), float(mxs),
                            np.asarray(field, order='Fortran'),
                            int(grdROMS.xi_rho),
                            int(grdROMS.eta_rho))

程序通过迭代方法在矩形坐标中用Neumann边界条件(dA/dn = 0)求解拉普拉斯方程,以在包含"undef"之类的值的网格点处填充合理的值.这对我很有用,也许您会发现它很有用.可以在我的github帐户此处上找到该程序.

The program solves Laplace's equation with Neumann boundary conditions (dA/dn = 0) in RECTANGULAR coordinates by an iterative method to fill in reasonable values at gridpoints containing values like "undef". This works great for me and perhaps you may find it useful. The program is available on my github account here.

这篇关于将网格从中心坐标重新采样到外部(即角)坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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