ftoolss 6.0.26__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.
Files changed (78) hide show
  1. ftoolss-6.0.26/MANIFEST.in +22 -0
  2. ftoolss-6.0.26/PKG-INFO +177 -0
  3. ftoolss-6.0.26/README.md +155 -0
  4. ftoolss-6.0.26/pyproject.toml +48 -0
  5. ftoolss-6.0.26/setup.cfg +4 -0
  6. ftoolss-6.0.26/setup.py +178 -0
  7. ftoolss-6.0.26/src/ftoolss/__init__.py +114 -0
  8. ftoolss-6.0.26/src/ftoolss/fgaussian/__init__.py +88 -0
  9. ftoolss-6.0.26/src/ftoolss/fgaussian/benchmark_all_variants.py +324 -0
  10. ftoolss-6.0.26/src/ftoolss/fgaussian/benchmark_fgaussian_f32.py +80 -0
  11. ftoolss-6.0.26/src/ftoolss/fgaussian/benchmark_fgaussian_f32_vs_f64.py +52 -0
  12. ftoolss-6.0.26/src/ftoolss/fgaussian/fgaussian_f32_ext.c +180 -0
  13. ftoolss-6.0.26/src/ftoolss/fgaussian/fgaussian_f64_ext.c +179 -0
  14. ftoolss-6.0.26/src/ftoolss/fgaussian/fgaussian_jacobian.py +28 -0
  15. ftoolss-6.0.26/src/ftoolss/fgaussian/fgaussian_jacobian_f32_ext.c +260 -0
  16. ftoolss-6.0.26/src/ftoolss/fgaussian/fgaussian_jacobian_f64_ext.c +260 -0
  17. ftoolss-6.0.26/src/ftoolss/fgaussian/fgaussian_jacobian_f64_f32_ext.c +310 -0
  18. ftoolss-6.0.26/src/ftoolss/fgaussian/test_subprocess_isolation.py +91 -0
  19. ftoolss-6.0.26/src/ftoolss/fmedian/__init__.py +95 -0
  20. ftoolss-6.0.26/src/ftoolss/fmedian/fmedian_ext.c +215 -0
  21. ftoolss-6.0.26/src/ftoolss/fmedian3/__init__.py +105 -0
  22. ftoolss-6.0.26/src/ftoolss/fmedian3/fmedian3_ext.c +226 -0
  23. ftoolss-6.0.26/src/ftoolss/fmpfit/__init__.py +693 -0
  24. ftoolss-6.0.26/src/ftoolss/fmpfit/benchmark_f32_vs_f64.py +321 -0
  25. ftoolss-6.0.26/src/ftoolss/fmpfit/benchmark_fmpfit_block_f32_vs_f64.py +178 -0
  26. ftoolss-6.0.26/src/ftoolss/fmpfit/cmpfit-1.5/DISCLAIMER +77 -0
  27. ftoolss-6.0.26/src/ftoolss/fmpfit/cmpfit-1.5/mpfit.c +2803 -0
  28. ftoolss-6.0.26/src/ftoolss/fmpfit/cmpfit-1.5/mpfit.h +172 -0
  29. ftoolss-6.0.26/src/ftoolss/fmpfit/compare_c_python.py +705 -0
  30. ftoolss-6.0.26/src/ftoolss/fmpfit/compare_errors.py +859 -0
  31. ftoolss-6.0.26/src/ftoolss/fmpfit/example_fmpfit_block_f32_5_N.py +182 -0
  32. ftoolss-6.0.26/src/ftoolss/fmpfit/example_fmpfit_block_f64_5_N.py +182 -0
  33. ftoolss-6.0.26/src/ftoolss/fmpfit/example_fmpfit_f32_5_N.py +223 -0
  34. ftoolss-6.0.26/src/ftoolss/fmpfit/example_fmpfit_f64_5_N.py +211 -0
  35. ftoolss-6.0.26/src/ftoolss/fmpfit/fmpfit_f32_block_ext.c +401 -0
  36. ftoolss-6.0.26/src/ftoolss/fmpfit/fmpfit_f32_ext.c +352 -0
  37. ftoolss-6.0.26/src/ftoolss/fmpfit/fmpfit_f64_block_ext.c +396 -0
  38. ftoolss-6.0.26/src/ftoolss/fmpfit/fmpfit_f64_ext.c +346 -0
  39. ftoolss-6.0.26/src/ftoolss/fmpfit/gaussian_deviate.c +121 -0
  40. ftoolss-6.0.26/src/ftoolss/fmpfit/test_xerror_bugcase.py +78 -0
  41. ftoolss-6.0.26/src/ftoolss/fmpfit/test_xerror_comparison.py +180 -0
  42. ftoolss-6.0.26/src/ftoolss/fsigma/__init__.py +84 -0
  43. ftoolss-6.0.26/src/ftoolss/fsigma/fsigma_ext.c +201 -0
  44. ftoolss-6.0.26/src/ftoolss/fsigma3/__init__.py +94 -0
  45. ftoolss-6.0.26/src/ftoolss/fsigma3/fsigma3_ext.c +212 -0
  46. ftoolss-6.0.26/src/ftoolss/quickselect/quickselect.c +68 -0
  47. ftoolss-6.0.26/src/ftoolss/sorting/benchmark_sortN.c +222 -0
  48. ftoolss-6.0.26/src/ftoolss/sorting/benchmark_sorts.c +285 -0
  49. ftoolss-6.0.26/src/ftoolss/sorting/demo_sortN.c +130 -0
  50. ftoolss-6.0.26/src/ftoolss/sorting/radix_sort_double.c +213 -0
  51. ftoolss-6.0.26/src/ftoolss/sorting/radix_sort_struct.c +246 -0
  52. ftoolss-6.0.26/src/ftoolss/sorting/radix_sort_uint64.c +51 -0
  53. ftoolss-6.0.26/src/ftoolss/sorting/sorting.c +933 -0
  54. ftoolss-6.0.26/src/ftoolss/sorting/sorting_general.c +198 -0
  55. ftoolss-6.0.26/src/ftoolss/sorting/sorting_networks_generated.c +3501 -0
  56. ftoolss-6.0.26/src/ftoolss/sorting/sorting_networks_generic.c +526 -0
  57. ftoolss-6.0.26/src/ftoolss/sorting/test_all_sorts.c +299 -0
  58. ftoolss-6.0.26/src/ftoolss/sorting/test_double_as_int.c +204 -0
  59. ftoolss-6.0.26/src/ftoolss/sorting/test_double_reversibility.c +201 -0
  60. ftoolss-6.0.26/src/ftoolss/sorting/test_sortN.c +285 -0
  61. ftoolss-6.0.26/src/ftoolss/sorting/test_sorting_general.c +314 -0
  62. ftoolss-6.0.26/src/ftoolss.egg-info/PKG-INFO +177 -0
  63. ftoolss-6.0.26/src/ftoolss.egg-info/SOURCES.txt +76 -0
  64. ftoolss-6.0.26/src/ftoolss.egg-info/dependency_links.txt +1 -0
  65. ftoolss-6.0.26/src/ftoolss.egg-info/not-zip-safe +1 -0
  66. ftoolss-6.0.26/src/ftoolss.egg-info/requires.txt +5 -0
  67. ftoolss-6.0.26/src/ftoolss.egg-info/top_level.txt +1 -0
  68. ftoolss-6.0.26/tests/test_fgaussian.py +286 -0
  69. ftoolss-6.0.26/tests/test_fmedian.py +412 -0
  70. ftoolss-6.0.26/tests/test_fmedian3.py +215 -0
  71. ftoolss-6.0.26/tests/test_fmpfit.py +194 -0
  72. ftoolss-6.0.26/tests/test_fmpfit_block_vs_curvefit.py +243 -0
  73. ftoolss-6.0.26/tests/test_fmpfit_concurrent.py +72 -0
  74. ftoolss-6.0.26/tests/test_fmpfit_consistency.py +1216 -0
  75. ftoolss-6.0.26/tests/test_fmpfit_vs_curvefit.py +240 -0
  76. ftoolss-6.0.26/tests/test_fsigma.py +453 -0
  77. ftoolss-6.0.26/tests/test_fsigma3.py +235 -0
  78. ftoolss-6.0.26/tests/test_integration.py +27 -0
