Index: trunk/psastro/src/psastroLoadGhosts.c
===================================================================
--- trunk/psastro/src/psastroLoadGhosts.c	(revision 41338)
+++ trunk/psastro/src/psastroLoadGhosts.c	(revision 41348)
@@ -105,4 +105,5 @@
     psPolynomial2D *centerX = NULL;
     psPolynomial2D *centerY = NULL;
+    psPolynomial1D *mirrorRad = NULL;
     psPolynomial1D *outerMajor = NULL;
     psPolynomial1D *outerMinor = NULL;
@@ -110,7 +111,7 @@
     psPolynomial1D *innerMinor = NULL;
 
-
     pmFPAview *view = pmFPAviewAlloc (0);
 
+    GET_1D_POLY ("GHOST.MIRROR.RAD", mirrorRad);
     GET_2D_POLY ("GHOST.CENTER.X", centerX);
     GET_2D_POLY ("GHOST.CENTER.Y", centerY);
@@ -178,9 +179,15 @@
 		    ghost->srcFP->y = ref->FP->y;
 
-		    // XXX it is stupid that this takes -X_fpa,-Y_fpa --> the analysis script is reporting the guess FPA position, and the fit is using that...
-		    ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
-		    ghost->FP->y = -ref->FP->y + psPolynomial2DEval(centerY, -ref->FP->x, -ref->FP->y);
-
-		    float rSrc = hypot (ref->FP->x, ref->FP->y);
+                    //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
+		    double rSrc = hypot (ref->FP->x, ref->FP->y);
+     	            double theta0 = atan2(ref->FP->y,ref->FP->x);
+
+		    double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
+		    double ghost_x_fpa_mirror = ref->FP->x + ((ref->FP->x*-1.)/abs(ref->FP->x)*abs(cos(theta0)*ghost_offset_rad));
+		    double ghost_y_fpa_mirror = ref->FP->y + ((ref->FP->y*-1.)/abs(ref->FP->y)*abs(sin(theta0)*ghost_offset_rad));
+
+		    // Now use the mirrored position together with the 2D ghost center fitting to get the actual ghost position in FPA coords 
+		    ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
+		    ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
 
 		    ghost->inner.major = psPolynomial1DEval (innerMajor, rSrc);
@@ -203,28 +210,4 @@
 		    ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y);
 		    // fprintf (stderr, "-> model chip position: %f, %f\n", ghost->chip->x, ghost->chip->y);
-
-	            psPlane coordFPA,ptCH2;
-    	            psPlane coordCell,ptFP2;
-	            coordCell.x = ghost->chip->x;
-	            coordCell.y = ghost->chip->y;
-                    psPlaneTransformApply(&coordFPA,ghostChip->toFPA,&coordCell);
-	            ptCH2.x = ghost->chip->x;
-               	    ptCH2.y = ghost->chip->y;
-                    psPlaneTransformApply(&ptFP2,ghostChip->toFPA,&ptCH2);
-
-	            psPlane ptCH, ptFP;
-	            ptFP.x = ghost->FP->x;
-               	    ptFP.y = ghost->FP->y;
-                    psPlaneTransformApply (&ptCH, ghostChip->fromFPA, &ptFP);
-
-                    psastroUpdateChipToFPA (fpa, ghostChip);
-	            psPlane ptCH3, ptFP3;
-	            ptCH3.x = ghost->chip->x;
-               	    ptCH3.y = ghost->chip->y;
-                    psPlaneTransformApply(&ptFP3,ghostChip->toFPA,&ptCH3);
-
-
-
-                    psLogMsg ("psastro", 3, "Ghost refpos: %f %f %s pos: %f %f %f %f %f %f %f %f %f %f %f %f mag: %f inshape: %f %f %f outshape: %f %f %f \n", ref->FP->x,ref->FP->y,psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"), ghost->FP->x,ghost->FP->y,coordFPA.x,coordFPA.y,ghost->chip->x, ghost->chip->y,ptCH.x,ptCH.y,ptFP2.x,ptFP2.y,ptFP3.x,ptFP3.y, ghost->Mag,ghost->inner.major,ghost->inner.minor,ghost->inner.theta/PM_RAD_DEG,ghost->outer.major,ghost->outer.minor,ghost->outer.theta/PM_RAD_DEG);
 
 		    if (ghostChip) {
@@ -257,7 +240,5 @@
 			      ghost->outer.major,ghost->outer.minor,ghost->outer.theta);
 		    }		      
-		      
-
-			    
+		      			    
 		    if (!ghostChip) goto skip;
 		    if (!ghostChip->cells) goto skip;
