feat: add slope-based edge detection for eclipse boundary detection#8
Merged
jackieblaum merged 14 commits intomainfrom Jan 23, 2026
Merged
Conversation
- Add edge detection functions (_detect_eclipse_edges_slope, _find_primary_and_secondary_from_edges) - Add boundary_method parameter to EclipsingBinaryBinner (default: 'flux_return', new: 'edge_detection') - Modify get_eclipse_boundaries() to support edge detection mode - Add edge detection parameters: edge_slope_threshold_percentile, edge_return_threshold_fraction, edge_min_eclipse_depth, edge_smoothing_window - Robust to ellipsoidal variations by using local slope instead of absolute flux levels - Automatically falls back to flux_return method if edge detection fails - Maintains full backward compatibility - default behavior unchanged - Add test script (test_edge_detection_integration.py) This addresses the issue where traditional methods fail when ellipsoidal variations cause the local baseline to be below the global median.
Implement Task 1 from robustness improvements plan. The _detect_eclipse_edges_slope function now returns a diagnostics dictionary containing intermediate computation results for debugging and parameter tuning. Changes: - Modified _detect_eclipse_edges_slope to return (boundaries, diagnostics) tuple - Added diagnostics dict with slopes, smoothed_fluxes, thresholds, candidates, and count - All early returns now include minimal diagnostics with empty/zero values - Added _edge_diagnostics attribute to EclipsingBinaryBinner class - Updated get_eclipse_boundaries to store diagnostics when using edge_detection method - Created comprehensive test suite in tests/test_edge_detection_diagnostics.py The diagnostics enable visualization and tuning of edge detection parameters in subsequent tasks.
- Baseline window scales with data density (2% of points, min 5) - Refinement range adapts to data (5% of points, min 10) - Gap detection uses adaptive threshold - Add validation for minimum window sizes - Add tests for adaptive behavior
- Include diagnostic information (thresholds, candidates) in warnings - Provide actionable suggestions for parameter adjustments - Specify which eclipse type (primary/secondary) wasn't found - Add tests for warning message content
- Use trimmed mean to handle outliers (10% trim from each end) - Add validation for minimum baseline flux (> 0.1) - Add validation for minimum window sizes (>= 3 points) - Graceful fallback to median if trimmed mean fails - Add tests for outliers, sparse data, and edge cases
- Warn if smoothing window is too large for narrow eclipses - Compare window size to eclipse width (warn if > 1/3 width) - Provide actionable suggestions in warning - Add tests for smoothing validation - Update test_edge_detection_warnings to handle multiple warnings
- Validate baseline > 0.1 before depth calculation - Return diagnostics even when no valid slopes found - Add tests for zero baseline, duplicate phases, constant flux - Improve code comments for division safety
- Add min_eclipse_separation parameter (default 0.2) - Update _find_primary_and_secondary_from_edges to accept parameter - Update _helper_secondary_minimum_mask to use parameter - Add documentation for parameter usage - Add tests for configurable separation
- Test with ellipsoidal variations - Test sparse and dense data - Test shallow and wrapped eclipses - Test parameter sensitivity - Compare edge detection vs flux_return methods - Validate diagnostics availability Also updated validation to allow n_points > nbins (instead of > 5*nbins)
- Add user guide with tuning instructions - Add example script demonstrating all features - Update API reference with edge detection parameters - Include diagnostic usage examples
- Split test_unwrapped_light_curves into 4 separate test functions - test_synthetic_unwrapped_light_curve: all parameter combinations - test_asas_sn_unwrapped_light_curve: all parameter combinations - test_tess_unwrapped_light_curve: skip fraction=0.1 (insufficient data) - test_tess_unwrapped_light_curve_low_fraction: fraction=0.1 with nbins=50 only - Remove pytest.skip logic from helper_bin_calculation - Avoid pathological parameter combinations at test definition level - Test count increased from 80 to 108 (better granularity) - All tests now pass with 0 skips (previously 2 skipped)
- Run black on all Python files to pass CI checks - 11 files reformatted - All tests still passing (108/108)
- Proper test suite exists in tests/ directory - Root-level file was an early/scratch version
- Fixture was missing np.random.seed(), causing non-deterministic failures - Added seed=42 to ensure reproducible test results - Fixes intermittent 'Not enough data' error in test_synthetic_unwrapped_light_curve[50-0.1]
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
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.
This addresses the issue where traditional methods fail when ellipsoidal variations cause the local baseline to be below the global median.