-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add an option to use the corner of the pixel to compute the footprint #2348
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
061066a
Rename calcFootprint to calc_footprint. Add an optional boolean keywo…
nden 409a073
fix docstrings
nden e3ffb56
rewrite calcFootprint to call calc_footprint
nden 1cc3f3b
correct typo in docstrings
nden 2b7f70d
add tests
nden 7b093e0
added an entry in CHANGES
nden 687a845
fix docstring
nden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -548,7 +548,12 @@ def fix(self, translate_units='', naxis=None): | |
| format(key, val), | ||
| FITSFixedWarning) | ||
|
|
||
| @deprecated("0.4", name="calcFootprint", alternative="calc_footprint") | ||
| def calcFootprint(self, header=None, undistort=True, axes=None): | ||
| return self.calc_footprint(header=header, undistort=undistort, axes=axes, | ||
| center=True) | ||
|
|
||
| def calc_footprint(self, header=None, undistort=True, axes=None, center=True): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change this: to this: |
||
| """ | ||
| Calculates the footprint of the image on the sky. | ||
|
|
||
|
|
@@ -558,7 +563,7 @@ def calcFootprint(self, header=None, undistort=True, axes=None): | |
|
|
||
| Parameters | ||
| ---------- | ||
| header : astropy.io.fits header object, optional | ||
| header : `~astropy.io.fits.Header` object, optional | ||
|
|
||
| undistort : bool, optional | ||
| If `True`, take SIP and distortion lookup table into | ||
|
|
@@ -570,9 +575,13 @@ def calcFootprint(self, header=None, undistort=True, axes=None): | |
| keywords from the header that was used to create this | ||
| `WCS` object. | ||
|
|
||
| center : bool, optional | ||
| If `True` use the center of the pixel, otherwise use the corner. | ||
|
|
||
| Returns | ||
| ------- | ||
| coord : (4, 2) array of (*x*, *y*) coordinates. | ||
| The order is counter-clockwise starting with the bottom left corner. | ||
| """ | ||
| if axes is not None: | ||
| naxis1, naxis2 = axes | ||
|
|
@@ -590,18 +599,20 @@ def calcFootprint(self, header=None, undistort=True, axes=None): | |
| naxis1 = header.get('NAXIS1', None) | ||
| naxis2 = header.get('NAXIS2', None) | ||
|
|
||
| corners = np.zeros(shape=(4, 2), dtype=np.float64) | ||
| if naxis1 is None or naxis2 is None: | ||
| return None | ||
|
|
||
| corners[0, 0] = 1. | ||
| corners[0, 1] = 1. | ||
| corners[1, 0] = 1. | ||
| corners[1, 1] = naxis2 | ||
| corners[2, 0] = naxis1 | ||
| corners[2, 1] = naxis2 | ||
| corners[3, 0] = naxis1 | ||
| corners[3, 1] = 1. | ||
| if center == True: | ||
| corners = np.array([[1, 1], | ||
| [1, naxis2], | ||
| [naxis1, naxis2], | ||
| [naxis1, 1]], dtype = np.float64) | ||
| else: | ||
| corners = np.array([[0.5, 0.5], | ||
| [0.5, naxis2 + 0.5], | ||
| [naxis1 + 0.5, naxis2 + 0.5], | ||
| [naxis1 + 0.5, 0.5]], dtype = np.float64) | ||
|
|
||
| if undistort: | ||
| return self.all_pix2world(corners, 1) | ||
| else: | ||
|
|
@@ -1721,7 +1732,7 @@ def footprint_to_file(self, filename=None, color='green', width=2): | |
| f.write(comments) | ||
| f.write('linear\n') | ||
| f.write('polygon(') | ||
| self.calcFootprint().tofile(f, sep=',') | ||
| self.calc_footprint().tofile(f, sep=',') | ||
| f.write(') # color={0}, width={1:d} \n'.format(color, width)) | ||
| f.close() | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
This shows up like this in the HTML docs:
Is this a bug or a feature of the
@deprecateddecorator that this doesn't show up like this?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.
Decorators don't easily preserve the call signature. If you want this to work we need to make use of the decorator.py package. Maybe you could open a new issue for this so we can discuss it? It might not be important since it's deprecated though - in fact, deprecated functions/methods should probably not show up in the API.
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.
If it's not easy to do, I don't think it's worth the trouble.
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.
There is a small bug in the
@deprecateddecorator (#2359), which unfortunately doesn't resolve this issue.functools.wraps(which is the stdlib's simpler implementation of whatdecorator.pydoes) doesn't adapt the function signature of the wrapper. I don't know if this is worth adding yet another dependency.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 might open an issue for this actually. I don't think it's worth it for the
@deprecateddecorator itself, but I have been intended to write my own (similar to what decorator.py has) function to safely write new functions with a given call signature, for use with the modeling package. Once I have that it should be easy to make a wrapper aroundfunctools.wrapsthat includes this capability.