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

Cosmics kgain #211

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Cosmics kgain #211

wants to merge 7 commits into from

Conversation

JuergenSchreiber
Copy link
Contributor

Added KGain calibration file as mandatory input parameter in detect_cosmic_rays

Type of change

  • New feature (non-breaking change which adds functionality)

Reference any relevant issues (don't forget the #)

#203

Checklist before requesting a review

  • I have linted my code
  • I have verified that all unit tests pass in a clean environment and added new unit tests, as needed
  • I have verified that all docstrings are properly formatted and added new documentation, as needed

@JuergenSchreiber
Copy link
Contributor Author

I guess I still have to update all the e2e tests with a kgain caldb entry where detect_cosmic_rays is used...

@semaphoreP
Copy link
Contributor

Can this be an optional calibration? since detect cosmic rays is a L2a level step, while Kgain is a L2b level calibration product

@kjl0025
Copy link
Contributor

kjl0025 commented Sep 26, 2024

Thanks for this, Juergen, but now that I think about this, to Jason's point, we do have an issue (#202 ) about enhancing the k gain and nonlin code to take into account flagged cosmics to improve k gain and nonlinearity calibration. (The II&T code did not account for cosmic rays, but ideally, that should be done.) So the recipe for making the k gain and nonlin calibrations will eventually use detect_cosmic_rays, which would be circular. So I'm sorry to say this given all your work on this, Juergen, but I think we should actually cancel this PR and leave the code as it is (drawing k gain from DetectorParams), and we would just update the DetectorParams default k gain value whenever a new k gain calibration is done. Jason can chime in if he has other thoughts.

@maxwellmb
Copy link
Contributor

Do I understand correctly that detect_cosmic_rays needs a KGain value, and its just that right now we're pulling it from DetectorParams, rather than a KGain file?

@semaphoreP
Copy link
Contributor

Can we handle it like how we handle Bias offset subtraction with NoiseMaps in prescan_biassub? We leave it as an optional keyword (it needs to be the first keyword for this to work), and the recipe species Kgain to be "AUTOMATIC,OPTIONAL". Basically, the walker will pass in a Kgain if we have one, or pass in None. If None gets passed in, let's just use the Kgain in the DetectorParams.

@kjl0025
Copy link
Contributor

kjl0025 commented Sep 26, 2024

Do I understand correctly that detect_cosmic_rays needs a KGain value, and its just that right now we're pulling it from DetectorParams, rather than a KGain file?

Yes, that is correct.

And I agree with Jason's proposal. That's probably better than having to update DetectorParams after a calibration.

@@ -207,7 +208,7 @@ def detect_cosmic_rays(input_dataset, detector_params, sat_thresh=0.7,


# Calculate the full well capacity for every frame in the dataset
kgain = np.array([detector_params.params['kgain'] for frame in crmasked_dataset])
Copy link
Contributor

Choose a reason for hiding this comment

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

If kgain is None, use the value from detector_params. And k_gain would have to be listed before detector_params in the list of arguments so that the "AUTOMATIC, OPTIONAL" works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way: is there a reason why an array of equal kgain values is made? We can divide an array by a scalar.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, not really needed to have an array since we are not assuming to deal with different kgain values right now

@maxwellmb
Copy link
Contributor

I don't think I understand why we have a KGain in DetectorParams. What is its relation to the KGain calibration. A backup?

@kjl0025
Copy link
Contributor

kjl0025 commented Sep 27, 2024

I think we put it in there initially, before we had started on the calibration script for k gain.

@JuergenSchreiber
Copy link
Contributor Author

@maxwellmb: yes, kgain in detetor_params works like a backup if I implement it like desired.

@JuergenSchreiber
Copy link
Contributor Author

To make this work as first parameter, I have to specify detector_params also as an optional parameter

@@ -154,7 +154,7 @@ def prescan_biassub(input_dataset, noise_maps=None, return_full_frame=False,

return output_dataset

def detect_cosmic_rays(input_dataset, detector_params, k_gain, sat_thresh=0.7,
def detect_cosmic_rays(input_dataset, k_gain = None, detector_params = None, sat_thresh=0.7,
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I was a bit unclear here: I meant that kgain should be the first optional keyword (i.e., input_dataset, detector_params, kgain=None, sat_thresh=0.7, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood, changed back again. I think now it should be ready for review.

Copy link
Contributor

@semaphoreP semaphoreP left a comment

Choose a reason for hiding this comment

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

Looks good. Only a few very very minor comments before we merge this.

@@ -19,7 +19,8 @@
{
"name" : "detect_cosmic_rays",
"calibs" : {
"DetectorParams" : "AUTOMATIC"
"DetectorParams" : "AUTOMATIC",
"KGain" : "AUTOMATIC, OPTIONAL"
Copy link
Contributor

Choose a reason for hiding this comment

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

for this and other recipes below, can the indentation be at the same level?

# Calculate the full well capacity for every frame in the dataset
kgain = np.array([detector_params.params['kgain'] for frame in crmasked_dataset])
if k_gain == None:
Copy link
Contributor

Choose a reason for hiding this comment

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

should use if k_gain is None (forget the exact reason, but is is preferred to ==)

@@ -207,7 +208,7 @@ def detect_cosmic_rays(input_dataset, detector_params, sat_thresh=0.7,


# Calculate the full well capacity for every frame in the dataset
kgain = np.array([detector_params.params['kgain'] for frame in crmasked_dataset])
Copy link
Contributor

Choose a reason for hiding this comment

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

agree, not really needed to have an array since we are not assuming to deal with different kgain values right now

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