Skip to content
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

tickets/DM-16801 #30

Merged
merged 2 commits into from
Dec 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions python/lsst/skymap/tractInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#
import numbers

import lsst.pex.exceptions
import lsst.afw.geom as afwGeom
from lsst.sphgeom import ConvexPolygon
Expand Down Expand Up @@ -154,6 +156,12 @@ def getSequentialPatchIndex(self, patchInfo):
nx, ny = self.getNumPatches()
return nx*y + x

def getPatchIndexPair(self, sequentialIndex):
nx, ny = self.getNumPatches()
x = sequentialIndex % nx
y = (sequentialIndex - x) / nx
return (x, y)

def findPatch(self, coord):
"""Find the patch containing the specified coord

Expand Down Expand Up @@ -240,12 +248,15 @@ def getPatchBorder(self):
def getPatchInfo(self, index):
"""Return information for the specified patch

@param[in] index: index of patch, as a pair of ints;
negative values are not supported
@param[in] index: index of patch, as a pair of ints,
or a sequential index as returned by getSequentialPatchIndex;
negative values are not supported.
@return patch info, an instance of PatchInfo

@raise IndexError if index is out of range
"""
if isinstance(index, numbers.Number):
index = self.getPatchIndexPair(index)
if (not 0 <= index[0] < self._numPatches[0]) \
or (not 0 <= index[1] < self._numPatches[1]):
raise IndexError("Patch index %s is not in range [0-%d, 0-%d]" %
Expand Down
16 changes: 16 additions & 0 deletions tests/test_equatSkyMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ def testDefaults(self):
skyMap = EquatSkyMap(config)
self.assertEqual(skyMap.config.projection, "CEA")

def test_gettingPatchInfo(self):
skyMap = EquatSkyMap(EquatSkyMap.ConfigClass())
tract = skyMap[0]
# Look up patchInfo with a coordinate pair
patchIndex = (3, 5)
pairPatchInfo = tract.getPatchInfo(patchIndex)
# Fetch the sequential index
sequentialPatchIndex = tract.getSequentialPatchIndex(pairPatchInfo)
# Turn the sequential index back into a pair
returnedPatchIndex = tract.getPatchIndexPair(sequentialPatchIndex)
# Test that the different indexes match
self.assertEqual(patchIndex, returnedPatchIndex)
# verify patch info can be retrieved with both indexes
sequentialPatchInfo = tract.getPatchInfo(sequentialPatchIndex)
self.assertEqual(pairPatchInfo, sequentialPatchInfo)

def testSymmetry(self):
"""Verify that the projection is symmetrical about the equator
"""
Expand Down