Index: trunk/psModules/src/objects/pmSourceIO_Ghosts.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41339)
+++ trunk/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41348)
@@ -104,4 +104,5 @@
     psPolynomial2D *centerX = NULL;
     psPolynomial2D *centerY = NULL;
+    psPolynomial1D *mirrorRad = NULL;
     psPolynomial1D *outerMajor = NULL;
     psPolynomial1D *outerMinor = NULL;
@@ -110,4 +111,6 @@
     psMetadata *ghostModel = NULL;
 
+    psLogMsg ("psastro", PS_LOG_INFO, "writing ghost positions");
+
     // select the current recipe
     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
@@ -132,4 +135,5 @@
     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);
@@ -187,5 +191,4 @@
  		    for (int i = 0; i < refstars->n; i++) {
  			pmAstromObj *ref = refstars->data[i];
- 			psTrace("psastro.ghost",5,"Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g)",i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI);
  			if (ref->Mag > MAX_MAG) continue;
 
@@ -194,9 +197,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);
@@ -278,5 +287,4 @@
     	psFree (ghostModel);
     	psFree (view);
-    	return true;
 
         if (table->n == 0) {
