Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t authored Jul 8, 2020
2 parents a644442 + 6e44b31 commit 273c67d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 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
39 changes: 30 additions & 9 deletions SciDataTool/Methods/DataFreq/freq_to_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ def freq_to_time(self):
module = __import__("SciDataTool.Classes.DataTime", fromlist=["DataTime"])
DataTime = getattr(module, "DataTime")

axes_str = [axis.name for axis in self.axes]
axes_str = ["time" if axis_name == "freqs" else axis_name for axis_name in axes_str]
axes_str = ["angle" if axis_name == "wavenumber" else axis_name for axis_name in axes_str]

axes_str = []
for i, axis in enumerate(self.axes):
if axis.is_components:
axis_str = axis.name + str(list(range(len(axis.values))))
elif axis.name == "freqs":
axis_str = "time"
elif axis.name == "wavenumber":
axis_str = "angle"
else:
axis_str = axis.name
axes_str.append(axis_str)
if axes_str == [axis.name for axis in self.axes]:
raise AxisError(
"ERROR: No available axis is compatible with fft (should be time or angle)"
Expand All @@ -29,14 +36,28 @@ def freq_to_time(self):
results = self.get_along(*axes_str)
values = results.pop(self.symbol)
Axes = []
for axis in results.keys():
if next((ax.is_components for ax in self.axes if ax.name==axis),False): # components axis
for axis in self.axes:
if axis.is_components: # components axis
name = axis.name
is_components = True
axis_values = next((ax.values for ax in self.axes if ax.name==axis))
axis_values = axis.values
unit = "SI"
elif axis.name == "freqs":
name = "time"
is_components = False
axis_values = results["time"]
unit = "s"
elif axis.name == "wavenumber":
name = "angle"
is_components = False
axis_values = results["angle"]
unit = "rad"
else:
name = axis.name
is_components = False
axis_values = results[axis]
Axes.append(Data1D(name=axis, values=axis_values, is_components=is_components))
axis_values = results[axis.name]
unit = axis.unit
Axes.append(Data1D(name=name, unit=unit, values=axis_values, is_components=is_components))
return DataTime(
name=self.name,
unit=self.unit,
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.4",
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.4.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 273c67d

Please sign in to comment.