Below is a detailed pseudocode plan for detecting dark matter subhalos using a PyAutoLens imaging object, following the structured approach outlined previously. This pseudocode is designed to be modular, logical, and mindful of computational efficiency, while addressing key challenges like noise, model degeneracies, and false positives. It assumes familiarity with PyAutoLens’ core functionality (e.g., Imaging, Model, FitImaging, AnalysisImaging) and general gravitational lensing concepts.
Pseudocode for Dark Matter Subhalo Detection
# Pseudocode for detecting dark matter subhalos using PyAutoLens
# Assumptions: Imaging data is pre-loaded, noise/PSF are characterized, and priors are informed by simulations.
# Import necessary libraries (PyAutoLens, NumPy, etc.)
IMPORT pyautolens as al
IMPORT numpy as np
IMPORT scipy.stats as stats
IMPORT astropy.convolution as conv
# Define constants and hyperparameters
SET noise_sigma = imaging.noise_map.mean() # Estimate noise level
SET subhalo_mass_range = [1e6, 1e10] # Solar masses (informed by simulations)
SET subhalo_profile = "NFW" # Subhalo mass profile (e.g., NFW, Burkert)
SET grid_resolution = 0.05 # Arcseconds (for subhalo position search)
SET significance_threshold = 3.0 # Sigma for residual peaks
SET bayesian_evidence_threshold = 5.0 # For model comparison
# Load imaging data
FUNCTION load_data():
imaging = al.Imaging.from_fits(
image_path="path/to/image.fits",
noise_map_path="path/to/noise_map.fits",
psf_path="path/to/psf.fits"
)
RETURN imaging
# Step 1: Fit the Main Lens Model
FUNCTION fit_main_model(imaging):
# Define main lens galaxy components
lens_galaxy = al.Galaxy(
redshift=0.5,
mass=al.mp.EllipticalIsothermal(
centre=(0.0, 0.0),
einstein_radius=1.0,
elliptical_comps=(0.1, 0.05)
),
light=al.lp.EllipticalSersic(
centre=(0.0, 0.0),
intensity=0.1,
effective_radius=0.6,
sersic_index=4.0
)
)
# Define source galaxy (unlensed)
source_galaxy = al.Galaxy(
redshift=2.0,
light=al.lp.EllipticalSersic(
centre=(0.0, 0.0),
intensity=0.05,
effective_radius=0.3,
sersic_index=1.0
)
)
# Create tracer for lensing
tracer = al.Tracer.from_galaxies(galaxies=[lens_galaxy, source_galaxy])
# Set up analysis and fit
analysis = al.AnalysisImaging(dataset=imaging)
model = al.Model(al.Galaxy, redshift=0.5, mass=al.mp.EllipticalIsothermal) + \
al.Model(al.Galaxy, redshift=2.0, light=al.lp.EllipticalSersic)
# Run MCMC/nested sampling to optimize fit
result = analysis.fit(model=model, tracer=tracer)
RETURN result, lens_galaxy, source_galaxy
# Step 2: Compute Residuals
FUNCTION compute_residuals(imaging, result):
# Get model image from best-fit
model_image = result.model_image
# Compute image-plane residuals
residuals = imaging.data - model_image
# Normalize residuals by noise map
normalized_residuals = residuals / imaging.noise_map
# Compute deflection field residuals (optional, if high-quality data)
observed_deflections = compute_observed_deflections(imaging) # Placeholder
model_deflections = result.tracer.deflections_2d_from_grid(imaging.grid)
deflection_residuals = observed_deflections - model_deflections
RETURN residuals, normalized_residuals, deflection_residuals
# Step 3: Statistical Detection of Subhalo Signatures
FUNCTION detect_residual_peaks(normalized_residuals, imaging):
# Smooth residuals to reduce noise (match PSF scale)
psf_kernel = imaging.psf
smoothed_residuals = conv.convolve(normalized_residuals, psf_kernel)
# Identify peaks > significance_threshold
peak_mask = smoothed_residuals > significance_threshold
# Extract peak positions
peak_positions = np.argwhere(peak_mask)
# Filter peaks based on spatial clustering (avoid noise artifacts)
filtered_peaks = cluster_peaks(peak_positions, min_separation=grid_resolution)
RETURN filtered_peaks
# Step 4: Parameterized Subhalo Search
FUNCTION search_subhalos(imaging, result, filtered_peaks, lens_galaxy, source_galaxy):
subhalo_candidates = []
# Define subhalo model priors
subhalo_model = al.Model(
al.mp.NFW,
mass_at_200=subhalo_mass_range,
centre=al.UniformPrior(lower_limit=-2.0, upper_limit=2.0), # Arcseconds
redshift=lens_galaxy.redshift
)
FOR peak IN filtered_peaks:
# Center subhalo search on peak position
subhalo_model.centre = peak
# Create new lens model with subhalo
lens_galaxy_with_subhalo = al.Galaxy(
redshift=lens_galaxy.redshift,
mass=lens_galaxy.mass,
subhalo=subhalo_model
)
# Create new tracer
tracer_with_subhalo = al.Tracer.from_galaxies(
galaxies=[lens_galaxy_with_subhalo, source_galaxy]
)
# Fit model with subhalo
analysis = al.AnalysisImaging(dataset=imaging)
result_with_subhalo = analysis.fit(model=tracer_with_subhalo)
# Compare Bayesian evidence
evidence_ratio = result_with_subhalo.log_evidence - result.log_evidence
IF evidence_ratio > bayesian_evidence_threshold:
# Subhalo candidate detected
subhalo_candidates.append({
"position": peak,
"mass": result_with_subhalo.instance.subhalo.mass_at_200,
"evidence_ratio": evidence_ratio
})
RETURN subhalo_candidates
# Step 5: Validate Results
FUNCTION validate_candidates(imaging, subhalo_candidates, result):
validated_candidates = []
FOR candidate IN subhalo_candidates:
# Test 1: Noise simulation
noise_realization = generate_noise_realization(imaging.noise_map)
simulated_imaging = imaging.data - result.model_image + noise_realization
simulated_result = fit_model_with_subhalo(simulated_imaging, candidate)
IF simulated_result.evidence_ratio < bayesian_evidence_threshold:
# Candidate is robust against noise
noise_robust = True
ELSE:
noise_robust = False
# Test 2: Model degeneracy check
alternative_model = perturb_main_model(result) # Placeholder for alternative main model
alternative_result = fit_model(alternative_model, imaging)
IF alternative_result.evidence_ratio > result.evidence_ratio:
# Subhalo may be degenerate with main model
degeneracy_flag = True
ELSE:
degeneracy_flag = False
# Test 3: Cross-check with external data (placeholder)
external_validation = check_external_data(candidate) # E.g., kinematics, SZ
IF noise_robust AND NOT degeneracy_flag AND external_validation:
validated_candidates.append(candidate)
RETURN validated_candidates
# Step 6: Main Execution
FUNCTION main():
# Load data
imaging = load_data()
# Fit main model
result, lens_galaxy, source_galaxy = fit_main_model(imaging)
# Compute residuals
residuals, normalized_residuals, deflection_residuals = compute_residuals(imaging, result)
# Detect potential subhalo signatures
filtered_peaks = detect_residual_peaks(normalized_residuals, imaging)
# Search for subhalos
subhalo_candidates = search_subhalos(imaging, result, filtered_peaks, lens_galaxy, source_galaxy)
# Validate candidates
validated_candidates = validate_candidates(imaging, subhalo_candidates, result)
# Output results
IF validated_candidates:
PRINT "Detected subhalos:", validated_candidates
ELSE:
PRINT "No subhalos detected."
# Helper Functions (placeholders for implementation)
FUNCTION compute_observed_deflections(imaging):
# Placeholder: Compute observed deflection angles (requires high-quality data)
RETURN deflections
FUNCTION cluster_peaks(peak_positions, min_separation):
# Placeholder: Cluster peaks to avoid duplicates
RETURN clustered_peaks
FUNCTION generate_noise_realization(noise_map):
# Placeholder: Generate noise realization
RETURN noise
FUNCTION perturb_main_model(result):
# Placeholder: Perturb main model parameters to test degeneracies
RETURN alternative_model
FUNCTION check_external_data(candidate):
# Placeholder: Cross-check with external data
RETURN True/False
# Run the pipeline
main()
Key Design Considerations
-
Modularity:
- Each step (fitting, residual analysis, subhalo search, validation) is encapsulated in a separate function to allow for easy debugging, testing, and extension.
- Helper functions (e.g.,
compute_observed_deflections, cluster_peaks) are placeholders for domain-specific implementations.
-
Efficiency:
- The subhalo search is constrained to regions with significant residuals (
filtered_peaks), reducing computational cost compared to a blind grid search.
- Bayesian evidence is used for model comparison, leveraging PyAutoLens’ built-in statistical tools.
-
Robustness:
- Residual peak detection accounts for noise and PSF effects via smoothing and clustering.
- Validation includes noise simulations, degeneracy checks, and (placeholder) external data cross-checks to mitigate false positives.
-
Flexibility:
- Hyperparameters (e.g.,
subhalo_mass_range, grid_resolution, significance_threshold) are defined at the top for easy tuning.
- The pipeline supports alternative subhalo profiles (e.g., NFW, Burkert) and main model parametrizations.
-
Challenges Addressed:
- Degeneracies: Validation step tests alternative main models to rule out subhalo-like artifacts.
- Noise: Noise realizations and significance thresholds ensure robust detection.
- Data Quality: Deflection residuals are optional, as they require high-quality data not always available.
Notes on Implementation
- PyAutoLens Integration: The pseudocode assumes familiarity with PyAutoLens’ API (e.g.,
Imaging, Tracer, AnalysisImaging). Actual implementation would require replacing placeholders with concrete calls to PyAutoLens functions.
- Computational Cost: The subhalo search loop could be parallelized (e.g., using
multiprocessing) to handle large numbers of peaks.
- Simulation-Informed Priors: Subhalo mass and position priors should be informed by cosmological simulations (e.g., Illustris, EAGLE) to ensure physical realism.
- External Data: The
check_external_data placeholder could integrate kinematic data, SZ effect maps, or other observables, depending on availability.
This pseudocode provides a solid foundation for a real implementation, balancing scientific rigor with practical considerations.