-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Helene Toubin
committed
Jun 9, 2020
1 parent
4374ee2
commit 7c87206
Showing
16 changed files
with
467 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
from SciDataTool.Functions import AxisError, NormError, UnitError | ||
from SciDataTool.Functions.fft_functions import comp_fft | ||
from SciDataTool.Functions.symmetries import rebuild_symmetries | ||
from SciDataTool.Functions.conversions import convert, to_dB, to_dBA | ||
from SciDataTool.Functions.parser import read_input_strings | ||
from SciDataTool.Functions.interpolations import get_common_base, get_interpolation | ||
from numpy import ( | ||
squeeze, | ||
take, | ||
apply_along_axis, | ||
argsort, | ||
negative, | ||
meshgrid, | ||
abs as np_abs, | ||
) | ||
|
||
|
||
def get_harmonics(self, N_harm, *args, unit="SI", is_norm=False, is_flat=False): | ||
"""Returns the complex Fourier Transform of the field, using conversions and symmetries if needed. | ||
Parameters | ||
---------- | ||
self: Data | ||
a Data object | ||
N_harm: int | ||
Number of largest harmonics to be extracted | ||
args: list | ||
Axes names, ranges and units | ||
unit: str | ||
Unit demanded by the user ("SI" by default) | ||
is_norm: bool | ||
Boolean indicating if the field must be normalized (False by default) | ||
is_flat: bool | ||
Boolean if the output data remains flattened (for 2D cases) | ||
Returns | ||
------- | ||
list of 1Darray of axes values, ndarray of magnitude of FT | ||
""" | ||
if len(args) == 1 and type(args[0]) == tuple: | ||
args = args[0] # if called from another script with *args | ||
return_dict = self.get_magnitude_along(args, unit=unit, is_norm=is_norm) | ||
values = return_dict[self.symbol] | ||
|
||
# 2D case | ||
if "freqs" in return_dict and "wavenumber" in return_dict: | ||
r = return_dict["wavenumber"] | ||
f = return_dict["freqs"] | ||
# Flatten the data | ||
values_flat = values.flatten() | ||
R, F = meshgrid(r, f) | ||
f = F.flatten() | ||
r = R.flatten() | ||
# Get the N_harm largest peaks | ||
indices = argsort(negative(values_flat)) | ||
indices = indices[:N_harm] | ||
values = values_flat[indices] | ||
f = f[indices] | ||
r = r[indices] | ||
if len(values.shape) == 2 and not is_flat: | ||
f.reshape((N_harm, N_harm)) | ||
r.reshape((N_harm, N_harm)) | ||
values.reshape((N_harm, N_harm)) | ||
return_dict["freqs"] = f | ||
return_dict["wavenumber"] = r | ||
return_dict[self.symbol] = values | ||
|
||
# 1D cases | ||
elif "freqs" in return_dict: | ||
f = return_dict["freqs"] | ||
indices = argsort(negative(values)) | ||
indices = indices[:N_harm] | ||
f = f[indices] | ||
values = values[indices] | ||
return_dict["freqs"] = f | ||
return_dict[self.symbol] = values | ||
elif "wavenumber" in return_dict: | ||
r = return_dict["wavenumber"] | ||
indices = argsort(negative(values)) | ||
indices = indices[:N_harm] | ||
r = r[indices] | ||
values = values[indices] | ||
return_dict["wavenumber"] = r | ||
return_dict[self.symbol] = values | ||
|
||
return return_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
from SciDataTool.Functions import NormError | ||
from SciDataTool.Functions.conversions import convert | ||
from numpy import angle as np_angle | ||
|
||
|
||
def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]): | ||
"""Returns the ndarray of the magnitude of the FT, using conversions and symmetries if needed. | ||
Parameters | ||
---------- | ||
self: Data | ||
a Data object | ||
*args: list of strings | ||
List of axes requested by the user, their units and values (optional) | ||
unit: str | ||
Unit requested by the user ("SI" by default) | ||
is_norm: bool | ||
Boolean indicating if the field must be normalized (False by default) | ||
axis_data: list | ||
list of ndarray corresponding to user-input data | ||
Returns | ||
------- | ||
list of 1Darray of axes values, ndarray of magnitude values | ||
""" | ||
if len(args) == 1 and type(args[0]) == tuple: | ||
args = args[0] # if called from another script with *args | ||
return_dict = self.get_along(args, axis_data=axis_data) | ||
values = return_dict[self.symbol] | ||
# Compute magnitude | ||
values = np_angle(values) | ||
# Convert into right unit (apart because of degree conversion) | ||
if unit == self.unit or unit == "SI": | ||
if is_norm: | ||
try: | ||
values = values / self.normalizations.get("ref") | ||
except: | ||
raise NormError( | ||
"ERROR: Reference value not specified for normalization" | ||
) | ||
elif unit == "°": | ||
values = convert(values, "rad", "°") | ||
elif unit in self.normalizations: | ||
values = values / self.normalizations.get(unit) | ||
else: | ||
values = convert(values, self.unit, unit) | ||
return_dict[self.symbol] = values | ||
return return_dict |
Oops, something went wrong.