Ejemplo n.º 1
0
Archivo: quad.py Proyecto: mtewes/alipy
def quadtrans(uknquad, refquad):
    """
    Quickly return a transform estimated from the stars A and B of two quads.
    """
    return star.fitstars(uknquad.stars[:2], refquad.stars[:2])
Ejemplo n.º 2
0
def quadtrans(uknquad, refquad):
    """
	Quickly return a transform estimated from the stars A and B of two quads.
	"""
    return star.fitstars(uknquad.stars[:2], refquad.stars[:2])
Ejemplo n.º 3
0
	def findtrans(self, r = 5.0, verbose=True):
		"""
		Find the best trans given the quads, and tests if the match is sufficient	
		"""
		
		# Some robustness checks
		if len(self.ref.starlist) < 4:
			if verbose:
				print "Not enough stars in the reference catalog."
			return
		if len(self.ukn.starlist) < 4:
			if verbose:
				print "Not enough stars in the unknown catalog."
			return
 
 		
		# First question : how many stars should match ?
		if len(self.ukn.starlist) < 5: # Then we should simply try to get the smallest distance...
			minnident = 4
		else:
			minnident = max(4, min(8, len(self.ukn.starlist)/5.0)) # Perfectly arbitrary, let's see how it works
		
		# Hmm, arbitrary for now :
		minquaddist = 0.005
		
		# Let's start :
		if self.ref.quadlevel == 0:
			self.ref.makemorequads(verbose=verbose)
		if self.ukn.quadlevel == 0:
			self.ukn.makemorequads(verbose=verbose)
			
		while self.ok == False:
			
			# Find the best candidates
			cands = quad.proposecands(self.ukn.quadlist, self.ref.quadlist, n=4, verbose=verbose)
			
			if len(cands) != 0 and cands[0]["dist"] < minquaddist:
				# If no quads are available, we directly try to make more ones.
				for cand in cands:
					# Check how many stars are identified...					
					nident = star.identify(self.ukn.starlist, self.ref.starlist, trans=cand["trans"], r=r, verbose=verbose, getstars=False)
					if nident >= minnident:
						self.trans = cand["trans"]
						self.cand = cand
						self.ok = True
						break # get out of the for
					
			if self.ok == False:
				# We add more quads...
				addedmorerefquads = self.ref.makemorequads(verbose=verbose)
				addedmoreuknquads = self.ukn.makemorequads(verbose=verbose)
				
				if addedmorerefquads == False and addedmoreuknquads == False:
					break # get out of the while, we failed.
	

		if self.ok: # we refine the transform
			# get matching stars :
			(self.uknmatchstars, self.refmatchstars) = star.identify(self.ukn.starlist, self.ref.starlist, trans=self.trans, r=r, verbose=False, getstars=True)
			# refit the transform on them :
			if verbose:
				print "Refitting transform (before/after) :"
				print self.trans
			newtrans = star.fitstars(self.uknmatchstars, self.refmatchstars)
			if newtrans != None:
				self.trans = newtrans
				if verbose:
					print self.trans
			# Generating final matched star lists :
			(self.uknmatchstars, self.refmatchstars) = star.identify(self.ukn.starlist, self.ref.starlist, trans=self.trans, r=r, verbose=verbose, getstars=True)

			if verbose:
				print "I'm done !"
	
		else:
			if verbose:
				print "Failed to find transform !"