def match_coordinates_3d(matchcoord, catalogcoord, nthneighbor=1, storekdtree=u'kdtree_3d'):
 if (catalogcoord.isscalar or (len(catalogcoord) < 1)):
  raise ValueError(u'The catalog for coordinate matching cannot be a scalar or length-0.')
 kdt = _get_cartesian_kdtree(catalogcoord, storekdtree)
 matchcoord = matchcoord.transform_to(catalogcoord)
 catunit = catalogcoord.cartesian.x.unit
 matchxyz = matchcoord.cartesian.xyz.to(catunit)
 matchflatxyz = matchxyz.reshape((3, (np.prod(matchxyz.shape) // 3)))
 (dist, idx) = kdt.query(matchflatxyz.T, nthneighbor)
 if (nthneighbor > 1):
  dist = dist[:, (-1)]
  idx = idx[:, (-1)]
 sep2d = catalogcoord[idx].separation(matchcoord)
 return (idx.reshape(matchxyz.shape[1:]), sep2d, (dist.reshape(matchxyz.shape[1:]) * catunit))

def match_coordinates_3d ( matchcoord , catalogcoord , nthneighbor = 1 , storekdtree = u'kdtree_3d' ) : if ( catalogcoord . isscalar or ( len ( catalogcoord ) < 1 ) ) : raise ValueError ( u'The catalog for coordinate matching cannot be a scalar or length-0.' ) kdt = _get_cartesian_kdtree ( catalogcoord , storekdtree ) matchcoord = matchcoord . transform_to ( catalogcoord ) catunit = catalogcoord . cartesian . x . unit matchxyz = matchcoord . cartesian . xyz . to ( catunit ) matchflatxyz = matchxyz . reshape ( ( 3 , ( np . prod ( matchxyz . shape ) // 3 ) ) ) ( dist , idx ) = kdt . query ( matchflatxyz . T , nthneighbor ) if ( nthneighbor > 1 ) : dist = dist [ : , ( - 1 ) ] idx = idx [ : , ( - 1 ) ] sep2d = catalogcoord [ idx ] . separation ( matchcoord ) return ( idx . reshape ( matchxyz . shape [ 1 : ] ) , sep2d , ( dist . reshape ( matchxyz . shape [ 1 : ] ) * catunit ) )
finds the nearest 3-dimensional matches of a coordinate or coordinates in a set of catalog coordinates .