Skip to content

Commit a1b9611

Browse files
committed
Merge branch 'main' into paper
2 parents 27fc8cf + 3644b00 commit a1b9611

File tree

3 files changed

+286
-0
lines changed

3 files changed

+286
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525

2626
Optical satellite communications is a growing research field with bright commercial perspectives. One of the challenges for optical links through the atmosphere is turbulence, which is also apparent by the twinkling of stars. The reduction of the quality can be calculated, but it needs the turbulence strength over the path the optical beam is running. Estimation of the turbulence strength is done at astronomic sites, but not at rural or urban sites. To be able to do this, a simple instrument is required. We want to propose to use a single star Scintillation Detection and Ranging (SCIDAR), which is an instrument that can estimate the turbulence strength, based on the observation of a single star. In this setting, reliable signal processing of the received images of the star is most challenging. We propose to solve this by Machine Learning.
2727

28+
## Statement of Need
29+
30+
`SpeckleCn2Profiler` addresses the challenge of atmospheric turbulence profiling for optical satellite communications using machine learning-based analysis of SCIDAR data. The primary target users include:
31+
32+
- **Aerospace engineers** working on free-space optical communication systems
33+
- **Atmospheric scientists** studying turbulence profiles and optical propagation
34+
- **Astronomers** characterizing atmospheric seeing conditions
35+
- **Researchers** in adaptive optics and atmospheric characterization
36+
37+
While traditional SCIDAR instruments require complex signal processing, `SpeckleCn2Profiler` provides a machine learning-based approach that enables simpler, more accessible turbulence profiling. Unlike classical methods that rely on analytical inversion techniques, our ML-based approach can handle noisy data more robustly and provides uncertainty quantification through ensemble predictions.
38+
2839
## Repository Contents
2940

