Skip to content

Commit

Permalink
Merge pull request #69 from EOMYS-Public/master
Browse files Browse the repository at this point in the history
Various bug corrections
  • Loading branch information
helene-t authored Oct 26, 2021
2 parents f3c74d2 + 425e3b5 commit 67ae75f
Show file tree
Hide file tree
Showing 74 changed files with 545 additions and 370 deletions.
6 changes: 4 additions & 2 deletions SciDataTool/Classes/Class_Dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
"get_axes",
"get_data_along",
"get_field",
"get_freqs",
"get_harmonics",
"get_magnitude_along",
"get_phase_along",
Expand All @@ -258,8 +259,8 @@
"plot_3D_Data",
"rebuild_symmetries",
"set_Ftparameters",
"orthogonal_mp",
"summing"
"summing",
"orthogonal_mp"
],
"mother": "Data",
"name": "DataND",
Expand Down Expand Up @@ -777,6 +778,7 @@
"get_mag_xyz_along",
"get_rphiz_along",
"get_xyz_along",
"get_vectorfield_along",
"plot_2D_Data",
"plot_2D_Data_Animated",
"plot_3D_Data",
Expand Down
40 changes: 27 additions & 13 deletions SciDataTool/Classes/DataND.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
except ImportError as error:
get_field = error

try:
from ..Methods.DataND.get_freqs import get_freqs
except ImportError as error:
get_freqs = error

try:
from ..Methods.DataND.get_harmonics import get_harmonics
except ImportError as error:
Expand Down Expand Up @@ -136,14 +141,14 @@
set_Ftparameters = error

try:
from ..Methods.DataND.orthogonal_mp import orthogonal_mp
from ..Methods.DataND.summing import summing
except ImportError as error:
orthogonal_mp = error
summing = error

try:
from ..Methods.DataND.summing import summing
from ..Methods.DataND.orthogonal_mp import orthogonal_mp
except ImportError as error:
summing = error
orthogonal_mp = error


from numpy import array, array_equal
Expand Down Expand Up @@ -300,6 +305,15 @@ class DataND(Data):
)
else:
get_field = get_field
# cf Methods.DataND.get_freqs
if isinstance(get_freqs, ImportError):
get_freqs = property(
fget=lambda x: raise_(
ImportError("Can't use DataND method get_freqs: " + str(get_freqs))
)
)
else:
get_freqs = get_freqs
# cf Methods.DataND.get_harmonics
if isinstance(get_harmonics, ImportError):
get_harmonics = property(
Expand Down Expand Up @@ -409,6 +423,15 @@ class DataND(Data):
)
else:
set_Ftparameters = set_Ftparameters
# cf Methods.DataND.summing
if isinstance(summing, ImportError):
summing = property(
fget=lambda x: raise_(
ImportError("Can't use DataND method summing: " + str(summing))
)
)
else:
summing = summing
# cf Methods.DataND.orthogonal_mp
if isinstance(orthogonal_mp, ImportError):
orthogonal_mp = property(
Expand All @@ -420,15 +443,6 @@ class DataND(Data):
)
else:
orthogonal_mp = orthogonal_mp
# cf Methods.DataND.summing
if isinstance(summing, ImportError):
summing = property(
fget=lambda x: raise_(
ImportError("Can't use DataND method summing: " + str(summing))
)
)
else:
summing = summing
# save and copy methods are available in all object
save = save
copy = copy
Expand Down
17 changes: 17 additions & 0 deletions SciDataTool/Classes/VectorField.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
except ImportError as error:
get_xyz_along = error

try:
from ..Methods.VectorField.get_vectorfield_along import get_vectorfield_along
except ImportError as error:
get_vectorfield_along = error

