我想对 X、Y 数据执行计算以生成计算的 Z。我的代码如下:
injection_wells.csv 的示例数据集
姓名 | X | 是 | 问 |
---|---|---|---|
MW-1 | 2517700 | 996400 | 5 |
MW-2 | 2517770 | 996420 | 5 |
import pandas as pd
import math
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.tri as tri
IW = pd.read_csv (r'Injection_wells.csv')
`Note that - Injection wells is a table of three wells with names, X, Y, and Q (flow rate).`
#pull all the relevant well information by well into their own arrays
MW1 = IW[IW['Name'] == 'MW1']
MW2 = IW[IW['Name'] == 'MW2']
MW3 = IW[IW['Name'] == 'MW3']
#initiate grid
xi = np.linspace(2517675,2517800,625)
yi = np.linspace(996300,996375,375)
#make it so i can apply np.float to an array
vector = np.vectorize(np.float)
X,Y = np.meshgrid(xi,yi)
#perform calculation over every X and Y.
PSI = ((MW1['Q']/(2*math.pi))*(np.arctan(((vector(X[None,:]))-np.float(MW1['X']))/(vector(Y[:,None])-np.float(MW1['Y']))))+
(MW2['Q']/(2*math.pi))*(np.arctan(((vector(X[None,:])-np.float(MW2['X']))/vector((Y[:,None])-np.float(MW2['Y'])))))+
(MW3['Q']/(2*math.pi))*(np.arctan(((vector((X[None,:])-np.float(MW3['X']))/vector((Y[:,None])-np.float(MW3['Y'])))))))
我得到错误:
ValueError Traceback (most recent call last)
<ipython-input-11-fd6ee058014f> in <module>
17 X,Y = np.meshgrid(xi,yi)
18
---> 19 PSI = ((MW1['Q']/(2*math.pi))*(np.arctan(((vector(X[None,:]))-np.float(MW1['X']))/(vector(Y[:,None])-np.float(MW1['Y']))))+
20 (MW2['Q']/(2*math.pi))*(np.arctan(((vector(X[None,:])-np.float(MW2['X']))/vector((Y[:,None])-np.float(MW2['Y'])))))+
21 (MW3['Q']/(2*math.pi))*(np.arctan(((vector((X[None,:])-np.float(MW3['X']))/vector((Y[:,None])-np.float(MW3['Y'])))))))
~\Anaconda3\lib\site-packages\pandas\core\ops\common.py in new_method(self, other)
63 other = item_from_zerodim(other)
64
---> 65 return method(self, other)
66
67 return new_method
~\Anaconda3\lib\site-packages\pandas\core\ops\__init__.py in wrapper(left, right)
343 result = arithmetic_op(lvalues, rvalues, op)
344
--> 345 return left._construct_result(result, name=res_name)
346
347 wrapper.__name__ = op_name
~\Anaconda3\lib\site-packages\pandas\core\series.py in _construct_result(self, result, name)
2755 # We do not pass dtype to ensure that the Series constructor
2756 # does inference in the case where `result` has object-dtype.
-> 2757 out = self._constructor(result, index=self.index)
2758 out = out.__finalize__(self)
2759
~\Anaconda3\lib\site-packages\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)
311 try:
312 if len(index) != len(data):
--> 313 raise ValueError(
314 f"Length of passed values is {len(data)}, "
315 f"index implies {len(index)}."
ValueError: Length of passed values is 375, index implies 1.
我知道这与我试图将函数应用于只接受一个值的数组有关。我正在尝试克服这个问题,并能够在整个网格数据集上执行此计算。对此的任何帮助将不胜感激。
我试图做的方程式如下。请注意,等式中的 theta 是从网格节点到注入井(对于每个网格节点)的距离的反正切值,这是我试图在代码中复制的。
谢谢