dct-toolkit 0.4.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.
- dct_toolkit-0.4.0/.gitignore +58 -0
- dct_toolkit-0.4.0/AGENTS.md +417 -0
- dct_toolkit-0.4.0/CHANGELOG.md +139 -0
- dct_toolkit-0.4.0/LICENSE +21 -0
- dct_toolkit-0.4.0/PKG-INFO +161 -0
- dct_toolkit-0.4.0/README.md +115 -0
- dct_toolkit-0.4.0/dct_toolkit/__init__.py +63 -0
- dct_toolkit-0.4.0/dct_toolkit/cartesian.py +41 -0
- dct_toolkit-0.4.0/dct_toolkit/core.py +123 -0
- dct_toolkit-0.4.0/dct_toolkit/gap_filling.py +815 -0
- dct_toolkit-0.4.0/dct_toolkit/polar.py +264 -0
- dct_toolkit-0.4.0/dct_toolkit/stats.py +300 -0
- dct_toolkit-0.4.0/docs/API_REFERENCE.md +94 -0
- dct_toolkit-0.4.0/docs/GAP_FILLING_BASIS.md +166 -0
- dct_toolkit-0.4.0/docs/MATHEMATICAL_BASIS.md +77 -0
- dct_toolkit-0.4.0/docs/PUBLICATION_GUIDE.md +76 -0
- dct_toolkit-0.4.0/examples/basic_polar.py +71 -0
- dct_toolkit-0.4.0/examples/comprehensive_demo.py +80 -0
- dct_toolkit-0.4.0/pyproject.toml +49 -0
- dct_toolkit-0.4.0/tests/test_cartesian.py +48 -0
- dct_toolkit-0.4.0/tests/test_core.py +39 -0
- dct_toolkit-0.4.0/tests/test_gap_filling.py +541 -0
- dct_toolkit-0.4.0/tests/test_polar.py +75 -0
- dct_toolkit-0.4.0/tests/test_stats.py +211 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Testing
|
|
24
|
+
.pytest_cache/
|
|
25
|
+
.coverage
|
|
26
|
+
htmlcov/
|
|
27
|
+
.tox/
|
|
28
|
+
|
|
29
|
+
# IDE
|
|
30
|
+
.vscode/
|
|
31
|
+
.idea/
|
|
32
|
+
*.swp
|
|
33
|
+
*.swo
|
|
34
|
+
*~
|
|
35
|
+
|
|
36
|
+
# OS
|
|
37
|
+
.DS_Store
|
|
38
|
+
Thumbs.db
|
|
39
|
+
|
|
40
|
+
# Jupyter
|
|
41
|
+
.ipynb_checkpoints/
|
|
42
|
+
*.ipynb
|
|
43
|
+
|
|
44
|
+
# Environment
|
|
45
|
+
.env
|
|
46
|
+
.venv
|
|
47
|
+
env/
|
|
48
|
+
venv/
|
|
49
|
+
ENV/
|
|
50
|
+
|
|
51
|
+
# Documentation builds
|
|
52
|
+
docs/_build/
|
|
53
|
+
site/
|
|
54
|
+
|
|
55
|
+
# mypy
|
|
56
|
+
.mypy_cache/
|
|
57
|
+
.dmypy.json
|
|
58
|
+
dmypy.json
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
# AGENTS.md - DCT Toolkit Agent Guidelines
|
|
2
|
+
|
|
3
|
+
**Project**: dct-toolkit
|
|
4
|
+
**Version**: 0.4.0
|
|
5
|
+
**Status**: Private Repository in Publication Preparation
|
|
6
|
+
**Last Updated**: 2026-04-10
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Critical Rule: Standalone Project
|
|
11
|
+
|
|
12
|
+
⚠️ **THIS IS A COMPLETELY STANDALONE PROJECT**
|
|
13
|
+
|
|
14
|
+
- ✅ ONLY import from within `dct_toolkit/dct_toolkit/` directory
|
|
15
|
+
- ✅ External dependencies: `numpy`, `scipy` ONLY
|
|
16
|
+
- ❌ NEVER import from parent directories (`../src/`, `../dct_stats/`, legacy code)
|
|
17
|
+
- ❌ NEVER import from any code outside this repository
|
|
18
|
+
- ❌ NEVER assume other projects are available
|
|
19
|
+
|
|
20
|
+
**Verification Command**:
|
|
21
|
+
```bash
|
|
22
|
+
grep -r "^from \.\./" dct_toolkit/
|
|
23
|
+
grep -r "^import .*\.\." dct_toolkit/
|
|
24
|
+
```
|
|
25
|
+
Should return NO matches.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Environment Setup
|
|
30
|
+
|
|
31
|
+
### Conda Environment
|
|
32
|
+
```bash
|
|
33
|
+
conda activate myenv
|
|
34
|
+
python --version # Should be 3.8+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### PYTHONPATH
|
|
38
|
+
When running tests or examples from project root:
|
|
39
|
+
```bash
|
|
40
|
+
export PYTHONPATH=$PYTHONPATH:$(pwd)/dct_toolkit
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Isolated Conda Environment for Testing/Building (Recommended)
|
|
44
|
+
To avoid dependency conflicts when building or testing the package, use an isolated conda environment:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Create isolated environment
|
|
48
|
+
conda create -n dct-toolkit-dev python=3.11 -y
|
|
49
|
+
conda activate dct-toolkit-dev
|
|
50
|
+
|
|
51
|
+
# Install package in development mode
|
|
52
|
+
pip install -e .
|
|
53
|
+
|
|
54
|
+
# Run tests
|
|
55
|
+
python -m pytest tests -q
|
|
56
|
+
|
|
57
|
+
# Build package artifacts (for PyPI)
|
|
58
|
+
conda install -c conda-forge build twine -y
|
|
59
|
+
python -m build
|
|
60
|
+
python -m twine check dist/*
|
|
61
|
+
|
|
62
|
+
# Clean up when done
|
|
63
|
+
conda deactivate
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Why isolated?** Building tools (`build`, `twine`) and their dependencies can conflict with other packages in your base environment (e.g., Sphinx, Streamlit). Always use an isolated environment for package operations.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Code Style - Scientific Repository Standards
|
|
71
|
+
|
|
72
|
+
### Docstrings (REQUIRED)
|
|
73
|
+
Use NumPy style:
|
|
74
|
+
```python
|
|
75
|
+
def function_name(param1: type, param2: type) -> return_type:
|
|
76
|
+
"""
|
|
77
|
+
Short description.
|
|
78
|
+
|
|
79
|
+
Longer description if needed.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
param1 : type
|
|
84
|
+
Description
|
|
85
|
+
param2 : type
|
|
86
|
+
Description
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
return_type
|
|
91
|
+
Description
|
|
92
|
+
|
|
93
|
+
Examples
|
|
94
|
+
--------
|
|
95
|
+
>>> result = function_name(1.0, 2.0)
|
|
96
|
+
"""
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Type Hints (REQUIRED)
|
|
100
|
+
All function parameters and returns must be typed:
|
|
101
|
+
```python
|
|
102
|
+
def smooth_data(data: np.ndarray, width: float) -> np.ndarray:
|
|
103
|
+
...
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Naming Conventions
|
|
107
|
+
- **Functions/Variables**: `snake_case` (e.g., `get_transfer_function`)
|
|
108
|
+
- **Classes**: `CamelCase` (e.g., `DCTSmoother`)
|
|
109
|
+
- **Constants**: `UPPER_SNAKE_CASE` (e.g., `DEFAULT_KERNEL`)
|
|
110
|
+
- **Private**: `_leading_underscore` (e.g., `_helper_func`)
|
|
111
|
+
|
|
112
|
+
### Formatting
|
|
113
|
+
- **Indentation**: 4 spaces (NO tabs)
|
|
114
|
+
- **Line Length**: 100 characters (soft limit)
|
|
115
|
+
- **Blank Lines**:
|
|
116
|
+
- 2 lines between top-level functions/classes
|
|
117
|
+
- 1 line between methods
|
|
118
|
+
- **Operators**: Spaces around operators (`x = y + 1`)
|
|
119
|
+
|
|
120
|
+
### Import Organization
|
|
121
|
+
```python
|
|
122
|
+
# 1. Standard library
|
|
123
|
+
import os
|
|
124
|
+
import sys
|
|
125
|
+
from typing import Tuple, Optional
|
|
126
|
+
|
|
127
|
+
# 2. Third-party (numpy, scipy)
|
|
128
|
+
import numpy as np
|
|
129
|
+
import scipy.fft
|
|
130
|
+
|
|
131
|
+
# 3. Local modules (relative imports)
|
|
132
|
+
from .core import get_dct_transfer_function
|
|
133
|
+
from .stats import dct_mean
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Project Structure
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
dct_toolkit/ # PROJECT ROOT
|
|
142
|
+
│
|
|
143
|
+
├── dct_toolkit/ # INSTALLABLE PACKAGE ⚠️ CODE GOES HERE
|
|
144
|
+
│ ├── __init__.py # Public API exports
|
|
145
|
+
│ ├── core.py # Transfer functions & 1D primitives
|
|
146
|
+
│ ├── cartesian.py # 2D Cartesian separable smoothing
|
|
147
|
+
│ ├── polar.py # 2D Polar smoothing (adaptive kernels)
|
|
148
|
+
│ ├── stats.py # Statistical ops (Normalized Convolution)
|
|
149
|
+
│ └── gap_filling.py # Gap-filling methods (deferred for public stats-first release)
|
|
150
|
+
│
|
|
151
|
+
├── tests/ # TEST SUITE ⚠️ TESTS GO HERE
|
|
152
|
+
│ ├── test_core.py
|
|
153
|
+
│ ├── test_cartesian.py
|
|
154
|
+
│ ├── test_polar.py
|
|
155
|
+
│ ├── test_stats.py
|
|
156
|
+
│ └── test_gap_filling.py
|
|
157
|
+
│
|
|
158
|
+
├── examples/ # USAGE EXAMPLES
|
|
159
|
+
│ ├── basic_polar.py
|
|
160
|
+
│ └── comprehensive_demo.py
|
|
161
|
+
│
|
|
162
|
+
├── exp_v3/ # EXPERIMENTS (reports + code)
|
|
163
|
+
│ ├── figures/ # Generated figures (PNG/PDF)
|
|
164
|
+
│ ├── test_width_impact.py
|
|
165
|
+
│ ├── plot_gap_filling_results.py
|
|
166
|
+
│ ├── GAP_FILLING_GUIDE.md
|
|
167
|
+
│ ├── TEST_REPORT_GAP_FILLING.md
|
|
168
|
+
│ ├── TEST_REPORT_CORE.md
|
|
169
|
+
│ └── gap_filling_results.csv
|
|
170
|
+
│
|
|
171
|
+
├── docs/ # DOCUMENTATION
|
|
172
|
+
│ ├── API_REFERENCE.md
|
|
173
|
+
│ ├── MATHEMATICAL_BASIS.md
|
|
174
|
+
│ └── GAP_FILLING_BASIS.md
|
|
175
|
+
│
|
|
176
|
+
├── README.md # Main documentation
|
|
177
|
+
├── CHANGELOG.md # Version history
|
|
178
|
+
└── AGENTS.md # This file
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Development Workflow
|
|
184
|
+
|
|
185
|
+
### Before Making Changes
|
|
186
|
+
|
|
187
|
+
1. **Activate Environment**
|
|
188
|
+
```bash
|
|
189
|
+
conda activate myenv
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
2. **Verify Baseline**
|
|
193
|
+
```bash
|
|
194
|
+
export PYTHONPATH=$PYTHONPATH:$(pwd)/dct_toolkit
|
|
195
|
+
python -m pytest tests/ -v
|
|
196
|
+
```
|
|
197
|
+
All tests in `tests/` must pass before you start.
|
|
198
|
+
|
|
199
|
+
3. **Review Documentation**
|
|
200
|
+
- Check `docs/MATHEMATICAL_BASIS.md` for theory
|
|
201
|
+
- Check `docs/GAP_FILLING_BASIS.md` for gap filling theory
|
|
202
|
+
- Check `docs/API_REFERENCE.md` for existing API
|
|
203
|
+
|
|
204
|
+
### Making Changes
|
|
205
|
+
|
|
206
|
+
1. **Edit Code**
|
|
207
|
+
- Modify appropriate module in `dct_toolkit/dct_toolkit/`
|
|
208
|
+
- Follow code style guidelines
|
|
209
|
+
- Add docstrings and type hints
|
|
210
|
+
|
|
211
|
+
2. **Add Tests**
|
|
212
|
+
- Add/update tests in `dct_toolkit/tests/`
|
|
213
|
+
- Tests should validate correctness with synthetic data
|
|
214
|
+
- Include edge cases (empty arrays, all NaN, etc.)
|
|
215
|
+
|
|
216
|
+
3. **Update Documentation**
|
|
217
|
+
- Update `API_REFERENCE.md` if API changes
|
|
218
|
+
- Update `CHANGELOG.md` with changes
|
|
219
|
+
- Update this file if workflow changes
|
|
220
|
+
|
|
221
|
+
### Testing (MANDATORY)
|
|
222
|
+
|
|
223
|
+
**Run Tests**:
|
|
224
|
+
```bash
|
|
225
|
+
export PYTHONPATH=$PYTHONPATH:$(pwd)/dct_toolkit
|
|
226
|
+
python -m pytest tests/ -v
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Expected Output**: all tests passing
|
|
230
|
+
|
|
231
|
+
**If Tests Fail**:
|
|
232
|
+
- Fix the code, not the tests
|
|
233
|
+
- Tests represent ground truth requirements
|
|
234
|
+
- Never commit with failing tests
|
|
235
|
+
|
|
236
|
+
### Pre-Completion Checklist
|
|
237
|
+
|
|
238
|
+
Before declaring task complete:
|
|
239
|
+
|
|
240
|
+
- [ ] All tests pass (`pytest tests/ -v`)
|
|
241
|
+
- [ ] No imports from outside `dct_toolkit/`
|
|
242
|
+
- [ ] All public functions have NumPy-style docstrings
|
|
243
|
+
- [ ] All functions have type hints
|
|
244
|
+
- [ ] Code follows naming conventions
|
|
245
|
+
- [ ] No tabs, 4-space indentation
|
|
246
|
+
- [ ] Line length ≤ 100 characters
|
|
247
|
+
- [ ] CHANGELOG.md updated
|
|
248
|
+
- [ ] Documentation updated if API changed
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Current Progress & Roadmap
|
|
253
|
+
|
|
254
|
+
### ✅ Completed (v0.4.0)
|
|
255
|
+
- [x] Core primitives (`core.py`)
|
|
256
|
+
- Transfer functions (boxcar, boxcar_discrete, gaussian)
|
|
257
|
+
- 1D DCT convolution
|
|
258
|
+
- [x] Cartesian smoothing (`cartesian.py`)
|
|
259
|
+
- Separable N-D smoothing
|
|
260
|
+
- [x] Polar smoothing (`polar.py`)
|
|
261
|
+
- Adaptive azimuth kernels
|
|
262
|
+
- Boundary conditions (reflective/periodic)
|
|
263
|
+
- [x] Statistical operations (`stats.py`)
|
|
264
|
+
- Normalized Convolution
|
|
265
|
+
- dct_count, dct_mean, dct_prefill, dct_variance, dct_std
|
|
266
|
+
- [x] Gap-filling module (`gap_filling.py`)
|
|
267
|
+
- iterative diffusion fill (`iterative_gap_fill`)
|
|
268
|
+
- DCT-PLS inpainting (`dct_inpaint`)
|
|
269
|
+
- [x] Test suite (`tests/`) passing
|
|
270
|
+
- [x] Documentation suite
|
|
271
|
+
|
|
272
|
+
### 🚧 In Progress: Publication Readiness (stats-first)
|
|
273
|
+
- [x] Fix immediate correctness issues in core statistics path
|
|
274
|
+
- [x] Create a dedicated publication-prep branch
|
|
275
|
+
- [ ] Update `AGENTS.md` / docs to reflect publication plan and current state
|
|
276
|
+
- [ ] Build clean public-facing scope focused on convolution/statistics
|
|
277
|
+
|
|
278
|
+
### 📋 Before Public Release
|
|
279
|
+
- [x] Add packaging metadata (`pyproject.toml`)
|
|
280
|
+
- [x] Add `LICENSE` and align README badges/claims
|
|
281
|
+
- [ ] Define public API surface (exclude gap filling for initial public release)
|
|
282
|
+
- [ ] Remove or relocate experimental assets from public-facing surface
|
|
283
|
+
- [x] Add CI for tests and minimum quality checks
|
|
284
|
+
|
|
285
|
+
### 🔭 Future (post-public v1)
|
|
286
|
+
- [ ] 3D support (volumetric data)
|
|
287
|
+
- [ ] Additional kernels (Savitzky-Golay, Hanning)
|
|
288
|
+
- [ ] Performance optimizations (numba?)
|
|
289
|
+
- [ ] Jupyter notebook examples
|
|
290
|
+
- [ ] conda-forge distribution
|
|
291
|
+
- [ ] Advanced gap filling (constrained optimization)
|
|
292
|
+
- [ ] GPU acceleration (CuPy)
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Key Technical Details
|
|
297
|
+
|
|
298
|
+
### Transfer Functions
|
|
299
|
+
- **Boxcar (Analytical)**: `H[k] = sin(W·θ)/(W·sin(θ))`, θ = πk/(2n)
|
|
300
|
+
- **Boxcar (Discrete)**: Sum of cosines for discrete kernels
|
|
301
|
+
- **Gaussian**: `H[k] = exp(-0.5·(ω·σ)²)`, σ = width/√12
|
|
302
|
+
|
|
303
|
+
### Normalized Convolution
|
|
304
|
+
Formula for robust mean with gaps:
|
|
305
|
+
```
|
|
306
|
+
μ = smooth(data * mask) / (smooth(mask) + ε)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Polar Coordinates
|
|
310
|
+
- **Data Layout**: (n_azimuth, n_range)
|
|
311
|
+
- **Adaptive Width**: w_az(r) = width / (r · dθ)
|
|
312
|
+
- **Boundary Conditions**:
|
|
313
|
+
- Reflective: DCT-II (even symmetry)
|
|
314
|
+
- Periodic: Real FFT (circular convolution)
|
|
315
|
+
|
|
316
|
+
### Testing Philosophy
|
|
317
|
+
- Synthetic data with known ground truth
|
|
318
|
+
- Verify theoretical properties (DC preservation, linearity)
|
|
319
|
+
- Edge case coverage (all NaN, single point, etc.)
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## Common Pitfalls & Solutions
|
|
324
|
+
|
|
325
|
+
### 1. Import Errors
|
|
326
|
+
**Problem**: `ModuleNotFoundError: No module named 'dct_toolkit'`
|
|
327
|
+
**Solution**:
|
|
328
|
+
```bash
|
|
329
|
+
export PYTHONPATH=$PYTHONPATH:$(pwd)/dct_toolkit
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### 2. Path Confusion
|
|
333
|
+
**Problem**: Tests run from wrong directory
|
|
334
|
+
**Solution**: Always run from project root (`dct_toolkit/`)
|
|
335
|
+
|
|
336
|
+
### 3. Polar Boundary Issues
|
|
337
|
+
**Problem**: Discontinuity at 360°/0°
|
|
338
|
+
**Solution**: Use `az_boundary='periodic'` for azimuth
|
|
339
|
+
|
|
340
|
+
### 4. Test Failures
|
|
341
|
+
**Problem**: Tests fail after changes
|
|
342
|
+
**Solution**: Fix the code, don't modify tests to pass
|
|
343
|
+
|
|
344
|
+
### 5. Legacy Code Contamination
|
|
345
|
+
**Problem**: Accidentally importing from `../src/`
|
|
346
|
+
**Solution**: Check with grep command in Critical Rule section
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Repository Management
|
|
351
|
+
|
|
352
|
+
### Private Repository (Current)
|
|
353
|
+
- Hosted on: GitHub (private)
|
|
354
|
+
- Access: Core team only
|
|
355
|
+
- Branching: feature branches → main
|
|
356
|
+
- Manual testing required until CI is added
|
|
357
|
+
|
|
358
|
+
### Planned Public Release Scope
|
|
359
|
+
- Initial public release is **convolution/statistics focused**
|
|
360
|
+
- Keep DCT + periodic FFT boundary support in smoothing/statistical APIs
|
|
361
|
+
- Defer gap-filling methods from initial public API surface
|
|
362
|
+
- Add packaging metadata + license before publication
|
|
363
|
+
|
|
364
|
+
### Publication Assets (Current Branch)
|
|
365
|
+
- `pyproject.toml` for pip builds and installation
|
|
366
|
+
- `LICENSE` (MIT)
|
|
367
|
+
- `.github/workflows/tests.yml` (pytest on push/PR)
|
|
368
|
+
- `docs/PUBLICATION_GUIDE.md` with pip + conda-forge steps
|
|
369
|
+
- `conda.recipe/meta.yaml` starter recipe for staged-recipes submission
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## Emergency Contacts & References
|
|
374
|
+
|
|
375
|
+
### Documentation
|
|
376
|
+
- **Math Theory**: `docs/MATHEMATICAL_BASIS.md`
|
|
377
|
+
- **Gap Filling Basis**: `docs/GAP_FILLING_BASIS.md`
|
|
378
|
+
- **API Details**: `docs/API_REFERENCE.md`
|
|
379
|
+
- **Core Test Report**: `exp_v3/TEST_REPORT_CORE.md`
|
|
380
|
+
- **Gap Filling Report**: `exp_v3/TEST_REPORT_GAP_FILLING.md`
|
|
381
|
+
|
|
382
|
+
### Code Examples
|
|
383
|
+
- **Polar Smoothing**: `examples/basic_polar.py`
|
|
384
|
+
- **Full Demo**: `examples/comprehensive_demo.py`
|
|
385
|
+
- **Gap Filling**: `exp_v3/test_width_impact.py`
|
|
386
|
+
|
|
387
|
+
### Key Papers & References
|
|
388
|
+
- Garcia (2010): DCT-PLS (contrast/background)
|
|
389
|
+
- Knutsson et al.: Normalized Convolution
|
|
390
|
+
- Ahmed et al.: DCT fundamentals
|
|
391
|
+
- Lecture 17 Notes: Objective Mapping / Kriging (for context)
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## Quick Reference Card
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
# Setup
|
|
399
|
+
conda activate myenv
|
|
400
|
+
export PYTHONPATH=$PYTHONPATH:$(pwd)/dct_toolkit
|
|
401
|
+
|
|
402
|
+
# Test
|
|
403
|
+
python -m pytest tests/ -v
|
|
404
|
+
|
|
405
|
+
# Run example
|
|
406
|
+
python examples/basic_polar.py
|
|
407
|
+
|
|
408
|
+
# Benchmark
|
|
409
|
+
python exp_v3/test_width_impact.py
|
|
410
|
+
|
|
411
|
+
# Check imports (should be empty)
|
|
412
|
+
grep -r "^from \.\./" dct_toolkit/dct_toolkit/
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
**Remember**: This is a standalone scientific package. Quality, correctness, and clarity are more important than speed. When in doubt, refer to the test suite - it defines the expected behavior.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Packaging + distribution groundwork**:
|
|
12
|
+
- Added `pyproject.toml` (PEP 517/518 via hatchling) for pip/wheel builds.
|
|
13
|
+
- Added `LICENSE` (MIT).
|
|
14
|
+
- Added GitHub Actions CI workflow `.github/workflows/tests.yml`.
|
|
15
|
+
- Added `docs/PUBLICATION_GUIDE.md` with PyPI + conda-forge release steps.
|
|
16
|
+
- Added `conda.recipe/meta.yaml` starter recipe for conda-forge submission prep.
|
|
17
|
+
- **Statistics API**:
|
|
18
|
+
- Added `dct_prefill` (iterative normalized-convolution prefill) and exported it
|
|
19
|
+
in the top-level API.
|
|
20
|
+
- Added regression tests for `dct_prefill` behavior and parameter validation.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- `stats.py`: improved dtype handling for integer inputs in `dct_mean`/`dct_variance`
|
|
24
|
+
with floating-point outputs and explicit mask-shape validation.
|
|
25
|
+
- `README.md` and `docs/API_REFERENCE.md`: refocused public surface on
|
|
26
|
+
convolution/statistics and documented `dct_prefill`.
|
|
27
|
+
- `examples/comprehensive_demo.py`: removed stale experimental imports and aligned
|
|
28
|
+
with stats-first public API.
|
|
29
|
+
|
|
30
|
+
## [0.4.0] - 2026-02-28
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
- **DCT Spectral Inpainting (`dct_inpaint`)**:
|
|
34
|
+
- New gap-filling method based on DCT-domain Penalised Least Squares (Garcia, 2010).
|
|
35
|
+
- Minimises ‖W·(y − û)‖² + λ·‖Δᵖ û‖² with automatic width-to-lambda mapping.
|
|
36
|
+
- Default order p=2 (bi-harmonic) preserves curvature across gaps — equivalent to
|
|
37
|
+
thin-plate spline interpolation.
|
|
38
|
+
- Supports both Cartesian (DCT-II reflective BC) and Polar (RFFT periodic azimuth +
|
|
39
|
+
DCT reflective range) coordinates.
|
|
40
|
+
- **Adaptive polar eigenvalues**: When `az_res_deg` is provided, azimuth penalty
|
|
41
|
+
scales with range (`1/(r·dθ)^(2p)`), mirroring `smooth_polar`'s adaptive kernels.
|
|
42
|
+
- Initialises with fast linear interpolation baseline, then refines iteratively.
|
|
43
|
+
- 2.9x more accurate than `iterative_gap_fill` and 34% more accurate than
|
|
44
|
+
`scipy.interpolate.griddata` on the standard polar benchmark (wrapping hole).
|
|
45
|
+
- **Input validation**: Rejects `width <= 0`, `order < 1`, invalid `coordinates`
|
|
46
|
+
and `az_boundary` values with clear error messages.
|
|
47
|
+
- **Helper functions**:
|
|
48
|
+
- `_width_to_lambda`: Derive Tikhonov lambda from smoothing width.
|
|
49
|
+
- `_eigenvalues_dct` / `_eigenvalues_dft`: Compute Laplacian eigenvalues for
|
|
50
|
+
reflective / periodic boundary conditions.
|
|
51
|
+
- `_compute_eigenvalues_2d`: Build 2-D eigenvalue tensor (isotropic or
|
|
52
|
+
polar-adaptive with range-dependent azimuth scaling).
|
|
53
|
+
- `_forward_transform` / `_inverse_transform`: Unified spectral transforms
|
|
54
|
+
supporting mixed BC (periodic azimuth + reflective range).
|
|
55
|
+
- **Test suite** (`tests/test_gap_filling.py`):
|
|
56
|
+
- 42 tests covering helpers, transform round-trips, convergence, 1D/2D Cartesian,
|
|
57
|
+
polar (periodic + reflective + adaptive eigenvalues), curvature preservation,
|
|
58
|
+
input validation, edge cases, and v3 comparison.
|
|
59
|
+
- **Benchmark** (`exp_v4/test_inpaint_vs_v3.py`):
|
|
60
|
+
- Reproduces exp_v3 polar benchmark with dct_inpaint added.
|
|
61
|
+
- **Noisy benchmark** (`exp_v4/test_noisy_inpaint.py`):
|
|
62
|
+
- Evaluates noise robustness across SNR levels 3–100.
|
|
63
|
+
- **Figures** (`exp_v4/figures/`):
|
|
64
|
+
- 8 publication-quality figures (PNG + PDF): spatial comparison (v3 vs v4 vs
|
|
65
|
+
griddata), error maps, width impact, convergence, method bar chart,
|
|
66
|
+
noisy spatial comparison, SNR sweep, and noisy width impact.
|
|
67
|
+
- **Documentation**:
|
|
68
|
+
- Updated `docs/API_REFERENCE.md` with full `dct_inpaint` entry.
|
|
69
|
+
- Updated `docs/GAP_FILLING_BASIS.md` with DCT-PLS theory, eigenvalue
|
|
70
|
+
diagonalisation, width-to-lambda bridge, and benchmark results.
|
|
71
|
+
- Updated `docs/MATHEMATICAL_BASIS.md` with cross-reference to inpainting theory.
|
|
72
|
+
- Updated `README.md` with gap filling features and usage examples.
|
|
73
|
+
- Updated `exp_v4/PLAN.md` with refined mathematical formulation.
|
|
74
|
+
|
|
75
|
+
### Changed
|
|
76
|
+
- `__init__.py`: Exports `dct_inpaint`; version bumped to `0.4.0`.
|
|
77
|
+
- `gap_filling.py`: Module docstring updated to document both algorithms.
|
|
78
|
+
`_compute_eigenvalues_2d` now accepts optional `az_res_deg` for polar-adaptive
|
|
79
|
+
eigenvalues.
|
|
80
|
+
|
|
81
|
+
## [0.2.1] - 2026-02-09
|
|
82
|
+
|
|
83
|
+
### Fixed
|
|
84
|
+
- **Gap Filling Initialization**:
|
|
85
|
+
- Improved `init='linear'` to prioritize azimuth interpolation without extrapolation (using range interpolation for edges), preventing artifacts on periodic boundaries.
|
|
86
|
+
- **Benchmark Consistency**:
|
|
87
|
+
- Unified `exp_v3/test_width_impact.py` and `exp_v3/plot_gap_filling_results.py` to use identical test scenarios (Index Space hole).
|
|
88
|
+
- Fixed MAE discrepancy in figures vs. report.
|
|
89
|
+
|
|
90
|
+
## [0.2.0] - 2026-02-09
|
|
91
|
+
|
|
92
|
+
### Added
|
|
93
|
+
- **Gap Filling Module (`gap_filling.py`)**:
|
|
94
|
+
- `iterative_gap_fill`: Constructive gap filling via iterative DCT-based diffusion.
|
|
95
|
+
- Linear interpolation initialization (axis-wise `np.interp`, default) — preserves spatial gradients across holes from the first iterate.
|
|
96
|
+
- Three initialization modes: `'linear'` (default), `'multiscale'` (coarse-to-fine DCT cascade), `'dct'` (single-pass Normalized Convolution).
|
|
97
|
+
- `smooth_output` option for combined gap-fill + noise reduction.
|
|
98
|
+
- Convergence via relative L2 norm change tolerance.
|
|
99
|
+
- **Comprehensive Gap Filling Test Suite** (`tests/test_gap_filling_comprehensive.py`):
|
|
100
|
+
- 13 tests covering accuracy, robustness, speed, convergence, init modes, backward compatibility, and edge cases.
|
|
101
|
+
- **Benchmark Suite** (`exp_v3/test_width_impact.py`):
|
|
102
|
+
- 84-evaluation benchmark (3 datasets x 7 gap scenarios x 4 methods) with auto-generated CSV results.
|
|
103
|
+
- **Figures** (`exp_v3/figures/`):
|
|
104
|
+
- 4 publication-quality figures (PNG + PDF): spatial comparison, width impact, iteration convergence, uncertainty maps.
|
|
105
|
+
- **Test Report** (`exp_v3/TEST_REPORT_GAP_FILLING.md`):
|
|
106
|
+
- Auto-generated benchmark report; all 5 evaluation criteria PASS.
|
|
107
|
+
- **Algorithm Documentation** (`exp_v3/GAP_FILLING_GUIDE.md`):
|
|
108
|
+
- Algorithm description, tuning guidance, and key findings from diagnostic analysis.
|
|
109
|
+
|
|
110
|
+
### Changed
|
|
111
|
+
- `__init__.py`: Exports `iterative_gap_fill`; version bumped to `0.2.0`.
|
|
112
|
+
- Gap filling promoted from `experimental/` to core module `dct_toolkit/gap_filling.py`.
|
|
113
|
+
|
|
114
|
+
### Deprecated
|
|
115
|
+
- `multiscale` parameter in `iterative_gap_fill` — use `init='multiscale'` or `init='dct'` instead. Emits `FutureWarning`.
|
|
116
|
+
|
|
117
|
+
## [0.1.0] - 2026-02-08
|
|
118
|
+
|
|
119
|
+
### Added
|
|
120
|
+
- **Core Package Structure**: Created `dct_toolkit` as a standalone python package.
|
|
121
|
+
- **Core Primitives (`core.py`)**:
|
|
122
|
+
- Analytical and Discrete transfer functions for 'boxcar', 'boxcar_discrete', 'gaussian'.
|
|
123
|
+
- `dct_convolve_1d` primitive using DCT-II/Ortho.
|
|
124
|
+
- **2D Cartesian Smoothing (`cartesian.py`)**:
|
|
125
|
+
- Separable N-D smoothing implementation.
|
|
126
|
+
- **2D Polar Smoothing (`polar.py`)**:
|
|
127
|
+
- Support for (Azimuth, Range) data layout.
|
|
128
|
+
- Adaptive azimuth kernel width (maintains constant physical width).
|
|
129
|
+
- Boundary conditions: 'reflective' (DCT) and 'periodic' (Real FFT) for azimuth.
|
|
130
|
+
- **Statistical Operations (`stats.py`)**:
|
|
131
|
+
- `dct_count`: Effective sample size calculation.
|
|
132
|
+
- `dct_mean`: Robust local mean using Normalized Convolution (handles NaNs).
|
|
133
|
+
- `dct_variance` & `dct_std`: Robust second-moment statistics.
|
|
134
|
+
- **Experimental Gap Filling (`experimental/`)**:
|
|
135
|
+
- Iterative Constructive Gap Filler based on `dct_mean`.
|
|
136
|
+
- Benchmark script showing >100x accuracy improvement over linear interpolation for smooth fields.
|
|
137
|
+
- **Validation**:
|
|
138
|
+
- Comprehensive test suite in `tests/`.
|
|
139
|
+
- Example script `examples/basic_polar.py` demonstrating boundary conditions.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jairo M. Valdivia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|