funcnodes-span 0.3.1__tar.gz → 0.3.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.3.1 → funcnodes_span-0.3.2}/PKG-INFO +3 -3
- funcnodes_span-0.3.2/README.md +1 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/__init__.py +1 -1
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/fitting.py +12 -4
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/peak_analysis.py +30 -29
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/pyproject.toml +2 -2
- funcnodes_span-0.3.1/README.md +0 -1
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/LICENSE +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/_baseline.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/_curves.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/_smoothing.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/baseline.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/curves.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/normalization.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/peaks.py +0 -0
- {funcnodes_span-0.3.1 → funcnodes_span-0.3.2}/funcnodes_span/smoothing.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: funcnodes-span
|
|
3
|
-
Version: 0.3.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: SPectral ANalysis (SPAN) for funcnodes
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Kourosh Rezaei
|
|
7
7
|
Author-email: kouroshrezaei90@gmail.com
|
|
@@ -25,5 +25,5 @@ Project-URL: source, https://github.com/Linkdlab/funcnodes_span
|
|
|
25
25
|
Project-URL: tracker, https://github.com/Linkdlab/funcnodes_span/issues
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
SPectral ANalysis (SPAN) for funcnodes
|
|
29
29
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
SPectral ANalysis (SPAN) for funcnodes
|
|
@@ -44,6 +44,7 @@ def group_signals(
|
|
|
44
44
|
# Assign each peak to its respective group based on start and end indices
|
|
45
45
|
for pi, p in enumerate(peaks):
|
|
46
46
|
ingroup = (baseline_cut >= p.i_index) & (baseline_cut <= p.f_index)
|
|
47
|
+
|
|
47
48
|
if ingroup.sum() == 0:
|
|
48
49
|
ingroup[(baseline_cut >= p.i_index).argmax()] = True
|
|
49
50
|
|
|
@@ -63,6 +64,9 @@ def group_signals(
|
|
|
63
64
|
else:
|
|
64
65
|
current_peak_group.update(pg)
|
|
65
66
|
|
|
67
|
+
if len(current_peak_group) > 0:
|
|
68
|
+
connected_peaks.append(list(current_peak_group))
|
|
69
|
+
|
|
66
70
|
# Return a list of grouped PeakProperties
|
|
67
71
|
return [[peaks[pi] for pi in cp] for cp in connected_peaks if len(cp) > 0]
|
|
68
72
|
|
|
@@ -111,7 +115,6 @@ def fit_local_peak(
|
|
|
111
115
|
Returns:
|
|
112
116
|
Model: The fitted model for the peak.
|
|
113
117
|
"""
|
|
114
|
-
|
|
115
118
|
x = np.asarray(x)
|
|
116
119
|
y = np.asarray(y)
|
|
117
120
|
|
|
@@ -135,13 +138,11 @@ def fit_local_peak(
|
|
|
135
138
|
if peak.yfull is None:
|
|
136
139
|
peak.yfull = y
|
|
137
140
|
|
|
138
|
-
model_class = AutoModelEnum.v(model_class)
|
|
139
|
-
incomplete_peak_model_class = AutoModelEnum.v(incomplete_peak_model_class)
|
|
140
|
-
|
|
141
141
|
if np.abs(yf[-1] - yf[0]) > incomplete_threshold * (local_max - local_min):
|
|
142
142
|
# Handle incomplete peak by extending the range and filling gaps
|
|
143
143
|
m_complete = incomplete_peak_model_class()
|
|
144
144
|
guess = m_complete.guess(data=yf, x=xf)
|
|
145
|
+
guess["center"].set(min=min(xf), max=max(xf))
|
|
145
146
|
fr_complete = m_complete.fit(data=yf, x=xf, params=guess, iter_cb=iter_cb)
|
|
146
147
|
|
|
147
148
|
fwhm = 2 * np.sqrt(2 * np.log(2)) * fr_complete.params["sigma"].value
|
|
@@ -350,10 +351,14 @@ def fit_peaks(
|
|
|
350
351
|
|
|
351
352
|
# Group peaks based on the baseline factor
|
|
352
353
|
connected_peaks = group_signals(x, y, peaks, baseline_factor=baseline_factor)
|
|
354
|
+
if len(connected_peaks) == 0:
|
|
355
|
+
raise ValueError("No peaks after grouping.")
|
|
353
356
|
|
|
354
357
|
global_model = None
|
|
355
358
|
# Fit each peak group
|
|
356
359
|
for pg in connected_peaks:
|
|
360
|
+
if len(pg) == 0:
|
|
361
|
+
continue
|
|
357
362
|
m = fit_peak_group(
|
|
358
363
|
x,
|
|
359
364
|
y,
|
|
@@ -371,6 +376,9 @@ def fit_peaks(
|
|
|
371
376
|
# Combine models for all peak groups
|
|
372
377
|
global_model += m
|
|
373
378
|
|
|
379
|
+
if global_model is None:
|
|
380
|
+
raise ValueError("No model created")
|
|
381
|
+
|
|
374
382
|
# Fit the global model to the full data
|
|
375
383
|
global_fit = global_model.fit(data=y, x=x, iter_cb=iter_cb)
|
|
376
384
|
|
|
@@ -2,7 +2,7 @@ from funcnodes import NodeDecorator, Shelf
|
|
|
2
2
|
import funcnodes as fn
|
|
3
3
|
import numpy as np
|
|
4
4
|
from exposedfunctionality import controlled_wrapper
|
|
5
|
-
from typing import Optional, List, Tuple
|
|
5
|
+
from typing import Optional, List, Tuple
|
|
6
6
|
from scipy.signal import find_peaks
|
|
7
7
|
from scipy.stats import norm
|
|
8
8
|
from scipy import signal, interpolate
|
|
@@ -223,32 +223,32 @@ def interpolation_1d(
|
|
|
223
223
|
def force_peak_finder(
|
|
224
224
|
x: np.array,
|
|
225
225
|
y: np.array,
|
|
226
|
-
|
|
226
|
+
basic_peak: PeakProperties,
|
|
227
227
|
) -> List[PeakProperties]:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
# """
|
|
241
|
-
if isinstance(basic_peaks, (list, np.ndarray, tuple)):
|
|
242
|
-
if len(basic_peaks) != 1:
|
|
243
|
-
raise ValueError(
|
|
244
|
-
"This method accepts one and only one main peak as an input."
|
|
245
|
-
)
|
|
246
|
-
basic_peaks = basic_peaks[0]
|
|
228
|
+
"""
|
|
229
|
+
Breaks down a given main peak into two individual peaks.
|
|
230
|
+
|
|
231
|
+
The function works by calculating the first and second derivatives of the signal and
|
|
232
|
+
finding the local maxima and minima of the derivatives. It then determines which peak
|
|
233
|
+
is on the left and right side of the main peak by comparing the distance between the
|
|
234
|
+
main peak and the closest peak on either side.
|
|
235
|
+
|
|
236
|
+
Parameters:
|
|
237
|
+
- x (np.array): The x-values of the signal.
|
|
238
|
+
- y (np.array): The y-values of the signal.
|
|
239
|
+
- basic_peak (PeakProperties): The main peak.
|
|
247
240
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
241
|
+
Returns:
|
|
242
|
+
- List[PeakProperties]: A list of two PeakProperties objects, one for each of the
|
|
243
|
+
individual peaks.
|
|
244
|
+
"""
|
|
245
|
+
if not isinstance(basic_peak, PeakProperties):
|
|
246
|
+
raise TypeError("The basic peak must be a single PeakProperties object.")
|
|
247
|
+
|
|
248
|
+
peak = copy.deepcopy(basic_peak)
|
|
249
|
+
main_peak_i_index = peak.i_index
|
|
250
|
+
main_peak_r_index = peak.index
|
|
251
|
+
main_peak_f_index = peak.f_index
|
|
252
252
|
y_array = y
|
|
253
253
|
x_array = x
|
|
254
254
|
# Calculate first and second derivatives
|
|
@@ -266,9 +266,9 @@ def force_peak_finder(
|
|
|
266
266
|
max_pp = signal.argrelmax(y_array_pp)[0]
|
|
267
267
|
# min_pp = signal.argrelmin(y_array_pp)[0]
|
|
268
268
|
|
|
269
|
-
# main_peak_i_index =
|
|
270
|
-
# main_peak_r_index =
|
|
271
|
-
# main_peak_f_index =
|
|
269
|
+
# main_peak_i_index = peak.i_index
|
|
270
|
+
# main_peak_r_index = peak.index
|
|
271
|
+
# main_peak_f_index = peak.f_index
|
|
272
272
|
|
|
273
273
|
# Determine which peak is on the left and right side of the main peak
|
|
274
274
|
if (
|
|
@@ -306,10 +306,11 @@ def force_peak_finder(
|
|
|
306
306
|
peak_lst = []
|
|
307
307
|
peak_lst.append([peak1["I.Index"], peak1["R.Index"], peak1["F.Index"]])
|
|
308
308
|
peak_lst.append([peak2["I.Index"], peak2["R.Index"], peak2["F.Index"]])
|
|
309
|
+
|
|
309
310
|
peak_properties_list = []
|
|
310
311
|
for peak_nr, peak in enumerate(peak_lst):
|
|
311
312
|
peak_properties = PeakProperties(
|
|
312
|
-
id=
|
|
313
|
+
id=basic_peak.id + f"_{peak_nr + 1}",
|
|
313
314
|
i_index=peak[0],
|
|
314
315
|
index=peak[1],
|
|
315
316
|
f_index=peak[2],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "funcnodes-span"
|
|
3
|
-
version = "0.3.
|
|
4
|
-
description = "
|
|
3
|
+
version = "0.3.2"
|
|
4
|
+
description = "SPectral ANalysis (SPAN) for funcnodes"
|
|
5
5
|
authors = ["Kourosh Rezaei <kouroshrezaei90@gmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
license = "MIT"
|
funcnodes_span-0.3.1/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Spectral Peak ANalysis (SPAN) for funcnodes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|