[英]z values appear to be mapping to the incorrect x and y values when transition from 2d to 3d
i have a function that calculates az values based on given xy values in space.我有一个函数可以根据空间中给定的 xy 值计算 az 值。 I am trying to combine all the data together into a 3D grid however i noticed that the z values are not mapping correctly.我试图将所有数据组合到一个 3D 网格中,但是我注意到 z 值没有正确映射。 In other words when print the xyz and perform the calculation as a check in excel I do not get the right z values, but i'm confident my function is calculating correctly.换句话说,当打印 xyz 并在 excel 中执行计算作为检查时,我没有得到正确的 z 值,但我确信我的函数计算正确。 If i check it on an individual basis it gives the result i'm looking for.如果我单独检查它,它会给出我正在寻找的结果。 So i'm pretty sure the z values are getting mapped to the incorrect x,y.所以我很确定 z 值被映射到不正确的 x,y。
FYI the reason i need the grid together as XYZ is: once i get the function running i need to perform grid math on the resulting grid.仅供参考,我需要将网格作为 XYZ 一起使用的原因是:一旦我运行该函数,我需要对生成的网格执行网格数学运算。 For example i need to find certain locations based on a given X and Y and then find nodes that correspond to a certain z value and sum the area of the nodes...etc.例如,我需要根据给定的 X 和 Y 找到某些位置,然后找到对应于某个 z 值的节点并对节点的面积求和......等等。 I haven't gotten there yet obviously.我显然还没有到达那里。 I'm new to python and working my way there.我是 python 的新手并在那里工作。
What am I doing wrong here?我在这里做错了什么? Note I don't get any errors.注意我没有收到任何错误。
Any help is greatly appreciated.任何帮助是极大的赞赏。
What am i doing wrong?我究竟做错了什么?
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)
I believe I was able to resolve the issue by changing this line of code:我相信我能够通过更改这行代码来解决这个问题:
xy = np.array([[(x, y) for y in yi] for x in xi])
to this:对此:
xy = np.array([[(x, y) for x in xi] for y in yi])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.