funcnodes-span 0.1.22__tar.gz → 0.2.0__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.22 → funcnodes_span-0.2.0}/PKG-INFO +1 -1
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/funcnodes_span/__init__.py +1 -1
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/funcnodes_span/baseline.py +687 -1
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/pyproject.toml +1 -1
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/README.md +0 -0
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/funcnodes_span/normalization.py +0 -0
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/funcnodes_span/peak_analysis.py +0 -0
- {funcnodes_span-0.1.22 → funcnodes_span-0.2.0}/funcnodes_span/smoothing.py +0 -0
|
@@ -5,7 +5,7 @@ from .smoothing import SMOOTH_NODE_SHELF as SMOOTH
|
|
|
5
5
|
from .peak_analysis import PEAKS_NODE_SHELF as PEAK
|
|
6
6
|
from .baseline import BASELINE_NODE_SHELF as BASELINE
|
|
7
7
|
|
|
8
|
-
__version__ = "0.
|
|
8
|
+
__version__ = "0.2.0"
|
|
9
9
|
|
|
10
10
|
NODE_SHELF = fn.Shelf(
|
|
11
11
|
name="Spectral Analysis",
|
|
@@ -2,7 +2,7 @@ from funcnodes import NodeDecorator, Shelf
|
|
|
2
2
|
from exposedfunctionality import controlled_wrapper
|
|
3
3
|
import numpy as np
|
|
4
4
|
from enum import Enum
|
|
5
|
-
from typing import Optional, Tuple
|
|
5
|
+
from typing import Optional, Tuple, Union, List
|
|
6
6
|
import pybaselines
|
|
7
7
|
|
|
8
8
|
|
|
@@ -1480,6 +1480,689 @@ SPLINE_NODE_SHELF = Shelf(
|
|
|
1480
1480
|
)
|
|
1481
1481
|
|
|
1482
1482
|
|
|
1483
|
+
@NodeDecorator(
|
|
1484
|
+
"pybaselines.smooth.ipsa",
|
|
1485
|
+
name="ipsa",
|
|
1486
|
+
outputs=[
|
|
1487
|
+
{"name": "baseline_corrected"},
|
|
1488
|
+
{"name": "baseline"},
|
|
1489
|
+
{"name": "params"},
|
|
1490
|
+
],
|
|
1491
|
+
)
|
|
1492
|
+
@controlled_wrapper(pybaselines.smooth.ipsa, wrapper_attribute="__fnwrapped__")
|
|
1493
|
+
def _ipsa(
|
|
1494
|
+
data: np.ndarray,
|
|
1495
|
+
x_data: Optional[np.ndarray] = None,
|
|
1496
|
+
half_window: Optional[int] = None,
|
|
1497
|
+
max_iter: int = 500,
|
|
1498
|
+
tol: Optional[float] = None,
|
|
1499
|
+
roi: Optional[np.ndarray] = None,
|
|
1500
|
+
original_criteria: bool = False,
|
|
1501
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1502
|
+
baseline, params = pybaselines.smooth.ipsa(
|
|
1503
|
+
data,
|
|
1504
|
+
x_data=x_data,
|
|
1505
|
+
max_iter=max_iter,
|
|
1506
|
+
half_window=half_window,
|
|
1507
|
+
roi=roi,
|
|
1508
|
+
tol=tol,
|
|
1509
|
+
original_criteria=original_criteria,
|
|
1510
|
+
)
|
|
1511
|
+
baseline_corrected = data - baseline
|
|
1512
|
+
return baseline_corrected, baseline, params
|
|
1513
|
+
|
|
1514
|
+
|
|
1515
|
+
@NodeDecorator(
|
|
1516
|
+
"pybaselines.smooth.noise_median",
|
|
1517
|
+
name="noise_median",
|
|
1518
|
+
outputs=[
|
|
1519
|
+
{"name": "baseline_corrected"},
|
|
1520
|
+
{"name": "baseline"},
|
|
1521
|
+
{"name": "params"},
|
|
1522
|
+
],
|
|
1523
|
+
)
|
|
1524
|
+
@controlled_wrapper(pybaselines.smooth.noise_median, wrapper_attribute="__fnwrapped__")
|
|
1525
|
+
def _noise_median(
|
|
1526
|
+
data: np.ndarray,
|
|
1527
|
+
x_data: Optional[np.ndarray] = None,
|
|
1528
|
+
half_window: Optional[int] = None,
|
|
1529
|
+
smooth_half_window: Optional[int] = None,
|
|
1530
|
+
sigma: Optional[float] = None,
|
|
1531
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1532
|
+
baseline, params = pybaselines.smooth.noise_median(
|
|
1533
|
+
data,
|
|
1534
|
+
x_data=x_data,
|
|
1535
|
+
smooth_half_window=smooth_half_window,
|
|
1536
|
+
half_window=half_window,
|
|
1537
|
+
sigma=sigma,
|
|
1538
|
+
)
|
|
1539
|
+
baseline_corrected = data - baseline
|
|
1540
|
+
return baseline_corrected, baseline, params
|
|
1541
|
+
|
|
1542
|
+
|
|
1543
|
+
class Side(Enum):
|
|
1544
|
+
both = "both"
|
|
1545
|
+
left = "left"
|
|
1546
|
+
right = "right"
|
|
1547
|
+
|
|
1548
|
+
@classmethod
|
|
1549
|
+
def default(cls):
|
|
1550
|
+
return cls.both.value
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
@NodeDecorator(
|
|
1554
|
+
"pybaselines.smooth.ria",
|
|
1555
|
+
name="ria",
|
|
1556
|
+
outputs=[
|
|
1557
|
+
{"name": "baseline_corrected"},
|
|
1558
|
+
{"name": "baseline"},
|
|
1559
|
+
{"name": "params"},
|
|
1560
|
+
],
|
|
1561
|
+
)
|
|
1562
|
+
@controlled_wrapper(pybaselines.smooth.ria, wrapper_attribute="__fnwrapped__")
|
|
1563
|
+
def _ria(
|
|
1564
|
+
data: np.ndarray,
|
|
1565
|
+
x_data: Optional[np.ndarray] = None,
|
|
1566
|
+
half_window: Optional[int] = None,
|
|
1567
|
+
max_iter: int = 500,
|
|
1568
|
+
tol: float = 0.01,
|
|
1569
|
+
side: Side = Side.default(),
|
|
1570
|
+
width_scale: float = 0.1,
|
|
1571
|
+
height_scale: float = 1.0,
|
|
1572
|
+
sigma_scale: float = 1.0 / 12.0,
|
|
1573
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1574
|
+
if isinstance(side, Side):
|
|
1575
|
+
side = side.value
|
|
1576
|
+
baseline, params = pybaselines.smooth.ria(
|
|
1577
|
+
data,
|
|
1578
|
+
x_data=x_data,
|
|
1579
|
+
max_iter=max_iter,
|
|
1580
|
+
tol=tol,
|
|
1581
|
+
half_window=half_window,
|
|
1582
|
+
side=side,
|
|
1583
|
+
width_scale=width_scale,
|
|
1584
|
+
height_scale=height_scale,
|
|
1585
|
+
sigma_scale=sigma_scale,
|
|
1586
|
+
)
|
|
1587
|
+
baseline_corrected = data - baseline
|
|
1588
|
+
return baseline_corrected, baseline, params
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
@NodeDecorator(
|
|
1592
|
+
"pybaselines.smooth.snip",
|
|
1593
|
+
name="snip",
|
|
1594
|
+
outputs=[
|
|
1595
|
+
{"name": "baseline_corrected"},
|
|
1596
|
+
{"name": "baseline"},
|
|
1597
|
+
{"name": "params"},
|
|
1598
|
+
],
|
|
1599
|
+
)
|
|
1600
|
+
@controlled_wrapper(pybaselines.smooth.snip, wrapper_attribute="__fnwrapped__")
|
|
1601
|
+
def _snip(
|
|
1602
|
+
data: np.ndarray,
|
|
1603
|
+
x_data: Optional[np.ndarray] = None,
|
|
1604
|
+
decreasing: bool = False,
|
|
1605
|
+
smooth_half_window: Optional[int] = None,
|
|
1606
|
+
filter_order: int = 2,
|
|
1607
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1608
|
+
baseline, params = pybaselines.smooth.snip(
|
|
1609
|
+
data,
|
|
1610
|
+
x_data=x_data,
|
|
1611
|
+
decreasing=decreasing,
|
|
1612
|
+
smooth_half_window=smooth_half_window,
|
|
1613
|
+
filter_order=filter_order,
|
|
1614
|
+
)
|
|
1615
|
+
baseline_corrected = data - baseline
|
|
1616
|
+
return baseline_corrected, baseline, params
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
@NodeDecorator(
|
|
1620
|
+
"pybaselines.smooth.swima",
|
|
1621
|
+
name="swima",
|
|
1622
|
+
outputs=[
|
|
1623
|
+
{"name": "baseline_corrected"},
|
|
1624
|
+
{"name": "baseline"},
|
|
1625
|
+
{"name": "params"},
|
|
1626
|
+
],
|
|
1627
|
+
)
|
|
1628
|
+
@controlled_wrapper(pybaselines.smooth.swima, wrapper_attribute="__fnwrapped__")
|
|
1629
|
+
def _swima(
|
|
1630
|
+
data: np.ndarray,
|
|
1631
|
+
x_data: Optional[np.ndarray] = None,
|
|
1632
|
+
min_half_window: int = 3,
|
|
1633
|
+
max_half_window: Optional[int] = None,
|
|
1634
|
+
smooth_half_window: Optional[int] = None,
|
|
1635
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1636
|
+
baseline, params = pybaselines.smooth.swima(
|
|
1637
|
+
data,
|
|
1638
|
+
x_data=x_data,
|
|
1639
|
+
min_half_window=min_half_window,
|
|
1640
|
+
smooth_half_window=smooth_half_window,
|
|
1641
|
+
max_half_window=max_half_window,
|
|
1642
|
+
)
|
|
1643
|
+
baseline_corrected = data - baseline
|
|
1644
|
+
return baseline_corrected, baseline, params
|
|
1645
|
+
|
|
1646
|
+
|
|
1647
|
+
SMOOTH_NODE_SHELF = Shelf(
|
|
1648
|
+
nodes=[_ipsa, _noise_median, _ria, _snip, _swima],
|
|
1649
|
+
subshelves=[],
|
|
1650
|
+
name="Smooth",
|
|
1651
|
+
description="Fits a smooth baseline",
|
|
1652
|
+
)
|
|
1653
|
+
|
|
1654
|
+
|
|
1655
|
+
@NodeDecorator(
|
|
1656
|
+
"pybaselines.classification.cwt_br",
|
|
1657
|
+
name="cwt_br",
|
|
1658
|
+
outputs=[
|
|
1659
|
+
{"name": "baseline_corrected"},
|
|
1660
|
+
{"name": "baseline"},
|
|
1661
|
+
{"name": "params"},
|
|
1662
|
+
],
|
|
1663
|
+
)
|
|
1664
|
+
@controlled_wrapper(
|
|
1665
|
+
pybaselines.classification.cwt_br, wrapper_attribute="__fnwrapped__"
|
|
1666
|
+
)
|
|
1667
|
+
def _cwt_br(
|
|
1668
|
+
data: np.ndarray,
|
|
1669
|
+
x_data: Optional[np.ndarray] = None,
|
|
1670
|
+
poly_order: int = 5,
|
|
1671
|
+
scale: Optional[np.ndarray] = None,
|
|
1672
|
+
num_std: float = 1.0,
|
|
1673
|
+
min_length: int = 2,
|
|
1674
|
+
max_iter: int = 50,
|
|
1675
|
+
tol: float = 0.001,
|
|
1676
|
+
symmetric: bool = False,
|
|
1677
|
+
weights: Optional[np.ndarray] = None,
|
|
1678
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1679
|
+
baseline, params = pybaselines.classification.cwt_br(
|
|
1680
|
+
data,
|
|
1681
|
+
x_data=x_data,
|
|
1682
|
+
poly_order=poly_order,
|
|
1683
|
+
scale=scale,
|
|
1684
|
+
num_std=num_std,
|
|
1685
|
+
min_length=min_length,
|
|
1686
|
+
max_iter=max_iter,
|
|
1687
|
+
tol=tol,
|
|
1688
|
+
symmetric=symmetric,
|
|
1689
|
+
weights=weights,
|
|
1690
|
+
)
|
|
1691
|
+
baseline_corrected = data - baseline
|
|
1692
|
+
return baseline_corrected, baseline, params
|
|
1693
|
+
|
|
1694
|
+
|
|
1695
|
+
@NodeDecorator(
|
|
1696
|
+
"pybaselines.classification.dietrich",
|
|
1697
|
+
name="dietrich",
|
|
1698
|
+
outputs=[
|
|
1699
|
+
{"name": "baseline_corrected"},
|
|
1700
|
+
{"name": "baseline"},
|
|
1701
|
+
{"name": "params"},
|
|
1702
|
+
],
|
|
1703
|
+
)
|
|
1704
|
+
@controlled_wrapper(
|
|
1705
|
+
pybaselines.classification.dietrich, wrapper_attribute="__fnwrapped__"
|
|
1706
|
+
)
|
|
1707
|
+
def _dietrich(
|
|
1708
|
+
data: np.ndarray,
|
|
1709
|
+
x_data: Optional[np.ndarray] = None,
|
|
1710
|
+
smooth_half_window: Optional[int] = None,
|
|
1711
|
+
interp_half_window: int = 5,
|
|
1712
|
+
poly_order: int = 5,
|
|
1713
|
+
max_iter: int = 50,
|
|
1714
|
+
tol: float = 0.001,
|
|
1715
|
+
num_std: float = 1.0,
|
|
1716
|
+
min_length: int = 2,
|
|
1717
|
+
return_coef: bool = False,
|
|
1718
|
+
weights: Optional[np.ndarray] = None,
|
|
1719
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1720
|
+
baseline, params = pybaselines.classification.dietrich(
|
|
1721
|
+
data,
|
|
1722
|
+
x_data=x_data,
|
|
1723
|
+
poly_order=poly_order,
|
|
1724
|
+
smooth_half_window=smooth_half_window,
|
|
1725
|
+
num_std=num_std,
|
|
1726
|
+
min_length=min_length,
|
|
1727
|
+
max_iter=max_iter,
|
|
1728
|
+
tol=tol,
|
|
1729
|
+
interp_half_window=interp_half_window,
|
|
1730
|
+
return_coef=return_coef,
|
|
1731
|
+
weights=weights,
|
|
1732
|
+
)
|
|
1733
|
+
baseline_corrected = data - baseline
|
|
1734
|
+
return baseline_corrected, baseline, params
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
@NodeDecorator(
|
|
1738
|
+
"pybaselines.classification.fabc",
|
|
1739
|
+
name="fabc",
|
|
1740
|
+
outputs=[
|
|
1741
|
+
{"name": "baseline_corrected"},
|
|
1742
|
+
{"name": "baseline"},
|
|
1743
|
+
{"name": "params"},
|
|
1744
|
+
],
|
|
1745
|
+
)
|
|
1746
|
+
@controlled_wrapper(pybaselines.classification.fabc, wrapper_attribute="__fnwrapped__")
|
|
1747
|
+
def _fabc(
|
|
1748
|
+
data: np.ndarray,
|
|
1749
|
+
x_data: Optional[np.ndarray] = None,
|
|
1750
|
+
lam: float = 1000000.0,
|
|
1751
|
+
scale: Optional[np.ndarray] = None,
|
|
1752
|
+
num_std: float = 3.0,
|
|
1753
|
+
diff_order: int = 2,
|
|
1754
|
+
min_length: int = 2,
|
|
1755
|
+
weights_as_mask: bool = False,
|
|
1756
|
+
weights: Optional[np.ndarray] = None,
|
|
1757
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1758
|
+
baseline, params = pybaselines.classification.fabc(
|
|
1759
|
+
data,
|
|
1760
|
+
x_data=x_data,
|
|
1761
|
+
lam=lam,
|
|
1762
|
+
scale=scale,
|
|
1763
|
+
num_std=num_std,
|
|
1764
|
+
min_length=min_length,
|
|
1765
|
+
diff_order=diff_order,
|
|
1766
|
+
weights_as_mask=weights_as_mask,
|
|
1767
|
+
weights=weights,
|
|
1768
|
+
)
|
|
1769
|
+
baseline_corrected = data - baseline
|
|
1770
|
+
return baseline_corrected, baseline, params
|
|
1771
|
+
|
|
1772
|
+
|
|
1773
|
+
@NodeDecorator(
|
|
1774
|
+
"pybaselines.classification.fastchrom",
|
|
1775
|
+
name="fastchrom",
|
|
1776
|
+
outputs=[
|
|
1777
|
+
{"name": "baseline_corrected"},
|
|
1778
|
+
{"name": "baseline"},
|
|
1779
|
+
{"name": "params"},
|
|
1780
|
+
],
|
|
1781
|
+
)
|
|
1782
|
+
@controlled_wrapper(
|
|
1783
|
+
pybaselines.classification.fastchrom, wrapper_attribute="__fnwrapped__"
|
|
1784
|
+
)
|
|
1785
|
+
def _fastchrom(
|
|
1786
|
+
data: np.ndarray,
|
|
1787
|
+
x_data: Optional[np.ndarray] = None,
|
|
1788
|
+
half_window: Optional[int] = None,
|
|
1789
|
+
threshold: Optional[float] = None,
|
|
1790
|
+
min_fwhm: Optional[int] = None,
|
|
1791
|
+
interp_half_window: int = 5,
|
|
1792
|
+
smooth_half_window: Optional[int] = None,
|
|
1793
|
+
max_iter: int = 100,
|
|
1794
|
+
min_length: int = 2,
|
|
1795
|
+
weights: Optional[np.ndarray] = None,
|
|
1796
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1797
|
+
baseline, params = pybaselines.classification.fastchrom(
|
|
1798
|
+
data,
|
|
1799
|
+
x_data=x_data,
|
|
1800
|
+
half_window=half_window,
|
|
1801
|
+
threshold=threshold,
|
|
1802
|
+
min_fwhm=min_fwhm,
|
|
1803
|
+
min_length=min_length,
|
|
1804
|
+
max_iter=max_iter,
|
|
1805
|
+
smooth_half_window=smooth_half_window,
|
|
1806
|
+
interp_half_window=interp_half_window,
|
|
1807
|
+
weights=weights,
|
|
1808
|
+
)
|
|
1809
|
+
baseline_corrected = data - baseline
|
|
1810
|
+
return baseline_corrected, baseline, params
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
@NodeDecorator(
|
|
1814
|
+
"pybaselines.classification.golotvin",
|
|
1815
|
+
name="golotvin",
|
|
1816
|
+
outputs=[
|
|
1817
|
+
{"name": "baseline_corrected"},
|
|
1818
|
+
{"name": "baseline"},
|
|
1819
|
+
{"name": "params"},
|
|
1820
|
+
],
|
|
1821
|
+
)
|
|
1822
|
+
@controlled_wrapper(
|
|
1823
|
+
pybaselines.classification.golotvin, wrapper_attribute="__fnwrapped__"
|
|
1824
|
+
)
|
|
1825
|
+
def _golotvin(
|
|
1826
|
+
data: np.ndarray,
|
|
1827
|
+
x_data: Optional[np.ndarray] = None,
|
|
1828
|
+
half_window: Optional[int] = None,
|
|
1829
|
+
num_std: float = 2.0,
|
|
1830
|
+
sections: int = 32,
|
|
1831
|
+
threshold: Optional[float] = None,
|
|
1832
|
+
interp_half_window: int = 5,
|
|
1833
|
+
smooth_half_window: Optional[int] = None,
|
|
1834
|
+
min_length: int = 2,
|
|
1835
|
+
weights: Optional[np.ndarray] = None,
|
|
1836
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1837
|
+
baseline, params = pybaselines.classification.golotvin(
|
|
1838
|
+
data,
|
|
1839
|
+
x_data=x_data,
|
|
1840
|
+
half_window=half_window,
|
|
1841
|
+
threshold=threshold,
|
|
1842
|
+
num_std=num_std,
|
|
1843
|
+
min_length=min_length,
|
|
1844
|
+
sections=sections,
|
|
1845
|
+
smooth_half_window=smooth_half_window,
|
|
1846
|
+
interp_half_window=interp_half_window,
|
|
1847
|
+
weights=weights,
|
|
1848
|
+
)
|
|
1849
|
+
baseline_corrected = data - baseline
|
|
1850
|
+
return baseline_corrected, baseline, params
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
@NodeDecorator(
|
|
1854
|
+
"pybaselines.classification.rubberband",
|
|
1855
|
+
name="rubberband",
|
|
1856
|
+
outputs=[
|
|
1857
|
+
{"name": "baseline_corrected"},
|
|
1858
|
+
{"name": "baseline"},
|
|
1859
|
+
{"name": "params"},
|
|
1860
|
+
],
|
|
1861
|
+
)
|
|
1862
|
+
@controlled_wrapper(
|
|
1863
|
+
pybaselines.classification.rubberband, wrapper_attribute="__fnwrapped__"
|
|
1864
|
+
)
|
|
1865
|
+
def _rubberband(
|
|
1866
|
+
data: np.ndarray,
|
|
1867
|
+
x_data: Optional[np.ndarray] = None,
|
|
1868
|
+
segments: Union[int, np.ndarray] = 1,
|
|
1869
|
+
lam: Optional[float] = None,
|
|
1870
|
+
diff_order: int = 2,
|
|
1871
|
+
smooth_half_window: Optional[int] = None,
|
|
1872
|
+
weights: Optional[np.ndarray] = None,
|
|
1873
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1874
|
+
baseline, params = pybaselines.classification.rubberband(
|
|
1875
|
+
data,
|
|
1876
|
+
x_data=x_data,
|
|
1877
|
+
segments=segments,
|
|
1878
|
+
lam=lam,
|
|
1879
|
+
diff_order=diff_order,
|
|
1880
|
+
smooth_half_window=smooth_half_window,
|
|
1881
|
+
weights=weights,
|
|
1882
|
+
)
|
|
1883
|
+
baseline_corrected = data - baseline
|
|
1884
|
+
return baseline_corrected, baseline, params
|
|
1885
|
+
|
|
1886
|
+
|
|
1887
|
+
@NodeDecorator(
|
|
1888
|
+
"pybaselines.classification.std_distribution",
|
|
1889
|
+
name="std_distribution",
|
|
1890
|
+
outputs=[
|
|
1891
|
+
{"name": "baseline_corrected"},
|
|
1892
|
+
{"name": "baseline"},
|
|
1893
|
+
{"name": "params"},
|
|
1894
|
+
],
|
|
1895
|
+
)
|
|
1896
|
+
@controlled_wrapper(
|
|
1897
|
+
pybaselines.classification.std_distribution, wrapper_attribute="__fnwrapped__"
|
|
1898
|
+
)
|
|
1899
|
+
def _std_distribution(
|
|
1900
|
+
data: np.ndarray,
|
|
1901
|
+
x_data: Optional[np.ndarray] = None,
|
|
1902
|
+
half_window: Optional[int] = None,
|
|
1903
|
+
interp_half_window: int = 5,
|
|
1904
|
+
fill_half_window: int = 3,
|
|
1905
|
+
num_std: float = 1.1,
|
|
1906
|
+
smooth_half_window: Optional[int] = None,
|
|
1907
|
+
weights: Optional[np.ndarray] = None,
|
|
1908
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1909
|
+
baseline, params = pybaselines.classification.std_distribution(
|
|
1910
|
+
data,
|
|
1911
|
+
x_data=x_data,
|
|
1912
|
+
half_window=half_window,
|
|
1913
|
+
interp_half_window=interp_half_window,
|
|
1914
|
+
fill_half_window=fill_half_window,
|
|
1915
|
+
smooth_half_window=smooth_half_window,
|
|
1916
|
+
num_std=num_std,
|
|
1917
|
+
weights=weights,
|
|
1918
|
+
)
|
|
1919
|
+
baseline_corrected = data - baseline
|
|
1920
|
+
return baseline_corrected, baseline, params
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
CLASSIFICATION_NODE_SHELF = Shelf(
|
|
1924
|
+
nodes=[
|
|
1925
|
+
_cwt_br,
|
|
1926
|
+
_dietrich,
|
|
1927
|
+
_fabc,
|
|
1928
|
+
_fastchrom,
|
|
1929
|
+
_golotvin,
|
|
1930
|
+
_rubberband,
|
|
1931
|
+
_std_distribution,
|
|
1932
|
+
],
|
|
1933
|
+
subshelves=[],
|
|
1934
|
+
name="Classification",
|
|
1935
|
+
description="Fits a classification baseline",
|
|
1936
|
+
)
|
|
1937
|
+
|
|
1938
|
+
|
|
1939
|
+
class Method(Enum):
|
|
1940
|
+
modpoly = "modpoly"
|
|
1941
|
+
imodpoly = "imodpoly"
|
|
1942
|
+
|
|
1943
|
+
@classmethod
|
|
1944
|
+
def default(cls):
|
|
1945
|
+
return cls.modpoly.value
|
|
1946
|
+
|
|
1947
|
+
|
|
1948
|
+
@NodeDecorator(
|
|
1949
|
+
"pybaselines.optimizers.adaptive_minmax",
|
|
1950
|
+
name="adaptive_minmax",
|
|
1951
|
+
outputs=[
|
|
1952
|
+
{"name": "baseline_corrected"},
|
|
1953
|
+
{"name": "baseline"},
|
|
1954
|
+
{"name": "params"},
|
|
1955
|
+
],
|
|
1956
|
+
)
|
|
1957
|
+
@controlled_wrapper(
|
|
1958
|
+
pybaselines.optimizers.adaptive_minmax, wrapper_attribute="__fnwrapped__"
|
|
1959
|
+
)
|
|
1960
|
+
def _adaptive_minmax(
|
|
1961
|
+
data: np.ndarray,
|
|
1962
|
+
x_data: Optional[np.ndarray] = None,
|
|
1963
|
+
poly_order: Optional[Union[int, List[int]]] = None,
|
|
1964
|
+
method: Method = Method.default(),
|
|
1965
|
+
constrained_fraction: Union[float, List[float]] = 0.01,
|
|
1966
|
+
constrained_weight: Union[float, List[float]] = 100000.0,
|
|
1967
|
+
estimation_poly_order: int = 2,
|
|
1968
|
+
weights: Optional[np.ndarray] = None,
|
|
1969
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
1970
|
+
if isinstance(method, Method):
|
|
1971
|
+
method = method.value
|
|
1972
|
+
baseline, params = pybaselines.optimizers.adaptive_minmax(
|
|
1973
|
+
data,
|
|
1974
|
+
x_data=x_data,
|
|
1975
|
+
poly_order=poly_order,
|
|
1976
|
+
constrained_fraction=constrained_fraction,
|
|
1977
|
+
constrained_weight=constrained_weight,
|
|
1978
|
+
method=method,
|
|
1979
|
+
estimation_poly_order=estimation_poly_order,
|
|
1980
|
+
weights=weights,
|
|
1981
|
+
)
|
|
1982
|
+
baseline_corrected = data - baseline
|
|
1983
|
+
return baseline_corrected, baseline, params
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
class MethodColab(Enum):
|
|
1987
|
+
airpls = "airpls"
|
|
1988
|
+
arpls = "arpls"
|
|
1989
|
+
asls = "asls"
|
|
1990
|
+
aspls = "aspls"
|
|
1991
|
+
derpsalsa = "derpsalsa"
|
|
1992
|
+
drpls = "drpls"
|
|
1993
|
+
iarpls = "iarpls"
|
|
1994
|
+
iasls = "iasls"
|
|
1995
|
+
psalsa = "psalsa"
|
|
1996
|
+
|
|
1997
|
+
@classmethod
|
|
1998
|
+
def default(cls):
|
|
1999
|
+
return cls.asls.value
|
|
2000
|
+
|
|
2001
|
+
|
|
2002
|
+
@NodeDecorator(
|
|
2003
|
+
"pybaselines.optimizers.collab_pls",
|
|
2004
|
+
name="collab_pls",
|
|
2005
|
+
outputs=[
|
|
2006
|
+
{"name": "baseline_corrected"},
|
|
2007
|
+
{"name": "baseline"},
|
|
2008
|
+
{"name": "params"},
|
|
2009
|
+
],
|
|
2010
|
+
)
|
|
2011
|
+
@controlled_wrapper(
|
|
2012
|
+
pybaselines.optimizers.collab_pls, wrapper_attribute="__fnwrapped__"
|
|
2013
|
+
)
|
|
2014
|
+
def _collab_pls(
|
|
2015
|
+
data: np.ndarray,
|
|
2016
|
+
x_data: Optional[np.ndarray] = None,
|
|
2017
|
+
average_dataset: bool = True,
|
|
2018
|
+
method: MethodColab = MethodColab.default(),
|
|
2019
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
2020
|
+
if isinstance(method, MethodColab):
|
|
2021
|
+
method = method.value
|
|
2022
|
+
baseline, params = pybaselines.optimizers.collab_pls(
|
|
2023
|
+
data,
|
|
2024
|
+
x_data=x_data,
|
|
2025
|
+
method=method,
|
|
2026
|
+
average_dataset=average_dataset,
|
|
2027
|
+
)
|
|
2028
|
+
baseline_corrected = data - baseline
|
|
2029
|
+
return baseline_corrected, baseline, params
|
|
2030
|
+
|
|
2031
|
+
|
|
2032
|
+
class MethodAll(Enum):
|
|
2033
|
+
goldindec = "goldindec"
|
|
2034
|
+
imodpoly = "imodpoly"
|
|
2035
|
+
loess = "loess"
|
|
2036
|
+
modpoly = "modpoly"
|
|
2037
|
+
penalizedpoly = "penalizedpoly"
|
|
2038
|
+
poly = "poly"
|
|
2039
|
+
quant_reg = "quant_reg"
|
|
2040
|
+
airpls = "airpls"
|
|
2041
|
+
arpls = "arpls"
|
|
2042
|
+
asls = "asls"
|
|
2043
|
+
aspls = "aspls"
|
|
2044
|
+
derpsalsa = "derpsalsa"
|
|
2045
|
+
drpls = "drpls"
|
|
2046
|
+
iarpls = "iarpls"
|
|
2047
|
+
iasls = "iasls"
|
|
2048
|
+
psalsa = "psalsa"
|
|
2049
|
+
amormol = "amormol"
|
|
2050
|
+
imor = "imor"
|
|
2051
|
+
jbcd = "jbcd"
|
|
2052
|
+
mor = "mor"
|
|
2053
|
+
mormol = "mormol"
|
|
2054
|
+
mpls = "mpls"
|
|
2055
|
+
mpspline = "mpspline"
|
|
2056
|
+
mwmv = "mwmv"
|
|
2057
|
+
rolling_ball = "rolling_ball"
|
|
2058
|
+
tophat = "tophat"
|
|
2059
|
+
corner_cutting = "corner_cutting"
|
|
2060
|
+
irsqr = "irsqr"
|
|
2061
|
+
mixture_model = "mixture_model"
|
|
2062
|
+
pspline_airpls = "pspline_airpls"
|
|
2063
|
+
pspline_asls = "pspline_asls"
|
|
2064
|
+
pspline_aspls = "pspline_aspls"
|
|
2065
|
+
pspline_derpsalsa = "pspline_derpsalsa"
|
|
2066
|
+
pspline_drpls = "pspline_drpls"
|
|
2067
|
+
pspline_iarpls = "pspline_iarpls"
|
|
2068
|
+
pspline_iasls = "pspline_iasls"
|
|
2069
|
+
pspline_mpls = "pspline_mpls"
|
|
2070
|
+
pspline_psalsa = "pspline_psalsa"
|
|
2071
|
+
cwt_br = "cwt_br"
|
|
2072
|
+
dietrich = "dietrich"
|
|
2073
|
+
fabc = "fabc"
|
|
2074
|
+
fastchrom = "fastchrom"
|
|
2075
|
+
golotvin = "golotvin"
|
|
2076
|
+
rubberband = "rubberband"
|
|
2077
|
+
std_distribution = "std_distribution"
|
|
2078
|
+
|
|
2079
|
+
@classmethod
|
|
2080
|
+
def default(cls):
|
|
2081
|
+
return cls.asls.value
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
@NodeDecorator(
|
|
2085
|
+
"pybaselines.optimizers.custom_bc",
|
|
2086
|
+
name="custom_bc",
|
|
2087
|
+
outputs=[
|
|
2088
|
+
{"name": "baseline_corrected"},
|
|
2089
|
+
{"name": "baseline"},
|
|
2090
|
+
{"name": "params"},
|
|
2091
|
+
],
|
|
2092
|
+
)
|
|
2093
|
+
@controlled_wrapper(pybaselines.optimizers.custom_bc, wrapper_attribute="__fnwrapped__")
|
|
2094
|
+
def _custom_bc(
|
|
2095
|
+
data: np.ndarray,
|
|
2096
|
+
x_data: Optional[np.ndarray] = None,
|
|
2097
|
+
sampling: Union[int, np.ndarray] = 1,
|
|
2098
|
+
lam: Optional[float] = None,
|
|
2099
|
+
diff_order: int = 2,
|
|
2100
|
+
method: MethodAll = MethodAll.default(),
|
|
2101
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
2102
|
+
if isinstance(method, MethodAll):
|
|
2103
|
+
method = method.value
|
|
2104
|
+
baseline, params = pybaselines.optimizers.custom_bc(
|
|
2105
|
+
data,
|
|
2106
|
+
x_data=x_data,
|
|
2107
|
+
diff_order=diff_order,
|
|
2108
|
+
lam=lam,
|
|
2109
|
+
method=method,
|
|
2110
|
+
sampling=sampling,
|
|
2111
|
+
)
|
|
2112
|
+
baseline_corrected = data - baseline
|
|
2113
|
+
return baseline_corrected, baseline, params
|
|
2114
|
+
|
|
2115
|
+
|
|
2116
|
+
@NodeDecorator(
|
|
2117
|
+
"pybaselines.optimizers.optimize_extended_range",
|
|
2118
|
+
name="optimize_extended_range",
|
|
2119
|
+
outputs=[
|
|
2120
|
+
{"name": "baseline_corrected"},
|
|
2121
|
+
{"name": "baseline"},
|
|
2122
|
+
{"name": "params"},
|
|
2123
|
+
],
|
|
2124
|
+
)
|
|
2125
|
+
@controlled_wrapper(
|
|
2126
|
+
pybaselines.optimizers.optimize_extended_range, wrapper_attribute="__fnwrapped__"
|
|
2127
|
+
)
|
|
2128
|
+
def _optimize_extended_range(
|
|
2129
|
+
data: np.ndarray,
|
|
2130
|
+
x_data: Optional[np.ndarray] = None,
|
|
2131
|
+
side: Side = Side.default(),
|
|
2132
|
+
width_scale: float = 0.1,
|
|
2133
|
+
height_scale: float = 1.0,
|
|
2134
|
+
sigma_scale: float = 1.0 / 12.0,
|
|
2135
|
+
min_value: float = 2.0,
|
|
2136
|
+
max_value: float = 8.0,
|
|
2137
|
+
step: int = 1,
|
|
2138
|
+
method: MethodAll = MethodAll.default(),
|
|
2139
|
+
) -> Tuple[np.ndarray, np.ndarray, dict]:
|
|
2140
|
+
if isinstance(method, MethodAll):
|
|
2141
|
+
method = method.value
|
|
2142
|
+
if isinstance(side, Side):
|
|
2143
|
+
side = side.value
|
|
2144
|
+
baseline, params = pybaselines.optimizers.optimize_extended_range(
|
|
2145
|
+
data,
|
|
2146
|
+
x_data=x_data,
|
|
2147
|
+
width_scale=width_scale,
|
|
2148
|
+
height_scale=height_scale,
|
|
2149
|
+
method=method,
|
|
2150
|
+
min_value=min_value,
|
|
2151
|
+
sigma_scale=sigma_scale,
|
|
2152
|
+
max_value=max_value,
|
|
2153
|
+
step=step,
|
|
2154
|
+
)
|
|
2155
|
+
baseline_corrected = data - baseline
|
|
2156
|
+
return baseline_corrected, baseline, params
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
OPTIMIZERS_NODE_SHELF = Shelf(
|
|
2160
|
+
nodes=[_adaptive_minmax, _collab_pls, _custom_bc, _optimize_extended_range],
|
|
2161
|
+
subshelves=[],
|
|
2162
|
+
name="Optimizers",
|
|
2163
|
+
description="Fits a optimizers baseline",
|
|
2164
|
+
)
|
|
2165
|
+
|
|
1483
2166
|
BASELINE_NODE_SHELF = Shelf(
|
|
1484
2167
|
nodes=[],
|
|
1485
2168
|
subshelves=[
|
|
@@ -1487,6 +2170,9 @@ BASELINE_NODE_SHELF = Shelf(
|
|
|
1487
2170
|
WHITTAKER_NODE_SHELF,
|
|
1488
2171
|
MORPHOLOGICAL_NODE_SHELF,
|
|
1489
2172
|
SPLINE_NODE_SHELF,
|
|
2173
|
+
SMOOTH_NODE_SHELF,
|
|
2174
|
+
CLASSIFICATION_NODE_SHELF,
|
|
2175
|
+
OPTIMIZERS_NODE_SHELF,
|
|
1490
2176
|
],
|
|
1491
2177
|
name="Baseline correction",
|
|
1492
2178
|
description="Provides different techniques for fitting baselines to experimental data using pybaselines.",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|