@@ -610,7 +610,8 @@ def solve_field(self,
610610 ra_keyword = "objctra" ,
611611 dec_keyword = "objctdec" ,
612612 overwrite = False ,
613- solver_bin = "solve-field" ):
613+ solver_bin = "solve-field" ,
614+ index_dir = None ):
614615
615616 """
616617 The astrometry engine will take any image and return
@@ -638,55 +639,79 @@ def solve_field(self,
638639 """
639640
640641 try :
642+ fo = FitsOps (image_path )
641643 if ra is None and dec is None :
642- fo = FitsOps (image_path )
643644 ra = fo .get_header (ra_keyword )
644645 dec = fo .get_header (dec_keyword )
645- ra = ra .strip ()
646- dec = dec .strip ()
647- ra = ra .replace (" " , ":" )
648- dec = dec .replace (" " , ":" )
649- else :
650- ra = ra .strip ()
651- dec = dec .strip ()
652- ra = ra .replace (" " , ":" )
653- dec = dec .replace (" " , ":" )
654-
655- system (("{0} --no-plots "
656- "--no-verify --tweak-order {1} "
657- "--downsample {2} --overwrite --radius {3} --no-tweak "
658- "--ra {4} --dec {5} {6}" ).format (solver_bin ,
659- tweak_order ,
660- downsample ,
661- radius ,
662- ra ,
663- dec ,
664- image_path ))
665- # Cleaning
646+ ra = ra .strip ().replace (" " , ":" )
647+ dec = dec .strip ().replace (" " , ":" )
648+
649+ # Determine pixel scale for scale-constrained solving (PhoPS approach).
650+ # Tries SCALE*XBINNING, then CD matrix, then CDELT — falls back to
651+ # unconstrained if none are available.
652+ pixel_scale = None
653+ try :
654+ scale_kw = fo .get_header ("SCALE" )
655+ if scale_kw :
656+ binning = fo .get_header ("XBINNING" ) or 1
657+ pixel_scale = float (scale_kw ) * float (binning )
658+ except Exception :
659+ pass
660+ if pixel_scale is None :
661+ try :
662+ cd1_1 = fo .get_header ("CD1_1" )
663+ cd1_2 = fo .get_header ("CD1_2" ) or 0
664+ if cd1_1 :
665+ pixel_scale = (float (cd1_1 ) ** 2 + float (cd1_2 ) ** 2 ) ** 0.5 * 3600
666+ except Exception :
667+ pass
668+ if pixel_scale is None :
669+ try :
670+ cdelt = fo .get_header ("CDELT1" ) or fo .get_header ("CDELT2" )
671+ if cdelt :
672+ pixel_scale = abs (float (cdelt )) * 3600
673+ except Exception :
674+ pass
675+
666676 if ".gz" in image_path :
667677 root = '.' .join (image_path .split ('.' )[:- 2 ])
668678 else :
669679 root , _ = path .splitext (image_path )
670-
671- system (("rm -rf {0}-indx.png {0}-indx.xyls "
672- "{0}-ngc.png {0}-objs.png "
673- "{0}.axy {0}.corr "
674- "{0}.match {0}.rdls "
675- "{0}.solved {0}.wcs" ).format (root ))
676-
677- if not path .exists (root + '.new' ):
680+ output_fits = root + "_new.fits" if not overwrite else root + ".fits"
681+
682+ # Build solve-field command following PhoPS conventions:
683+ # explicit output file, scale constraints when available, and
684+ # all temporary outputs suppressed inline instead of post-cleanup.
685+ cmd = [
686+ solver_bin ,
687+ image_path ,
688+ "--no-plots" , "--overwrite" ,
689+ "--new-fits" , output_fits ,
690+ "--ra" , ra , "--dec" , dec , "--radius" , str (radius ),
691+ "--solved" , "none" ,
692+ "--corr" , "none" ,
693+ "--rdls" , "none" ,
694+ "--match" , "none" ,
695+ "--index-xyls" , "none" ,
696+ "--axy" , "none" ,
697+ ]
698+ if pixel_scale is not None :
699+ cmd += [
700+ "--scale-units" , "arcsecperpix" ,
701+ "--scale-low" , str (round (pixel_scale * 0.7 , 4 )),
702+ "--scale-high" , str (round (pixel_scale * 1.4 , 4 )),
703+ ]
704+ if index_dir :
705+ cmd += ["--index-dir" , str (index_dir )]
706+
707+ system (" " .join (str (c ) for c in cmd ))
708+
709+ if not path .exists (output_fits ):
678710 print (image_path + ' cannot be solved!' )
679711 return False
680- else :
681- if overwrite is False :
682- system ("mv {0}.new {0}_new.fits" .format (root ))
683- print ("{0}.fits --> {0}_new.fits: solved!" .format (root ))
684- elif overwrite is True :
685- print ("Overwrite is True!" )
686- system ("mv {0}.new {0}.fits" .format (root ))
687- print ("{0}.new --> {0}.fits: solved!" .format (root ))
688-
689- return True
712+
713+ print ("{0} --> {1}: solved!" .format (path .basename (image_path ), path .basename (output_fits )))
714+ return True
690715
691716 except Exception as e :
692717 print (e )
0 commit comments