8000 JP-1796: Fix wfs_combine bugs; add unit tests by jdavies-st · Pull Request #5519 · spacetelescope/jwst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

JP-1796: Fix wfs_combine bugs; add unit tests #5519

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

Merged
merged 6 commits into from
Dec 7, 2020

Conversation

jdavies-st
Copy link
Collaborator

Fixes some bugs introduced in #5500 that showed up in the wfs_combine regression tests. Adds some unit tests for the expected behavior.

Resolves #5515 / JP-1796

@jdavies-st jdavies-st added this to the Build 7.7 milestone Dec 7, 2020
err_data_1 = im_1_a.err.copy()
err_data_2 = im_2_a.err.copy()

bad1 = np.bitwise_and(dq_data_1, dqflags.pixel['DO_NOT_USE'])
Copy link
Collaborator Author
@jdavies-st jdavies-st Dec 7, 2020

Choose a reason for hiding this comment

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

The bug was here (and 2 lines down). np.bitwise_and returns an array of 0 and 1 values, and cannot be used to index another array without being converted to a boolean array. Once converted, it can have the True/False values flipped via that ~ operator.

An example:

In [1]: import numpy as np

In [2]: a = np.arange(15)

In [3]: a
Out[3]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 1
8000
4])

In [4]: np.bitwise_and(a, 1)
Out[4]: array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0])

@codecov
Copy link
codecov bot commented Dec 7, 2020

Codecov Report

Merging #5519 (e5d70a5) into master (0131037) will increase coverage by 0.32%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5519      +/-   ##
==========================================
+ Coverage   71.25%   71.57%   +0.32%     
==========================================
  Files         410      410              
  Lines       36321    37180     +859     
  Branches     5594     5763     +169     
==========================================
+ Hits        25879    26613     +734     
- Misses       8800     8913     +113     
- Partials     1642     1654      +12     
Flag Coverage Δ *Carryforward flag
nightly 71.24% <100.00%> (ø) Carriedforward from 19d0874
unit 51.77% <85.71%> (+0.29%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

Impacted Files Coverage Δ
jwst/wfs_combine/wfs_combine_step.py 97.61% <88.88%> (-2.39%) ⬇️
jwst/wfs_combine/wfs_combine.py 78.76% <95.23%> (-16.00%) ⬇️
jwst/associations/asn_gather.py 66.29% <0.00%> (-1.45%) ⬇️
jwst/associations/lib/rules_level3.py 97.00% <0.00%> (-1.38%) ⬇️
jwst/associations/lib/dms_base.py 89.01% <0.00%> (-1.11%) ⬇️
jwst/associations/lib/rules_level3_base.py 88.80% <0.00%> (+0.50%) ⬆️
jwst/associations/lib/rules_level2b.py 96.14% <0.00%> (+1.85%) ⬆️
jwst/associations/lib/rules_level2_base.py 84.38% <0.00%> (+3.95%) ⬆️

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 0131037...0d90dd6. Read the comment docs.

@jemorrison
Copy link
Collaborator

Ha I see my problem (bug). Hopefully I will not make that mistake again.

Copy link
Collaborator
@hbushouse hbushouse left a comment

Choose a reason for hiding this comment

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

Looks great overall (lots of nice cleanup), but just one question about saving the results.


# Save the output file
self.save_model(
output_model, suffix='wfscmb', output_file=outfile, format=False
)

return None
return output_model
Copy link
Collaborator

Choose a reason for hiding this comment

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

So lines 59-61 are still in there to save the results to a file, as well as now passing output_model back to stpipe. Is stpipe going to try to save the model to a file too?

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 a good question. Let me check in the regression test run.

Copy link
Collaborator Author
@jdavies-st jdavies-st Dec 7, 2020

Choose a reason for hiding this comment

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

Yes, it does auto write out each result under the wrong name. Lovely. Let me fix this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So if I put it into a if self.save_results: block, it will then save it out properly. One then needs to supress the autosaving because there's the return statement. Perhaps @stscieisenhamer has a better way of handling this. I think this can be taken care of in issue #5511, as currently this step theoretically could return multiple products, but has no way to do so without utilizing a ModelContainer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What kind of wrong name is stpipe using when it saves to file? We should be able to tell it the proper product name suffix. @stscieisenhamer is the expert in that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And one also needs control over the format arg in Step.save_model(format=False). Without this, one gets:

jw00632-o003_t001_nircam_f212n-wlp8-nrca4_{suffix}-05_wfscmb.fits

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The formatting template in the association file is:

"name": "jw00632-o003_t001_nircam_f212n-wlp8-nrca4_{suffix}-05",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the current state of this PR produces the correct name, doesn't produce the incorrect name, and does so by hijacking the knowledge of when stpipe turns on save_results. This is not ideal, but given that doing it properly would require a small refactor, I don't think we can do it before 7.7

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the only time this step would return multiple results is if you gave it an input ASN file that defines multiple products. This is not the case in normal operations (only 1 product per ASN).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added some comments to why it is implemented in this hacky way now. In the future, perhaps we can refactor Step.save_model to expose format as a class or instance attribute.

Once tests pass I will merge.

8000

@jdavies-st
Copy link
Collaborator Author

Ha I see my problem (bug). Hopefully I will not make that mistake again.

Count on making it again. 😅

I've made this mistake countless times myself, and did while trying to debug this. Writing the test sorted me out.

Copy link
Collaborator
@hbushouse hbushouse left a comment

Choose a reason for hiding this comment

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

I'm Howard Bushouse and I approve this PR.

@jdavies-st jdavies-st merged commit fd652cd into spacetelescope:master Dec 7, 2020
@jdavies-st jdavies-st deleted the wfs-unit-test branch December 7, 2020 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve regression tests with wfs_combine
4 participants
0