-
Notifications
You must be signed in to change notification settings - Fork 31
[WIP] - Add spectral line profile models and velocity fitting tools #319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nikhil-sarin
wants to merge
16
commits into
master
Choose a base branch
from
claude/add-spectral-models-pcygni-01HjuY8Nu8qchUh7HWJvJthc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] - Add spectral line profile models and velocity fitting tools #319
nikhil-sarin
wants to merge
16
commits into
master
from
claude/add-spectral-models-pcygni-01HjuY8Nu8qchUh7HWJvJthc
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add new spectral models including: - Voigt profile (Gaussian + Lorentzian convolution) - Gaussian and Lorentzian line profiles - P-Cygni profiles using Sobolev approximation - Elementary P-Cygni with simple parameterization - Multi-line P-Cygni spectrum generation - SYNOW-style parameterized line model - Blackbody spectrum with P-Cygni lines - Voigt absorption line synthesis Add SpectralVelocityFitter class for measuring: - Line velocities from absorption features - Multiple line velocity measurements - Photospheric velocity evolution - High-velocity feature identification - Velocity gradients (dv/dt) These tools enable analysis of supernova spectra, particularly Type Ia SNe, for photospheric velocity measurements and spectral line identification.
- Add comprehensive example script demonstrating: - P-Cygni profile generation (physical and elementary) - Voigt, Gaussian, and Lorentzian line profiles - Multi-line Type Ia SN spectrum synthesis - Velocity measurements from absorption features - Photospheric velocity evolution tracking - High-velocity feature detection - SYNOW-style line models - Add detailed documentation for spectral models including: - Line profile functions (Voigt, Gaussian, Lorentzian) - P-Cygni profile models (physical and parameterized) - Multi-line spectrum generation - SpectralVelocityFitter class and methods - Complete workflow examples with references - Update analysis.txt to document SpectralVelocityFitter - Add spectral_models to docs index
Tests include: - Voigt profile function (symmetry, peak position, continuum handling) - Gaussian and Lorentzian line profiles - P-Cygni profile (absorption/emission, velocity dependence, optical depth) - Elementary P-Cygni profile - Multi-line P-Cygni spectrum synthesis - SYNOW-style line model - Blackbody with P-Cygni lines - Voigt absorption line synthesis - SpectralVelocityFitter class: - Multiple velocity measurement methods (min, centroid, gaussian, fit) - Multiple line measurements - Photospheric velocity evolution - High-velocity feature detection - Velocity gradient calculation - Edge cases and error handling Priors added for: - p_cygni_profile (tau_sobolev, v_phot, lambda_rest) - elementary_p_cygni_profile (v_absorption, absorption_depth, emission) - voigt_profile (sigma_gaussian, gamma_lorentz) - gaussian_line_profile (lambda_center, amplitude, sigma) - lorentzian_line_profile (lambda_center, amplitude, gamma) - blackbody_spectrum_with_p_cygni_lines (redshift, rph, temp, v_phot) - synow_line_model (tau_ref, v_phot, v_max, n_power) These enable Bayesian inference for spectral line fitting.
P-Cygni profile fixes: - Fix absorption region to extend from v=0 to v_max (was incorrectly limited) - Properly center absorption maximum at photospheric velocity - Adjust source function values for more realistic profiles - Absorption now correctly uses Gaussian profile peaked at v_phot Test fixes: - Increase velocity search window (v_window) to 15000-20000 km/s for high-velocity measurements (default 5000 km/s was too narrow) - Use larger velocity differences in evolution tests for clearer signal - Use wider wavelength ranges to capture all spectral features - Adjust test tolerances for source function effects - Pass v_window parameter through measure_velocity_gradient to photospheric_velocity_evolution Analysis improvements: - Add **kwargs support to measure_velocity_gradient for passing parameters like v_window to underlying velocity measurements All 56 tests now pass successfully.
Spectral line profile models (P-Cygni, Voigt, Gaussian, Lorentzian, etc.) are not standard time-domain transient models - they don't take time as the first argument. They are spectral analysis tools meant for direct use. Added skip lists in: - TestModels.test_models - TestPhaseModels.test_models - TestMagnitudeOutput.test_models Models skipped: - p_cygni_profile - elementary_p_cygni_profile - voigt_profile - gaussian_line_profile - lorentzian_line_profile - blackbody_spectrum_with_p_cygni_lines - synow_line_model These models are properly tested in test/spectral_models_test.py
Increases test count from 56 to 99 tests with extensive coverage: - Exception handling and edge cases for SpectralVelocityFitter - P-Cygni fit failure fallback behavior - Velocity gradient with weighted fits - Power law spectrum models - Blackbody spectrum at redshift tests - SYNOW model parameter variations - Multi-line P-Cygni spectrum tests
Increases test count from 99 to 124 tests covering: - Internal functions (_get_blackbody_spectrum, _get_powerlaw_spectrum) - Velocity measurement edge cases (sparse data, error estimation) - Multi-line P-Cygni continuum models (powerlaw, callable) - SYNOW model dilution factors and parameter variations - P-Cygni source function variations - Photospheric velocity evolution methods - High-velocity feature detection thresholds - Elementary P-Cygni edge cases
Increases test count from 124 to 139 tests covering: - Velocity gradient edge cases (NaN errors, zero errors) - Lorentzian and Gaussian emission/absorption variations - Blackbody with lines parameter variations - HVF detection with low absorption thresholds - Powerlaw plus blackbody before/after peak times - Min method edge cases (uniform flux, noisy spectra) - Additional parameter coverage throughout
Increases test count from 139 to 154 tests with: - Velocity measurement branch coverage (n_err paths, emission lines) - P-Cygni fit method successful fitting path - Spectrum combination edge cases (zero tau, no absorption regions) - Integration/validation tests (roundtrip velocity, Wien's law) - Physical behavior validation (gradient signs, temperature effects) - Additional edge cases (high redshift, narrow widths)
Include the new spectral models test suite in the CI pipeline so that coverage is measured and reported to Coveralls.
The previous workflow only uploaded XML coverage files, but coverage combine needs .coverage database files. Now: - Upload both .coverage database files and XML from each test group - Properly combine .coverage files from all 4 test groups - Generate combined XML report for Coveralls - This ensures all tests (including new spectral_models_test.py) contribute to the total coverage percentage
Increases test count from 154 to 164 with explicit coverage for: - All 4 velocity measurement methods (min, centroid, gaussian, fit) - __init__ with lists and arrays, with/without flux_err - from_spectrum_object with/without flux_density_err attribute - measure_multiple_lines exception handling path - photospheric_velocity_evolution as static method - identify_high_velocity_features edge cases - measure_velocity_gradient weighted vs unweighted paths - Invalid method ValueError exception
…ts.py, use improved coverage workflow
…'s new tests and Group 5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add new spectral models including:
Add SpectralVelocityFitter class for measuring: