-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from mhvk/axis-extent
Move axis_extent from examples/docs to actual utility.
- Loading branch information
Showing
8 changed files
with
60 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from astropy.units import Quantity | ||
|
||
|
||
def axis_extent(*args): | ||
"""Treat the arguments as axis arrays of an image, and get their extent. | ||
Just the first and last element of each array, but properly taking into | ||
account that the limits of the image are half a pixel before and after. | ||
Parameters | ||
---------- | ||
args : array | ||
Arrays with coordinates of the images. Assumed to be contiguous, | ||
and have only one dimension with non-unity shape. | ||
Returns | ||
------- | ||
extent : list of int | ||
Suitable for passing into matplotlib's ``imshow``. | ||
""" | ||
result = [] | ||
for a in args: | ||
x = Quantity(a).squeeze().value | ||
result.extend([x[0] - (x[1]-x[0])/2, x[-1] + (x[-1]-x[-2])/2]) | ||
return result |