Skip to content

Commit

Permalink
[BC] Not divide by 2 in inverse fft
Browse files Browse the repository at this point in the history
  • Loading branch information
Helene Toubin committed Jul 8, 2020
1 parent 789debd commit 3779caa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
19 changes: 12 additions & 7 deletions SciDataTool/Functions/fft_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from numpy import prod, mean, hanning, linspace, argmin, abs, where, isclose
from numpy.fft import fft, rfftn, ifftn, fftn, fftshift, ifftshift, rfft2
from numpy.fft import fft, ifft, rfftn, ifftn, fftn, fftshift, ifftshift, rfft2
from numpy import (
pi,
zeros,
Expand Down Expand Up @@ -143,10 +143,15 @@ def comp_fft(values):
-------
Complex Fourier Transform
"""
values_FT = fftn(values)
values_shape = values_FT.shape
values_FT[tuple(zeros(len(values_shape), dtype=int))] *= 0.5
values_FT = 2.0 * fftshift(values_FT) / float(prod(values_shape))
# values_FT = fftn(values, axes=axes)
# values_shape = values_FT.shape
# size = len(values_shape)
# print(values_shape)
# values_FT[tuple([0 if i in axes else None for i in range(size)])] *= 0.5
# values_FT = 2.0 * fftshift(values_FT, axes=axes) / float(prod([shape for i,shape in enumerate(values_shape) if i in axes]))
values_FT = fft(values)
values_FT[0] *= 0.5
values_FT = 2.0 * fftshift(values_FT) / len(values)
return values_FT


Expand All @@ -160,8 +165,8 @@ def comp_ifft(values):
-------
ndarray of the field
"""
values_shape = values.shape
values = ifftn(ifftshift(values)) * float(prod(values_shape)) / 2.0

values = ifft(ifftshift(values)) * len(values)
return values.real


Expand Down
14 changes: 7 additions & 7 deletions SciDataTool/Methods/DataND/transform.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from SciDataTool.Functions.fft_functions import comp_fft, comp_ifft
from SciDataTool.Functions.conversions import rphiz_to_xyz_field, xyz_to_rphiz_field
from numpy import apply_along_axis
from numpy import apply_along_axis, apply_over_axes

def transform(self, values, axes_list):
"""Returns the values of the field transformed or converted.
Expand All @@ -19,16 +19,16 @@ def transform(self, values, axes_list):
values of the transformed field
"""

is_fft = True
#is_fft = True
#values = comp_fft(values, axes=[axis_requested.index for axis_requested in axes_list if axis_requested.transform == "fft"])
for axis_requested in axes_list:

# Transform (fft, coordinates, etc)
if axis_requested.transform == "fft" and is_fft:
if axis_requested.transform == "fft":
values = apply_along_axis(comp_fft, axis_requested.index, values)
is_fft = False
elif axis_requested.transform == "ifft" and is_fft:
elif axis_requested.transform == "ifft":
values = apply_along_axis(comp_ifft, axis_requested.index, values)
is_fft = False
elif axis_requested.transform == "pol2cart":
if axis_requested.transform == "pol2cart":
values = apply_along_axis(rphiz_to_xyz_field, axis_requested.index, values, axis_requested.values[:,1])
elif axis_requested.transform == "cart2pol":
values = apply_along_axis(xyz_to_rphiz_field, axis_requested.index, values, axis_requested.values[:,1])
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

setuptools.setup(
name="SciDataTool",
version="1.0.3",
version="1.0.5",
author="Helene Toubin",
author_email="[email protected]",
description="Scientific Data Tool",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Eomys/SciDataTool",
download_url="https://github.com/Eomys/SciDataTool/archive/1.0.3.tar.gz",
download_url="https://github.com/Eomys/SciDataTool/archive/1.0.5.tar.gz",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit 3779caa

Please sign in to comment.