Skip to content

Refactor synthetic data utilities#311

Merged
hpparvi merged 18 commits into
astropy:mainfrom
tepickering:refactor_synthdata
Jun 7, 2026
Merged

Refactor synthetic data utilities#311
hpparvi merged 18 commits into
astropy:mainfrom
tepickering:refactor_synthdata

Conversation

@tepickering

Copy link
Copy Markdown
Contributor

This PR is basically a full re-write of specreduce.utils.synth_data. The old architecture was too limiting and made it difficult to add new functionality. This new architecture implements a SynthImage class that builds synthetic images by chaining method calls. This is a much cleaner, more flexible approach that is also much more easily extensible. More importantly, it makes iteration a lot more straightforward. This will be needed to appropriately model data from multi-object/fiber and echelle spectrographs.

The old functions still exist, but have been refactored as thin wrappers and flagged for deprecation as of version 2.0. The docs have been updated accordingly and the examples that were in docstrings have been moved to the new dedicated .rst file.

A feature has been added to allow a spectrum of a source to be specified. Previously sources were hard-coded to be flat spectra.

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.05%. Comparing base (2e1a900) to head (079c63d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #311      +/-   ##
==========================================
+ Coverage   91.68%   92.05%   +0.37%     
==========================================
  Files          18       18              
  Lines        2128     2241     +113     
==========================================
+ Hits         1951     2063     +112     
- Misses        177      178       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tepickering tepickering requested a review from hpparvi June 2, 2026 03:39

@hpparvi hpparvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tepickering! This refactor allows for significantly cleaner code and will also be a great help with the tutorials. The only issue I could find was with trace_coeffs.

Comment thread specreduce/utils/synth_data.py Outdated
def render(self, ctx: _RenderContext) -> np.ndarray:
trace_center = ctx.ny / 2 if self.trace_center is None else self.trace_center
trace_coeffs = (
{"c0": 0, "c1": 50, "c2": 100}

@hpparvi hpparvi Jun 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default trace_coeffs raises an error if the user sets trace_order < 2. I've opened a PR targeting this branch with a fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! this was pre-existing bug as well with the hard-coded defaults. i pushed a fix that should take care of it.

@hpparvi hpparvi merged commit d022455 into astropy:main Jun 7, 2026
16 checks passed
@hpparvi

hpparvi commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Merged!

@tepickering tepickering deleted the refactor_synthdata branch June 7, 2026 08:56
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