Skip to content

Commit 31bd01c

Browse files
CopilotSierd
andcommitted
Fix frequency array alignment in FFT shear calculation
The kx and ky frequency arrays were misaligned with the FFT output. The code was creating frequency arrays with fftfreq(n+1)[1:] which skips the DC component, but the FFT includes all frequencies. This caused incorrect mapping between frequencies and FFT coefficients, leading to wrong shear perturbations. Fixed by using fftfreq(n) which properly matches the FFT output dimensions and includes the DC component at the correct index. Co-authored-by: Sierd <14054272+Sierd@users.noreply.github.com>
1 parent 1992889 commit 31bd01c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

aeolis/shear.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ def compute_shear(self, u0, nfilter=(1., 2.)):
544544
return
545545

546546
ny, nx = gc['z'].shape
547-
kx, ky = np.meshgrid(2. * np.pi * np.fft.fftfreq(nx+1, gc['dx'])[1:],
548-
2. * np.pi * np.fft.fftfreq(ny+1, gc['dy'])[1:])
547+
kx, ky = np.meshgrid(2. * np.pi * np.fft.fftfreq(nx, gc['dx']),
548+
2. * np.pi * np.fft.fftfreq(ny, gc['dy']))
549549

550550
hs = np.fft.fft2(gc['z'])
551551
hs = self.filter_highfrequenies(kx, ky, hs, nfilter)

0 commit comments

Comments
 (0)