LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.skymap.detail.dodecahedron Namespace Reference

Classes

class  Dodecahedron
 

Functions

def computeRotationMatrix
 
def _computeCoordTransform
 
def _computeDodecahedronVertices
 
def _computeFullVecList
 
def _findCloseIndexSet
 
def _findCloseList
 
def _findClosePair
 
def _sortedVectorList
 

Variables

tuple vertexDodec = Dodecahedron(withFacesOnPoles=False)
 
tuple faceVec = vertexDodec.getFaceCtr(i)
 

Function Documentation

def lsst.skymap.detail.dodecahedron._computeCoordTransform (   vec0,
  vec1,
  vec1NegativeX = False 
)
private
Compute a rotation matrix that puts vec0 along z and vec1 along +x in the xz plane

Inputs:
- vec0: vector 0
- vec1: vector 1
- vec1NegativeX: if True then vec1 is rotated to face negative x

Definition at line 106 of file dodecahedron.py.

107 def _computeCoordTransform(vec0, vec1, vec1NegativeX=False):
108  """Compute a rotation matrix that puts vec0 along z and vec1 along +x in the xz plane
109 
110  Inputs:
111  - vec0: vector 0
112  - vec1: vector 1
113  - vec1NegativeX: if True then vec1 is rotated to face negative x
114  """
115  # rotate around x by angle of vec0 from z to y
116  xAng = math.atan2(vec0[1], vec0[2])
117  xRotMat = computeRotationMatrix(xAng, 0)
118 
119  # rotate around y by -angle of rotated vec0 from z to x
120  vec0RotX = numpy.dot(xRotMat, vec0)
121  yAng = -math.atan2(vec0RotX[0], vec0RotX[2])
122  yRotMat = computeRotationMatrix(yAng, 1)
123  xyRotMat = numpy.dot(yRotMat, xRotMat)
124 
125  # rotate around z by -angle of rotated vec1 from +/-x to y
126  vec1RotXY = numpy.dot(xyRotMat, vec1)
127  xVal = vec1RotXY[0]
128  if vec1NegativeX:
129  xVal = -xVal
130  zAng = -math.atan2(vec1RotXY[1], xVal)
131  zRotMat = computeRotationMatrix(zAng, 2)
132  xyzRotMat = numpy.dot(zRotMat, xyRotMat)
133  return xyzRotMat
def lsst.skymap.detail.dodecahedron._computeDodecahedronVertices (   faceVecList)
private
Given a vector of face positions of a Dodecahedron compute the vertices

Definition at line 134 of file dodecahedron.py.

135 def _computeDodecahedronVertices(faceVecList):
136  """Given a vector of face positions of a Dodecahedron compute the vertices
137  """
138  closeIndSetList = []
139  vertexDict = {}
140  for i in range(len(faceVecList)):
141  closeIndSet = _findCloseIndexSet(faceVecList, i)
142  if len(closeIndSet) != 5:
143  raise RuntimeError("Found %s vertices instead of 5 near %s: %s" % \
144  (len(closeIndSet), faceVecList[i], closeIndSet))
145  closeIndSetList.append(closeIndSet)
146  for i, iCloseIndSet in enumerate(closeIndSetList):
147  for j in iCloseIndSet:
148  jCloseIndSet = closeIndSetList[j]
149  sharedCloseIndSet = iCloseIndSet.intersection(jCloseIndSet)
150  if len(sharedCloseIndSet) != 2:
151  raise RuntimeError("Found %s vertices instead of 2 near %s and %s: %s" % \
152  (len(sharedCloseIndSet), faceVecList[i], faceVecList[j], sharedCloseIndSet))
153  for k in sharedCloseIndSet:
154  key = frozenset((i, j, k))
155  if key in vertexDict:
156  continue
157  vertexVec = faceVecList[i] + faceVecList[j] + faceVecList[k]
158  vertexVec /= numpy.sqrt(numpy.sum(vertexVec**2))
159  vertexDict[key] = vertexVec
160  return vertexDict.values()
def lsst.skymap.detail.dodecahedron._computeFullVecList (   basisSet)
private
Given a collection of basis vectors, compute all permutations with both signs of all nonzero values

For example: [(0, 1, 2)] -> [(0, 1, 2), (0, -1, 2), (0, 1, -2), (0, -1, -2)]

Definition at line 161 of file dodecahedron.py.

162 def _computeFullVecList(basisSet):
163  """Given a collection of basis vectors, compute all permutations with both signs of all nonzero values
164 
165  For example: [(0, 1, 2)] -> [(0, 1, 2), (0, -1, 2), (0, 1, -2), (0, -1, -2)]
166  """
167  fullSet = []
168  for basisVec in basisSet:
169  vecLen = math.sqrt(numpy.sum(numpy.array(basisVec)**2))
170  valueList = []
171  for basisValue in basisVec:
172  if basisValue == 0:
173  valueList.append((0,))
174  else:
175  valueList.append((basisValue, -basisValue))
176  fullSet += list(numpy.array((x, y, z))/vecLen
177  for z in valueList[2]
178  for y in valueList[1]
179  for x in valueList[0]
180  )
181  return fullSet
def lsst.skymap.detail.dodecahedron._findCloseIndexSet (   vecList,
  ind 
)
private
Given a list of cartesian vectors, return a set of indices of those closest to one of them

