繁体   English   中英

当从 2d 过渡到 3d 时,z 值似乎映射到不正确的 x 和 y 值

[英]z values appear to be mapping to the incorrect x and y values when transition from 2d to 3d

我有一个函数可以根据空间中给定的 xy 值计算 az 值。 我试图将所有数据组合到一个 3D 网格中,但是我注意到 z 值没有正确映射。 换句话说,当打印 xyz 并在 excel 中执行计算作为检查时,我没有得到正确的 z 值,但我确信我的函数计算正确。 如果我单独检查它,它会给出我正在寻找的结果。 所以我很确定 z 值被映射到不正确的 x,y。

仅供参考,我需要将网格作为 XYZ 一起使用的原因是:一旦我运行该函数,我需要对生成的网格执行网格数学运算。 例如,我需要根据给定的 X 和 Y 找到某些位置,然后找到对应于某个 z 值的节点并对节点的面积求和......等等。 我显然还没有到达那里。 我是 python 的新手并在那里工作。

我在这里做错了什么? 注意我没有收到任何错误。

任何帮助是极大的赞赏。

我究竟做错了什么?

import pandas as pd
import math
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.tri as tri
import matplotlib.pyplot as plt
from matplotlib import rcParams

#define the flow potential equation where X,Y is the injection well locations and x,y is the point of interest, Q is flow rate
def func(X, Y, x, y, Q):
    return (Q / (2 * np.pi)) * np.arctan((y-Y)/(x-X))

# necessary data
X1=2318743.658
Y1=797346.704
Q1=5
X2=2318690.718
Y2=797343.693
Q2=5
X3=2318715.221
Y3=797309.685
Q3=5

#initiate the XY grid - this will be a standard that will encompass all IW and MW
xi = np.linspace(2318675,2318800,625)
yi = np.linspace(797300,797375,375)

#mesh the grid in to x,y space
x,y = np.meshgrid(xi,yi)

#calculate the valus over the grid at every x,y using the defined function above
zi = (func(X1,Y1,x,y,Q1)+func(X2,Y2,x,y,Q2)+func(X3,Y3,x,y,Q3))

#reshape the xy space into 3d space
xy = np.array([[(x, y) for y in yi] for x in xi])

#reshape z into 3d space
z = np.array(zi).reshape(xy.shape[0],xy.shape[1], -1)

#combined xyz into a single grid
xyz = np.concatenate((xy, z), axis = -1)

我相信我能够通过更改这行代码来解决这个问题:

xy = np.array([[(x, y) for y in yi] for x in xi])

对此:

xy = np.array([[(x, y) for x in xi] for y in yi])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM