diff --git a/boututils/calculus.py b/boututils/calculus.py index c94be47..3cdb233 100644 --- a/boututils/calculus.py +++ b/boututils/calculus.py @@ -44,18 +44,20 @@ def deriv(*args, **kwargs): n = var.size if periodic: + # assume uniform grid + dx = x[1] - x[0] # Use FFTs to take derivatives f = rfft(var) f[0] = 0.0 # Zero constant term if n % 2 == 0: # Even n for i in arange(1, old_div(n, 2)): - f[i] *= 2.0j * pi * float(i) / float(n) + f[i] *= 2.0j * pi * float(i) / (float(n)*dx) f[-1] = 0.0 # Nothing from Nyquist frequency else: # Odd n for i in arange(1, old_div((n - 1), 2) + 1): - f[i] *= 2.0j * pi * float(i) / float(n) + f[i] *= 2.0j * pi * float(i) / (float(n)*dx) return irfft(f) else: # Non-periodic function