Skip to content

Commit

Permalink
Cookbook passes PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
leouieda committed Jul 18, 2014
1 parent 27bcdf9 commit 834eaf3
Show file tree
Hide file tree
Showing 77 changed files with 423 additions and 387 deletions.
10 changes: 7 additions & 3 deletions cookbook/datasets_crust2.0_tesseroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
lons, lats, heights = gridder.regular(area, shape, z=250000)

# Divide the model into nproc slices and calculate them in parallel


def calculate(chunk):
return tesseroid.gz(lons, lats, heights, chunk)


def split(model, nproc):
chunksize = len(model)/nproc
chunksize = len(model) / nproc
for i in xrange(nproc - 1):
yield model[i*chunksize : (i + 1)*chunksize]
yield model[(nproc - 1)*chunksize : ]
yield model[i * chunksize: (i + 1) * chunksize]
yield model[(nproc - 1) * chunksize:]
start = time.time()
nproc = 8
pool = Pool(processes=nproc)
Expand Down
4 changes: 2 additions & 2 deletions cookbook/geothermal_climsig_abrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# along a well at these depths
zp = numpy.arange(0, 100, 1)
temp, error = utils.contaminate(abrupt(amp, age, zp), 0.02,
percent=True, return_stddev=True)
percent=True, return_stddev=True)

# Preparing for the inversion
data = SingleChange(temp, zp, mode='abrupt').config('levmarq', initial=[1, 1])
Expand All @@ -23,7 +23,7 @@
print " true: amp=%.3f age=%.3f" % (amp, age)
print " estimated: amp=%.3f age=%.3f" % (amp_, age_)

mpl.figure(figsize=(4,5))
mpl.figure(figsize=(4, 5))
mpl.title("Residual well temperature")
mpl.plot(temp, zp, 'ok', label='Observed')
mpl.plot(data.predicted(), zp, '--r', linewidth=3, label='Predicted')
Expand Down
2 changes: 1 addition & 1 deletion cookbook/geothermal_climsig_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# along a well at these depths
zp = numpy.arange(0, 100, 1)
temp, error = utils.contaminate(linear(amp, age, zp), 0.02,
percent=True, return_stddev=True)
percent=True, return_stddev=True)

# Preparing for the inversion
data = SingleChange(temp, zp, mode='linear').config('levmarq', initial=[1, 1])
Expand Down
2 changes: 1 addition & 1 deletion cookbook/geothermal_climsig_wrong.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# along a well at these depths
zp = numpy.arange(0, 100, 1)
temp, error = utils.contaminate(abrupt(amp, age, zp), 0.02,
percent=True, return_stddev=True)
percent=True, return_stddev=True)

# Preparing for the inversion
data = SingleChange(temp, zp, mode='linear').config('levmarq', initial=[1, 1])
Expand Down
6 changes: 3 additions & 3 deletions cookbook/gravmag_2d_polygon_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
mpl.ylabel("Z")
mpl.axis('scaled')
polygons = [mesher.Polygon(mpl.draw_polygon(area, axes),
{'density':500})]
{'density': 500})]
xp = numpy.arange(-4500, 4500, 100)
zp = numpy.zeros_like(xp)
gz = talwani.gz(xp, zp, polygons)

mpl.figure()
mpl.axis('scaled')
mpl.subplot(2,1,1)
mpl.subplot(2, 1, 1)
mpl.title(r"Gravity anomaly produced by the model")
mpl.plot(xp, gz, '-k', linewidth=2)
mpl.ylabel("mGal")
mpl.xlim(-5000, 5000)
mpl.subplot(2,1,2)
mpl.subplot(2, 1, 2)
mpl.polygon(polygons[0], 'o-k', linewidth=2, fill='k', alpha=0.5)
mpl.xlabel("X")
mpl.ylabel("Z")
Expand Down
6 changes: 3 additions & 3 deletions cookbook/gravmag_basin2d_trapezoidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from fatiando.vis import mpl

verts = [(10000, 1.), (90000, 1.), (90000, 7000), (10000, 3330)]
model = Polygon(verts, {'density':-100})
model = Polygon(verts, {'density': -100})
x = numpy.arange(0., 100000., 1000.)
z = numpy.zeros_like(x)
gz = utils.contaminate(talwani.gz(x, z, [model]), 0.5)

