コード例 #1
0
    def test_angle_preserved(self):
        """
        Test that the angle between two vectors is preserved under rotation.
        """
        for i in xrange(n_tests):
            vectors_0 = np.array((random_polaz(), random_polaz()), dtype=float)
            d_0 = su.angle_between_points(*vectors_0)

            a, b, c = random_euler_angle()
            vectors_1 = su.rotate_euler(vectors_0, a, b, c)
            d_1 = su.angle_between_points(*vectors_1)
            self.assertAlmostEqual(d_0, d_1)
コード例 #2
0
    def test_angle_preserved(self):
        """
        Test that the angle between two vectors is preserved under rotation.
        """
        for i in xrange(n_tests):
            vectors_0 = np.array((random_polaz(), random_polaz()),
                dtype=float)
            d_0 = su.angle_between_points(*vectors_0)

            a, b, c = random_euler_angle()
            vectors_1 = su.rotate_euler(vectors_0, a, b, c)
            d_1 = su.angle_between_points(*vectors_1)
            self.assertAlmostEqual(d_0, d_1)
コード例 #3
0
 def test_identity(self):
     """
     Test that Euler angles of zero are the identity operation.
     """
     for i in xrange(n_tests):
         vector = np.array([random_polaz()])
         err = su.angle_between_points(vector,
                                       su.rotate_euler(vector, 0., 0., 0.))
         self.assertAlmostEqual(err, 0.)
コード例 #4
0
 def test_identity(self):
     """
     Test that Euler angles of zero are the identity operation.
     """
     for i in xrange(n_tests):
         vector = np.array([random_polaz()])
         err = su.angle_between_points(vector,
             su.rotate_euler(vector, 0., 0., 0.))
         self.assertAlmostEqual(err, 0.)
コード例 #5
0
 def test_inverse(self):
     """
     Test that rotation * inverse = identity.
     """
     for i in xrange(n_tests):
         vector = np.array([random_polaz()])
         a, b, c = random_euler_angle()
         err = su.angle_between_points(vector, \
             su.rotate_euler(su.rotate_euler(vector, a, b, c), -c, -b, -a))
         self.assertAlmostEqual(err, 0.)
コード例 #6
0
 def test_inverse(self):
     """
     Test that rotation * inverse = identity.
     """
     for i in xrange(n_tests):
         vector = np.array([random_polaz()])
         a, b, c = random_euler_angle()
         err = su.angle_between_points(vector, \
             su.rotate_euler(su.rotate_euler(vector, a, b, c), -c, -b, -a))
         self.assertAlmostEqual(err, 0.)
コード例 #7
0
 def test_north_pole(self):
     """
     Test that new_z_to_euler() gives Euler angles that will rotate the
     original z axis to the requested z axis.
     """
     north_pole = np.array([[0., 0.]])
     for i in xrange(n_tests):
         new_dir = random_polaz()
         a, b = su.new_z_to_euler(new_dir)
         new_north = su.rotate_euler(north_pole, a, b, 0)
         self.assertAlmostEqual(0., \
             su.angle_between_points(new_north, np.array([new_dir])))
コード例 #8
0
 def test_north_pole(self):
     """
     Test that new_z_to_euler() gives Euler angles that will rotate the
     original z axis to the requested z axis.
     """
     north_pole = np.array([[0., 0.]])
     for i in xrange(n_tests):
         new_dir = random_polaz()
         a, b = su.new_z_to_euler(new_dir)
         new_north = su.rotate_euler(north_pole, a, b, 0)
         self.assertAlmostEqual(0., \
             su.angle_between_points(new_north, np.array([new_dir])))
コード例 #9
0
ファイル: skylocutils.py プロジェクト: llondon6/lalsuite-mmrd
def sbin(bins,pt,res=0.4):
  """
  bin points on the sky
  returns the index of the point in bin that is closest to pt
  """
  #there's probably a better way to do this, but it works
  #the assumption is that bins is generated from gridsky
  ds = pi*res/180.0
  #first pare down possibilities
  xindex = bisect(bins,pt)
  xminus = xindex - 1
  newbins = []
  while 1:
    #the 3 in the denominator should be a 4, but this allows for a little slop
    #that helps you get closer in ra in the next step
    if xindex < len(bins)-1 \
        and (bins[xindex][0]-pt[0])*(bins[xindex][0]-pt[0]) <= ds*ds/4.0:
      newbins.append((bins[xindex][1],bins[xindex][0]))
      xindex += 1
    else:
      break
  while 1:
    if (bins[xminus][0]-pt[0])*(bins[xminus][0]-pt[0]) <= ds*ds/4.0:
      newbins.append((bins[xminus][1],bins[xminus][0]))
      xminus -= 1
    else:
      break
  if len(newbins) == 1:
    return bins.index((newbins[0][1],newbins[0][0]))
  #now break out the full spherical distance formula
  newbins.sort()
  rpt = (pt[1],pt[0])
  yindex = bisect(newbins,rpt)
  finalbins = {}
  #if it's the last index then work backwards from the bottom
  if yindex > len(newbins)-1:
    print yindex
    print len(newbins)-1
    mindist = angle_between_points(asarray(rpt),asarray(newbins[len(newbins)-1]))
    finalbins[newbins[len(newbins)-1]] = mindist
    i = 2
    while 1:
      angdist = angle_between_points(asarray(rpt),asarray(newbins[len(newbins)-i]))
      if angdist <= mindist:
        finalbins[newbins[len(newbins)-i]] = angdist
        i += 1
      else:
        break
  #make sure to cover the top, too
    i = 0
    while 1:
      angdist = angle_between_points(asarray(rpt),asarray(newbins[i]))
      if angdist <= mindist:
        finalbins[newbins[i]] = angdist
        i += 1
      else:
        break
  else:
    mindist = angle_between_points(asarray(rpt),asarray(newbins[yindex]))
    finalbins[newbins[yindex]] = mindist
    i = 1
    while yindex + i < len(newbins) -1:
      angdist = angle_between_points(asarray(rpt),asarray(newbins[yindex+i]))
      if angdist <= mindist:
        finalbins[newbins[yindex+i]] = angdist
        i += 1
      else:
        break
    i = 1
    while yindex - i >= 0:
      angdist = angle_between_points(asarray(rpt),asarray(newbins[yindex-i]))
      if angdist <= mindist:
        finalbins[newbins[yindex-i]] = angdist
        i += 1
      else:
        break
  mindist = min(finalbins.values())
  for key in finalbins.keys():
    if finalbins[key] == mindist:
      sky_bin = key

  return bins.index((sky_bin[1],sky_bin[0]))