def match_coordinates_sky(matchcoord, catalogcoord, nthneighbor=1, storekdtree=u'kdtree_sky'):
 if (catalogcoord.isscalar or (len(catalogcoord) < 1)):
  raise ValueError(u'The catalog for coordinate matching cannot be a scalar or length-0.')
 newmatch = matchcoord.transform_to(catalogcoord)
 match_urepr = newmatch.data.represent_as(UnitSphericalRepresentation)
 newmatch_u = newmatch.realize_frame(match_urepr)
 cat_urepr = catalogcoord.data.represent_as(UnitSphericalRepresentation)
 newcat_u = catalogcoord.realize_frame(cat_urepr)
 storekdtree = catalogcoord.cache.get(storekdtree, storekdtree)
 (idx, sep2d, sep3d) = match_coordinates_3d(newmatch_u, newcat_u, nthneighbor, storekdtree)
 if (not (isinstance(catalogcoord.data, UnitSphericalRepresentation) or isinstance(newmatch.data, UnitSphericalRepresentation))):
  sep3d = catalogcoord[idx].separation_3d(newmatch)
 if isinstance(storekdtree, six.string_types):
  catalogcoord.cache[storekdtree] = newcat_u.cache[storekdtree]
 elif (storekdtree is True):
  catalogcoord.cache[u'kdtree'] = newcat_u.cache[u'kdtree']
 return (idx, sep2d, sep3d)

def match_coordinates_sky ( matchcoord , catalogcoord , nthneighbor = 1 , storekdtree = u'kdtree_sky' ) : if ( catalogcoord . isscalar or ( len ( catalogcoord ) < 1 ) ) : raise ValueError ( u'The catalog for coordinate matching cannot be a scalar or length-0.' ) newmatch = matchcoord . transform_to ( catalogcoord ) match_urepr = newmatch . data . represent_as ( UnitSphericalRepresentation ) newmatch_u = newmatch . realize_frame ( match_urepr ) cat_urepr = catalogcoord . data . represent_as ( UnitSphericalRepresentation ) newcat_u = catalogcoord . realize_frame ( cat_urepr ) storekdtree = catalogcoord . cache . get ( storekdtree , storekdtree ) ( idx , sep2d , sep3d ) = match_coordinates_3d ( newmatch_u , newcat_u , nthneighbor , storekdtree ) if ( not ( isinstance ( catalogcoord . data , UnitSphericalRepresentation ) or isinstance ( newmatch . data , UnitSphericalRepresentation ) ) ) : sep3d = catalogcoord [ idx ] . separation_3d ( newmatch ) if isinstance ( storekdtree , six . string_types ) : catalogcoord . cache [ storekdtree ] = newcat_u . cache [ storekdtree ] elif ( storekdtree is True ) : catalogcoord . cache [ u'kdtree' ] = newcat_u . cache [ u'kdtree' ] return ( idx , sep2d , sep3d )
finds the nearest on-sky matches of a coordinate or coordinates in a set of catalog coordinates .