Skip to content

Refactor duplicated code in curvit.py#24

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-1685962-229944105-7f1837da-6123-4906-af37-3181d9033516
Draft

Refactor duplicated code in curvit.py#24
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-1685962-229944105-7f1837da-6123-4906-af37-3181d9033516

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 3, 2025

Eliminated ~239 lines of duplicated code across curve(), curve_orbitwise(), combine_events_lists(), and image_astrometry() by extracting 6 helper functions.

Changes

Helper Functions Extracted

  • adjust_detection_threshold() - Consolidates 34-line duplication of threshold adjustment logic in both single_star and multiple_star branches of combine_events_lists()
  • get_framerate_from_header() - Consolidates 18-line duplication of framerate reading logic across two locations in combine_events_lists()
  • setup_auto_background() - Wrapper for auto_bg() eliminating 12-line duplication between curve() and curve_orbitwise()
  • create_quicklook_figure() - Consolidates 23-line matplotlib visualization code duplicated in curve() and curve_orbitwise()
  • handle_background_estimation() - Consolidates 38-line background estimation workflow duplicated in curve() and curve_orbitwise()
  • remove_wcs_header_keys() - Consolidates WCS header cleanup, eliminating 30 lines of duplicate try/except blocks in image_astrometry()

Example

Before:

# Duplicated in both curve() and curve_orbitwise()
if background == "auto":
    lowres_counts, bg_CPS, bg_CPS_e = auto_bg(fx, fy, time, photons, ...)
    
bins = np.arange(0, 4801, 4096 / whole_figure_resolution)
plt.hist2d(fx, fy, bins=(bins, bins), weights=weights, norm=LogNorm())
# ... 20 more lines of matplotlib setup

After:

if background == "auto":
    lowres_counts, bg_CPS, bg_CPS_e = setup_auto_background(fx, fy, time, photons, ...)
    
create_quicklook_figure(fx, fy, weights, xp, yp, x_bg, y_bg, background, whole_figure_resolution)

Impact

  • Single point of maintenance for shared logic
  • Bug fixes propagate automatically to all call sites
  • No API changes; full backward compatibility maintained
Original prompt

Find and refactor duplicated code


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 3, 2025 12:29
Co-authored-by: prajwel <1685962+prajwel@users.noreply.github.com>
Co-authored-by: prajwel <1685962+prajwel@users.noreply.github.com>
Co-authored-by: prajwel <1685962+prajwel@users.noreply.github.com>
Copilot AI changed the title [WIP] Find and refactor duplicated code Refactor duplicated code in curvit.py Nov 3, 2025
Copilot AI requested a review from prajwel November 3, 2025 12:42
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.

2 participants