try:
from ..Methods.VectorField.plot_2D_Data import plot_2D_Data
except ImportError as error:
Expand Down Expand Up @@ -186,6 +191,18 @@ class VectorField(FrozenClass):
)
else:
get_xyz_along = get_xyz_along
# cf Methods.VectorField.get_vectorfield_along
if isinstance(get_vectorfield_along, ImportError):
get_vectorfield_along = property(
fget=lambda x: raise_(
ImportError(
"Can't use VectorField method get_vectorfield_along: "
+ str(get_vectorfield_along)
)
)
)
else:
get_vectorfield_along = get_vectorfield_along
# cf Methods.VectorField.plot_2D_Data
if isinstance(plot_2D_Data, ImportError):
plot_2D_Data = property(
Expand Down
2 changes: 0 additions & 2 deletions SciDataTool/Classes/_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from numpy import array, empty, int32, squeeze, expand_dims


Expand Down
1 change: 0 additions & 1 deletion SciDataTool/Classes/_frozen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from numpy import array_equal, ndarray


Expand Down
1 change: 0 additions & 1 deletion SciDataTool/Functions/Plot/init_fig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from matplotlib.pyplot import subplots
import io
import pickle
Expand Down
7 changes: 0 additions & 7 deletions SciDataTool/Functions/Plot/plot_2D.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
# -*- coding: utf-8 -*-

from itertools import repeat

import matplotlib.pyplot as plt

from numpy import (
ceil,
argmin,
abs,
arange,
squeeze,
split,
ndarray,
cumsum,
zeros,
shape,
max as np_max,
)

from SciDataTool.Functions.Plot.init_fig import init_fig
Expand Down
2 changes: 0 additions & 2 deletions SciDataTool/Functions/Plot/plot_3D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from numpy import min as np_min, max as np_max, abs as np_abs, log10

import matplotlib.pyplot as plt
Expand Down
2 changes: 0 additions & 2 deletions SciDataTool/Functions/Plot/plot_4D.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from numpy import log10, abs as np_abs, max as np_max, NaN, zeros_like
import matplotlib.pyplot as plt

Expand Down
1 change: 0 additions & 1 deletion SciDataTool/Functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
class FTError(Exception):
"""Raised when there is an error within the Fourier Transform methods (Data Object)"""

Expand Down
43 changes: 31 additions & 12 deletions SciDataTool/Functions/conversions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from SciDataTool.Functions import UnitError
from SciDataTool.Functions.fft_functions import (
comp_fft_freqs,
Expand Down Expand Up @@ -28,6 +27,7 @@
take,
zeros,
floor,
ones,
)

# List of the unit symbols, their normalizing value and their dimensions "MLTTempAngleCurrent"
Expand Down Expand Up @@ -102,16 +102,19 @@ def get_dim_prefix(unit_str):
if prefix_str in unit_prefixes.keys():
prefix = (unit_prefixes.get(prefix_str) * key[1]) ** p
else:
raise UnitError("ERROR: Prefix " + prefix_str + " unknown")
raise UnitError("Prefix " + prefix_str + " unknown")
break
if not dim:
raise UnitError("ERROR: Unit " + unit_str + " unknown")
raise UnitError("Unit " + unit_str + " unknown")
return (dim, prefix)


def get_unit_derivate(unit_str, axis_unit):
unit_str = unit_str.replace("*", "").replace(" ", "").replace("^", "")
if axis_unit == "Hz":
axis_unit = "s"
if axis_unit == "rad":
axis_unit = "m"
p = 0
if "/" in unit_str:
unit_num = unit_str.split("/")[0]
Expand Down Expand Up @@ -153,8 +156,11 @@ def get_unit_derivate(unit_str, axis_unit):


def get_unit_integrate(unit_str, axis_unit):
unit_str = unit_str.replace("*", "").replace(" ", "").replace("^", "")
if axis_unit == "Hz":
axis_unit = "s"
if axis_unit == "rad":
axis_unit = "m"
p = 0
if "/" in unit_str:
unit_num = unit_str.split("/")[0]
Expand Down Expand Up @@ -248,7 +254,7 @@ def convert(values, unit1, unit2):
dim2 = [i - j for i, j in zip(dim2_num, dim2_denom)]
if dim1 != dim2:
raise UnitError(
"ERROR: Units " + unit1_save + " and " + unit2_save + " do not match"
"Units " + unit1_save + " and " + unit2_save + " do not match"
)
else:
return (
Expand Down Expand Up @@ -281,7 +287,7 @@ def to_dB(values, unit, ref_value=1.0):
try:
convert(values, unit, "W")
values_dB = 10.0 * where(mask, log10(values / ref_value, where=mask), 0)
except:
except Exception:
values_dB = 20.0 * where(mask, log10(values / ref_value, where=mask), 0)
return values_dB

Expand Down Expand Up @@ -407,11 +413,8 @@ def dB_to_dBA(values, freqs, noct=None):
)
Aweight = 2.0 + 20.0 * log10(RA)
Aweight[isnan(Aweight)] = -100 # replacing NaN by -100 dB
try:
values += Aweight
return values
except:
raise UnitError("ERROR: dBA conversion only available for 1D fft")


def to_noct(values, freqs, noct=3):
Expand Down Expand Up @@ -607,8 +610,16 @@ def cart2pol(field_x, field_y, phi):
cos_phi = cos(phi)
sin_phi = sin(phi)

field_r = cos_phi * field_x + sin_phi * field_y
field_phi = -sin_phi * field_x + cos_phi * field_y
dim_array = ones((1, field_x.ndim), int).ravel()
dim_array[1] = -1

# Reshape b with dim_array and perform elementwise multiplication with
# broadcasting along the singleton dimensions for the final output
cos_phi_reshaped = cos_phi.reshape(dim_array)
sin_phi_reshaped = sin_phi.reshape(dim_array)

field_r = field_x * cos_phi_reshaped + field_y * sin_phi_reshaped
field_phi = -field_x * sin_phi_reshaped + field_y * cos_phi_reshaped

return (field_r, field_phi)

Expand All @@ -617,7 +628,15 @@ def pol2cart(field_r, field_phi, phi):
cos_phi = cos(phi)
sin_phi = sin(phi)

field_x = cos_phi * field_r - sin_phi * field_phi
field_y = sin_phi * field_r + cos_phi * field_phi
dim_array = ones((1, field_r.ndim), int).ravel()
dim_array[1] = -1

# Reshape b with dim_array and perform elementwise multiplication with
# broadcasting along the singleton dimensions for the final output
cos_phi_reshaped = cos_phi.reshape(dim_array)
sin_phi_reshaped = sin_phi.reshape(dim_array)

field_x = field_r * cos_phi_reshaped - field_phi * sin_phi_reshaped
field_y = field_r * sin_phi_reshaped + field_phi * cos_phi_reshaped

return (field_x, field_y)
4 changes: 2 additions & 2 deletions SciDataTool/Functions/derivation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def integrate(values, ax_val, index, Nper, is_aper, is_phys, is_mean=False):
values_full[-1, ...] = values[0, ...]
# Integrate along axis
values = Nper * np.trapz(values_full, x=ax_full, axis=0)
# Get N first values and swap axes back to origin
values = np.swapaxes(values, 0, index - 1)
# Readd first dim and swap axes back to origin
values = np.swapaxes(values[None, ...], 0, index)

if is_mean:
# Taking mean value by dividing by integration interval
Expand Down
Loading

0 comments on commit 67ae75f

Please sign in to comment.