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

Move lampstat check #1822

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Move lampstat check #1822

merged 5 commits into from
Jul 19, 2024

Conversation

rcooke-ast
Copy link
Collaborator

Moving the lamp check to outside the CombineImage task. Unit tests are good on my machine.

@rcooke-ast rcooke-ast requested a review from jhennawi June 29, 2024 12:32
Copy link
Collaborator

@jhennawi jhennawi left a comment

Choose a reason for hiding this comment

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

My opinion is that this lamp checking code has no place in image combination tasks. I consulted you about this because I think I saw that you added it, but I could be wrong. This image combine task should run on images that have been vetted to be good elsewhere. This should be done in calibrations. That reduces the number of inputs and simplifies the image combining code here.

# Load raw image
rawImage = rawimage.RawImage(ifile, spectrograph, det)
# Process
rawImage_list.append(rawImage.process(
frame_par['process'], scattlight=scattlight, bias=bias,
bpm=bpm, dark=dark, flatimages=flatimages, slits=slits, mosaic=mosaic))


Copy link
Collaborator

Choose a reason for hiding this comment

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

My opinion is that this code has no place in image combination tasks. The task should run on images that have been vetted to be good elsewhere. This should be done in calibrations. That reduces the number of inputs and simplifies the code here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's right - and I don't disagree. Indeed, there is a TODO item about this because this should really come from the fitstbl so we don't need to keep reading in files multiple times for just one reduction, but this is not currently possible. The lamp check needs to be something that's checked when images are being combined (it's the same as exposure times). It's inherently a check to do with frame combination. The reason I have moved the check is so that you don't need to add the fudge function into jwst_nirspec.

So, can you please confirm - Does this code change at least resolve the issue with you having to add a fudge function to jwst_nirspec?

As far as I see it, I think there are two possibilities:

  1. The calibrations.py code calls this function when building calibrations images, so it would be easiest to manage the lamp check code here. To ensure it's just the calibrations that execute the lamp check, we can add an argument to this function (e.g. check_lamps=False) and set it to True when the calibrations call the buildimage.
  2. We create a separate function that is only in calibrations.py to check the lamps before we pass it in to buildimage. This is what you are advocating, I think, but it comes with an overhead of re-reading multiple fits files over and over again, and also has some duplicate code.

In my opinion, option 1 is cleaner, and I'm happy to implement the changes to support that. How do you feel?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks @rcooke-ast, I see your point. I don't think we need to reread the files, only the headers. I would prefer to check neither exposure times nor lamps in a combine function as it reduces the dependencies and simplifies the code. I'm fine with leaving the exposure times in there for now (perhaps a todo). We don't do anything about this anyway, just throw warnings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jhennawi - I have moved this to calibrations now, and should make it easier to add calibrations checks in the future. I think this is what you were wanting, correct? I've left the exposure time check where it is for now, as I feel that is somewhat more important to be there.

I think we should deal with this now, so that you don't need to add a fudge function into the jwst_nirspec code. I've refactored this a few times now, and I think I keep misinterpreting what you would like to see in the code. If there's something specific that you would like changed, could you please comment on the PR? Thanks!

@kbwestfall kbwestfall mentioned this pull request Jul 18, 2024
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 45.16129% with 17 lines in your changes missing coverage. Please review.

Project coverage is 38.50%. Comparing base (1827eb3) to head (e509422).

Files Patch % Lines
pypeit/calibrations.py 43.33% 17 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@                Coverage Diff                @@
##           combine_refactor    #1822   +/-   ##
=================================================
  Coverage             38.49%   38.50%           
=================================================
  Files                   207      207           
  Lines                 48157    48171   +14     
=================================================
+ Hits                  18538    18546    +8     
- Misses                29619    29625    +6     

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

@@ -209,6 +210,44 @@ def __init__(self, fitstbl, par, spectrograph, caldir, qadir=None,
self.success = False
self.failed_step = None

def check_calibrations(self, file_list, check_lamps=True):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make it more clear what this routine does? It does not return anything and it does not appear to crash out if the calibrations are not okay. It appears to only print warnings to the screen. Can you please make that clear in the docs.

@@ -254,14 +254,14 @@ def buildimage_fromlist(spectrograph, det, frame_par, file_list, bias=None, bpm=

rawImage_list = []
# Loop on the files
for ifile in file_list:
for ii, ifile in enumerate(file_list):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the enumerate here?

Copy link
Collaborator

@jhennawi jhennawi left a comment

Choose a reason for hiding this comment

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

Thanks @rcooke-ast. Only a very minor comment. Sorry for the delay as I was traveling.

Copy link
Collaborator

@jhennawi jhennawi left a comment

Choose a reason for hiding this comment

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

I just made the quick changes I requested myself. Thanks @rcooke-ast.

@jhennawi
Copy link
Collaborator

Merging!

@jhennawi jhennawi closed this Jul 19, 2024
@jhennawi jhennawi reopened this Jul 19, 2024
@jhennawi jhennawi merged commit fe00d01 into combine_refactor Jul 19, 2024
23 checks passed
@rcooke-ast
Copy link
Collaborator Author

You just beat me to it - I was in the process of editing - thanks!!

@rcooke-ast rcooke-ast deleted the combine_refactor_delta branch July 19, 2024 12:30
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