funcnodes-span 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {funcnodes_span-0.1.1 → funcnodes_span-0.1.2}/PKG-INFO +1 -1
- {funcnodes_span-0.1.1 → funcnodes_span-0.1.2}/funcnodes_span/__init__.py +1 -1
- {funcnodes_span-0.1.1 → funcnodes_span-0.1.2}/funcnodes_span/normalization.py +12 -14
- {funcnodes_span-0.1.1 → funcnodes_span-0.1.2}/funcnodes_span/smoothing.py +9 -8
- {funcnodes_span-0.1.1 → funcnodes_span-0.1.2}/pyproject.toml +1 -1
- {funcnodes_span-0.1.1 → funcnodes_span-0.1.2}/README.md +0 -0
|
@@ -15,10 +15,10 @@ class NormMode(Enum):
|
|
|
15
15
|
@classmethod
|
|
16
16
|
def default(cls) -> "NormMode":
|
|
17
17
|
"""Returns the default normalization mode."""
|
|
18
|
-
return cls.ZERO_ONE
|
|
18
|
+
return cls.ZERO_ONE.value
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
@NodeDecorator(id="span.basics.norm", name="
|
|
21
|
+
@NodeDecorator(id="span.basics.norm", name="Normalization node")
|
|
22
22
|
def _norm(array: np.ndarray, mode: NormMode = NormMode.default()) -> np.ndarray:
|
|
23
23
|
# """
|
|
24
24
|
# Apply different normalizations to the array.
|
|
@@ -33,23 +33,21 @@ def _norm(array: np.ndarray, mode: NormMode = NormMode.default()) -> np.ndarray:
|
|
|
33
33
|
# Raises:
|
|
34
34
|
# ValueError: If an unsupported normalization mode is provided.
|
|
35
35
|
# """
|
|
36
|
+
if isinstance(mode, NormMode):
|
|
37
|
+
mode = mode.value
|
|
36
38
|
normalization_methods = {
|
|
37
|
-
NormMode.ZERO_ONE: lambda x: (x - np.amin(x)) / (np.amax(x) - np.amin(x)),
|
|
38
|
-
NormMode.MINUS_ONE_ONE: lambda x: 2
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
NormMode.
|
|
42
|
-
NormMode.
|
|
43
|
-
NormMode.
|
|
44
|
-
NormMode.MEAN_STD: lambda x: (x - x.mean()) / x.std(),
|
|
45
|
-
NormMode.MAX: lambda x: x / x.max(),
|
|
39
|
+
NormMode.ZERO_ONE.value: lambda x: (x - np.amin(x)) / (np.amax(x) - np.amin(x)),
|
|
40
|
+
NormMode.MINUS_ONE_ONE.value: lambda x: 2 * ((x - np.amin(x)) / (np.amax(x) - np.amin(x))) - 1,
|
|
41
|
+
NormMode.SUM_ABS.value: lambda x: x / np.abs(x).sum(),
|
|
42
|
+
NormMode.SUM.value: lambda x: x / x.sum(),
|
|
43
|
+
NormMode.EUCLIDEAN.value: lambda x: x / np.sqrt((x**2).sum()),
|
|
44
|
+
NormMode.MEAN_STD.value: lambda x: (x - x.mean()) / x.std(),
|
|
45
|
+
NormMode.MAX.value: lambda x: x / x.max()
|
|
46
46
|
}
|
|
47
|
-
if mode not in normalization_methods:
|
|
47
|
+
if mode not in normalization_methods.keys():
|
|
48
48
|
raise ValueError(f"Unsupported normalization mode: {mode}")
|
|
49
|
-
|
|
50
49
|
return normalization_methods[mode](array)
|
|
51
50
|
|
|
52
|
-
|
|
53
51
|
NORM_NODE_SHELF = Shelf(
|
|
54
52
|
nodes=[_norm],
|
|
55
53
|
subshelves=[],
|
|
@@ -18,7 +18,7 @@ class SmoothMode(Enum):
|
|
|
18
18
|
@classmethod
|
|
19
19
|
def default(cls) -> 'SmoothMode':
|
|
20
20
|
"""Returns the default smoothing mode."""
|
|
21
|
-
return cls.SAVITZKY_GOLAY
|
|
21
|
+
return cls.SAVITZKY_GOLAY.value
|
|
22
22
|
|
|
23
23
|
@NodeDecorator("span.basics.smooth", name="Smoothing")
|
|
24
24
|
|
|
@@ -37,7 +37,8 @@ def _smooth(array: np.ndarray, mode: SmoothMode = SmoothMode.default(), window:
|
|
|
37
37
|
# Raises:
|
|
38
38
|
# ValueError: If an unsupported smoothing mode is provided.
|
|
39
39
|
# """
|
|
40
|
-
|
|
40
|
+
if isinstance(mode, SmoothMode):
|
|
41
|
+
mode = mode.value
|
|
41
42
|
def smooth_savgol(x: np.ndarray) -> np.ndarray:
|
|
42
43
|
return savgol_filter(x, window, 2)
|
|
43
44
|
|
|
@@ -68,14 +69,14 @@ def _smooth(array: np.ndarray, mode: SmoothMode = SmoothMode.default(), window:
|
|
|
68
69
|
return medfilt(x, window)
|
|
69
70
|
|
|
70
71
|
smoothing_methods = {
|
|
71
|
-
SmoothMode.SAVITZKY_GOLAY: smooth_savgol,
|
|
72
|
-
SmoothMode.GAUSSIAN: smooth_gaussian,
|
|
73
|
-
SmoothMode.MOVING_AVERAGE: smooth_ma,
|
|
74
|
-
SmoothMode.EXPONENTIAL_MOVING_AVERAGE: smooth_ema,
|
|
75
|
-
SmoothMode.MEDIAN: smooth_median
|
|
72
|
+
SmoothMode.SAVITZKY_GOLAY.value: smooth_savgol,
|
|
73
|
+
SmoothMode.GAUSSIAN.value: smooth_gaussian,
|
|
74
|
+
SmoothMode.MOVING_AVERAGE.value: smooth_ma,
|
|
75
|
+
SmoothMode.EXPONENTIAL_MOVING_AVERAGE.value: smooth_ema,
|
|
76
|
+
SmoothMode.MEDIAN.value: smooth_median
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
if mode not in smoothing_methods:
|
|
79
|
+
if mode not in smoothing_methods.keys():
|
|
79
80
|
raise ValueError(f"Unsupported smoothing mode: {mode}")
|
|
80
81
|
|
|
81
82
|
return smoothing_methods[mode](array)
|
|
File without changes
|