Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to measure cross-dispersion profile #214

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

cshanahan1
Copy link
Contributor

This PR adds a function to measure the cross-dispersion profile at a single wavelength, or the average profile in a set/range of wavelengths. It takes in a 'width' for the window in the cross dispersion axis, which moves around the trace. A 1D array is returned with either the profile at that single wavelength/pixel or the mean or median profile across several wavelength/pixels.

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

Attention: Patch coverage is 96.25000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 83.14%. Comparing base (408547c) to head (f9176b4).

Files Patch % Lines
specreduce/utils/utils.py 97.14% 2 Missing ⚠️
specreduce/extract.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
+ Coverage   82.16%   83.14%   +0.98%     
==========================================
  Files          10       12       +2     
  Lines        1015     1086      +71     
==========================================
+ Hits          834      903      +69     
- Misses        181      183       +2     

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

along the dispersion axis.

If a single number is specified for `pixel`, then the profile at that pixel
(i.e wavelength) will be returned. If several pixels are specified in a list or

Choose a reason for hiding this comment

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

If pixels are mapped to wavelength, can user input the wavelength directly? Does it need units?

Copy link
Contributor

Choose a reason for hiding this comment

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

my take is that the core routine for this should work in pixel space. if we want to work in wavelength space, then we can wrap or decorate this to accept a WCS and input wavelengths to determine pixel and pixel_range.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you ok with that being a follow up effort?

Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

Do we want this as a method on any of the extraction steps, perhaps on trace itself? If there are other uses, it makes sense to have the general capability as a standalone function, but it might be convenient to be able to call trace.cross_dispersion_profile and/or trace.plot_cross_dispersion_profile(), etc.

specreduce/utils/utils.py Outdated Show resolved Hide resolved
specreduce/utils/utils.py Show resolved Hide resolved
specreduce/utils/utils.py Outdated Show resolved Hide resolved
specreduce/utils/utils.py Outdated Show resolved Hide resolved
@cshanahan1
Copy link
Contributor Author

@camipacifici @kecnry this is ready for a final review - i added some of the tests for a non-flat trace with and without aligning the image along the trace.

the only outstanding item is the pixels vs wavelengths thing. right now, since its clear that the input is pixels, i personally think its OK to add wavelength as another parameter (that can't be set simultaneously with pixels) later on. what do you think?

@cshanahan1
Copy link
Contributor Author

cshanahan1 commented Mar 25, 2024

test data with a non-flat trace:
Screen Shot 2024-03-25 at 10 19 12 AM

the returned profile with align_along_trace = False, at different pixels. the center moves as expected:
Screen Shot 2024-03-25 at 10 19 53 AM

And with align_along_trace = True - since the trace is rolled to the nearest integer value, the center for the profile is the same + or - one pixel:
Screen Shot 2024-03-25 at 10 19 43 AM

and when all pixels are used to measure the average profile for the whole image:
Screen Shot 2024-03-25 at 10 34 39 AM
Screen Shot 2024-03-25 at 10 34 47 AM

specreduce/extract.py Show resolved Hide resolved
specreduce/utils/utils.py Outdated Show resolved Hide resolved
specreduce/utils/utils.py Show resolved Hide resolved
Copy link
Member

@kecnry kecnry left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks!

@camipacifici
Copy link

Looks great, thank you!

@@ -1,3 +1,5 @@
"""
General purpose utilities for specreduce
"""

from .utils import * # noqa
Copy link
Contributor

@tepickering tepickering Mar 27, 2024

Choose a reason for hiding this comment

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

do we want relative imports here? i don't have strong feelings personally, but i've been chided in the past for using them...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have an opinion either... we can always change this later if we come up with a policy/standard we want to follow, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

well, the PEP8 guide recommends absolute imports, fwiw: https://peps.python.org/pep-0008/#imports.

Copy link
Contributor

@tepickering tepickering left a comment

Choose a reason for hiding this comment

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

good stuff! thanks for this. a couple minor comments, but otherwise is good to go as far as i'm concerned.

@cshanahan1
Copy link
Contributor Author

merging this - wavelength input can be addressed in a follow up

@cshanahan1 cshanahan1 merged commit c2d1715 into astropy:main Mar 28, 2024
12 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.

4 participants