solver = basin2d.Trapezoidal(x, z, gz, verts[0:2], density=-100).config(
'levmarq', initial=[9000, 500]).fit()
'levmarq', initial=[9000, 500]).fit()
estimate = solver.estimate_

mpl.figure()
Expand All @@ -27,7 +27,7 @@
mpl.xlim(0, 100000)
mpl.subplot(2, 1, 2)
mpl.polygon(estimate, 'o-r', linewidth=2, fill='r',
alpha=0.3, label='Estimated')
alpha=0.3, label='Estimated')
mpl.polygon(model, '--k', linewidth=2, label='True')
mpl.legend(loc='lower left', numpoints=1)
mpl.xlabel("X")
Expand Down
6 changes: 3 additions & 3 deletions cookbook/gravmag_basin2d_triangular.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from fatiando.vis import mpl

verts = [(10000, 1.), (90000, 1.), (80000, 5000)]
model = Polygon(verts, {'density':-100})
model = Polygon(verts, {'density': -100})
x = numpy.arange(0., 100000., 1000.)
z = numpy.zeros_like(x)
gz = utils.contaminate(talwani.gz(x, z, [model]), 1)

solver = basin2d.Triangular(x, z, gz, verts[0:2], density=-100).config(
'levmarq', initial=[10000, 1000]).fit()
'levmarq', initial=[10000, 1000]).fit()
estimate = solver.estimate_

mpl.figure()
Expand All @@ -27,7 +27,7 @@
mpl.xlim(0, 100000)
mpl.subplot(2, 1, 2)
mpl.polygon(estimate, 'o-r', linewidth=2, fill='r',
alpha=0.3, label='Estimated')
alpha=0.3, label='Estimated')
mpl.polygon(model, '--k', linewidth=2, label='True')
mpl.legend(loc='lower left', numpoints=1)
mpl.xlabel("X")
Expand Down
9 changes: 5 additions & 4 deletions cookbook/gravmag_eqlayer_joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fatiando.vis import mpl

# Make synthetic data
props = {'density':1000}
props = {'density': 1000}
model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)]
area = [-5000, 5000, -5000, 5000]
x1, y1, z1 = gridder.scatter(area, 80, z=0, seed=0)
Expand All @@ -21,12 +21,13 @@
# and the inversion
# Apply a scaling factor to make both portions of the misfit the same order of
# magnitude
scale = np.linalg.norm(gz)**2/np.linalg.norm(gzz)**2
scale = np.linalg.norm(gz) ** 2 / np.linalg.norm(gzz) ** 2
misfit = (EQLGravity(x1, y1, z1, gz, layer)
+ scale*EQLGravity(x2, y2, z2, gzz, layer, field='gzz'))
+ scale * EQLGravity(x2, y2, z2, gzz, layer, field='gzz'))
regul = Smoothness2D(layer.shape)
# Use an L-curve analysis to find the best regularization parameter
solver = LCurve(misfit, regul, [10**i for i in range(-30, -20)], jobs=8).fit()
solver = LCurve(
misfit, regul, [10 ** i for i in range(-30, -20)], jobs=8).fit()
layer.addprop('density', solver.estimate_)

# Now I can forward model gz using my layer to produce an integrated map in a
Expand Down
4 changes: 2 additions & 2 deletions cookbook/gravmag_eqlayer_pel_polereduc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Make synthetic data
inc, dec = -60, 23
props = {'magnetization':10}
props = {'magnetization': 10}
model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)]
shape = (50, 50)
x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-150)
Expand All @@ -24,7 +24,7 @@
misfit = PELTotalField(x, y, z, tf, inc, dec, layer, windows, degree)
regul = PELSmoothness(layer, windows, degree)
# Use an L-curve analysis to find the best regularization parameter
solver = LCurve(misfit, regul, [10**i for i in range(-20, -10)]).fit()
solver = LCurve(misfit, regul, [10 ** i for i in range(-20, -10)]).fit()
layer.addprop('magnetization', solver.estimate_)
residuals = solver.residuals()
print "Residuals:"
Expand Down
4 changes: 2 additions & 2 deletions cookbook/gravmag_eqlayer_pel_upcontinue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fatiando.vis import mpl