@@ -0,0 +1,22 @@
1
+ # Include sorting network implementation files
2
+ recursive-include src/ftoolss/sorting *.c *.h
3
+
4
+ # Include cmpfit library files
5
+ recursive-include src/ftoolss/fmpfit/cmpfit-1.5 *.c *.h
6
+
7
+ # Include all C extension source files
8
+ recursive-include src/ftoolss *.c *.h
9
+
10
+ # Include documentation
11
+ include README.md
12
+ include LICENSE
13
+
14
+ # Include test files
15
+ recursive-include tests *.py
16
+
17
+ # Exclude compiled files and caches
18
+ global-exclude *.pyc
19
+ global-exclude *.pyo
20
+ global-exclude __pycache__
21
+ global-exclude *.so
22
+ global-exclude *.dylib
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: ftoolss
3
+ Version: 6.0.26
4
+ Summary: Small C extensions for local image filters (fmedian, fsigma)
5
+ Author:
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: C
9
+ Classifier: Operating System :: OS Independent
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: numpy>=1.20
12
+ Requires-Dist: scipy>=1.7
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest>=6.0; extra == "test"
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: license
19
+ Dynamic: provides-extra
20
+ Dynamic: requires-dist
21
+ Dynamic: summary
22
+
23
+ # ftoolss
24
+
25
+ High-performance C extensions for image processing and curve fitting.
26
+
27
+ ## Features
28
+
29
+ | Export | Description |
30
+ |--------|-------------|
31
+ | `fmedian` | Local median filter (2D/3D auto-dispatch) |
32
+ | `fmedian2d`, `fmedian3d` | Direct 2D/3D median |
33
+ | `fsigma` | Local ? filter (2D/3D auto-dispatch) |
34
+ | `fsigma2d`, `fsigma3d` | Direct 2D/3D sigma |
35
+ | `fgaussian_f32`, `fgaussian_f64` | Gaussian profile (Accelerate-optimized) |
36
+ | `fmpfit_pywrap` | Auto dtype dispatch (single spectrum) |
37
+ | `fmpfit_f64_pywrap`, `fmpfit_f32_pywrap` | Single spectrum fitting |
38
+ | `fmpfit_block_pywrap` | Auto dtype dispatch (block fitting) |
39
+ | `fmpfit_f64_block_pywrap`, `fmpfit_f32_block_pywrap` | Block fitting |
40
+ | `MPFitResult` | Named tuple for fit results |
41
+
42
+ **Common features:** NaN handling, edge handling, optional center exclusion (fmedian/fsigma).
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install . # Standard install
48
+ pip install -e . # Editable (development)
49
+ python setup.py build_ext --inplace # Build extensions only
50
+ ```
51
+
52
+ **Requirements:** Python 3.8+, NumPy ?1.20, C compiler. macOS Accelerate used when available.
53
+
54
+ ## Quick Start
55
+
56
+ ```python
57
+ import numpy as np
58
+ from ftoolss import fmedian, fsigma, fgaussian_f32, fgaussian_f64
59
+
60
+ # 2D/3D median and sigma filters
61
+ data = np.random.randn(100, 200)
62
+ median = fmedian(data, (3, 3), exclude_center=1)
63
+ sigma = fsigma(data, (3, 3), exclude_center=1)
64
+
65
+ # 3D works the same way
66
+ data_3d = np.random.randn(50, 100, 50)
67
+ median_3d = fmedian(data_3d, (3, 3, 3))
68
+
69
+ # Gaussian profiles
70
+ x = np.linspace(-10, 10, 1000, dtype=np.float32)
71
+ profile = fgaussian_f32(x, i0=1.0, mu=0.0, sigma=1.5)
72
+ ```
73
+
74
+ ### Curve Fitting (fmpfit)
75
+
76
+ Single-spectrum fitting with auto dtype dispatch:
77
+
78
+ ```python
79
+ from ftoolss.fmpfit import fmpfit_pywrap
80
+ import numpy as np
81
+
82
+ x = np.linspace(-5, 5, 100)
83
+ y = 2.5 * np.exp(-0.5 * ((x - 1.0) / 0.8)**2) + np.random.randn(100) * 0.1
84
+
85
+ result = fmpfit_pywrap(
86
+ deviate_type=0, # Gaussian model
87
+ parinfo=[
88
+ {'value': 1.0, 'limits': [0.0, 10.0]}, # amplitude
89
+ {'value': 0.0, 'limits': [-5.0, 5.0]}, # mean
90
+ {'value': 1.0, 'limits': [0.1, 5.0]} # sigma
91
+ ],
92
+ functkw={'x': x, 'y': y, 'error': np.ones_like(y) * 0.1}
93
+ )
94
+ print(f"Best-fit: {result.best_params}, ?²={result.bestnorm:.2f}")
95
+ print(f"SciPy-style errors (full Hessian): {result.xerror_scipy}")
96
+ ```
97
+
98
+ Block fitting (multiple spectra in one call, GIL-free):
99
+
100
+ ```python
101
+ from ftoolss.fmpfit import fmpfit_block_pywrap
102
+ import numpy as np
103
+
104
+ n_spectra, mpoints, npar = 100, 200, 3
105
+ x = np.tile(np.linspace(-5, 5, mpoints), (n_spectra, 1))
106
+ y = ... # shape (n_spectra, mpoints)
107
+ error = np.ones_like(y) * 0.1
108
+ p0 = np.tile([1.0, 0.0, 1.0], (n_spectra, 1))
109
+ bounds = np.array([[[0, 10], [-5, 5], [0.1, 5]]] * n_spectra)
110
+
111
+ results = fmpfit_block_pywrap(0, x, y, error, p0, bounds)
112
+ # results['best_params'] shape: (n_spectra, npar)
113
+ ```
114
+
115
+ ## API Reference
116
+
117
+ ### fmedian / fsigma
118
+
119
+ ```python
120
+ fmedian(data, window_size, exclude_center=0)
121
+ fsigma(data, window_size, exclude_center=0)
122
+ ```
123
+
124
+ - `window_size`: `(x, y)` or `(x, y, z)` ? odd positive integers
125
+ - `exclude_center`: 1 to exclude center from calculation (useful for outlier detection)
126
+ - Returns: float64 array, same shape as input
127
+
128
+ ### fgaussian_f32 / fgaussian_f64
129
+
130
+ Computes: `i0 * exp(-((x - mu)² / (2 * sigma²))`
131
+
132
+ ```python
133
+ fgaussian_f32(x, i0, mu, sigma) # float32, fastest
134
+ fgaussian_f64(x, i0, mu, sigma) # float64
135
+ ```
136
+
137
+ ### fmpfit
138
+
139
+ Levenberg-Marquardt least-squares fitting. See `src/ftoolss/fmpfit/README.md` for details.
140
+
141
+ | Function | Description |
142
+ |----------|-------------|
143
+ | `fmpfit_pywrap` | Auto dtype dispatch (single spectrum) |
144
+ | `fmpfit_f64_pywrap` | float64 single spectrum |
145
+ | `fmpfit_f32_pywrap` | float32 single spectrum |
146
+ | `fmpfit_block_pywrap` | Auto dtype dispatch (block of spectra) |
147
+ | `fmpfit_f64_block_pywrap` | float64 block fitting |
148
+ | `fmpfit_f32_block_pywrap` | float32 block fitting |
149
+
150
+ ## Examples
151
+
152
+ See `examples/` directory for complete working examples.
153
+
154
+ ## Testing
155
+
156
+ ```bash
157
+ pytest # Run all tests
158
+ pytest --cov=ftoolss --cov-report=html # With coverage
159
+ ```
160
+
161
+ ## Performance
162
+
163
+ | Module | Speedup vs NumPy | Notes |
164
+ |--------|------------------|-------|
165
+ | fgaussian_f32 | 5-10× | Accelerate vvexpf |
166
+ | fgaussian_f64 | 2-3× | Accelerate vvexp |
167
+ | fmedian/fsigma | ? | Sorting networks for small windows |
168
+ | fmpfit | ? | GIL-free, 4× speedup with 6 threads |
169
+
170
+ ## License
171
+
172
+ MIT
173
+
174
+ ## Credits
175
+
176
+ - Sorting networks: [Bert Dobbelaere](https://bertdobbelaere.github.io/sorting_networks.html)
177
+ - MPFIT: Craig Markwardt (cmpfit, MINPACK-1 derivative)
@@ -0,0 +1,155 @@
1
+ # ftoolss
2
+
3
+ High-performance C extensions for image processing and curve fitting.
4
+
5
+ ## Features
6
+
7
+ | Export | Description |
8
+ |--------|-------------|
9
+ | `fmedian` | Local median filter (2D/3D auto-dispatch) |
10
+ | `fmedian2d`, `fmedian3d` | Direct 2D/3D median |
11
+ | `fsigma` | Local ? filter (2D/3D auto-dispatch) |
12
+ | `fsigma2d`, `fsigma3d` | Direct 2D/3D sigma |
13
+ | `fgaussian_f32`, `fgaussian_f64` | Gaussian profile (Accelerate-optimized) |
14
+ | `fmpfit_pywrap` | Auto dtype dispatch (single spectrum) |
15
+ | `fmpfit_f64_pywrap`, `fmpfit_f32_pywrap` | Single spectrum fitting |
16
+ | `fmpfit_block_pywrap` | Auto dtype dispatch (block fitting) |
17
+ | `fmpfit_f64_block_pywrap`, `fmpfit_f32_block_pywrap` | Block fitting |
18
+ | `MPFitResult` | Named tuple for fit results |
19
+
20
+ **Common features:** NaN handling, edge handling, optional center exclusion (fmedian/fsigma).
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install . # Standard install
26
+ pip install -e . # Editable (development)
27
+ python setup.py build_ext --inplace # Build extensions only
28
+ ```
29
+
30
+ **Requirements:** Python 3.8+, NumPy ?1.20, C compiler. macOS Accelerate used when available.
31
+
32
+ ## Quick Start
33
+
34
+ ```python
35
+ import numpy as np
36
+ from ftoolss import fmedian, fsigma, fgaussian_f32, fgaussian_f64
37
+
38
+ # 2D/3D median and sigma filters
39
+ data = np.random.randn(100, 200)
40
+ median = fmedian(data, (3, 3), exclude_center=1)
41
+ sigma = fsigma(data, (3, 3), exclude_center=1)
42
+
43
+ # 3D works the same way
44
+ data_3d = np.random.randn(50, 100, 50)
45
+ median_3d = fmedian(data_3d, (3, 3, 3))
46
+
47
+ # Gaussian profiles
48
+ x = np.linspace(-10, 10, 1000, dtype=np.float32)
49
+ profile = fgaussian_f32(x, i0=1.0, mu=0.0, sigma=1.5)
50
+ ```
51
+
52
+ ### Curve Fitting (fmpfit)
53
+
54
+ Single-spectrum fitting with auto dtype dispatch:
55
+
56
+ ```python
57
+ from ftoolss.fmpfit import fmpfit_pywrap
58
+ import numpy as np
59
+
60
+ x = np.linspace(-5, 5, 100)
61
+ y = 2.5 * np.exp(-0.5 * ((x - 1.0) / 0.8)**2) + np.random.randn(100) * 0.1
62
+
63
+ result = fmpfit_pywrap(
64
+ deviate_type=0, # Gaussian model
65
+ parinfo=[
66
+ {'value': 1.0, 'limits': [0.0, 10.0]}, # amplitude
67
+ {'value': 0.0, 'limits': [-5.0, 5.0]}, # mean
68
+ {'value': 1.0, 'limits': [0.1, 5.0]} # sigma
69
+ ],
70
+ functkw={'x': x, 'y': y, 'error': np.ones_like(y) * 0.1}
71
+ )
72
+ print(f"Best-fit: {result.best_params}, ?²={result.bestnorm:.2f}")
73
+ print(f"SciPy-style errors (full Hessian): {result.xerror_scipy}")
74
+ ```
75
+
76
+ Block fitting (multiple spectra in one call, GIL-free):
77
+
78
+ ```python
79
+ from ftoolss.fmpfit import fmpfit_block_pywrap
80
+ import numpy as np
81
+
82
+ n_spectra, mpoints, npar = 100, 200, 3
83
+ x = np.tile(np.linspace(-5, 5, mpoints), (n_spectra, 1))
84
+ y = ... # shape (n_spectra, mpoints)
85
+ error = np.ones_like(y) * 0.1
86
+ p0 = np.tile([1.0, 0.0, 1.0], (n_spectra, 1))
87
+ bounds = np.array([[[0, 10], [-5, 5], [0.1, 5]]] * n_spectra)
88
+
89
+ results = fmpfit_block_pywrap(0, x, y, error, p0, bounds)
90
+ # results['best_params'] shape: (n_spectra, npar)
91
+ ```
92
+
93
+ ## API Reference
94
+
95
+ ### fmedian / fsigma
96
+
97
+ ```python
98
+ fmedian(data, window_size, exclude_center=0)
99
+ fsigma(data, window_size, exclude_center=0)
100
+ ```
101
+
102
+ - `window_size`: `(x, y)` or `(x, y, z)` ? odd positive integers
103
+ - `exclude_center`: 1 to exclude center from calculation (useful for outlier detection)
104
+ - Returns: float64 array, same shape as input
105
+
106
+ ### fgaussian_f32 / fgaussian_f64
107
+
108
+ Computes: `i0 * exp(-((x - mu)² / (2 * sigma²))`
109
+
110
+ ```python
111
+ fgaussian_f32(x, i0, mu, sigma) # float32, fastest
112
+ fgaussian_f64(x, i0, mu, sigma) # float64
113
+ ```
114
+
115
+ ### fmpfit
116
+
117
+ Levenberg-Marquardt least-squares fitting. See `src/ftoolss/fmpfit/README.md` for details.
118
+
119
+ | Function | Description |
120
+ |----------|-------------|
121
+ | `fmpfit_pywrap` | Auto dtype dispatch (single spectrum) |
122
+ | `fmpfit_f64_pywrap` | float64 single spectrum |
123
+ | `fmpfit_f32_pywrap` | float32 single spectrum |
124
+ | `fmpfit_block_pywrap` | Auto dtype dispatch (block of spectra) |
125
+ | `fmpfit_f64_block_pywrap` | float64 block fitting |
126
+ | `fmpfit_f32_block_pywrap` | float32 block fitting |
127
+
128
+ ## Examples
129
+
130
+ See `examples/` directory for complete working examples.
131
+
132
+ ## Testing
133
+
134
+ ```bash
135
+ pytest # Run all tests
136
+ pytest --cov=ftoolss --cov-report=html # With coverage
137
+ ```
138
+
139
+ ## Performance
140
+
141
+ | Module | Speedup vs NumPy | Notes |
142
+ |--------|------------------|-------|
143
+ | fgaussian_f32 | 5-10× | Accelerate vvexpf |
144
+ | fgaussian_f64 | 2-3× | Accelerate vvexp |
145
+ | fmedian/fsigma | ? | Sorting networks for small windows |
146
+ | fmpfit | ? | GIL-free, 4× speedup with 6 threads |
147
+
148
+ ## License
149
+
150
+ MIT
151
+
152
+ ## Credits
153
+
154
+ - Sorting networks: [Bert Dobbelaere](https://bertdobbelaere.github.io/sorting_networks.html)
155
+ - MPFIT: Craig Markwardt (cmpfit, MINPACK-1 derivative)
@@ -0,0 +1,48 @@
1
+ # Ruff configuration for ftoolss project
2
+ # See: https://docs.astral.sh/ruff/configuration/
3
+
4
+ [tool.ruff]
5
+ # Exclude directories that should not be linted
6
+ exclude = [
7
+ ".git",
8
+ "__pycache__",
9
+ "build",
10
+ "dist",
11
+ "venv",
12
+ "htmlcov",
13
+ ".pytest_cache",
14
+ "*.egg-info",
15
+ ]
16
+
17
+ [tool.ruff.lint]
18
+ # Enable specific rule categories
19
+ select = [
20
+ "E", # pycodestyle errors
21
+ "F", # pyflakes (critical errors only)
22
+ ]
23
+
24
+ # Ignore specific rules that are too noisy for this codebase
25
+ ignore = [
26
+ "E501", # Line too long (handled by formatter)
27
+ "E402", # Module level import not at top of file
28
+ "E701", # Multiple statements on one line
29
+ "E702", # Multiple statements on one line (semicolon)
30
+ "E741", # Ambiguous variable name
31
+ "F541", # f-string without placeholders (common in print statements)
32
+ ]
33
+
34
+ [tool.ruff.lint.per-file-ignores]
35
+ # Ignore unused imports in __init__.py files
36
+ "__init__.py" = ["F401"]
37
+ # Ignore certain issues in test files
38
+ "test_*.py" = ["F401", "F811", "F841"]
39
+ # Ignore issues in example scripts
40
+ "example_*.py" = ["F541", "F841"]
41
+ # Ignore issues in benchmark scripts
42
+ "benchmark_*.py" = ["F401", "F841"]
43
+ # Ignore issues in comparison scripts
44
+ "compare_*.py" = ["F401", "F841"]
45
+ # Ignore issues in scripts directory
46
+ "scripts/*.py" = ["F401", "F841"]
47
+ # Ignore issues in instruction-given directory (external code)
48
+ "src/ftoolss/fits_file_to_fmpfit/instructions-given/*.py" = ["F401", "F811", "F841", "E"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,178 @@
1
+ from __future__ import annotations
2
+
3
+ import io
4
+ import os
5
+ import sys
6
+ from setuptools import setup, find_packages, Extension
7
+
8
+
9
+ def read_readme():
10
+ here = os.path.abspath(os.path.dirname(__file__))
11
+ readme = os.path.join(here, "README.md")
12
+ if os.path.exists(readme):
13
+ with io.open(readme, "r", encoding="utf8") as fh:
14
+ return fh.read()
15
+ return "ftoolss: C-based local image filters (fmedian, fsigma)"
16
+
17
+
18
+ # Try to obtain numpy include dir; setup_requires ensures numpy is available when
19
+ # building via setuptools, but fall back gracefully to an empty list at import-time.
20
+ include_dirs = []
21
+ try:
22
+ import numpy as _np
23
+
24
+ include_dirs = [_np.get_include()]
25
+ except Exception:
26
+ # numpy may not yet be available at import time; setup_requires=['numpy'] will
27
+ # request it at build time.
28
+ include_dirs = []
29
+
30
+ # Check for FORCE_SCALAR environment variable to disable Accelerate framework
31
+ force_scalar = os.environ.get("FORCE_SCALAR", "0") == "1"
32
+ fgaussian_extra_compile_args = ["-O3"]
33
+ if force_scalar:
34
+ fgaussian_extra_compile_args.append("-DFORCE_SCALAR")
35
+
36
+ # No platform-specific link arguments needed
37
+ fgaussian_extra_link_args = []
38
+ if sys.platform == "darwin":
39
+ # macOS: use Accelerate framework
40
+ fgaussian_extra_link_args = ["-framework", "Accelerate"]
41
+ else:
42
+ # Linux/other platforms: explicitly link math library for vectorized functions
43
+ fgaussian_extra_link_args = ["-lm", "-lmvec"]
44
+
45
+ ext_modules = [
46
+ Extension(
47
+ "ftoolss.fmedian.fmedian_ext",
48
+ sources=[os.path.join("src", "ftoolss", "fmedian", "fmedian_ext.c")],
49
+ include_dirs=include_dirs,
50
+ ),
51
+ Extension(
52
+ "ftoolss.fsigma.fsigma_ext",
53
+ sources=[os.path.join("src", "ftoolss", "fsigma", "fsigma_ext.c")],
54
+ include_dirs=include_dirs,
55
+ ),
56
+ Extension(
57
+ "ftoolss.fmedian3.fmedian3_ext",
58
+ sources=[os.path.join("src", "ftoolss", "fmedian3", "fmedian3_ext.c")],
59
+ include_dirs=include_dirs,
60
+ ),
61
+ Extension(
62
+ "ftoolss.fsigma3.fsigma3_ext",
63
+ sources=[os.path.join("src", "ftoolss", "fsigma3", "fsigma3_ext.c")],
64
+ include_dirs=include_dirs,
65
+ ),
66
+ Extension(
67
+ "ftoolss.fgaussian.fgaussian_f32_ext",
68
+ sources=[os.path.join("src", "ftoolss", "fgaussian", "fgaussian_f32_ext.c")],
69
+ include_dirs=include_dirs,
70
+ extra_compile_args=fgaussian_extra_compile_args,
71
+ extra_link_args=fgaussian_extra_link_args,
72
+ ),
73
+ Extension(
74
+ "ftoolss.fgaussian.fgaussian_f64_ext",
75
+ sources=[os.path.join("src", "ftoolss", "fgaussian", "fgaussian_f64_ext.c")],
76
+ include_dirs=include_dirs,
77
+ extra_compile_args=fgaussian_extra_compile_args,
78
+ extra_link_args=fgaussian_extra_link_args,
79
+ ),
80
+ Extension(
81
+ "ftoolss.fgaussian.fgaussian_jacobian_f32_ext",
82
+ sources=[os.path.join("src", "ftoolss", "fgaussian", "fgaussian_jacobian_f32_ext.c")],
83
+ include_dirs=include_dirs,
84
+ extra_compile_args=fgaussian_extra_compile_args,
85
+ extra_link_args=fgaussian_extra_link_args,
86
+ ),
87
+ Extension(
88
+ "ftoolss.fgaussian.fgaussian_jacobian_f64_ext",
89
+ sources=[os.path.join("src", "ftoolss", "fgaussian", "fgaussian_jacobian_f64_ext.c")],
90
+ include_dirs=include_dirs,
91
+ extra_compile_args=fgaussian_extra_compile_args,
92
+ extra_link_args=fgaussian_extra_link_args,
93
+ ),
94
+ Extension(
95
+ "ftoolss.fgaussian.fgaussian_jacobian_f64_f32_ext",
96
+ sources=[os.path.join("src", "ftoolss", "fgaussian", "fgaussian_jacobian_f64_f32_ext.c")],
97
+ include_dirs=include_dirs,
98
+ extra_compile_args=fgaussian_extra_compile_args,
99
+ extra_link_args=fgaussian_extra_link_args,
100
+ ),
101
+ Extension(
102
+ "ftoolss.fmpfit.fmpfit_f64_ext",
103
+ sources=[
104
+ os.path.join("src", "ftoolss", "fmpfit", "fmpfit_f64_ext.c"),
105
+ os.path.join("src", "ftoolss", "fmpfit", "cmpfit-1.5", "mpfit.c"),
106
+ ],
107
+ include_dirs=include_dirs + [os.path.join("src", "ftoolss", "fmpfit")],
108
+ extra_compile_args=["-O3"],
109
+ extra_link_args=fgaussian_extra_link_args,
110
+ ),
111
+ Extension(
112
+ "ftoolss.fmpfit.fmpfit_f32_ext",
113
+ sources=[
114
+ os.path.join("src", "ftoolss", "fmpfit", "fmpfit_f32_ext.c"),
115
+ os.path.join("src", "ftoolss", "fmpfit", "cmpfit-1.5", "mpfit.c"),
116
+ ],
117
+ include_dirs=include_dirs + [os.path.join("src", "ftoolss", "fmpfit")],
118
+ extra_compile_args=["-O3", "-DMPFIT_FLOAT"],
119
+ extra_link_args=fgaussian_extra_link_args,
120
+ ),
121
+ Extension(
122
+ "ftoolss.fmpfit.fmpfit_f64_block_ext",
123
+ sources=[
124
+ os.path.join("src", "ftoolss", "fmpfit", "fmpfit_f64_block_ext.c"),
125
+ os.path.join("src", "ftoolss", "fmpfit", "cmpfit-1.5", "mpfit.c"),
126
+ ],
127
+ include_dirs=include_dirs + [os.path.join("src", "ftoolss", "fmpfit")],
128
+ extra_compile_args=["-O3"],
129
+ extra_link_args=fgaussian_extra_link_args,
130
+ ),
131
+ Extension(
132
+ "ftoolss.fmpfit.fmpfit_f32_block_ext",
133
+ sources=[
134
+ os.path.join("src", "ftoolss", "fmpfit", "fmpfit_f32_block_ext.c"),
135
+ os.path.join("src", "ftoolss", "fmpfit", "cmpfit-1.5", "mpfit.c"),
136
+ ],
137
+ include_dirs=include_dirs + [os.path.join("src", "ftoolss", "fmpfit")],
138
+ extra_compile_args=["-O3", "-DMPFIT_FLOAT"],
139
+ extra_link_args=fgaussian_extra_link_args,
140
+ ),
141
+ ]
142
+
143
+
144
+ setup(
145
+ name="ftoolss",
146
+ # Version 5 introduced fmpfit
147
+ # Version 5.2 introduces xerror_scipy (different handling of bounded params)
148
+ # Version 6 changed name to ftoolss (ftools, Stein's) for publishing to PiPY
149
+ version="6.0.26",
150
+ description="Small C extensions for local image filters (fmedian, fsigma)",
151
+ long_description=read_readme(),
152
+ long_description_content_type="text/markdown",
153
+ author="",
154
+ license="MIT",
155
+ package_dir={"": "src"},
156
+ packages=find_packages("src"),
157
+ # Include mpfit C source files so other packages can compile against them
158
+ package_data={
159
+ "ftoolss.fmpfit": [
160
+ "cmpfit-1.5/mpfit.h",
161
+ "cmpfit-1.5/mpfit.c",
162
+ "cmpfit-1.5/DISCLAIMER",
163
+ "gaussian_deviate.c",
164
+ ],
165
+ },
166
+ ext_modules=ext_modules,
167
+ setup_requires=["numpy>=1.20"],
168
+ install_requires=["numpy>=1.20", "scipy>=1.7"],
169
+ extras_require={
170
+ "test": ["pytest>=6.0"],
171
+ },
172
+ classifiers=[
173
+ "Programming Language :: Python :: 3",
174
+ "Programming Language :: C",
175
+ "Operating System :: OS Independent",
176
+ ],
177
+ zip_safe=False,
178
+ )
@@ -0,0 +1,114 @@
1
+ """Top level package for ftoolss.
2
+
3
+ Expose unified function names at package level so users can call
4
+ `fmedian` and `fsigma` with either 2D or 3D arrays.
5
+ """
6
+ from .fmedian import fmedian as _fmedian2d
7
+ from .fsigma import fsigma as _fsigma2d
8
+ from .fmedian3 import fmedian3 as _fmedian3d
9
+ from .fsigma3 import fsigma3 as _fsigma3d
10
+ from .fgaussian import fgaussian_f32, fgaussian_f64
11
+ from .fmpfit import fmpfit_pywrap, fmpfit_f64_pywrap, fmpfit_f32_pywrap
12
+ from .fmpfit import fmpfit_block_pywrap, fmpfit_f64_block_pywrap, fmpfit_f32_block_pywrap
13
+ from .fmpfit import MPFitResult
14
+
15
+
16
+ def fmedian(input_array, window_size: tuple, exclude_center: int = 0):
17
+ """Compute filtered median for 2D or 3D arrays.
18
+
19
+ Automatically dispatches to the appropriate implementation based on window_size length.
20
+
21
+ Parameters:
22
+ - input_array: 2D or 3D numpy array
23
+ - window_size: Tuple of window dimensions (xsize, ysize) for 2D or (xsize, ysize, zsize) for 3D
24
+ All values must be odd positive integers
25
+ - exclude_center: Whether to exclude center pixel/voxel (default: 0)
26
+
27
+ Returns:
28
+ - Filtered array of same shape as input
29
+
30
+ Examples:
31
+ >>> # 2D array
32
+ >>> result = fmedian(array_2d, (3, 3))
33
+ >>> # 3D array
34
+ >>> result = fmedian(array_3d, (3, 3, 3))
35
+ """
36
+ import numpy as np
37
+
38
+ arr = np.asarray(input_array)
39
+
40
+ if not isinstance(window_size, (tuple, list)):
41
+ raise TypeError("window_size must be a tuple or list")
42
+
43
+ if len(window_size) == 2:
44
+ xsize, ysize = window_size
45
+ from .fmedian import fmedian as fmedian2d
46
+ return fmedian2d(arr, xsize, ysize, exclude_center)
47
+
48
+ elif len(window_size) == 3:
49
+ xsize, ysize, zsize = window_size
50
+ from .fmedian3 import fmedian3
51
+ return fmedian3(arr, xsize, ysize, zsize, exclude_center)
52
+
53
+ else:
54
+ raise ValueError(f"window_size must be a 2-tuple or 3-tuple, got {len(window_size)} elements")
55
+
56
+
57
+ def fsigma(input_array, window_size: tuple, exclude_center: int = 0):
58
+ """Compute local population standard deviation for 2D or 3D arrays.
59
+
60
+ Automatically dispatches to the appropriate implementation based on window_size length.
61
+
62
+ Parameters:
63
+ - input_array: 2D or 3D numpy array
64
+ - window_size: Tuple of window dimensions (xsize, ysize) for 2D or (xsize, ysize, zsize) for 3D
65
+ All values must be odd positive integers
66
+ - exclude_center: Whether to exclude center pixel/voxel (default: 0)
67
+
68
+ Returns:
69
+ - Array of local standard deviations, same shape as input
70
+
71
+ Examples:
72
+ >>> # 2D array
73
+ >>> result = fsigma(array_2d, (3, 3))
74
+ >>> # 3D array
75
+ >>> result = fsigma(array_3d, (3, 3, 3))
76
+ """
77
+ import numpy as np
78
+
79
+ arr = np.asarray(input_array)
80
+
81
+ if not isinstance(window_size, (tuple, list)):
82
+ raise TypeError("window_size must be a tuple or list")
83
+
84
+ if len(window_size) == 2:
85
+ xsize, ysize = window_size
86
+ from .fsigma import fsigma as fsigma2d
87
+ return fsigma2d(arr, xsize, ysize, exclude_center)
88
+
89
+ elif len(window_size) == 3:
90
+ xsize, ysize, zsize = window_size
91
+ from .fsigma3 import fsigma3
92
+ return fsigma3(arr, xsize, ysize, zsize, exclude_center)
93
+
94
+ else:
95
+ raise ValueError(f"window_size must be a 2-tuple or 3-tuple, got {len(window_size)} elements")
96
+
97
+
98
+ # Keep the specific implementations available for direct access if needed
99
+ fmedian2d = _fmedian2d
100
+ fsigma2d = _fsigma2d
101
+ fmedian3d = _fmedian3d
102
+ fsigma3d = _fsigma3d
103
+
104
+ # Get version from package metadata (set by setup.py)
105
+ try:
106
+ from importlib.metadata import version as _get_version
107
+ __version__ = _get_version("ftoolss")
108
+ except Exception:
109
+ __version__ = "unknown"
110
+
111
+ __all__ = ["fmedian", "fsigma", "fgaussian_f32", "fgaussian_f64", "fmedian2d", "fsigma2d", "fmedian3d", "fsigma3d",
112
+ "fmpfit_pywrap", "fmpfit_f64_pywrap", "fmpfit_f32_pywrap",
113
+ "fmpfit_block_pywrap", "fmpfit_f64_block_pywrap", "fmpfit_f32_block_pywrap",
114
+ "MPFitResult"]