Configuration¶
PFB-Imaging uses a flexible configuration system based on YAML schemas. Each worker has its own configuration schema that automatically generates CLI parameters.
Configuration Methods¶
1. Command Line Arguments¶
The simplest way to configure PFB-Imaging:
2. Configuration Files¶
Create a YAML configuration file:
Use with:
3. Environment Variables¶
Set configuration via environment variables:
Common Configuration Options¶
Global Options¶
These options are available for all workers:
# Processing
nworkers: 4 # Number of parallel workers
nthreads_per_worker: 2 # Threads per worker
scheduler: threads # Dask scheduler type
# Output
output_filename: my_image # Base name for outputs
fits_output_folder: outputs/ # Directory for FITS files
log_level: INFO # Logging level
# Performance
chunks: 4096 # Chunk size for arrays
memory_limit: 8GB # Memory limit per worker
Gridding Options¶
Configure the gridding process:
# Image parameters
nx: 2048 # Image width
ny: 2048 # Image height
cell_size: 2.0 # Cell size in arcseconds
field_of_view: 2.0 # Field of view in degrees
# Gridding
epsilon: 1e-7 # Gridding accuracy
do_psf: true # Compute PSF
do_residual: true # Compute residual
do_dirty: true # Compute dirty image
# Weighting
robust: 0.0 # Robust weighting parameter
natural: false # Use natural weighting
Deconvolution Options¶
Classical CLEAN (kclean)¶
# Basic parameters
niter: 1000 # Maximum iterations
threshold: 0.01 # Cleaning threshold
gain: 0.1 # CLEAN gain
# Advanced
cyclefactor: 2.5 # Major cycle trigger
nchan: 1 # Number of channels
nband: 1 # Number of bands
SARA Deconvolution¶
# Regularization
gamma: 0.1 # Regularization parameter
l1_reweight_from: 100 # Start reweighting iteration
reweight_alpha: 0.8 # Reweighting parameter
# Constraints
positivity: true # Enforce positivity
flux_constraint: false # Enforce flux constraint
peak_constraint: false # Enforce peak constraint
# Optimization
tol: 1e-5 # Convergence tolerance
maxit: 500 # Maximum iterations
Schema-Based Configuration¶
PFB-Imaging uses YAML schemas to define configuration parameters. Schemas are located in pfb/parser/ and automatically generate CLI interfaces.
Example Schema¶
# pfb/parser/kclean.yaml
niter:
dtype: int
default: 1000
help: Maximum number of iterations
threshold:
dtype: float
default: 0.01
help: Cleaning threshold as fraction of peak
gain:
dtype: float
default: 0.1
help: CLEAN gain factor
Custom Configuration¶
Create custom configurations for specific use cases:
Environment-Specific Configuration¶
Development¶
Production¶
# prod_config.yaml
log_level: INFO
nworkers: 16
nthreads_per_worker: 2
memory_limit: 16GB
chunks: 8192
Cluster Computing¶
Performance Tuning¶
Memory Management¶
# Memory optimization
chunks: 2048 # Smaller chunks for less memory
memory_limit: 4GB # Per-worker memory limit
spill_to_disk: true # Enable disk spilling
CPU Optimization¶
# CPU optimization
nthreads_per_worker: 4 # Match CPU cores
scheduler: threads # Use threaded scheduler
I/O Optimization¶
Advanced Configuration¶
Dask Configuration¶
Create a Dask configuration file:
# dask.yaml
distributed:
worker:
memory:
target: 0.8
spill: 0.9
pause: 0.95
terminate: 0.98
scheduler:
allowed-failures: 10
work-stealing: true
Set with:
Logging Configuration¶
# logging.yaml
version: 1
formatters:
standard:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
default:
class: logging.StreamHandler
formatter: standard
level: INFO
loggers:
pfb:
level: DEBUG
handlers: [default]
Configuration Validation¶
PFB-Imaging validates configuration parameters:
# Check configuration
pfb kclean --config config.yaml --validate-only
# Show default configuration
pfb kclean --show-config
Best Practices¶
1. Use Version Control¶
Store configuration files in version control:
2. Environment-Specific Configs¶
Maintain separate configs for different environments:
3. Parameter Sweeps¶
Use configuration files for parameter studies:
# Different regularization parameters
for gamma in 0.01 0.1 1.0; do
sed "s/gamma: .*/gamma: $gamma/" config.yaml > config_$gamma.yaml
pfb sara --config config_$gamma.yaml --output-filename image_$gamma
done
4. Documentation¶
Document your configuration choices:
# config.yaml
# Configuration for high dynamic range imaging
# Optimized for point source recovery
niter: 10000 # High iteration count for deep cleaning
threshold: 0.001 # Low threshold for faint sources
gain: 0.05 # Conservative gain for stability