# Make synthetic data
props = {'density':1000}
props = {'density': 1000}
model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)]
shape = (50, 50)
x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0)
Expand All @@ -22,7 +22,7 @@
misfit = PELGravity(x, y, z, gz, layer, windows, degree)
regul = PELSmoothness(layer, windows, degree)
# Use an L-curve analysis to find the best regularization parameter
solver = LCurve(misfit, regul, [10**i for i in range(-30, -18)]).fit()
solver = LCurve(misfit, regul, [10 ** i for i in range(-30, -18)]).fit()
layer.addprop('density', solver.estimate_)
residuals = solver.residuals()
print "Residuals:"
Expand Down
8 changes: 4 additions & 4 deletions cookbook/gravmag_eqlayer_polereduc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
GravMag: Use an equivalent layer to reduce a magnetic total field anomaly to the
pole
GravMag: Use an equivalent layer to reduce a magnetic total field anomaly to
the pole
"""
from fatiando.gravmag import prism, sphere
from fatiando.gravmag.eqlayer import EQLTotalField
Expand All @@ -10,7 +10,7 @@

# Make synthetic data
inc, dec = -60, 23
props = {'magnetization':10}
props = {'magnetization': 10}
model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)]
shape = (25, 25)
x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0)
Expand All @@ -22,7 +22,7 @@
misfit = EQLTotalField(x, y, z, tf, inc, dec, layer)
regul = Damping(layer.size)
# Use an L-curve analysis to find the best regularization parameter
solver = LCurve(misfit, regul, [10**i for i in range(-30, -15)]).fit()
solver = LCurve(misfit, regul, [10 ** i for i in range(-30, -15)]).fit()
residuals = solver.residuals()
layer.addprop('magnetization', solver.estimate_)
print "Residuals:"
Expand Down
4 changes: 2 additions & 2 deletions cookbook/gravmag_eqlayer_upcontinue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fatiando.vis import mpl

# Make synthetic data
props = {'density':1000}
props = {'density': 1000}
model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)]
shape = (25, 25)
x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0)
Expand All @@ -20,7 +20,7 @@
misfit = EQLGravity(x, y, z, gz, layer)
regul = Damping(layer.size)
# Use an L-curve analysis to find the best regularization parameter
solver = LCurve(misfit, regul, [10**i for i in range(-30, -20)]).fit()
solver = LCurve(misfit, regul, [10 ** i for i in range(-30, -20)]).fit()
layer.addprop('density', solver.estimate_)
residuals = solver.residuals()
print "Residuals:"
Expand Down
2 changes: 1 addition & 1 deletion cookbook/gravmag_euler_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Make a model
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
Prism(-1500, -500, -500, 500, 1000, 2000, {'magnetization':2})]
Prism(-1500, -500, -500, 500, 1000, 2000, {'magnetization': 2})]
# Generate some data from the model
shape = (200, 200)
area = bounds[0:4]
Expand Down
6 changes: 3 additions & 3 deletions cookbook/gravmag_euler_classic_expanding_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# Make a model
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
Prism(-1500, -500, -1500, -500, 1000, 2000, {'magnetization':2}),
Prism(500, 1500, 1000, 2000, 1000, 2000, {'magnetization':2})]
Prism(-1500, -500, -1500, -500, 1000, 2000, {'magnetization': 2}),
Prism(500, 1500, 1000, 2000, 1000, 2000, {'magnetization': 2})]
# Generate some data from the model
shape = (100, 100)
area = bounds[0:4]
Expand Down Expand Up @@ -66,7 +66,7 @@
myv.figure()
myv.points([r.estimate_ for r in results], size=100.)
myv.prisms(model, opacity=0.5)
axes = myv.axes(myv.outline(bounds), ranges=[b*0.001 for b in bounds])
axes = myv.axes(myv.outline(bounds), ranges=[b * 0.001 for b in bounds])
myv.wall_bottom(bounds)
myv.wall_north(bounds)
myv.show()
6 changes: 3 additions & 3 deletions cookbook/gravmag_euler_classic_moving_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# Make a model
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
Prism(-1500, -500, -1500, -500, 500, 1500, {'density':1000}),
Prism(500, 1500, 1000, 2000, 500, 1500, {'density':1000})]
Prism(-1500, -500, -1500, -500, 500, 1500, {'density': 1000}),
Prism(500, 1500, 1000, 2000, 500, 1500, {'density': 1000})]
# Generate some data from the model
shape = (100, 100)
area = bounds[0:4]
Expand Down Expand Up @@ -51,7 +51,7 @@
myv.figure()
myv.points(solver.estimate_, size=100.)
myv.prisms(model, opacity=0.5)
axes = myv.axes(myv.outline(bounds), ranges=[b*0.001 for b in bounds])
axes = myv.axes(myv.outline(bounds), ranges=[b * 0.001 for b in bounds])
myv.wall_bottom(bounds)
myv.wall_north(bounds)
myv.title('Euler solutions')
Expand Down
4 changes: 2 additions & 2 deletions cookbook/gravmag_fourier_ansig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fatiando.gravmag import prism, fourier
from fatiando.vis import mpl

model = [mesher.Prism(-100,100,-100,100,0,2000,{'magnetization':10})]
model = [mesher.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': 10})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
Expand All @@ -14,7 +14,7 @@
tf = utils.contaminate(prism.tf(xp, yp, zp, model, inc, dec), 0.001,
percent=True)

# Need to convert gz to SI units so that the result is also in SI
# Need to convert gz to SI units so that the result is also in SI
ansig = fourier.ansig(xp, yp, utils.nt2si(tf), shape)

mpl.figure()
Expand Down
4 changes: 2 additions & 2 deletions cookbook/gravmag_fourier_deriv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fatiando.gravmag import prism, fourier
from fatiando.vis import mpl

model = [mesher.Prism(-1000,1000,-1000,1000,0,2000,{'density':100})]
model = [mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': 100})]
area = (-5000, 5000, -5000, 5000)
shape = (51, 51)
z0 = -500
Expand All @@ -28,7 +28,7 @@
mpl.colorbar(shrink=0.7)
mpl.m2km()

mpl.figure(figsize=(14,10))
mpl.figure(figsize=(14, 10))
mpl.subplots_adjust(top=0.95, left=0.05, right=0.95)
mpl.subplot(2, 3, 1)
mpl.title("x deriv (contour) + true (color map)")
Expand Down
4 changes: 2 additions & 2 deletions cookbook/gravmag_grav_polyprism.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
model.append(
mesher.PolygonalPrism(
mpl.draw_polygon(area, axes, xy2ne=True),
depths[i - 1], depths[i], {'density':500}))
depths[i - 1], depths[i], {'density': 500}))
# Calculate the effect
shape = (100, 100)
xp, yp, zp = gridder.regular(area, shape, z=-1)
Expand All @@ -35,5 +35,5 @@
# Show the model
myv.figure()
myv.polyprisms(model, 'density')
myv.axes(myv.outline(bounds), ranges=[i*0.001 for i in bounds])
myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds])
myv.show()
13 changes: 7 additions & 6 deletions cookbook/gravmag_grav_prism.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from fatiando.gravmag import prism
from fatiando.vis import mpl, myv

model = [mesher.Prism(-4000,-3000,-4000,-3000,0,2000,{'density':1000}),
mesher.Prism(-1000,1000,-1000,1000,0,2000,{'density':-900}),
mesher.Prism(2000,4000,3000,4000,0,2000,{'density':1300})]
shape = (100,100)
model = [mesher.Prism(-4000, -3000, -4000, -3000, 0, 2000, {'density': 1000}),
mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -900}),
mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'density': 1300})]
shape = (100, 100)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150)
fields = [prism.potential(xp, yp, zp, model),
prism.gx(xp, yp, zp, model),
Expand All @@ -30,9 +30,10 @@
mpl.subplot(4, 3, i + 3)
mpl.axis('scaled')
mpl.title(titles[i])
levels = mpl.contourf(yp*0.001, xp*0.001, field, shape, 15)
levels = mpl.contourf(yp * 0.001, xp * 0.001, field, shape, 15)
cb = mpl.colorbar()
mpl.contour(yp*0.001, xp*0.001, field, shape, levels, clabel=False, linewidth=0.1)
mpl.contour(yp * 0.001, xp * 0.001, field, shape,
levels, clabel=False, linewidth=0.1)
mpl.show()

myv.figure()
Expand Down
2 changes: 1 addition & 1 deletion cookbook/gravmag_grav_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fatiando.gravmag import sphere
from fatiando.vis import mpl

model = [mesher.Sphere(0, 0, 2000, 1000, {'density':1000})]
model = [mesher.Sphere(0, 0, 2000, 1000, {'density': 1000})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
x, y, z = gridder.regular(area, shape, z=-100)
Expand Down
Loading

0 comments on commit 834eaf3

Please sign in to comment.