Skip to content

Commit

Permalink
Merge pull request #85 from EOMYS-Public/Filter
Browse files Browse the repository at this point in the history
New filter feature
  • Loading branch information
helene-t authored Feb 8, 2022
2 parents df2df2d + 43e474f commit 8df72d8
Show file tree
Hide file tree
Showing 21 changed files with 1,033 additions and 78 deletions.
31 changes: 30 additions & 1 deletion SciDataTool/Classes/Class_Dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
"get_axis_periodic",
"has_period",
"get_periodicity",
"to_linspace"
"to_linspace",
"get_filter",
"check_filter"
],
"mother": "Data",
"name": "Data1D",
Expand Down Expand Up @@ -121,6 +123,33 @@
"type": "bool",
"unit": "",
"value": false
},
{
"desc": "Character used to separate attributes in string case (e.g. \"r=0, stator, radial\")",
"max": "",
"min": "",
"name": "delimiter",
"type": "str",
"unit": "",
"value": "None"
},
{
"desc": "List of indices to use to sort axis",
"max": "",
"min": "",
"name": "sort_indices",
"type": "list",
"unit": "",
"value": null
},
{
"desc": "Dict of filter keys",
"max": "",
"min": "",
"name": "filter",
"type": "dict",
"unit": "",
"value": null
}
]
},
Expand Down
135 changes: 135 additions & 0 deletions SciDataTool/Classes/Data1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
except ImportError as error:
to_linspace = error

try:
from ..Methods.Data1D.get_filter import get_filter
except ImportError as error:
get_filter = error

try:
from ..Methods.Data1D.check_filter import check_filter
except ImportError as error:
check_filter = error


