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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcnodes-span
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary:
5
5
  Author: Kourosh Rezaei
6
6
  Author-email: kouroshrezaei90@gmail.com
@@ -4,7 +4,7 @@ from .normalization import NORM_NODE_SHELF as NORM
4
4
  from .smoothing import SMOOTH_NODE_SHELF as SMOOTH
5
5
 
6
6
 
7
- __version__ = "0.1.1"
7
+ __version__ = "0.1.2"
8
8
 
9
9
  NODE_SHELF = fn.Shelf(
10
10
  name="Spectral Analysis",
@@ -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="Normalizations")
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
- * ((x - np.amin(x)) / (np.amax(x) - np.amin(x)))
40
- - 1,
41
- NormMode.SUM_ABS: lambda x: x / np.abs(x).sum(),
42
- NormMode.SUM: lambda x: x / x.sum(),
43
- NormMode.EUCLIDEAN: lambda x: x / np.sqrt((x**2).sum()),
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)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "funcnodes-span"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = ""
5
5
  authors = ["Kourosh Rezaei <kouroshrezaei90@gmail.com>"]
6
6
  readme = "README.md"
File without changes