Skip to content

Conversation

harry353
Copy link

This changes how uncertainties are handled in:

  • BoxcarExtract.__call__
  • HorneExtract.__call__
  • HorneExtract._fit_gaussian_spatial_profile

as described in #282. Now they:

  • Work correctly with both standard deviation and variance uncertainties.
  • Pass the right uncertainty through to the extracted 1D spectrum.
  • Keep units consistent.
  • Handle NaNs and masked pixels better when fitting the Gaussian profile.

Also, I have added test scripts under the tests directory, as well as a .ipynb file for the Horne case with some examples.

@harry353
Copy link
Author

Also currently working on issue #281 as well

Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 84.00000% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.68%. Comparing base (0cfc970) to head (450b09d).

Files with missing lines Patch % Lines
specreduce/extract.py 84.00% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #286      +/-   ##
==========================================
- Coverage   87.11%   86.68%   -0.44%     
==========================================
  Files          15       15              
  Lines        1281     1419     +138     
==========================================
+ Hits         1116     1230     +114     
- Misses        165      189      +24     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

@hpparvi hpparvi left a comment

Choose a reason for hiding this comment

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

Promising work @harry353! Here are a couple of initial comments. Can you ensure that the tests you've written run without errors and check also the code style (I'd recommend running your code through black).

@@ -194,6 +194,139 @@ class BoxcarExtract(SpecreduceOperation):
def spectrum(self):
return self.__call__()

def _variance2d_from_image(self, image):
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify uncertainty parsing because the _ImageParser._parse_image method always assures that the image.uncertainty attribute always exists, and is a subclass of astropy.nddata.NDUncertainty.

@@ -673,6 +919,7 @@ def __call__(
bkgrd_prof = models.Polynomial1D(2)

self.image = self._parse_image(image, variance, mask, unit, disp_axis)
var2d_q = self._var2d_as_quantity()
Copy link
Contributor

Choose a reason for hiding this comment

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

var2d_q is not used later in the code.

@@ -565,6 +783,34 @@ def _fit_spatial_profile(

return RectBivariateSpline(x=bin_centers, y=np.arange(nrows), z=samples, kx=kx, ky=ky)

def _var2d_as_quantity(self) -> u.Quantity:
Copy link
Contributor

Choose a reason for hiding this comment

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

This utility method is not really needed. The HorneExtract._parse_image method already ensures that the image.uncertainty attribute exists and contains a VarianceUncertainty uncertainty.

@hpparvi hpparvi added this to the v1.9 milestone Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants