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

Refactor light-leak function and remove light-leak files from repository #180

Merged
merged 7 commits into from
Sep 22, 2023

Conversation

wtbarnes
Copy link
Collaborator

@wtbarnes wtbarnes commented Sep 1, 2023

This PR removes the light-leak files from the repository in favor of pulling them from one of two possible solarsoft mirrors with the goal of reducing the total size of the repository. It also significantly refactors the light-leak removal function.

At a high-level, the changes to the light-leak function are:

  • If it is passed to the function, the light-leak array must now be a sunpy.map.Map object, not just a bare array
  • The customrebin function has been removed in favor of just calling Map.resample to the resolution of the input map. My understanding is that this is basically what was being achieved by rebinning from 1024 to 2048 and then dividing by 4.
  • leak_image is now called leak_map to reflect the fact that it is a sunpy.map.Map, not just a bare array
  • k_fact is now called scale because I found k_fact to be ambiguous. The name scale reflects the fact that the light-leak image is being scaled by this factor.

Copy link
Contributor

@jslavin jslavin left a comment

Choose a reason for hiding this comment

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

As written the change from rebin to the resample method are not equivalent. I have to say that I don't understand the inclusion of the factor of 0.25, though it does conserve the sum of the light leak image pixels. I found that rebin and resample don't lead to identical results and both differ a bit from the results using IDL rebin. Also I discovered that the tests we run don't test the rebinning because all of the test files are 1024 x 1024. In fact 2048 x 2048 images are quite rare in the archive.

…lated light leak subtracted image to test rebinning code. Also added test that uses these files.
@wtbarnes
Copy link
Collaborator Author

wtbarnes commented Sep 6, 2023

After adding those two full-resolution light-leak files, I'll point out that this PR actually makes the repo even larger than it already was. If those are going to be used as test data, I would suggest they be stored remotely and we can pull them down using the same strategy that is employed here.

@jslavin
Copy link
Contributor

jslavin commented Sep 7, 2023

By the repo, do you mean the package to be released? I thought we decided that none of the tests or test data would be included in that. If you just mean the github repo, I didn't think there was a size problem for that.

@wtbarnes
Copy link
Collaborator Author

wtbarnes commented Sep 7, 2023

By the repo, do you mean the package to be released? I thought we decided that none of the tests or test data would be included in that. If you just mean the github repo, I didn't think there was a size problem for that.

I was forgetting that this is test data that can be dropped from the package that can be pushed to PyPI. Yes, that is true, though I would still be reluctant to continue to add large files to the git repository even if they do not get included in the package. Could we instead just resample one of the existing 1024-by-1024 images to 2048-by-2048 on the fly before testing?

@wtbarnes
Copy link
Collaborator Author

wtbarnes commented Sep 7, 2023

Re: the factor of 0.25, what is the actual intention in calling rebin in the original code?

As written now (with the factor of 0.25), the interpolated stray light map will have 1/4 the intensity of the original stray light map as the resample method is not flux conserving. Is that what is supposed to happen? If so, we should compute what this factor is based on the relative resolution of the two images rather than just assume it is 1/4.

If I understand the actual intention of this scaling factor, an even more correct solution would be to reproject the stray light map to a WCS with the appropriate size and resolution while conserving flux.

@jslavin
Copy link
Contributor

jslavin commented Sep 7, 2023

So the scaling factor comes from the fact that the lightleak images are summed by a factor of 2 on chip. So the image pixels are a factor of 2 (in each dimension) larger, physically than a full resolution image. To simulate a full resolution image then we want to split the flux in each pixel into four pixels. So a flux conserving approach would be better, though I don't think any reprojection would be needed. In practice I think resample is adequate given the accuracy needed. There are a variety of approximations involved in doing a simple subtraction as is done by the original IDL code.

they need not be the same multiple
if in_map.dimensions != leak_map.dimensions:
leak_map = leak_map.resample(u.Quantity(in_map.dimensions))
leak_map *= 0.25
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a comment here about why this is multiplied by 0.25?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, will do. Also need to restrict the condition to cases in which the in_map.dimensions are twice the leak_map.dimensions.
I was also thinking that we should probably issue a warning if the image has the wrong dimensions generally. The use of the routine as written is supposed to be for composite images that are either 1024 x 1024 or 2048 x 2048. It won't work for images with different sizes.

@namurphy
Copy link
Contributor

Should we add a changelog entry for this pull request too?

Changed error for input file with light leak previously removed to a warning. Made the dimensions test more specific for case of 2048x2048 input image. Added comment.
@jslavin
Copy link
Contributor

jslavin commented Sep 21, 2023

pre-commit.ci autofix

@jslavin jslavin merged commit a8cf639 into HinodeXRT:main Sep 22, 2023
7 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.

3 participants