8000 Fix _apply_sky in skymatch for single group input by mcara · Pull Request #5440 · spacetelescope/jwst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix _apply_sky in skymatch for single group input #5440

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 2 commits into from
Oct 29, 2020

Conversation

mcara
Copy link
Member
@mcara mcara commented Oct 28, 2020

Fixes a bug in skymatch.skymatch._apply_sky() that would result in a crash when skymethod contains 'global' and input image is a single image group whose sky cannot be computed, e.g., because its images contains no "good" pixels.

This bug was revealed after PR #5423 which permitted processing of single image/group inputs.

Fixes failing test test_nircam_image.py::test_image3_closedfile. The test will still be failing for two reasons:

  1. Extra keyword 'S_SKYMAT' - that's expected
  2. Small differences in many image pixels. This failure is not related to this PR and probably is caused by unrelated changes. This test was not OKified before because it was crashing.

@mcara mcara requested a review from jdavies-st October 28, 2020 03:52
@mcara mcara self-assigned this Oct 28, 2020
@codecov
Copy link
codecov bot commented Oct 28, 2020

Codecov Report

Merging #5440 into master will decrease coverage by 0.63%.
The diff coverage is 63.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5440      +/-   ##
==========================================
- Coverage   71.72%   71.08%   -0.64%     
==========================================
  Files         414      414              
  Lines       37755    38170     +415     
  Branches     5843     6029     +186     
==========================================
+ Hits        27079    27133      +54     
- Misses       8956     9310     +354     
- Partials     1720     1727       +7     
Flag Coverage Δ *Carryforward flag
#nightly 71.71% <87.50%> (ø) Carriedforward from 5ff48fa
#unit 52.45% <0.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
jwst/skymatch/skyimage.py 47.30% <ø> (-9.29%) ⬇️
jwst/extract_1d/extract.py 52.72% <50.00%> (-7.47%) ⬇️
jwst/skymatch/skymatch.py 69.54% <71.42%> (-15.03%) ⬇️
jwst/regtest/conftest.py 70.77% <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 933f19a...8aa1a93. Read the comment docs.

@hbushouse hbushouse added this to the Build 7.7 milestone Oct 28, 2020
log.warning(" * {:s} ID={}: Unable to compute sky value"
.format(img_type, img.id))
.format(img_type[is_group], img.id))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it kosher to use a boolean (is_group) as an index into a list? I guess it sort of works by having False and True equate to 0 and 1, but ...

Copy link
Member Author
@mcara mcara Oct 28, 2020

Choose a reason for hiding this comment

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

Is there anything kosher in Python? Unfortunately not a Python priest here. Although, booleans are a subclass of int and so I do not think there is anything wrong with this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Possible alternatives:

img_type[int(is_group)]

or

img_type[is_group + 0]

I like this last one above :)

Other alternatives (both overkill IMO): make img_type a dictionary or have an if statement.

Copy link
Member Author

Choose a reason for hiding this comment

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

I found something: https://www.python.org/dev/peps/pep-0285/ - see point 6:

Should bool inherit from int?

=> Yes.

In an ideal world, bool might be better implemented as a separate integer type that knows how to perform mixed-mode arithmetic. However, inheriting bool from int eases the implementation enormously (in part since all C code that calls PyInt_Check() will continue to work -- this returns true for subclasses of int). Also, I believe this is right in terms of substitutability: code that requires an int can be fed a bool and it will behave the same as 0 or 1.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You like the last one above, because it's clever (adding an int value will cause the result to be int), while I like the first one (explicitly casting the result to int), because it's explicit (and hence doesn't require a reader to think about what's happening).

Copy link
Member Author
@mcara mcara Oct 28, 2020

Choose a reason for hiding this comment

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

Ha! priest has spoken (see same PEP, "Compatibility" section):

Because of backwards compatibility, the bool type lacks many properties that some would like to see. For example, arithmetic operations with one or two bool arguments is allowed, treating False as 0 and True as 1. Also, a bool may be used as a sequence index.

I don't see this as a problem, and I don't want evolve the language in this direction either. I don't believe that a stricter interpretation of "Booleanness" makes the language any clearer.

Copy link
Collaborator
@jdavies-st jdavies-st 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. Just a request for a comment.

@@ -382,24 +380,26 @@ def match(images, skymethod='global+match', match_down=True, subtract=False):


def _apply_sky(images, sky_deltas, do_global, do_skysub, show_old):
img_type = ['Image', 'Group']
Copy link
Collaborator
@jdavies-st jdavies-st Oct 28, 2020

Choose a reason for hiding this comment

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

I would add a comment here,

# The following to be indexed by boolean is_group
img_type = ['Image', 'Group']

to make this clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member Author

Choose a reason for hiding this comment

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

Done again

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.

3 participants
0