Skip to content

Commit 0c4e97a

Browse files
author
chris-langfield
committed
incoroprate previous hexagonal ifftshift into filter_shift()
1 parent 10ec961 commit 0c4e97a

File tree

5 files changed

+83
-83
lines changed

5 files changed

+83
-83
lines changed

src/hexfft/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .hexfft import fftshift, ifftshift, fft, ifft, FFT
1+
from .hexfft import fft, ifft, FFT
22
from .array import HexArray

src/hexfft/hexfft.py

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -503,79 +503,6 @@ def mersereau_ifft(PX):
503503
return px.T / 4
504504

505505

506-
def fftshift(X):
507-
N = X.shape[0]
508-
n1, n2 = X.indices
509-
m = hsupport(N, X.pattern).astype(bool)
510-
shifted = HexArray(np.zeros_like(X), X.pattern)
511-
if X.pattern == "oblique":
512-
regI = (n1 < N // 2) & (n2 < N // 2)
513-
regII = m & (n1 < n2) & (n2 >= N // 2)
514-
regIII = m & (n2 <= n1) & (n1 >= N // 2)
515-
516-
_regI = (n1 >= N // 2) & (n2 >= N // 2)
517-
_regII = m & (n1 >= n2) & (n2 < N // 2)
518-
_regIII = m & (n2 > n1) & (n1 < N // 2)
519-
520-
shifted[_regI] = X[regI]
521-
shifted[_regII] = X[regII]
522-
shifted[_regIII] = X[regIII]
523-
524-
elif X.pattern == "offset":
525-
m = m.T
526-
n2 = n2 - N // 4
527-
regI = m & (n1 < N // 2) & (n2 < N // 2)
528-
regII = m & (n1 <= n2) & (n2 >= N // 2)
529-
regIII = m & (n2 < n1) & (n1 >= N // 2)
530-
531-
_regI = m & (n1 >= N // 2) & (n2 >= N // 2)
532-
_regII = m & (n1 > n2) & (n2 < N // 2)
533-
_regIII = m & (n2 >= n1) & (n1 < N // 2)
534-
535-
shifted[_regI.T] = X[regI.T]
536-
shifted[_regII.T] = X[regII.T]
537-
shifted[_regIII.T] = X[regIII.T]
538-
539-
return shifted
540-
541-
542-
def ifftshift(X):
543-
N = X.shape[0]
544-
n1, n2 = X.indices
545-
m = hsupport(N, X.pattern).astype(bool)
546-
shifted = HexArray(np.zeros_like(X), X.pattern)
547-
548-
if X.pattern == "oblique":
549-
_regI = (n1 < N // 2) & (n2 < N // 2)
550-
_regII = m & (n1 < n2) & (n2 >= N // 2)
551-
_regIII = m & (n2 <= n1) & (n1 >= N // 2)
552-
553-
regI = (n1 >= N // 2) & (n2 >= N // 2)
554-
regII = m & (n1 >= n2) & (n2 < N // 2)
555-
regIII = m & (n2 > n1) & (n1 < N // 2)
556-
557-
shifted[_regI] = X[regI]
558-
shifted[_regII] = X[regII]
559-
shifted[_regIII] = X[regIII]
560-
561-
elif X.pattern == "offset":
562-
m = m.T
563-
n2 = n2 - N // 4
564-
regI = m & (n1 < N // 2) & (n2 < N // 2)
565-
regII = m & (n1 <= n2) & (n2 >= N // 2)
566-
regIII = m & (n2 < n1) & (n1 >= N // 2)
567-
568-
_regI = m & (n1 >= N // 2) & (n2 >= N // 2)
569-
_regII = m & (n1 > n2) & (n2 < N // 2)
570-
_regIII = m & (n2 >= n1) & (n1 < N // 2)
571-
572-
shifted[regI.T] = X[_regI.T]
573-
shifted[regII.T] = X[_regII.T]
574-
shifted[regIII.T] = X[_regIII.T]
575-
576-
return shifted
577-
578-
579506
def _hexdft_pgram(px):
580507
""""""
581508
dtype = px.dtype

src/hexfft/utils.py

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,88 @@ def pgram_to_hex(p, N, pattern="oblique"):
111111
return HexArray(h, pattern)
112112

113113

114-
def filter_shift(x):
114+
def fftshift(X):
115+
N = X.shape[0]
116+
n1, n2 = X.indices
117+
m = hsupport(N, X.pattern).astype(bool)
118+
shifted = HexArray(np.zeros_like(X), X.pattern)
119+
if X.pattern == "oblique":
120+
regI = (n1 < N // 2) & (n2 < N // 2)
121+
regII = m & (n1 < n2) & (n2 >= N // 2)
122+
regIII = m & (n2 <= n1) & (n1 >= N // 2)
123+
124+
_regI = (n1 >= N // 2) & (n2 >= N // 2)
125+
_regII = m & (n1 >= n2) & (n2 < N // 2)
126+
_regIII = m & (n2 > n1) & (n1 < N // 2)
127+
128+
shifted[_regI] = X[regI]
129+
shifted[_regII] = X[regII]
130+
shifted[_regIII] = X[regIII]
131+
132+
elif X.pattern == "offset":
133+
m = m.T
134+
n2 = n2 - N // 4
135+
regI = m & (n1 < N // 2) & (n2 < N // 2)
136+
regII = m & (n1 <= n2) & (n2 >= N // 2)
137+
regIII = m & (n2 < n1) & (n1 >= N // 2)
138+
139+
_regI = m & (n1 >= N // 2) & (n2 >= N // 2)
140+
_regII = m & (n1 > n2) & (n2 < N // 2)
141+
_regIII = m & (n2 >= n1) & (n1 < N // 2)
142+
143+
shifted[_regI.T] = X[regI.T]
144+
shifted[_regII.T] = X[regII.T]
145+
shifted[_regIII.T] = X[regIII.T]
146+
147+
return shifted
148+
149+
150+
def ifftshift(X):
151+
N = X.shape[0]
152+
n1, n2 = X.indices
153+
m = hsupport(N, X.pattern).astype(bool)
154+
shifted = HexArray(np.zeros_like(X), X.pattern)
155+
156+
if X.pattern == "oblique":
157+
_regI = (n1 < N // 2) & (n2 < N // 2)
158+
_regII = m & (n1 < n2) & (n2 >= N // 2)
159+
_regIII = m & (n2 <= n1) & (n1 >= N // 2)
160+
161+
regI = (n1 >= N // 2) & (n2 >= N // 2)
162+
regII = m & (n1 >= n2) & (n2 < N // 2)
163+
regIII = m & (n2 > n1) & (n1 < N // 2)
164+
165+
shifted[_regI] = X[regI]
166+
shifted[_regII] = X[regII]
167+
shifted[_regIII] = X[regIII]
168+
169+
elif X.pattern == "offset":
170+
m = m.T
171+
n2 = n2 - N // 4
172+
regI = m & (n1 < N // 2) & (n2 < N // 2)
173+
regII = m & (n1 <= n2) & (n2 >= N // 2)
174+
regIII = m & (n2 < n1) & (n1 >= N // 2)
175+
176+
_regI = m & (n1 >= N // 2) & (n2 >= N // 2)
177+
_regII = m & (n1 > n2) & (n2 < N // 2)
178+
_regIII = m & (n2 >= n1) & (n1 < N // 2)
179+
180+
shifted[regI.T] = X[_regI.T]
181+
shifted[regII.T] = X[_regII.T]
182+
shifted[regIII.T] = X[_regIII.T]
183+
184+
return shifted
185+
186+
187+
def filter_shift(x, periodicity="rect"):
115188
"""
116-
Shift the quadrants of a HexArray to move the origin to/from
189+
Shift the quadrants/thirds of a HexArray to move the origin to/from
117190
the center of the grid. Useful if a filter kernel is easier to define
118191
the origin at the center of the grid.
119192
"""
120-
if not isinstance(x, HexArray):
121-
x = HexArray(x)
193+
194+
if periodicity == "hex":
195+
return ifftshift(x)
122196

123197
N1, N2 = x.shape
124198
out = HexArray(np.zeros_like(x), x.pattern)

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hexfft import HexArray, fft, ifft, FFT, fftshift, ifftshift
1+
from hexfft import HexArray, fft, ifft, FFT
22
from hexfft.array import rect_shift, rect_unshift
33
import numpy as np
44
import pytest

tests/test_hexfft.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hexfft import fftshift, ifftshift, HexArray
1+
from hexfft import fft, ifft, FFT, HexArray
22
from hexfft.hexfft import (
33
_hexdft_pgram,
44
_hexidft_pgram,
@@ -8,15 +8,14 @@
88
mersereau_ifft,
99
rect_fft,
1010
rect_ifft,
11-
FFT,
12-
fft,
13-
ifft,
1411
)
1512
from hexfft.utils import (
1613
hsupport,
1714
pgram_to_hex,
1815
nice_test_function,
1916
hex_to_pgram,
17+
fftshift,
18+
ifftshift,
2019
)
2120
from hexfft.array import rect_shift, rect_unshift
2221
from hexfft.reference import (

0 commit comments

Comments
 (0)