from numpy import array, array_equal
from numpy import isnan
Expand Down Expand Up @@ -117,6 +127,26 @@ class Data1D(Data):
)
else:
to_linspace = to_linspace
# cf Methods.Data1D.get_filter
if isinstance(get_filter, ImportError):
get_filter = property(
fget=lambda x: raise_(
ImportError("Can't use Data1D method get_filter: " + str(get_filter))
)
)
else:
get_filter = get_filter
# cf Methods.Data1D.check_filter
if isinstance(check_filter, ImportError):
check_filter = property(
fget=lambda x: raise_(
ImportError(
"Can't use Data1D method check_filter: " + str(check_filter)
)
)
)
else:
check_filter = check_filter
# save and copy methods are available in all object
save = save
copy = copy
Expand All @@ -127,6 +157,9 @@ def __init__(
is_components=False,
symmetries=-1,
is_overlay=False,
delimiter=None,
sort_indices=None,
filter=None,
symbol="",
name="",
unit="",
Expand Down Expand Up @@ -157,6 +190,12 @@ def __init__(
symmetries = init_dict["symmetries"]
if "is_overlay" in list(init_dict.keys()):
is_overlay = init_dict["is_overlay"]
if "delimiter" in list(init_dict.keys()):
delimiter = init_dict["delimiter"]
if "sort_indices" in list(init_dict.keys()):
sort_indices = init_dict["sort_indices"]
if "filter" in list(init_dict.keys()):
filter = init_dict["filter"]
if "symbol" in list(init_dict.keys()):
symbol = init_dict["symbol"]
if "name" in list(init_dict.keys()):
Expand All @@ -170,6 +209,9 @@ def __init__(
self.is_components = is_components
self.symmetries = symmetries
self.is_overlay = is_overlay
self.delimiter = delimiter
self.sort_indices = sort_indices
self.filter = filter
# Call Data init
super(Data1D, self).__init__(
symbol=symbol, name=name, unit=unit, normalizations=normalizations
Expand All @@ -193,6 +235,14 @@ def __str__(self):
Data1D_str += "is_components = " + str(self.is_components) + linesep
Data1D_str += "symmetries = " + str(self.symmetries) + linesep
Data1D_str += "is_overlay = " + str(self.is_overlay) + linesep
Data1D_str += 'delimiter = "' + str(self.delimiter) + '"' + linesep
Data1D_str += (
"sort_indices = "
+ linesep
+ str(self.sort_indices).replace(linesep, linesep + "\t")
+ linesep
)
Data1D_str += "filter = " + str(self.filter) + linesep
return Data1D_str

def __eq__(self, other):
Expand All @@ -212,6 +262,12 @@ def __eq__(self, other):
return False
if other.is_overlay != self.is_overlay:
return False
if other.delimiter != self.delimiter:
return False
if other.sort_indices != self.sort_indices:
return False
if other.filter != self.filter:
return False
return True

def compare(self, other, name="self", ignore_list=None):
Expand All @@ -233,6 +289,12 @@ def compare(self, other, name="self", ignore_list=None):
diff_list.append(name + ".symmetries")
if other._is_overlay != self._is_overlay:
diff_list.append(name + ".is_overlay")
if other._delimiter != self._delimiter:
diff_list.append(name + ".delimiter")
if other._sort_indices != self._sort_indices:
diff_list.append(name + ".sort_indices")
if other._filter != self._filter:
diff_list.append(name + ".filter")
# Filter ignore differences
diff_list = list(filter(lambda x: x not in ignore_list, diff_list))
return diff_list
Expand All @@ -250,6 +312,13 @@ def __sizeof__(self):
for key, value in self.symmetries.items():
S += getsizeof(value) + getsizeof(key)
S += getsizeof(self.is_overlay)
S += getsizeof(self.delimiter)
if self.sort_indices is not None:
for value in self.sort_indices:
S += getsizeof(value)
if self.filter is not None:
for key, value in self.filter.items():
S += getsizeof(value) + getsizeof(key)
return S

def as_dict(self, type_handle_ndarray=0, keep_function=False, **kwargs):
Expand Down Expand Up @@ -287,6 +356,11 @@ def as_dict(self, type_handle_ndarray=0, keep_function=False, **kwargs):
self.symmetries.copy() if self.symmetries is not None else None
)
Data1D_dict["is_overlay"] = self.is_overlay
Data1D_dict["delimiter"] = self.delimiter
Data1D_dict["sort_indices"] = (
self.sort_indices.copy() if self.sort_indices is not None else None
)
Data1D_dict["filter"] = self.filter.copy() if self.filter is not None else None
# The class name is added to the dict for deserialisation purpose
# Overwrite the mother class name
Data1D_dict["__class__"] = "Data1D"
Expand All @@ -299,6 +373,9 @@ def _set_None(self):
self.is_components = None
self.symmetries = None
self.is_overlay = None
self.delimiter = None
self.sort_indices = None
self.filter = None
# Set to None the properties inherited from Data
super(Data1D, self)._set_None()

Expand Down Expand Up @@ -382,3 +459,61 @@ def _set_is_overlay(self, value):
:Type: bool
""",
)

def _get_delimiter(self):
"""getter of delimiter"""
return self._delimiter

def _set_delimiter(self, value):
"""setter of delimiter"""
check_var("delimiter", value, "str")
self._delimiter = value

delimiter = property(
fget=_get_delimiter,
fset=_set_delimiter,
doc=u"""Character used to separate attributes in string case (e.g. "r=0, stator, radial")
:Type: str
""",
)

def _get_sort_indices(self):
"""getter of sort_indices"""
return self._sort_indices

def _set_sort_indices(self, value):
"""setter of sort_indices"""
if type(value) is int and value == -1:
value = list()
check_var("sort_indices", value, "list")
self._sort_indices = value

sort_indices = property(
fget=_get_sort_indices,
fset=_set_sort_indices,
doc=u"""List of indices to use to sort axis
:Type: list
""",
)

def _get_filter(self):
"""getter of filter"""
return self._filter

def _set_filter(self, value):
"""setter of filter"""
if type(value) is int and value == -1:
value = dict()
check_var("filter", value, "dict")
self._filter = value

filter = property(
fget=_get_filter,
fset=_set_filter,
doc=u"""Dict of filter keys
:Type: dict
""",
)
6 changes: 5 additions & 1 deletion SciDataTool/GUI/DDataPlotter/DDataPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(
plot_arg_dict : dict
Dictionnary with arguments that must be given to the plot
frozen_type : int
0 to let the user modify the axis of the plot, 1 to let him switch them, 2 to not let him change them, 3 to freeze both axes and operations
0 to let the user modify the axis of the plot, 1 to let him switch them, 2 to not let him change them, 3 to freeze both axes and operations, 4 to freeze fft
"""

# Build the interface according to the .ui file
Expand Down Expand Up @@ -541,6 +541,7 @@ def set_info(
axes_request_list=None,
plot_arg_dict=None,
is_keep_config=False,
frozen_type=0,
):
"""Method to set the DDataPlotter with information given
self : DDataPlotter
Expand All @@ -551,6 +552,8 @@ def set_info(
list of RequestedAxis which are the info given for the autoplot (for the axes and DataSelection)
plot_arg_dict : dict
Dictionnary with arguments that must be given to the plot
frozen_type : int
0 to let the user modify the axis of the plot, 1 to let him switch them, 2 to not let him change them, 3 to freeze both axes and operations, 4 to freeze fft
"""

self.plot_arg_dict = plot_arg_dict
Expand All @@ -560,6 +563,7 @@ def set_info(
unit=unit,
axes_request_list=axes_request_list,
is_keep_config=is_keep_config,
frozen_type=frozen_type,
)

def showEvent(self, ev):
Expand Down
15 changes: 14 additions & 1 deletion SciDataTool/GUI/WAxisManager/WAxisManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from SciDataTool.GUI.WAxisManager.Ui_WAxisManager import Ui_WAxisManager
from SciDataTool.GUI.WSliceOperator.WSliceOperator import WSliceOperator
from SciDataTool.Functions import axes_dict, rev_axes_dict
from SciDataTool.Functions.Plot import ifft_dict


EXTENSION_DICT = {
Expand Down Expand Up @@ -216,7 +217,7 @@ def set_axis_widgets(
axes_request_list:
list of RequestedAxis which are the info given for the autoplot (for the axes and DataSelection)
frozen_type : int
0 to let the user modify the axis of the plot, 1 to let him switch them, 2 to not let him change them, 3 to freeze both axes and operations
0 to let the user modify the axis of the plot, 1 to let him switch them, 2 to not let him change them, 3 to freeze both axes and operations, 4 to freeze fft
"""
if is_keep_config: # Only update slider
for wid in self.w_slice_op:
Expand All @@ -243,6 +244,10 @@ def set_axis_widgets(
self.w_axis_1.blockSignals(True)
self.w_axis_2.blockSignals(True)

# Reinitialize filter indices
self.w_axis_1.indices = None
self.w_axis_2.indices = None

if axes_request_list == []:
# Case where no user_input was given
# Sending the info of data to the widget (mainly the axis)
Expand Down Expand Up @@ -329,6 +334,14 @@ def set_axis_widgets(
if len(axes_list) == 1:
self.w_axis_2.hide()

elif frozen_type == 4:
self.w_axis_1.c_axis.setDisabled(True)
self.w_axis_2.c_axis.setDisabled(True)
if axes_list[0].name in ifft_dict:
self.w_axis_1.c_action.setDisabled(True)
if len(axes_list) == 2 and axes_list[1].name in ifft_dict:
self.w_axis_2.c_action.setDisabled(True)

self.w_axis_1.blockSignals(False)
self.w_axis_2.blockSignals(False)

Expand Down
Loading

0 comments on commit 8df72d8

Please sign in to comment.