|
| 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. |
0 commit comments