3041
This repository contains the workflow to implement and train machine learning models for turbulence strength estimation from SCIDAR data. Extensive **[Documentation](https://males-project.github.io/SpeckleCn2Profiler/)** is available to explain the methodology, algorithms used, and guidelines for using the code.
@@ -108,6 +119,45 @@ where `<mycode.py>` is the name of the script that trains/uses the `speckcn2` mo
108119

109120
[Here](https://males-project.github.io/SpeckleCn2Profiler/examples/run) you can find a typical example run and an explanation of all the main configuration parameter. In the [example submodule](https://github.com/MALES-project/examples_speckcn2/) you can find multiple examples and multiple configuration to take inspiration from.
110121

122+
### Quick Example
123+
124+
Here's a minimal working example to train a model on sample data:
125+
126+
```python
127+
import speckcn2 as sp2
128+
import torch
129+
130+
# Load configuration
131+
config = sp2.load_config('path/to/config.yaml')
132+
133+
# Prepare data
134+
all_images, all_tags, all_ensemble_ids = sp2.prepare_data(config)
135+
136+
# Normalize tags
137+
nz = sp2.Normalizer(config)
138+
139+
# Split data
140+
train_set, test_set = sp2.train_test_split(all_images, all_tags,
141+
all_ensemble_ids, nz)
142+
143+
# Setup model
144+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
145+
model, last_model_state = sp2.setup_model(config)
146+
model = model.to(device)
147+
148+
# Define loss and optimizer
149+
criterion = sp2.ComposableLoss(config, nz, device)
150+
optimizer = sp2.setup_optimizer(config, model)
151+
152+
# Train
153+
model, avg_loss = sp2.train(model, last_model_state, config,
154+
train_set, test_set, device,
155+
optimizer, criterion, criterion)
156+
print(f'Training complete. Final loss: {avg_loss:.5f}')
157+
```
158+
159+
Sample data and configuration files are available in the [examples/](examples/) directory.
160+
111161
## What can we predict?
112162

113163
A machine learning model trained using `speckcn2` can predict:
@@ -124,6 +174,23 @@ The model can also estimate important parameters that are useful for the analysi
124174

125175
We also provide histograms of the estimated parameters and the error of the estimation.
126176

177+
## Running Tests
178+
179+
To verify your installation and ensure everything works correctly, you can run the test suite using [pytest](https://docs.pytest.org/):
180+
181+
```bash
182+
pytest
183+
```
184+
185+
**Note:** Some tests may fail on first run because test data needs to be set up. If this happens, run:
186+
187+
```bash
188+
python ./scripts/setup_test.py
189+
pytest
190+
```
191+
192+
For more details on testing and development, see our [Contributing Guidelines](CONTRIBUTING.md#Running-tests).
193+
127194
## Contribution Guidelines
128195

129196
We welcome contributions to improve and expand the capabilities of this project. If you have ideas, bug fixes, or enhancements, please submit a pull request.

docs/quickstart.md

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Quickstart Guide
2+
3+
This guide will help you get started with `speckcn2` quickly. Follow these steps to install the package, verify your installation, and run your first example.
4+
5+
## 1. Install SpeckleCn2Profiler
6+
7+
First, install the package using pip. We recommend using a virtual environment:
8+
9+
```bash
10+
# Create and activate a virtual environment
11+
python -m venv speckcn2-env
12+
source speckcn2-env/bin/activate # On Windows: speckcn2-env\Scripts\activate
13+
14+
# Install the package
15+
pip install speckcn2
16+
```
17+
18+
!!! tip "Need more details?"
19+
For platform-specific instructions and troubleshooting, see the full [Installation Guide](installation.md).
20+
21+
## 2. Verify Installation
22+
23+
Verify that the package is installed correctly:
24+
25+
```bash
26+
python -c "import speckcn2; print('Installation successful!')"
27+
```
28+
29+
## 3. Run Tests
30+
31+
To ensure everything is working properly, run the test suite:
32+
33+
```bash
34+
# Install pytest if not already installed
35+
pip install pytest
36+
37+
# Run tests
38+
pytest
39+
```
40+
41+
!!! note "First-time test setup"
42+
Some tests may fail on the first run because test data needs to be set up. If this happens, run:
43+
```bash
44+
python ./scripts/setup_test.py
45+
pytest
46+
```
47+
48+
## 4. Try a Minimal Example
49+
50+
Here's a minimal working example to train a model on sample data. Save this as `quickstart_train.py`:
51+
52+
```python
53+
import speckcn2 as sp2
54+
import torch
55+
56+
def main():
57+
# Load configuration (you'll need to provide your own config file)
58+
config = sp2.load_config('path/to/config.yaml')
59+
60+
# Prepare data
61+
print("Preparing data...")
62+
all_images, all_tags, all_ensemble_ids = sp2.prepare_data(config)
63+
64+
# Normalize tags (helps the model work with reasonable numbers)
65+
nz = sp2.Normalizer(config)
66+
67+
# Split data into training and testing sets
68+
train_set, test_set = sp2.train_test_split(
69+
all_images, all_tags, all_ensemble_ids, nz
70+
)
71+
72+
# Setup device (GPU if available, otherwise CPU)
73+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
74+
print(f'Using device: {device}')
75+
76+
# Load and configure the model
77+
model, last_model_state = sp2.setup_model(config)
78+
model = model.to(device)
79+
80+
# Define loss function and optimizer
81+
criterion = sp2.ComposableLoss(config, nz, device)
82+
optimizer = sp2.setup_optimizer(config, model)
83+
84+
# Train the model
85+
print("Training model...")
86+
model, avg_loss = sp2.train(
87+
model, last_model_state, config,
88+
train_set, test_set, device,
89+
optimizer, criterion, criterion
90+
)
91+
92+
print(f'Training complete! Final loss: {avg_loss:.5f}')
93+
94+
if __name__ == '__main__':
95+
main()
96+
```
97+
98+
Run the script with:
99+
100+
```bash
101+
python quickstart_train.py
102+
```
103+
104+
## 5. Working with Example Data
105+
106+
The repository includes sample data and configuration files. To use them:
107+
108+
### Clone the Examples Repository
109+
110+
```bash
111+
git clone https://github.com/MALES-project/examples_speckcn2.git
112+
cd examples_speckcn2
113+
```
114+
115+
### Run with Sample Configuration
116+
117+
Use one of the provided configuration files:
118+
119+
```bash
120+
python example_train.py configurations/configuration_ResNet18.yaml
121+
```
122+
123+
This will:
124+
125+
- Load the sample speckle pattern data
126+
- Train a ResNet18 model to predict turbulence profiles
127+
- Save the trained model and results
128+
129+
### Expected Output
130+
131+
You should see output similar to:
132+
133+
```
134+
Using cuda.
135+
Preparing data...
136+
Loading images from ./data/
137+
Training model...
138+
Epoch 1/100, Loss: 0.12345
139+
Epoch 2/100, Loss: 0.11234
140+
...
141+
Finished Training, Loss: 0.05432
142+
```
143+
144+
## 6. Next Steps
145+
146+
Now that you have `speckcn2` running, here are some suggested next steps:
147+
148+
### Learn More About Configuration
149+
150+
The configuration file controls all aspects of training, from data preprocessing to model architecture. Learn how to customize it:
151+
152+
- **[Configuration Guide](examples/run.md#configuration-file-explanation)** - Detailed explanation of all configuration parameters
153+
154+
### Explore Different Models
155+
156+
`speckcn2` supports multiple model architectures:
157+
158+
- ResNet18, ResNet50, ResNet152
159+
- Custom SCNN (Steerable CNN)
160+
- Equivariant models for rotation-invariant predictions
161+
162+
See the [Models API](api/models.md) for more details.
163+
164+
### Understand Your Data
165+
166+
Learn about the input data format and how to prepare your own SCIDAR observations:
167+
168+
- **[Input Data Guide](examples/input_data.md)** - Data format specifications and preparation
169+
170+
### Run Postprocessing and Analysis
171+
172+
After training, analyze your model's performance:
173+
174+
```python
175+
# Score the model on test data
176+
test_tags, test_losses, test_measures, test_cn2_pred, test_cn2_true, \
177+
test_recovered_tag_pred, test_recovered_tag_true = sp2.score(
178+
model, test_set, device, criterion, nz
179+
)
180+
181+
# Plot results
182+
sp2.plot_J_error_details(config, test_recovered_tag_true, test_recovered_tag_pred)
183+
sp2.plot_loss(config, model, datadirectory)
184+
```
185+
186+
See the [Postprocessing Guide](examples/run.md#plotting) for visualization examples.
187+
188+
### Predict Turbulence Parameters
189+
190+
Beyond Cn² profiles, `speckcn2` can predict important atmospheric parameters:
191+
192+
- **Fried parameter** (`r₀`) - measures atmospheric coherence length
193+
- **Isoplanatic angle** (`θ₀`) - angular size of coherent atmospheric regions
194+
- **Rytov index** (`σ`) - scintillation strength indicator
195+
196+
Configure these in the `preproc` section of your configuration file.
197+
198+
## Need Help?
199+
200+
- **Full Documentation**: Browse the complete [documentation](index.md) for in-depth guides
201+
- **API Reference**: Check the [Python API](api/api.md) for detailed function documentation
202+
- **Examples**: Explore more [examples](examples/run.md) and use cases
203+
- **Issues**: Report bugs or request features on [GitHub Issues](https://github.com/MALES-project/SpeckleCn2Profiler/issues)
204+
- **Contributing**: Want to contribute? See our [Contributing Guidelines](CONTRIBUTING.md)
205+
206+
## Quick Reference
207+
208+
| Task | Command |
209+
|------|---------|
210+
| Install package | `pip install speckcn2` |
211+
| Verify installation | `python -c "import speckcn2"` |
212+
| Run tests | `pytest` |
213+
| Train a model | `python train.py config.yaml` |
214+
| Check documentation | Visit [https://males-project.github.io/SpeckleCn2Profiler/](https://males-project.github.io/SpeckleCn2Profiler/) |
215+
216+
---
217+
218+
**Ready to dive deeper?** Head to the [Examples section](examples/run.md) for complete walkthroughs and detailed explanations.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ repo_name: Speckcn2
55

66
nav:
77
- Home: index.md
8+
- Quickstart: quickstart.md
89
- Installation: installation.md
910
- Examples:
1011
- Input data: examples/input_data.md

0 commit comments

Comments
 (0)