Skip to content

Alternate Cosmic Ray Rejection Option#2095

Open
jhod0 wants to merge 2 commits intopypeit:developfrom
jhod0:cosmic-ray-threshold
Open

Alternate Cosmic Ray Rejection Option#2095
jhod0 wants to merge 2 commits intopypeit:developfrom
jhod0:cosmic-ray-threshold

Conversation

@jhod0
Copy link
Copy Markdown
Contributor

@jhod0 jhod0 commented Mar 25, 2026

This PR adds a ProcessImagesPar parameter called crthresh, which when present bypasses the LA Cosmic CR detection algorithm and identifies CR contamination as all pixels above a certain threshold.

This is a crude approach, and is probably a "bad idea" 99% of the time. My use case for this is for KCRM, where LA Cosmic really struggles. I'm not sure what is unique about KCRM or its detector, but I invested more time than I would like trying to tune LA Cosmic to work well without finding a satisfying solution. The best LA Cosmic configurations I found erroneously rejected lots of good data, while still allowing some CR-contaminated pixels through. This crthresh is the best approach I have found with my data. I can share comparisons of how this performs on my data set later.

As this is a crude approach, I understand if the PypeIt devs would prefer not to allow this option. The implementation was very small and straightforward, so I figured I should make it available for discussion.

jhod0 added 2 commits March 26, 2026 17:35
- When present, should be an int/float threshold for cosmic ray
  rejection
- Overrides default LACosmic routine
- Makes cosmic ray mask by thresholding, and expanding by one pixel
the LA Cosmic cosmic ray finding algorithm, and instead identifies
CR contaminated pixels as everything above a certain level
@jhod0 jhod0 force-pushed the cosmic-ray-threshold branch from 96ab8c4 to dc7d8b8 Compare March 27, 2026 00:35
Copy link
Copy Markdown
Collaborator

@kbwestfall kbwestfall left a comment

Choose a reason for hiding this comment

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

Thanks, @jhod0 ! I'm fine with adding this. My only request is some clarification in the parameter definition.


from astropy.io import fits

import os
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this needed?

saturation = self.map_detector_value('saturation')
nonlinear = self.map_detector_value('nonlinear')

# crthresh = os.environ.get('PYPEIT_CRTHRESH')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove

defaults['crthresh'] = None
dtypes['crthresh'] = [int, float]
descr['crthresh'] = 'Crude threshold to detect cosmic rays. Overrides ' \
'other options and skips LA Cosmic'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd add a bit more to this.

  • Specify that this just sets a threshold pixel value such that any value above this threshold is masked. You're using it to remove cosmic rays, but it's actually more general than that.
  • Specify the context of the value the user should provide. I.e., can users simply set the value based on what they see in a ds9 inspection of the raw frame, or do they need to account for the gain, bias subtraction, etc.
  • Make clear that the grow parameter is still used to grow the mask. I.e., "skips LA Cosmic" doesn't mean that all the L.A.Cosmic parameters are ignored.

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