-
Notifications
You must be signed in to change notification settings - Fork 7
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
DM-32402: Add TractBuilders and sub-patch cell capability. #56
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d84da1
Add TractBuilders and sub-patch cell capability.
erykoff 738047e
Add configuration for number of cells in the patch border.
erykoff cf96cfa
Add properties, patch and cell wcs access, and tests.
erykoff 5bf378b
Add check if coordinate has nan values.
erykoff bc8a3f0
Make patch and cell indexes a named tuple.
erykoff 1ead253
Refactor locations of methods; return Index2D for numPatches/Cells
erykoff File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# | ||
# LSST Data Management System | ||
# Copyright 2008, 2009, 2010 LSST Corporation. | ||
# | ||
# This product includes software developed by the | ||
# LSST Project (http://www.lsst.org/). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the LSST License Statement and | ||
# the GNU General Public License along with this program. If not, | ||
# see <http://www.lsstcorp.org/LegalNotices/>. | ||
# | ||
|
||
__all__ = ["CellInfo"] | ||
|
||
from .detail import makeSkyPolygonFromBBox | ||
|
||
|
||
class CellInfo: | ||
"""Information about a cell within a patch of a tract of a sky map. | ||
|
||
See `PatchInfo` and `TractInfo` for more information. | ||
|
||
Parameters | ||
---------- | ||
index : `lsst.skymap.Index2D` | ||
x,y index of a cell (a pair of ints) | ||
innerBBox : `lsst.geom.Box2I` | ||
Inner bounding box. | ||
outerBBox : `lsst.geom.Box2I` | ||
Outer bounding box. | ||
sequentialIndex : `int` | ||
Cell sequential index. | ||
tractWcs : `lsst.afw.geom.SkyWcs` | ||
Tract WCS object. | ||
""" | ||
def __init__(self, index, innerBBox, outerBBox, sequentialIndex, tractWcs): | ||
self._index = index | ||
self._sequentialIndex = sequentialIndex | ||
self._innerBBox = innerBBox | ||
self._outerBBox = outerBBox | ||
self._wcs = tractWcs | ||
if not outerBBox.contains(innerBBox): | ||
raise RuntimeError("outerBBox=%s does not contain innerBBox=%s" % (outerBBox, innerBBox)) | ||
|
||
def getIndex(self): | ||
"""Return cell index: a tuple of (x, y) | ||
|
||
Returns | ||
------- | ||
result : `lsst.skymap.Index2D` | ||
Patch index (x, y). | ||
""" | ||
return self._index | ||
|
||
index = property(getIndex) | ||
|
||
def getSequentialIndex(self): | ||
"""Return cell sequential index. | ||
|
||
Returns | ||
------- | ||
result : `int` | ||
Sequential cell index. | ||
""" | ||
return self._sequentialIndex | ||
|
||
sequential_index = property(getSequentialIndex) | ||
|
||
def getWcs(self): | ||
"""Return the associated tract wcs | ||
|
||
Returns | ||
------- | ||
wcs : `lsst.afw.geom.SkyWcs` | ||
Tract WCS. | ||
""" | ||
return self._wcs | ||
|
||
wcs = property(getWcs) | ||
|
||
def getInnerBBox(self): | ||
"""Get inner bounding box. | ||
|
||
Returns | ||
------- | ||
bbox : `lsst.geom.Box2I` | ||
The inner bounding Box. | ||
""" | ||
return self._innerBBox | ||
|
||
inner_bbox = property(getInnerBBox) | ||
|
||
def getOuterBBox(self): | ||
"""Get outer bounding box. | ||
|
||
Returns | ||
------- | ||
bbox : `lsst.geom.Box2I` | ||
The outer bounding Box. | ||
""" | ||
return self._outerBBox | ||
|
||
outer_bbox = property(getOuterBBox) | ||
|
||
def getInnerSkyPolygon(self, tractWcs=None): | ||
"""Get the inner on-sky region. | ||
|
||
Parameters | ||
---------- | ||
tractWcs : `lsst.afw.image.SkyWcs`, optional | ||
WCS for the associated tract. | ||
|
||
Returns | ||
------- | ||
result : `lsst.sphgeom.ConvexPolygon` | ||
The inner sky region. | ||
""" | ||
_tractWcs = tractWcs if tractWcs is not None else self._wcs | ||
return makeSkyPolygonFromBBox(bbox=self.getInnerBBox(), wcs=_tractWcs) | ||
|
||
@property | ||
def inner_sky_polygon(self): | ||
return self.getInnerSkyPolygon() | ||
|
||
def getOuterSkyPolygon(self, tractWcs=None): | ||
"""Get the outer on-sky region. | ||
|
||
Parameters | ||
---------- | ||
tractWcs : `lsst.afw.image.SkyWcs`, optional | ||
WCS for the associated tract. | ||
|
||
Returns | ||
------- | ||
result : `lsst.sphgeom.ConvexPolygon` | ||
The outer sky region. | ||
""" | ||
_tractWcs = tractWcs if tractWcs is not None else self._wcs | ||
return makeSkyPolygonFromBBox(bbox=self.getOuterBBox(), wcs=_tractWcs) | ||
|
||
@property | ||
def outer_sky_polygon(self): | ||
return self.getOuterSkyPolygon() | ||
|
||
def __eq__(self, rhs): | ||
return (self.getIndex() == rhs.getIndex()) \ | ||
and (self.getInnerBBox() == rhs.getInnerBBox()) \ | ||
and (self.getOuterBBox() == rhs.getOuterBBox()) | ||
|
||
def __ne__(self, rhs): | ||
return not self.__eq__(rhs) | ||
|
||
def __str__(self): | ||
return "CellInfo(index=%s)" % (self.getIndex(),) | ||
|
||
def __repr__(self): | ||
return "CellInfo(index=%s, innerBBox=%s, outerBBox=%s)" % \ | ||
(self.getIndex(), self.getInnerBBox(), self.getOuterBBox()) |
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 |
---|---|---|
|
@@ -20,14 +20,14 @@ | |
# see <http://www.lsstcorp.org/LegalNotices/>. | ||
# | ||
|
||
__all__ = ["coordFromVec"] | ||
__all__ = ["coordFromVec", "makeSkyPolygonFromBBox", "Index2D"] | ||
|
||
from typing import NamedTuple | ||
import numpy | ||
|
||
import lsst.sphgeom | ||
import lsst.geom as geom | ||
|
||
|
||
_TinyFloat = numpy.finfo(float).tiny | ||
|
||
|
||
|
@@ -56,3 +56,38 @@ def coordFromVec(vec, defRA=None): | |
decDeg = -90.0 | ||
return geom.SpherePoint(defRA, decDeg*geom.degrees) | ||
return geom.SpherePoint(lsst.sphgeom.Vector3d(*vec)) | ||
|
||
|
||
def makeSkyPolygonFromBBox(bbox, wcs): | ||
"""Make an on-sky polygon from a bbox and a SkyWcs | ||
|
||
Parameters | ||
---------- | ||
bbox : `lsst.geom.Box2I` or `lsst.geom.Box2D` | ||
Bounding box of region, in pixel coordinates | ||
wcs : `lsst.afw.geom.SkyWcs` | ||
Celestial WCS | ||
|
||
Returns | ||
------- | ||
polygon : `lsst.sphgeom.ConvexPolygon` | ||
On-sky region | ||
""" | ||
pixelPoints = geom.Box2D(bbox).getCorners() | ||
skyPoints = wcs.pixelToSky(pixelPoints) | ||
return lsst.sphgeom.ConvexPolygon([sp.getVector() for sp in skyPoints]) | ||
|
||
|
||
class Index2D(NamedTuple): | ||
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. This needs a docstring, mainly to provide context on its use cases. |
||
"""Two dimensional index for patches and cells. | ||
|
||
This class contains the x and y values of the location of a patch | ||
within a tract, or a cell within a patch. | ||
|
||
Parameters | ||
---------- | ||
x : `int` | ||
y : `int` | ||
""" | ||
x: int | ||
y: int |
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
Oops, something went wrong.
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.
Shouldn't these throw an error if we are not using legacy tract builder. And the docstring should make it clear that these can be used only with the legacy 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.
So the way that registries work these always exist, and you don't know when it's set if the mode will be overridden. So there's no way to throw an error. But I can add more documentation!