This is intended for regular grids where distances are quantized

Inputs:
- vecList: list of cartesian vectors
- ind: index of vector to be nearest

Definition at line 182 of file dodecahedron.py.

183 def _findCloseIndexSet(vecList, ind):
184  """Given a list of cartesian vectors, return a set of indices of those closest to one of them
185 
186  This is intended for regular grids where distances are quantized
187 
188  Inputs:
189  - vecList: list of cartesian vectors
190  - ind: index of vector to be nearest
191  """
192  dotProductList = numpy.round(numpy.dot(vecList, vecList[ind]), 2)
193  dotProductList[ind] = -9e99
194  minDist = numpy.max(dotProductList)
195  indList = numpy.arange(len(dotProductList))[dotProductList==minDist]
196  return set(indList)
def lsst.skymap.detail.dodecahedron._findCloseList (   vecList,
  vec 
)
private
Given a list of cartesian vectors, return all those closest to a specified position

This is intended for regular grids where distances are quantized

Inputs:
- vecList: list of cartesian vectors
- vec: vector to be near

@return two items:
- list of closest vectors
- list if indices of those vectors

Definition at line 197 of file dodecahedron.py.

198 def _findCloseList(vecList, vec):
199  """Given a list of cartesian vectors, return all those closest to a specified position
200 
201  This is intended for regular grids where distances are quantized
202 
203  Inputs:
204  - vecList: list of cartesian vectors
205  - vec: vector to be near
206 
207  @return two items:
208  - list of closest vectors
209  - list if indices of those vectors
210  """
211  dotProductList = numpy.round(numpy.dot(vecList, vec), 2)
212  minDist = numpy.max(dotProductList)
213  indList = numpy.arange(len(dotProductList))[dotProductList==minDist]
214  retList = numpy.take(vecList, indList, 0)
215  return retList, indList
def lsst.skymap.detail.dodecahedron._findClosePair (   vecList,
  ind = 0 
)
private
Given a list of cartesian vectors and an index, return the vector and one of its closest neighbors

Inputs:
- vecList: list of cartesian vectors
- ind: index of first vector

Definition at line 216 of file dodecahedron.py.

217 def _findClosePair(vecList, ind=0):
218  """Given a list of cartesian vectors and an index, return the vector and one of its closest neighbors
219 
220  Inputs:
221  - vecList: list of cartesian vectors
222  - ind: index of first vector
223  """
224  vec = vecList[ind]
225  otherVecList = vecList[0:ind] + vecList[ind+1:]
226  ind1 = numpy.argmax(numpy.dot(otherVecList, vec))
227  return vec, otherVecList[ind1]
def lsst.skymap.detail.dodecahedron._sortedVectorList (   vecList)
private
Return a list of cartesian vectors sorted by decreasing latitude and increasing longitude

Definition at line 228 of file dodecahedron.py.

229 def _sortedVectorList(vecList):
230  """Return a list of cartesian vectors sorted by decreasing latitude and increasing longitude
231  """
232  def vecToSort(vec):
233  ang = round(math.atan2(vec[1], vec[0]), 2)
234  if ang < 0:
235  ang += 2.0 * math.pi
236  return (-round(vec[2], 1), ang, vec)
237 
238  decoratedList = [vecToSort(v) for v in vecList]
239  decoratedList.sort()
240  return [d[2] for d in decoratedList]
def lsst.skymap.detail.dodecahedron.computeRotationMatrix (   angle,
  axis 
)
Return a 3D rotation matrix for rotation by a specified amount around a specified axis

Inputs:
- angle: amount of rotation (rad)
- axis: axis of rotation; one of 0, 1 or 2 for x, y or z

Definition at line 89 of file dodecahedron.py.

89 
90 def computeRotationMatrix(angle, axis):
91  """Return a 3D rotation matrix for rotation by a specified amount around a specified axis
92 
93  Inputs:
94  - angle: amount of rotation (rad)
95  - axis: axis of rotation; one of 0, 1 or 2 for x, y or z
96  """
97  cosAng = math.cos(angle)
98  sinAng = math.sin(angle)
99  rotMat = numpy.zeros((3,3), dtype=float)
100  rotMat[axis, axis] = 1
101  rotMat[(axis + 1) % 3, (axis + 1) % 3] = cosAng
102  rotMat[(axis + 2) % 3, (axis + 1) % 3] = sinAng
103  rotMat[(axis + 1) % 3, (axis + 2) % 3] = -sinAng
104  rotMat[(axis + 2) % 3, (axis + 2) % 3] = cosAng
105  return rotMat

Variable Documentation

tuple lsst.skymap.detail.dodecahedron.faceVec = vertexDodec.getFaceCtr(i)

Definition at line 249 of file dodecahedron.py.

tuple lsst.skymap.detail.dodecahedron.vertexDodec = Dodecahedron(withFacesOnPoles=False)

Definition at line 247 of file dodecahedron.py.