In [11]:
# Get processor information
tmp = !cat /proc/cpuinfo | grep "model name"
processor = tmp[0].split(':')[1].strip()
print(processor)
# Make a model for testing
from __future__ import division, print_function
import numpy as np
from fatiando import gridder, utils
from fatiando.mesher import PrismMesh
model = PrismMesh((-200, 200, -200, 200, 0, 400), (10, 10, 10))
model.addprop('density', np.ones(model.size))
model.addprop('magnetization', utils.ang2vec(2*np.ones(model.size), 25, -10))
inc, dec = -30, 50
x, y, z = gridder.regular((-500, 500, -500, 500), (50, 50), z=-1)
print('Model size: {}'.format(model.size))
print('Grid size: {}'.format(x.size))
# Time the forward modeling of gravity, gradients and mag
from fatiando.gravmag import prism
print('Times:')
print(' gz: ', end='')
%timeit prism.gz(x, y, z, model)
print(' gzz: ', end='')
%timeit prism.gzz(x, y, z, model)
print(' tf: ', end='')
%timeit prism.tf(x, y, z, model, inc, dec)
In [15]:
# Get processor information
tmp = !cat /proc/cpuinfo | grep "model name"
processor = tmp[0].split(':')[1].strip()
print(processor)
# Make a model for testing
from __future__ import division, print_function
import numpy as np
from fatiando import gridder, utils
from fatiando.mesher import PointGrid
model = PointGrid((-200, 200, -200, 200), 100, (50, 50))
model.addprop('density', np.ones(model.size))
model.addprop('magnetization', utils.ang2vec(2*np.ones(model.size), 25, -10))
inc, dec = -30, 50
x, y, z = gridder.regular((-500, 500, -500, 500), (100, 100), z=-1)
print('Model size: {}'.format(model.size))
print('Grid size: {}'.format(x.size))
# Time the forward modeling of gravity, gradients and mag
from fatiando.gravmag import sphere
print('Times:')
print(' gz: ', end='')
%timeit sphere.gz(x, y, z, model)
print(' gzz: ', end='')
%timeit sphere.gzz(x, y, z, model)
print(' tf: ', end='')
%timeit sphere.tf(x, y, z, model, inc, dec)
In [13]:
# Get processor information
tmp = !cat /proc/cpuinfo | grep "model name"
processor = tmp[0].split(':')[1].strip()
print(processor)
# Make a model for testing
from __future__ import division, print_function
import numpy as np
from fatiando import gridder, utils
from fatiando.mesher import PolygonalPrism
vertices = utils.circular_points([-300, 300, -300, 300], 1000)[::-1]
props = {'density': 1000, 'magnetization': utils.ang2vec(2, 25, -10)}
model = [PolygonalPrism(vertices, 0, 2000, props)]
inc, dec = -30, 50
x, y, z = gridder.regular((-500, 500, -500, 500), (50, 50), z=-1)
print('Model size: {}'.format(len(vertices)))
print('Grid size: {}'.format(x.size))
# Time the forward modeling of gravity, gradients and mag
from fatiando.gravmag import polyprism
print('Times:')
print(' gz: ', end='')
%timeit polyprism.gz(x, y, z, model)
print(' gzz: ', end='')
%timeit polyprism.gzz(x, y, z, model)
print(' tf: ', end='')
%timeit polyprism.tf(x, y, z, model, inc, dec)
In [2]:
import numpy as np
In [5]:
np.all(1 > 0)
Out[5]:
In [13]:
x = np.ones(100000000)
In [14]:
%timeit x*x
In [15]:
%timeit x**2
In [ ]:
np.allclose()
In [1]:
%matplotlib inline
from __future__ import division, print_function
import numpy as np
In [2]:
%load_ext memory_profiler
In [2]:
tmp = !cat /proc/cpuinfo | grep "model name"
processor = tmp[0].split(':')[1].strip()
print(processor)
In [2]:
from fatiando import gridder, utils
from fatiando.mesher import PrismMesh, Prism
In [6]:
model = PrismMesh((-200, 200, -200, 200, 0, 400), (10, 10, 10))
model.addprop('density', np.ones(model.size))
model.addprop('magnetization', utils.ang2vec(2*np.ones(model.size), 25, -10))
inc, dec = -30, 50
x, y, z = gridder.regular((-500, 500, -500, 500), (100, 100), z=-1)
In [21]:
%timeit prism.gz(x, y, z, model)
In [22]:
%timeit _prism_numpy.gz(x, y, z, model)
In [9]:
x, y, z= np.arange(3).reshape((3, 1))
x, y, z
Out[9]:
In [ ]:
np.testing.assert_allclose()
In [40]:
x = np.ones(10000)
M = 1000
In [41]:
field = 'gz'
In [42]:
def kernel(x):
return np.arctan2(x, x)
In [43]:
%%timeit
a = np.zeros_like(x)
for p in range(M):
for i in range(2):
for j in range(2):
for k in range(2):
a += np.arctan2(x, x)
In [44]:
%%timeit
a = np.zeros_like(x)
for p in range(M):
for i in range(2):
for j in range(2):
for k in range(2):
a += kernel(x)
In [45]:
%%timeit
a = np.zeros_like(x)
for p in range(M):
for i in range(2):
for j in range(2):
for k in range(2):
if field == 'gz':
a += np.arctan2(x, x)
elif field == 'gzz':
a += np.arctan2(x, x)
elif field == 'gxz':
a += np.arctan2(x, x)
elif field == 'gyz':
a += np.arctan2(x, x)
elif field == 'gyy':
a += np.arctan2(x, x)
In [46]:
%%timeit
a = np.zeros_like(x)
for p in range(M):
for i in range(2):
for j in range(2):
for k in range(2):
if field == 'gz':
a += kernel(x)
elif field == 'gzz':
a += kernel(x)
elif field == 'gxz':
a += kernel(x)
elif field == 'gyz':
a += kernel(x)
elif field == 'gyy':
a += kernel(x)
In [ ]: