-
Notifications
You must be signed in to change notification settings - Fork 32
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
Pull common parts of skymatch from romancal and jwst into stcal #310
base: main
Are you sure you want to change the base?
Pull common parts of skymatch from romancal and jwst into stcal #310
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #310 +/- ##
===========================================
+ Coverage 29.57% 85.05% +55.47%
===========================================
Files 36 53 +17
Lines 7949 10028 +2079
===========================================
+ Hits 2351 8529 +6178
+ Misses 5598 1499 -4099 ☔ View full report in Codecov by Sentry. |
c7e296c
to
9ab3734
Compare
9ed58df
to
cfaf7eb
Compare
ba12908
to
2aee80f
Compare
2aee80f
to
6202d38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks William! I just had a few questions about whether some of the ruff and mypy problems could be fixed instead of ignored.
I also had a few questions about the code itself, but those also exist on jwst main, so they're technically beyond the scope of this PR. But I'm still curious to know the answers to those and I figure now is as good a time as any to ensure the code is written as cleanly as possible
pix_area=1.0, | ||
convf=1.0, | ||
mask=None, | ||
id=None, # noqa: A002 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of hiding the style complaint could this be renamed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest sky_id
as it would work with both SkyImage
and SkyGroup
.
The functionality to support this conversion is not yet | ||
implemented and at this moment `convf` is ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there plans to implement this? If not, perhaps now is a good time to remove the option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on ancient (>9 years old) discussions with relevant people, this feature, in theory, may not be needed for JWST. In practice, however, we don't know. I suggest leaving this alone as is.
@property | ||
def id(self): # noqa: A003 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you most likely just copied all of this from JWST, so not strictly in the scope of this PR, but is there a reason that getter-setter methods are being used here for id
, pix_area
, sky
, is_sky_valid
, radec
, polygon
, and skystat
? These don't seem to add any functionality.
These do make it so that this class has the same underscore-protected variable names as SkyGroup
, but is there any reason that has to be the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the original code was written ~11-12 years ago (not sure about this but I think so), I no longer remember the intention. Maybe during the development I thought that, for example, pix_area
will be computed on demand but ended up storing it for efficiency. It just allows more flexibility. Also, since both SkyImage
and SkyGroup
can be used as inputs to match
, they should have a common set of properties. I do not remember what was the Python version used during the development but it may have been 2.x
(due to PyRAF / Tables/ whatever limitations) so I don't think ABC
was available at that time and even if it was, I am not sure properties or attributes of classes could be made abstract. Another reason may have been the desire to get these properties documented (in the docstrings).
I do not think anything should be changed in this PR but in the future they could subclass from a BaseSky
, ABCSky
or something like that.
I do not see what is the harm in using properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no harm it's just unnecessarily verbose since neither the getter nor the setter does anything. It's therefore confusing, because when I see those methods, I expect them to do something. But it doesn't matter- I agree with William's comment that these changes shouldn't go into this PR, if they happen at all.
|
||
""" | ||
|
||
def __init__(self, images, id=None, sky=0.0): # noqa: A002 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again here can id
be renamed instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest sky_id
as it would work with both SkyImage
and SkyGroup
.
for im in self._images: | ||
im.sky += sky | ||
|
||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question here RE why id
, polygon
, and radec
go through the trouble to use @property
log.setLevel(logging.DEBUG) | ||
|
||
|
||
def match(images, skymethod="global+match", match_down=True, subtract=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this name also violates https://docs.astral.sh/ruff/rules/builtin-variable-shadowing/ and will likely be changed in JWST by spacetelescope/jwst#9053 to be skymatch()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest something along the lines do_match
or perform_match
, or match_sky
. The intent for the name of this function was for it to be a verb. skymatch
does not sound to me (a non-native English speaker) as a verb but I may be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with whatever name
from copy import deepcopy | ||
|
||
# THIRD PARTY | ||
from stsci.imagestats import ImageStats # type: ignore[import-untyped] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth considering making the relevant third-party type ignores global by putting them here
Line 212 in d6a87c3
[[tool.mypy.overrides]] |
This is a superclass build on top of | ||
:py:class:`stsci.imagestats.ImageStats`. Compared to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is confusing because the class doesn't actually inherit from ImageStats
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs could be changed to explain that SkyStats
delegates calls to an ImageStats
object if that is more clear but the comment about persistence of settings is important as it is what differentiates it from ImageStats
and I think it helps with performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that the comment itself explains an important distinction, and yes the simple wording change from "superclass built on top of" to "delegates calls to" would be clearer
I agree they should be fixed. However, as you said they are beyond the scope of this PR. I think for making it possible to trace the history of changes it makes sense to move the code in as close a state as possible from JWST to stcal and then do a follow on PR making cleanups and addressing the issues uncovered here. |
|
||
# "bottom" points: | ||
borderx[:nptx] = xs | ||
bordery[:nptx] = -0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest a comment explaining the -0.5 number or the use of a descriptive constant detailing what this number is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, and I believe this has something to do with all the pixel offsetting. However this is largely just a copy of the stuff from JWST with minimal changes. If someone knows exactly what this is I would be happy to add a comment here.
Really, we should be maintaining a common "constants" object/module to document these and back reference that as opposed to having a bunch of ad hoc magic numbers some of which are documented with comments. This however, is something to consider later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Centers of pixels have integer image coordinates. Edges of the pixels are located +/- 0.5
pixels away from centers. I think this convention is explained somewhere in the docs. IMO, it does not make sense to add a comment like this every single time we see a 0.5 in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and -0.5
is shorter than coordinate_of_left_pixel_border(_relative_to_center)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Mihai that in the context of pixels it's relatively clear what a 0.5 offset is doing.
However it looks to me like calc_bounding_polygon
is the only function where this is really relevant, so would it work to add a note to the docstring saying something like,
Notes
-----
The bounding polygon is defined from corners of pixels
whereas the reference pixel is defined at the center of a pixel
and therefore the lower-left corner is located at (-0.5, -0.5)
or whatever you want, I'm sure I made some small inaccuracies in describing that but you get the idea
IMO making the code adhere to the more stringent style rules in stcal remains within the scope. I don't much like ignoring them. I think the downstream testing should assuage any concerns that those changes might break something. I agree that my comment RE the potentially unnecessary use of |
This PR pulls the common parts of skymatch from romancal and jwst into stcal to be shared.
Note, no tests are included because it is well tested by the step tests in both romancal and jwst.
Tasks
docs/
pageno-changelog-entry-needed
)changes/
:echo "changed something" > changes/<PR#>.<changetype>.rst
(see below for change types)"git+https://github.com/<fork>/stcal@<branch>"
)jwst
regression testromancal
regression testnews fragment change types...
changes/<PR#>.apichange.rst
: change to public APIchanges/<PR#>.bugfix.rst
: fixes an issuechanges/<PR#>.general.rst
: infrastructure or miscellaneous change