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

Refactoring SHWFS code #369

Merged
merged 2 commits into from Jun 26, 2020
Merged

Refactoring SHWFS code #369

merged 2 commits into from Jun 26, 2020

Conversation

fanpeng-kong
Copy link
Contributor

  1. Refactored code in sub_sampled_optics.py by removing extra white
    spaces
  2. Comparisons with None values using is/is not instead of =/!=
  3. Solve minor bug in 'get_centroids' method due to wrong code
    indention

1. Refactored code in sub_sampled_optics.py by removing extra white
spaces
2. Comparisons with None values using is/is not instead of =/!=
3. Solve minor bug in 'get_centroids' method due to wrong code
indention
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #369 into develop will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #369      +/-   ##
===========================================
- Coverage    71.02%   71.00%   -0.02%     
===========================================
  Files           17       17              
  Lines         5732     5733       +1     
===========================================
  Hits          4071     4071              
- Misses        1661     1662       +1     
Impacted Files Coverage Δ
poppy/sub_sampled_optics.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15a4278...8e75d2a. Read the comment docs.

@mperrin
Copy link
Collaborator

mperrin commented Jun 23, 2020

@fanpeng-kong Thank you for this pull request! Much appreciated. We will take a look as soon as time permits.

@mperrin
Copy link
Collaborator

mperrin commented Jun 23, 2020

FYI @remorgan123, would you have time to take a look at this PR with some updates to the SHWFS code, please?

else:
intensity_array = sub_wf.intensity
self.centroid_list[:,i,j] = cent_function(intensity_array,**kwargs, relativeto = relativeto)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is a bug since the asFITS case wouldn't lead to a centroid list if the function is only called inside the else statement - @remorgan123 do we have a test that includes this line?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

him, not sure linking into codecov works well... if you go to the codecov link at the bottom of this PR, click to files, and browse to this file, then it shows 0% coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I overlooked the asFITS case. I encountered the following error earlier while running Shack Hartmann Wavefront Sensor Demo.ipynb by changing the pixel_pitch from 2.2um to 5um. This leads to negative indices of XLOC and YLOC which I am not sure if it's intended by fwcentroid:

~/Projects/Python/Optics/poppy_sim/shwfs_demo.py in
88 shwfs.sample_wf(wf_flat)
89 shwfs.get_psfs()
---> 90 flat_centroid_list = shwfs.get_centroids()
91
92 #sample actual wf and propagate to detector:

~/Projects/Python/Modules/poppy/poppy/sub_sampled_optics.py in get_centroids(self, cent_function, relativeto, asFITS, **kwargs)
272 else:
273 intensity_array = sub_wf.intensity
--> 274 self.centroid_list[:, i, j] = cent_function(intensity_array, **kwargs, relativeto=relativeto)
275
276 self._centroided_flag = True

~/Projects/Python/Modules/poppy/poppy/utils.py in measure_centroid(HDUlist_or_filename, ext, slice, boxsize, verbose, units, relativeto, **kwargs)
1024 image = image[slice, :, :]
1025
-> 1026 cent_of_mass = fwcentroid(image, halfwidth=boxsize, **kwargs)
1027
1028 if verbose:

~/Projects/Python/Modules/poppy/poppy/fwcentroid.py in fwcentroid(image, checkbox, maxiterations, threshold, halfwidth, verbose)
102 YLOC = j
103 # print " (%d, %d)" % (XLOC, YLOC)
--> 104 SUM += image[j, i]
105 XSUM += XLOC * image[j, i]
106 XSUM2 += XLOC ** 2 * image[j, i]

IndexError: index 30 is out of bounds for axis 0 with size 30

My previous wrong intent bypassed the asFITS case and therefore hided the error but also led to no centroid estimation.

The error itself may not necessarily be a bug but could depend on a correct selections of the pixels per lenslet and halfwidth:

def fwcentroid(image, checkbox=1, maxiterations=20, threshold=1e-4, halfwidth=5, verbose=False):

@mperrin Could you please point me to some written materials on the two JWST materials so I can investigate further?

See JWST technical reports JWST-STScI-001117 and JWST-STScI-001134 for details.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, common error in my experience with fwcentroid() that usually requires adjusting the halfwidth size.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I agree the fwcentroid function isn't so sophisticated as it could be (by design... the flight version of this algorithm runs in a very tiny and not so smart computer.) We could make the version here more intelligent about choosing good default parameter sizes, or at least giving a more informative error message that says the box size should be increased.

@mperrin
Copy link
Collaborator

mperrin commented Jun 26, 2020

Thanks @fanpeng-kong for this contribution! Much appreciated. Looks good and I will go ahead and merge this now.

However as a broader question to you, @douglase, and @remorgan123: As I noted in my comment the other day, right now there's no test coverage right now at all for any of the SHWFS code. It would be nice if we could improve that at some point. I think some of the code from the example notebook could be adapted to make a test case fairly easily for this. @douglase let me know if you agree that could maybe be a good student project sometime? Not immediately urgent but would be nice to have at some point at least basic test coverage on this code.

Cheers and have a good weekend, all.

@mperrin mperrin merged commit 1887dd5 into spacetelescope:develop Jun 26, 2020
@mperrin mperrin added this to the 0.9.2 milestone Feb 9, 2021
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.

None yet

3 participants