Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
- Fix lower/upper behavior of fftplot
- Final tuning of Kerelsky_plus
  • Loading branch information
TAdeJong committed Oct 21, 2021
1 parent 52ad05f commit ed4085f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions pyGPA/imagetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ def fftplot(fftim, d=1, pcolormesh=True, contour=False, levels=None, **kwargs):
Any other kwargs are forwarded to the call to
`pcolormesh`"""
x, y = [fftbounds(n, d) for n in fftim.shape]
origin = kwargs.pop('origin', 'upper')
if 'ax' in kwargs:
ax = kwargs.pop('ax')
else:
fig, ax = plt.subplots()
if pcolormesh:
X, Y = np.meshgrid(x, y, indexing='xy')
im = ax.pcolormesh(X, Y, fftim.T, **kwargs)
im = ax.pcolormesh(X, Y, fftim.T, origin=origin, **kwargs)
else:
extent = [x[0], x[-1], y[0], y[-1]]
im = ax.imshow(fftim.T, extent=extent, origin='lower', **kwargs)
im = ax.imshow(fftim.T, extent=extent, origin=origin, **kwargs)
if contour:
ax.contour(fftim.T, colors='white', origin='lower',
ax.contour(fftim.T, colors='white',
extent=extent, alpha=0.3, levels=levels)
ax.set_aspect('equal')
return im
Expand Down
2 changes: 1 addition & 1 deletion pyGPA/property_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def moire_diffs(args):
print(res2)
if res2.cost < res.cost:
res = res2
if res.success and (res.cost <= 1e-10):
if res.success and (res.cost <= 0.1):
params = res.x
else:
params = np.full(4, np.nan)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_phase_unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
def test_equivalent_phase_unwrap_ref_phase_unwrap(kmax):
N = 256
xx, yy = np.meshgrid(np.arange(N), np.arange(N), indexing='ij')
psi0 = (yy+xx)/(4*np.sqrt(2))
psi0 = (yy+xx) / (4*np.sqrt(2))
psi = pu._wrapToPi(psi0)
weight = np.ones_like(psi)
result_phase_unwrap_ref = pu.phase_unwrap_ref(
psi=psi, weight=weight, kmax=kmax
)
assert np.allclose(result_phase_unwrap_ref - result_phase_unwrap_ref.mean(), psi0-psi0.mean())
assert np.allclose(result_phase_unwrap_ref - result_phase_unwrap_ref.mean(),
psi0 - psi0.mean())
result_phase_unwrap = pu.phase_unwrap(
psi=psi, weight=weight, kmax=kmax
)
Expand All @@ -33,7 +34,7 @@ def test_equivalent_phase_unwrap_ref_phase_unwrap(kmax):
def test_equivalent_phase_unwrap_gaussian_weight():
N = 256
xx, yy = np.meshgrid(np.arange(N), np.arange(N), indexing='ij')
psi0 = (yy+xx)/(4*np.sqrt(2))
psi0 = (yy+xx) / (4*np.sqrt(2))
psi = pu._wrapToPi(psi0)
gaussian = np.exp(-((xx-N//2)**2+(yy-N//2)**2)/(0.3*N**2))
result_phase_unwrap = pu.phase_unwrap(
Expand All @@ -50,7 +51,7 @@ def test_equivalent_phase_unwrap_gaussian_weight():
def test_equivalent_phase_unwrap_ref_prediff_phase_unwrap_prediff(kmax):
N = 256
xx, yy = np.meshgrid(np.arange(N), np.arange(N), indexing='ij')
psi0 = (yy+xx)/(4*np.sqrt(2))
psi0 = (yy+xx) / (4*np.sqrt(2))
psi = pu._wrapToPi(psi0)
dx = np.diff(psi, axis=1)
dy = np.diff(psi, axis=0)
Expand Down

0 comments on commit ed4085f

Please sign in to comment.