Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Pad arrays #239

Merged
merged 19 commits into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
18417fd
Added padding routine to gridder.
drandykass Dec 1, 2015
e1ba617
Began unpad_array function
drandykass Dec 1, 2015
4bfdb34
Working unpad. Ready for PR.
drandykass Dec 2, 2015
1bcb7e4
Frobbed function call. Ensured PEP8 compliance.
drandykass Dec 3, 2015
0d86a6a
Added tests and cleaned up the docs.
drandykass Dec 3, 2015
4278005
Spell checked and final docs tweaked.
drandykass Dec 3, 2015
e7d076f
Modified contributors.rst
drandykass Dec 4, 2015
524106c
Applied recommended changes. Separated pad_array from pad_coords. Pad…
drandykass Dec 11, 2015
3edc879
Added seeds to unittests. Added a loop to test all padding options to…
drandykass Dec 14, 2015
a267f74
Fixed pep8 compliance.
drandykass Dec 14, 2015
903ee3c
Fixed docstring errors. Added myself to contributors. Edited Changelog.
drandykass Dec 14, 2015
0417e64
Fixed the docstring test error. Had an older version of numpy on my …
drandykass Dec 14, 2015
83a0ce5
Last commit? Fixed pep8 compliance.
drandykass Dec 14, 2015
5169d6d
Renamed pad_coords, changed s to shape, added docstring examples, and…
drandykass Dec 17, 2015
d31d11c
Minor docstring fixes and another docstring example added.
drandykass Dec 17, 2015
3dc24a2
Added instructions for making the flattened meshgrid style output fro…
drandykass Dec 22, 2015
be4e0e2
Changed output of pad_array to give the list of vectors in the same f…
drandykass Dec 23, 2015
e7d623f
Fixed minor docstring error in gridder.py
drandykass Dec 23, 2015
dec6aa1
Minor typo fixes to the changelog entry
leouieda May 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions cookbook/grid_pad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
Gridding: Pad gridded data
"""

from fatiando import mesher, gridder
from fatiando.gravmag import prism
from fatiando.vis import mpl
import numpy as np

# Generate gridded data
shape = (101, 172)
x, y, z = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150)
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})]
gz = prism.gz(x, y, z, model)
gz = gz.reshape(shape)

# Pad arrays with all the padding options
pads = []
xy = [x, y]

# Pad with zeros, or any other number
# (note padtype can be a string or numeric, so long as it
# can be cast as a float.) For example, both 0 and '0' are valid, as
# would be any other number.
g, nps = gridder.pad_array(gz, padtype='0')
pads.append(g.flatten())

# Pad with the mean of each vector
g, _ = gridder.pad_array(gz, padtype='mean')
pads.append(g.flatten())

# Pad with the edge of each vector
g, _ = gridder.pad_array(gz, padtype='edge')
pads.append(g.flatten())

# Pad with a linear taper
g, _ = gridder.pad_array(gz, padtype='lintaper')
pads.append(g.flatten())

# Pad with the even reflection
g, _ = gridder.pad_array(gz, padtype='reflection')
pads.append(g.flatten())

# Pad with the odd reflection
g, _ = gridder.pad_array(gz, padtype='OddReflection')
pads.append(g.flatten())

# Pad with the odd reflection and a cosine taper (default)
g, _ = gridder.pad_array(gz, padtype='OddReflectionTaper')
pads.append(g.flatten())

# Get coordinate vectors
N = gridder.pad_coords(xy, gz.shape, nps)

shapepad = g.shape

# Generate new meshgrid and plot results
yp = N[1]
xp = N[0]
titles = ['Original', 'Zero', 'Mean', 'Edge', 'Linear Taper', 'Reflection',
'Odd Reflection', 'Odd Reflection/Taper']
mpl.figure(figsize=(17, 9))
mpl.suptitle('Padding algorithms for a 2D array')
for ii, p in enumerate(pads):
mpl.subplot(2, 4, ii+2)
mpl.axis('scaled')
mpl.title(titles[ii+1])
levels = mpl.contourf(yp*0.001, xp*0.001, p, shapepad, 15)
cb = mpl.colorbar()
mpl.contour(yp*0.001, xp*0.001, p, shapepad, levels, clabel=False,
linewidth=0.1)
mpl.subplot(2, 4, 1)
mpl.axis('scaled')
mpl.title(titles[0])
levels = mpl.contourf(y*0.001, x*0.001, gz, shape, 15)
cb = mpl.colorbar()
mpl.contour(y*0.001, x*0.001, gz, shape, levels, clabel=False, linewidth=0.1)
mpl.show()
6 changes: 6 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Version 0.5

**Changes**:

* Added several functions for padding arrays of arbitrary dimension.
``fatiando.gridder.pad_array`` pads an array with a variety of padding and
taper options. ``fatiando.gridder.unpad_array`` returns the original,
unpadded array. ``fatiando.gridder.pad_coords`` pads the coordinate vectors
associated with the arrays padded above. Added Kass in the contributors.
(`PR 239 <https://github.com/fatiando/fatiando/pull/239>`__)
* Better navigation for long pages in the docs by adding a sidebar with links
to subsections.
(`PR 275 <https://github.com/fatiando/fatiando/pull/275>`__)
Expand Down
2 changes: 2 additions & 0 deletions doc/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A (hopefully) updated list of people who contributed to Fatiando a Terra:
* Graham Markall - Continuum Analytics, Inc.
* `Martin Bentley`_ - Nelson Mandela Metropolitan University, South Africa and AEON, South Africa
* `Victor Almeida`_ - UERJ, Brazil.
* `M. Andy Kass`_ - United States Geological Survey, USA

.. _Leonardo Uieda: http://www.leouieda.com
.. _Vanderlei Coelho de Oliveira Junior: http://fatiando.org/people/oliveira-jr
Expand All @@ -21,3 +22,4 @@ A (hopefully) updated list of people who contributed to Fatiando a Terra:
.. _André Ferreira: http://fatiando.org/people/ferreira
.. _Martin Bentley: https://twitter.com/astonsplat
.. _Victor Almeida: http://www.pinga-lab.org/people/victor-almeida.html
.. _M. Andy Kass: https://twitter.com/drandykass
Loading