【发布时间】:2022-01-03 06:51:45
【问题描述】:
我有根据 x,y,z 作为原始数据的温度。
我想把x,y,z,t的原始数据变成网格数据。
在根据 z 将 t 值应用于 x 和 z 坐标来转换数据时,我创建了一个零数组并将其转换为 pandas 数据框。
之后用for语句改变每个位置的值来处理数据,耗时很长。
在100x100的情况下,for循环重复10000次,耗时16s到20s。 我想要更少的计算时间。
有没有有效的方法来做到这一点?
data = Data_load()
resolution = 100
step = 100 / resolution
zero = np.zeros((100,100))
zero_df = pd.DataFrame(zero)
for x in zero_df.index:
for y in zero_df.columns:
data.query('z == 0.25')
t_data = data.query('{}< x <={} and {} < y <= {}'.format(x, x+step, y, y+step))
if len(t_data) != 0:
t = np.sum(t_data['T']) / len(t_data)
zero_df[x][y] = t
print(zero_df)
print(np.max(zero_df))
fig, ax = plt.subplots()
im = ax.imshow(zero_df, cmap='jet',vmin=1000, vmax=2000)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Layer : {}'.format(0.25))
ax.set_ylim(100, 0)
plt.tight_layout()
plt.colorbar(im)
plt.show()
数据示例
x y z c a T
32 16.300 15.501 0.00 0.0 0.0 1652.1
33 16.833 15.501 0.00 0.0 0.0 1750.2
34 17.367 15.501 0.00 0.0 0.0 1719.9
35 17.900 15.501 0.00 0.0 0.0 1714.4
36 18.433 15.501 0.00 0.0 0.0 1706.3
... ... ... ... ... ... ...
238242 84.500 84.500 9.75 0.0 0.0 1449.6
238243 84.500 84.500 9.75 0.0 0.0 1446.7
238244 84.510 84.500 9.75 0.0 0.0 1317.4
238245 84.510 84.500 9.75 0.0 0.0 1251.9
238246 84.510 84.500 9.75 0.0 0.0 1221.5
【问题讨论】:
-
data = Data_load()。请生成可重现的样本数据。 -
抱歉,添加了我的数据示例