Skip to content

Commit

Permalink
[BC] Slicing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed May 13, 2020
1 parent bb3ab37 commit 7d4947e
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 197 deletions.
6 changes: 1 addition & 5 deletions SciDataTool/Methods/DataFreq/get_FT_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
for index, axis in enumerate(self.axes):
if axis.name == axis_name:
is_match = True
break
if not is_match:
sys.stderr.write(
"WARNING: Requested axis ["
Expand All @@ -46,7 +45,7 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
)
axes_list.remove(axis_requested)
# Extract the requested axes (symmetries + unit)
for i, axis_requested in enumerate(axes_list):
for axis_requested in axes_list:
if axis_requested[3] == "values":
# Get original values of the axis
axis_requested.append(
Expand All @@ -73,7 +72,6 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
values = rebuild_symmetries(
values, index, self.symmetries.get(axis.name)
)
break
# Extract the slices of the field
for index, axis in enumerate(self.axes):
is_match = False
Expand All @@ -82,7 +80,6 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
is_match = True
if axis_requested[3] == "indices":
values = take(values, axis_requested[4], axis=index)
break
if not is_match: # Axis was not specified -> take slice at the first value
values = take(values, [0], axis=index)
# Eliminate dimensions=1
Expand All @@ -98,7 +95,6 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
break
# Eliminate dimensions=1
values = squeeze(values)
# Convert into right unit
Expand Down
35 changes: 12 additions & 23 deletions SciDataTool/Methods/DataFreq/get_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
args = args[0] # if called from another script with *args
axes_list = read_input_strings(args, axis_data)
# Extract the requested axes (symmetries + unit)
for i, axis_requested in enumerate(axes_list):
for axis_requested in axes_list:
if axis_requested[3] == "values":
# Get original values of the axis
axis_requested.append(self.get_axis(axis_requested[0] + axis_requested[1]))
Expand Down Expand Up @@ -61,7 +61,6 @@ def get_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
for index, axis in enumerate(self.axes):
if axis.name == axis_name:
is_match = True
break
if not is_match:
sys.stderr.write(
"WARNING: Requested axis ["
Expand All @@ -77,7 +76,6 @@ def get_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
values = rebuild_symmetries(
values, index, self.symmetries.get(axis.name)
)
break
# Perform Inverse Fourier Transform
values = comp_ifft(values)
# Extract the slices of the field (single values)
Expand All @@ -88,14 +86,10 @@ def get_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
is_match = True
if axis_requested[3] == "indices" and axis_requested[2] == "single":
values = take(values, axis_requested[4], axis=index)
break
if not is_match: # Axis was not specified -> take slice at the first value
values = take(values, [0], axis=index)
# Eliminate dimensions=1
values = squeeze(values)
# Interpolate over axis values (single values)
index = 0
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
Expand All @@ -109,23 +103,20 @@ def get_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
index += 1
break
# Eliminate dimensions=1
values = squeeze(values)
# Extract slices again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
if axis.name == axis_requested[0]:
if axis_requested[2] == "indices" and axis_requested[2] == "interval":
values = take(values, axis_requested[4], axis=index)
index += 1
break
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[2] == "indices"
and axis_requested[2] == "interval"
):
values = take(values, axis_requested[4], axis=index)
# Interpolate over axis values again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[3] == "values"
Expand All @@ -138,8 +129,6 @@ def get_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
index += 1
break
# Convert into right unit
if unit == self.unit or unit == "SI":
if is_norm:
Expand Down
35 changes: 13 additions & 22 deletions SciDataTool/Methods/DataFreq/get_magnitude_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_magnitude_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axes_list = read_input_strings(args, axis_data)
is_FTslice = False
# Extract the requested axes (symmetries + unit)
for i, axis_requested in enumerate(axes_list):
for axis_requested in axes_list:
if axis_requested[3] == "values":
# Get original values of the axis
axis_requested.append(
Expand Down Expand Up @@ -66,7 +66,6 @@ def get_magnitude_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
for index, axis in enumerate(self.axes):
if axis.name == axis_name:
is_match = True
break
if not is_match:
sys.stderr.write(
"WARNING: Requested axis ["
Expand All @@ -82,7 +81,6 @@ def get_magnitude_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
values = rebuild_symmetries(
values, index, self.symmetries.get(axis.name)
)
break
# If a slice at a given time or angle is requested, perform inverse FT, then slice, then FT
if is_FTslice:
values = comp_ifft(values)
Expand All @@ -94,11 +92,8 @@ def get_magnitude_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
is_match = True
if axis_requested[3] == "indices" and axis_requested[2] == "single":
values = take(values, axis_requested[4], axis=index)
break
if not is_match: # Axis was not specified -> take slice at the first value
values = take(values, [0], axis=index)
# Eliminate dimensions=1
values = squeeze(values)
# Interpolate over axis values (single values)
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
Expand All @@ -114,27 +109,23 @@ def get_magnitude_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
break
# Eliminate dimensions=1
values = squeeze(values)
# If a slice at a given time or angle is requested, perform inverse FT, then slice, then FT
if is_FTslice:
values = np_abs(comp_fft(values))
else:
values = np_abs(values)
# Extract slices again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
if axis.name == axis_requested[0]:
if axis_requested[2] == "indices" and axis_requested[2] == "interval":
values = take(values, axis_requested[4], axis=index)
index += 1
break
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[2] == "indices"
and axis_requested[2] == "interval"
):
values = take(values, axis_requested[4], axis=index)
# Interpolate over axis values again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[3] == "values"
Expand All @@ -147,8 +138,8 @@ def get_magnitude_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
index += 1
break
# Eliminate dimensions=1
values = squeeze(values)
# Convert into right unit
if unit == self.unit or unit == "SI":
if is_norm:
Expand Down
35 changes: 13 additions & 22 deletions SciDataTool/Methods/DataFreq/get_phase_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axes_list = read_input_strings(args, axis_data)
is_FTslice = False
# Extract the requested axes (symmetries + unit)
for i, axis_requested in enumerate(axes_list):
for axis_requested in axes_list:
if axis_requested[3] == "values":
# Get original values of the axis
axis_requested.append(
Expand Down Expand Up @@ -66,7 +66,6 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
for index, axis in enumerate(self.axes):
if axis.name == axis_name:
is_match = True
break
if not is_match:
sys.stderr.write(
"WARNING: Requested axis ["
Expand All @@ -82,7 +81,6 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
values = rebuild_symmetries(
values, index, self.symmetries.get(axis.name)
)
break
# If a slice at a given time or angle is requested, perform inverse FT, then slice, then FT
if is_FTslice:
values = comp_ifft(values)
Expand All @@ -94,11 +92,8 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
is_match = True
if axis_requested[3] == "indices" and axis_requested[2] == "single":
values = take(values, axis_requested[4], axis=index)
break
if not is_match: # Axis was not specified -> take slice at the first value
values = take(values, [0], axis=index)
# Eliminate dimensions=1
values = squeeze(values)
# Interpolate over axis values (single values)
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
Expand All @@ -114,9 +109,6 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
break
# Eliminate dimensions=1
values = squeeze(values)
# If a slice at a given time or angle is requested, perform inverse FT, then slice, then FT
if is_FTslice:
if unit == "°":
Expand All @@ -129,18 +121,17 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
else:
values = np_angle(values)
# Extract slices again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
if axis.name == axis_requested[0]:
if axis_requested[2] == "indices" and axis_requested[2] == "interval":
values = take(values, axis_requested[4], axis=index)
index += 1
break
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[2] == "indices"
and axis_requested[2] == "interval"
):
values = take(values, axis_requested[4], axis=index)
# Interpolate over axis values again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[3] == "values"
Expand All @@ -153,8 +144,8 @@ def get_phase_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
index += 1
break
# Eliminate dimensions=1
values = squeeze(values)
# Convert into right unit
if unit == self.unit or unit == "SI" or unit == "°":
if is_norm:
Expand Down
37 changes: 11 additions & 26 deletions SciDataTool/Methods/DataTime/get_FT_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
args = args[0] # if called from another script with *args
axes_list = read_input_strings(args, axis_data)
# Extract the requested axes (symmetries + unit)
for i, axis_requested in enumerate(axes_list):
for axis_requested in axes_list:
if axis_requested[3] == "values":
# Get original values of the axis
axis_requested.append(
Expand Down Expand Up @@ -63,7 +63,6 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
for index, axis in enumerate(self.axes):
if axis.name == axis_name:
is_match = True
break
if not is_match:
sys.stderr.write(
"WARNING: Requested axis ["
Expand All @@ -79,7 +78,6 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
values = rebuild_symmetries(
values, index, self.symmetries.get(axis.name)
)
break
# Extract the slices of the field (single values)
for index, axis in enumerate(self.axes):
is_match = False
Expand All @@ -88,14 +86,10 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
is_match = True
if axis_requested[3] == "indices" and axis_requested[2] == "single":
values = take(values, axis_requested[4], axis=index)
break
if not is_match: # Axis was not specified -> take slice at the first value
values = take(values, [0], axis=index)
# Eliminate dimensions=1
values = squeeze(values)
# Interpolate over axis values (single values)
index = 0
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
Expand All @@ -109,39 +103,30 @@ def get_FT_along(self, *args, unit="SI", is_norm=False, axis_data=[]):
axis_requested[5],
axis_requested[4],
)
index += 1
break
# Eliminate dimensions=1
values = squeeze(values)
# Perform Fourier Transform
values = comp_fft(values)
# Extract slices again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if axis.name == axis_requested[0]:
if axis_requested[2] == "indices" and axis_requested[2] == "interval":
values = take(values, axis_requested[4], axis=index)
index += 1
break
# Interpolate over axis values again (intervals)
index = 0
for axis_requested in axes_list:
for axis in self.axes:
for index, axis in enumerate(self.axes):
for axis_requested in axes_list:
if (
axis.name == axis_requested[0]
and axis_requested[3] == "values"
and axis_requested[2] == "interval"
):
and axis_requested[3] == "values" and axis_requested[2] == "interval"
):
values = apply_along_axis(
get_interpolation,
index,
values,
axis_requested[5],
axis_requested[4],
)
index += 1
break
)
# Eliminate dimensions=1
values = squeeze(values)
# Convert into right unit
if unit == self.unit or unit == "SI":
if is_norm:
Expand Down
Loading

0 comments on commit 7d4947e

Please sign in to comment.