waveforge 0.1.0__py3-none-any.whl
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.
- waveforge/__init__.py +6 -0
- waveforge/models.py +35 -0
- waveforge/py.typed +0 -0
- waveforge/wavelets/__init__.py +0 -0
- waveforge/wavelets/quadratic_spline/__init__.py +13 -0
- waveforge/wavelets/quadratic_spline/generator.py +91 -0
- waveforge/wavelets/quadratic_spline/loader.py +39 -0
- waveforge-0.1.0.dist-info/METADATA +198 -0
- waveforge-0.1.0.dist-info/RECORD +11 -0
- waveforge-0.1.0.dist-info/WHEEL +4 -0
- waveforge-0.1.0.dist-info/licenses/LICENSE +21 -0
waveforge/__init__.py
ADDED
waveforge/models.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ScaleConfiguration(BaseModel):
|
|
5
|
+
"""Configuration of DWT filter coefficients at a specific scale."""
|
|
6
|
+
|
|
7
|
+
model_config = ConfigDict(extra="forbid")
|
|
8
|
+
|
|
9
|
+
min_index: int
|
|
10
|
+
max_index: int
|
|
11
|
+
terms: int = Field(gt=0)
|
|
12
|
+
numerators: list[int]
|
|
13
|
+
denominator: float = Field(gt=0)
|
|
14
|
+
|
|
15
|
+
@model_validator(mode="after")
|
|
16
|
+
def validate_configuration(self):
|
|
17
|
+
expected_terms = self.max_index - self.min_index + 1
|
|
18
|
+
|
|
19
|
+
if self.terms != expected_terms:
|
|
20
|
+
raise ValueError("Terms must equal max_index - min_index + 1.")
|
|
21
|
+
|
|
22
|
+
if len(self.numerators) != self.terms:
|
|
23
|
+
raise ValueError("The number of numerators must equal terms.")
|
|
24
|
+
|
|
25
|
+
return self
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DWTConfiguration(BaseModel):
|
|
29
|
+
"""Configuration containing DWT coefficients across multiple scales."""
|
|
30
|
+
|
|
31
|
+
model_config = ConfigDict(extra="forbid")
|
|
32
|
+
|
|
33
|
+
wavelet: str
|
|
34
|
+
version: str
|
|
35
|
+
scales: dict[int, ScaleConfiguration]
|
waveforge/py.typed
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .generator import (
|
|
2
|
+
generate_coefficients,
|
|
3
|
+
generate_scale_configuration,
|
|
4
|
+
save_coefficients,
|
|
5
|
+
)
|
|
6
|
+
from .loader import load_coefficients
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"generate_coefficients",
|
|
10
|
+
"generate_scale_configuration",
|
|
11
|
+
"save_coefficients",
|
|
12
|
+
"load_coefficients",
|
|
13
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from waveforge.models import DWTConfiguration, ScaleConfiguration
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def generate_scale_configuration(scale: int) -> ScaleConfiguration:
|
|
8
|
+
"""
|
|
9
|
+
Generate Quadratic Spline DWT coefficients for a given scale.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
if type(scale) is not int or scale < 1:
|
|
13
|
+
raise ValueError("Scale must be a positive integer.")
|
|
14
|
+
|
|
15
|
+
# Calculate scale-dependent parameters
|
|
16
|
+
min_index = -(2**scale + 2 ** (scale - 1) - 2)
|
|
17
|
+
max_index = 2 ** (scale - 1) - 1
|
|
18
|
+
terms = 2 ** (scale + 1) - 2
|
|
19
|
+
denominator = float(2 ** (3 * scale - 4))
|
|
20
|
+
|
|
21
|
+
half_terms = terms // 2
|
|
22
|
+
|
|
23
|
+
# Generate the first half of the numerator sequence
|
|
24
|
+
first_half: list[int] = []
|
|
25
|
+
|
|
26
|
+
for k in range(1, half_terms + 1):
|
|
27
|
+
if k <= 2 ** (scale - 1):
|
|
28
|
+
# Triangular number sequence
|
|
29
|
+
numerator = k * (k + 1) // 2
|
|
30
|
+
|
|
31
|
+
else:
|
|
32
|
+
# Remaining first-half coefficients
|
|
33
|
+
r = half_terms - k + 1
|
|
34
|
+
|
|
35
|
+
numerator = (-3 * r**2 + 3 * r + 2**scale * (2 * r - 1)) // 2
|
|
36
|
+
|
|
37
|
+
first_half.append(numerator)
|
|
38
|
+
|
|
39
|
+
# Second half: negative reverse of the first half
|
|
40
|
+
second_half = [-value for value in reversed(first_half)]
|
|
41
|
+
|
|
42
|
+
numerators = first_half + second_half
|
|
43
|
+
|
|
44
|
+
return ScaleConfiguration(
|
|
45
|
+
min_index=min_index,
|
|
46
|
+
max_index=max_index,
|
|
47
|
+
terms=terms,
|
|
48
|
+
numerators=numerators,
|
|
49
|
+
denominator=denominator,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def generate_coefficients(max_scale: int) -> DWTConfiguration:
|
|
54
|
+
"""
|
|
55
|
+
Generate Quadratic Spline DWT configurations from scale 1
|
|
56
|
+
up to the specified maximum scale.
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
if type(max_scale) is not int or max_scale < 1:
|
|
60
|
+
raise ValueError("Maximum scale must be a positive integer.")
|
|
61
|
+
|
|
62
|
+
scales = {
|
|
63
|
+
scale: generate_scale_configuration(scale) for scale in range(1, max_scale + 1)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return DWTConfiguration(wavelet="Quadratic Spline", version="1.0", scales=scales)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def save_coefficients(config: DWTConfiguration, dir: str | Path | None = None) -> Path:
|
|
70
|
+
"""Save coefficients using configuration metadata."""
|
|
71
|
+
|
|
72
|
+
wavelet_name = re.sub(r"[^a-zA-Z0-9]+", "_", config.wavelet).strip("_").lower()
|
|
73
|
+
|
|
74
|
+
scale_numbers = sorted(config.scales)
|
|
75
|
+
|
|
76
|
+
if not scale_numbers:
|
|
77
|
+
raise ValueError("Cannot save an empty configuration.")
|
|
78
|
+
|
|
79
|
+
filename = (
|
|
80
|
+
f"{wavelet_name}_v{config.version}_"
|
|
81
|
+
f"scales_{scale_numbers[0]}-{scale_numbers[-1]}.json"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
output_dir = Path(dir) if dir is not None else Path.cwd()
|
|
85
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
86
|
+
|
|
87
|
+
output_path = output_dir / filename
|
|
88
|
+
|
|
89
|
+
output_path.write_text(config.model_dump_json(indent=4), encoding="utf-8")
|
|
90
|
+
|
|
91
|
+
return output_path
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from waveforge.models import DWTConfiguration
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def load_coefficients(filename: str, dir: str | Path | None = None) -> DWTConfiguration:
|
|
7
|
+
"""
|
|
8
|
+
Load Quadratic Spline DWT coefficients from a JSON file.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
filename : str
|
|
13
|
+
Name of the JSON file.
|
|
14
|
+
dir : str or Path, optional
|
|
15
|
+
Directory containing the JSON file.
|
|
16
|
+
Defaults to the current working directory.
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
DWTConfiguration
|
|
21
|
+
Validated DWT coefficient configuration.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
input_dir = Path(dir) if dir is not None else Path.cwd()
|
|
25
|
+
file_path = input_dir / filename
|
|
26
|
+
|
|
27
|
+
if not file_path.is_file():
|
|
28
|
+
raise FileNotFoundError(f"Coefficient configuration not found: {file_path}")
|
|
29
|
+
|
|
30
|
+
json_data = file_path.read_text(encoding="utf-8")
|
|
31
|
+
|
|
32
|
+
config = DWTConfiguration.model_validate_json(json_data)
|
|
33
|
+
|
|
34
|
+
if config.wavelet != "Quadratic Spline":
|
|
35
|
+
raise ValueError(
|
|
36
|
+
f"Expected Quadratic Spline configuration, got '{config.wavelet}'."
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
return config
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: waveforge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A toolkit for generating and managing DWT configurations.
|
|
5
|
+
Author-email: Agra Bima Yuda <hub.agrayuda@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.14
|
|
9
|
+
Requires-Dist: pydantic>=2.14.4
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# WaveForge
|
|
13
|
+
|
|
14
|
+
A Python toolkit for generating, storing, and loading Discrete Wavelet Transform (DWT) coefficient configurations.
|
|
15
|
+
|
|
16
|
+
## Overview
|
|
17
|
+
|
|
18
|
+
WaveForge provides a structured approach to managing DWT filter coefficient configurations across different wavelet families.
|
|
19
|
+
|
|
20
|
+
Currently, WaveForge implements the **Quadratic Spline Wavelet** coefficient generator, supporting the generation of coefficient configurations at multiple scales. Configurations can be saved as JSON files and loaded back into validated Python objects using Pydantic.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- Generate Quadratic Spline DWT coefficients for individual scales.
|
|
25
|
+
- Generate coefficient configurations across multiple scales.
|
|
26
|
+
- Automatically generate configuration filenames based on wavelet metadata.
|
|
27
|
+
- Save coefficient configurations as JSON files.
|
|
28
|
+
- Load and validate coefficient configurations from JSON files.
|
|
29
|
+
- Validate configuration structures using Pydantic.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Clone the repository:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone <repository-url>
|
|
37
|
+
cd waveforge
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Install the package in editable mode:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### 1. Generate Coefficient Configurations
|
|
49
|
+
|
|
50
|
+
Generate coefficients for a specific scale:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from waveforge.wavelets.quadratic_spline import (
|
|
54
|
+
generate_scale_configuration
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
scale_config = generate_scale_configuration(3)
|
|
58
|
+
|
|
59
|
+
print(scale_config)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Generate configurations from scale 1 up to a specified maximum scale:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from waveforge.wavelets.quadratic_spline import (
|
|
66
|
+
generate_coefficients
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
config = generate_coefficients(5)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. Save Coefficient Configurations
|
|
73
|
+
|
|
74
|
+
Save a configuration as a JSON file:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from waveforge.wavelets.quadratic_spline import (
|
|
78
|
+
generate_coefficients,
|
|
79
|
+
save_coefficients
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
config = generate_coefficients(5)
|
|
83
|
+
|
|
84
|
+
output_path = save_coefficients(config)
|
|
85
|
+
|
|
86
|
+
print(output_path)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
By default, the file is saved in the current working directory.
|
|
90
|
+
|
|
91
|
+
You can also specify a destination directory:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
output_path = save_coefficients(
|
|
95
|
+
config,
|
|
96
|
+
dir="data/coefficients"
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The filename is automatically generated using the wavelet name, configuration version, and scale range.
|
|
101
|
+
|
|
102
|
+
Example:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
quadratic_spline_v1.0_scales_1-5.json
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 3. Load Coefficient Configurations
|
|
109
|
+
|
|
110
|
+
Load a previously saved configuration:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from waveforge.wavelets.quadratic_spline import (
|
|
114
|
+
load_coefficients
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
config = load_coefficients(
|
|
118
|
+
"quadratic_spline_v1.0_scales_1-5.json"
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
You can also specify the directory containing the JSON file:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
config = load_coefficients(
|
|
126
|
+
"quadratic_spline_v1.0_scales_1-5.json",
|
|
127
|
+
dir="data/coefficients"
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The loader reconstructs and validates the configuration using Pydantic.
|
|
132
|
+
|
|
133
|
+
## Configuration Models
|
|
134
|
+
|
|
135
|
+
WaveForge uses two primary data models:
|
|
136
|
+
|
|
137
|
+
| Model | Description |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `ScaleConfiguration` | Represents DWT filter coefficients and their associated parameters at a specific scale. |
|
|
140
|
+
| `DWTConfiguration` | Represents a complete DWT configuration containing coefficient data across multiple scales. |
|
|
141
|
+
|
|
142
|
+
Both models are available directly from the main package:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from waveforge import DWTConfiguration, ScaleConfiguration
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Project Structure
|
|
149
|
+
|
|
150
|
+
```text
|
|
151
|
+
waveforge/
|
|
152
|
+
├── pyproject.toml
|
|
153
|
+
├── README.md
|
|
154
|
+
├── src/
|
|
155
|
+
│ └── waveforge/
|
|
156
|
+
│ ├── __init__.py
|
|
157
|
+
│ ├── models.py
|
|
158
|
+
│ ├── wavelets/
|
|
159
|
+
│ │ ├── __init__.py
|
|
160
|
+
│ │ └── quadratic_spline/
|
|
161
|
+
│ │ ├── __init__.py
|
|
162
|
+
│ │ ├── generator.py
|
|
163
|
+
│ │ └── loader.py
|
|
164
|
+
│ └── data/
|
|
165
|
+
└── tests/
|
|
166
|
+
├── test_models.py
|
|
167
|
+
└── wavelets/
|
|
168
|
+
└── quadratic_spline/
|
|
169
|
+
├── test_generator.py
|
|
170
|
+
└── test_loader.py
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Testing
|
|
174
|
+
|
|
175
|
+
WaveForge uses `pytest` for automated testing.
|
|
176
|
+
|
|
177
|
+
Install pytest:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pip install pytest
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Run the test suite from the project root:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pytest -v
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Dependencies
|
|
190
|
+
|
|
191
|
+
- Python 3.10 or later
|
|
192
|
+
- Pydantic 2.x
|
|
193
|
+
- pytest (development and testing)
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
No license has been specified yet.
|
|
198
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
waveforge/__init__.py,sha256=F6l7-G2f1dIGaWgYykWhO8EyQ68R5tt0FuWZMzGos0k,122
|
|
2
|
+
waveforge/models.py,sha256=124WhlJsGuN5djQGSWWL3UgTM_1JVdv9J0CcaawR0QE,990
|
|
3
|
+
waveforge/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
waveforge/wavelets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
waveforge/wavelets/quadratic_spline/__init__.py,sha256=o9-QjmDWkODO7eqtjXIe9hPtWucZfIwZiDCfHjDH8Bw,279
|
|
6
|
+
waveforge/wavelets/quadratic_spline/generator.py,sha256=mLw5abLK1XnyiUSbfkoIvvWuAA0t3BufYqQ4lhC0wtw,2654
|
|
7
|
+
waveforge/wavelets/quadratic_spline/loader.py,sha256=SDza6cDeMFZGpY__vQjGmhBleD2LRlJCcIS0wXb0oVE,1058
|
|
8
|
+
waveforge-0.1.0.dist-info/METADATA,sha256=lqrse4eTPsXWETMXoVtVufg9FLkbB8BxeZ6QlAM6rFA,4445
|
|
9
|
+
waveforge-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
10
|
+
waveforge-0.1.0.dist-info/licenses/LICENSE,sha256=rXuFbcy_7GiEvLkbqAkThPs0d28jmyMieQ6NJ7FzpwI,1066
|
|
11
|
+
waveforge-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agra Yuda
|
|
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.
|