AttributeError:'module'对象没有属性'grd'

时间:2014-04-04 02:55:21

标签: python

我知道此网站之前已经多次询问过,但没有一个解决方案对我有所帮助。我正在运行以下脚本,它给出了标题中的错误:

import numpy as np
import fatiando as ft

shape = (41, 41)
x, y = ft.grd.regular((-10, 10, 30, 50), shape)
height = 800 - 1000*ft.utils.gaussian2d(x, y, 3, 1, x0=0, y0=37)
rel = -7000*ft.utils.gaussian2d(x, y, 3, 5, x0=0, y0=40)
thick = height - rel
dens = 1900*np.ones_like(thick)
data = np.transpose([x, y, height, thick, dens])
with open('layers.txt', 'w') as f:
    f.write("# Synthetic layer model of sediments and topography\n")
    f.write("# Columns are:\n")
    f.write("#   lon   lat   height   thickness   density\n")
    np.savetxt(f, data, fmt='%g')
ft.vis.figure(figsize=(4, 3))
ft.vis.title('Depth of sediments [m]')
ft.vis.axis('scaled')
ft.vis.pcolor(x, y, rel, shape)
ft.vis.colorbar()
ft.vis.savefig('depth.png')
ft.vis.figure(figsize=(4, 3))
ft.vis.title('Topography [m]')
ft.vis.axis('scaled')
ft.vis.pcolor(x, y, height, shape)
ft.vis.colorbar()
ft.vis.savefig('topography.png')
ft.vis.figure(figsize=(4, 3))
ft.vis.title('Thickness of sediment layer [m]')
ft.vis.axis('scaled')
ft.vis.pcolor(x, y, thick, shape)
ft.vis.colorbar()
ft.vis.savefig('thickness.png')
ft.vis.show()

这个脚本不是我自己创建的,而是带有我安装的程序(Tesseroids)的预打包演示脚本,所以我不知道为什么我在使用它时会出错。我已经安装了fatiando。

1 个答案:

答案 0 :(得分:2)

似乎fatiando.grd已更名为fatiando.gridder。如果我这样做,进口就可以了:

import numpy as np
import fatiando as ft
from fatiando import gridder

shape = (41, 41)
x, y = gridder.regular((-10, 10, 30, 50), shape)

我在项目的github repository找到了更改。