Skip to content

feat: add slope-based edge detection for eclipse boundary detection#8

Merged
jackieblaum merged 14 commits intomainfrom
feature/edge-detection-eclipse-boundaries
Jan 23, 2026
Merged

feat: add slope-based edge detection for eclipse boundary detection#8
jackieblaum merged 14 commits intomainfrom
feature/edge-detection-eclipse-boundaries

Conversation

@jackieblaum
Copy link
Owner

  • 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.

- 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]
@jackieblaum jackieblaum merged commit 4fe8f0c into main Jan 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant