Changeset 30616 for trunk/Ohana/src/relastro/src/UpdateChips.c
- Timestamp:
- Feb 13, 2011, 11:30:02 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/relastro/src/UpdateChips.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/relastro/src/UpdateChips.c
r29001 r30616 1 1 # include "relastro.h" 2 int plotChipFits (double *Ro, double *Do, char *mode, int Nimage); 3 int saveCenter (Image *image, double *Ro, double *Do, int im); 2 4 3 5 int UpdateChips (Catalog *catalog, int Ncatalog) { 4 6 7 int Nskip, Nmosaic, NnewFit, NoldFit; 8 5 9 /* we can measure new image parameters for each non-mosaic chip independently */ 6 off_t i, Nimage, Nraw, Nref ;10 off_t i, Nimage, Nraw, Nref, nFitAstr; 7 11 Image *image; 8 12 StarData *raw, *ref; 9 13 Coords *oldCoords; 14 float dXpixSys, dYpixSys; 15 double *Ro, *Do; 16 char *mode; 17 18 Nskip = Nmosaic = NnewFit = NoldFit = 0; 10 19 11 20 image = getimages (&Nimage); 12 21 22 // save fit results for summary plot 23 ALLOCATE (Ro, double, Nimage); 24 ALLOCATE (Do, double, Nimage); 25 ALLOCATE (mode, char, Nimage); 26 13 27 for (i = 0; i < Nimage; i++) { 14 28 15 29 /* skip all except WRP images */ 16 if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue; 30 if (strcmp(&image[i].coords.ctype[4], "-WRP")) { 31 Nmosaic ++; 32 mode[i] = 0; 33 continue; 34 } 17 35 18 36 /* convert measure coordinates to raw entries */ 19 37 raw = getImageRaw (catalog, Ncatalog, i, &Nraw, MODE_MOSAIC); 20 if (!raw) continue; 38 if (!raw) { 39 Nskip ++; 40 mode[i] = 0; 41 continue; 42 } 21 43 22 44 /* convert average coordinates to ref entries */ 23 45 ref = getImageRef (catalog, Ncatalog, i, &Nref, MODE_MOSAIC); 24 if (!ref) continue; 46 if (!ref) { 47 Nskip ++; 48 mode[i] = 0; 49 continue; 50 } 25 51 26 52 // note that Nraw & Nref must be equal: if not, we made a programming error in one of these two functions. 27 53 assert (Nraw == Nref); 28 54 55 // save these in case of failure 29 56 saveCoords (&image[i].coords, i); 57 dXpixSys = image[i].dXpixSys; 58 dYpixSys = image[i].dYpixSys; 59 nFitAstr = image[i].nFitAstrom; 30 60 31 61 // FitChip does iterative, clipped fitting … … 33 63 if (!FitChip (raw, ref, Nraw, &image[i])) { 34 64 if (VERBOSE) fprintf (stderr, "reject fit for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name, i, Nraw); 65 66 // restore status quo ante 35 67 oldCoords = getCoords (i); 36 68 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 69 image[i].dXpixSys = dXpixSys; 70 image[i].dYpixSys = dYpixSys; 71 image[i].nFitAstrom = nFitAstr; 72 73 saveCenter (image, &Ro[i], &Do[i], i); 74 mode[i] = 1; 75 NoldFit ++; 37 76 free (raw); 38 77 free (ref); … … 42 81 if (!checkStarMap (i)) { 43 82 if (VERBOSE) fprintf (stderr, "fit diverges too much for image %s ("OFF_T_FMT") : Nstars: "OFF_T_FMT"\n", image[i].name, i, Nraw); 83 // restore status quo ante 44 84 oldCoords = getCoords (i); 45 85 memcpy (&image[i].coords, oldCoords, sizeof(Coords)); 86 image[i].dXpixSys = dXpixSys; 87 image[i].dYpixSys = dYpixSys; 88 image[i].nFitAstrom = nFitAstr; 89 90 saveCenter (image, &Ro[i], &Do[i], i); 91 mode[i] = 2; 46 92 image[i].flags |= ID_IMAGE_ASTROM_POOR; 47 } 48 93 NoldFit ++; 94 free (raw); 95 free (ref); 96 continue; 97 } 98 99 saveCenter (image, &Ro[i], &Do[i], i); 100 mode[i] = 3; 101 NnewFit ++; 49 102 free (raw); 50 103 free (ref); 51 104 } 52 105 106 plotChipFits (Ro, Do, mode, Nimage); 107 108 fprintf (stderr, "UpdateChips: %d fitted, %d keep old, %d skipped, %d mosaic (skipped)\n", NnewFit, NoldFit, Nskip, Nmosaic); 53 109 return (TRUE); 54 110 } 55 111 112 int saveCenter (Image *image, double *Ro, double *Do, int im) { 113 114 Mosaic *mosaic; 115 Coords *moscoords, *imcoords; 116 double X, Y, L, M, P, Q, R, D; 117 118 moscoords = NULL; 119 if (!strcmp(&image[im].coords.ctype[4], "-WRP")) { 120 mosaic = getMosaicForImage (im); 121 if (mosaic == NULL) return FALSE; // if we cannot find the associated image, skip it 122 moscoords = &mosaic[0].coords; 123 } 124 imcoords = &image[im].coords; 125 126 if (!strcmp(&image[im].coords.ctype[4], "-WRP")) { 127 X = 0.5*image[im].NX; 128 Y = 0.5*image[im].NY; 129 } else { 130 X = 0.0; 131 Y = 0.0; 132 } 133 134 if (moscoords == NULL) { 135 // this is a Simple image (not a mosaic) 136 // note that for a Simple image, L,M = P,Q 137 XY_to_LM (&L, &M, X, Y, imcoords); 138 LM_to_RD (&R, &D, L, M, imcoords); 139 } else { 140 XY_to_LM (&L, &M, X, Y, imcoords); 141 XY_to_LM (&P, &Q, L, M, moscoords); 142 LM_to_RD (&R, &D, P, Q, moscoords); 143 } 144 145 double Rmid; 146 if (UserCatalog) { 147 Rmid = UserCatalogRA; 148 } else { 149 Rmid = 0.5*(UserPatch.Rmin + UserPatch.Rmax); 150 } 151 152 R = ohana_normalize_angle_to_midpoint (R, Rmid); 153 154 *Ro = R; 155 *Do = D; 156 157 return (TRUE); 158 } 159 160 int plotChipFits (double *Ro, double *Do, char *mode, int Nimage) { 161 162 static int kapa = -1; 163 164 int i, N; 165 double Rmin, Rmax, Dmin, Dmax; 166 float *xvec, *yvec; 167 Graphdata graphdata; 168 169 if (!relastroGetVisual()) return (TRUE); 170 171 if (kapa == -1) { 172 kapa = KapaOpenNamedSocket("kapa", "relastro"); 173 if (kapa == -1) { 174 fprintf (stderr, "can't open kapa window\n"); 175 return FALSE; 176 } 177 } 178 179 Rmin = +720; 180 Rmax = -720; 181 Dmin = +90; 182 Dmax = -90; 183 184 // find the R, D range 185 for (i = 0; i < Nimage; i++) { 186 if (!mode[i]) continue; 187 188 Rmin = MIN(Rmin, Ro[i]); 189 Rmax = MAX(Rmax, Ro[i]); 190 Dmin = MIN(Dmin, Do[i]); 191 Dmax = MAX(Dmax, Do[i]); 192 } 193 194 ALLOCATE (xvec, float, Nimage); 195 ALLOCATE (yvec, float, Nimage); 196 197 bzero (&graphdata, sizeof(Graphdata)); 198 plot_defaults (&graphdata); 199 graphdata.xmin = Rmin; 200 graphdata.xmax = Rmax; 201 graphdata.ymin = Dmin; 202 graphdata.ymax = Dmax; 203 graphdata.style = 2; 204 graphdata.size = 1; 205 206 KapaSetFont (kapa, "helvetica", 14); 207 KapaSetLimits (kapa, &graphdata); 208 KapaBox (kapa, &graphdata); 209 210 // *** good images *** 211 N = 0; 212 for (i = 0; i < Nimage; i++) { 213 if (mode[i] != 3) continue; 214 xvec[N] = Ro[i]; 215 yvec[N] = Do[i]; 216 N++; 217 } 218 graphdata.ptype = 7; 219 graphdata.color = KapaColorByName("black"); 220 KapaPrepPlot (kapa, N, &graphdata); 221 KapaPlotVector (kapa, N, xvec, "x"); 222 KapaPlotVector (kapa, N, yvec, "y"); 223 224 // *** reject fit *** 225 N = 0; 226 for (i = 0; i < Nimage; i++) { 227 if (mode[i] != 1) continue; 228 xvec[N] = Ro[i]; 229 yvec[N] = Do[i]; 230 N++; 231 } 232 graphdata.ptype = 3; 233 graphdata.color = KapaColorByName("red"); 234 KapaPrepPlot (kapa, N, &graphdata); 235 KapaPlotVector (kapa, N, xvec, "x"); 236 KapaPlotVector (kapa, N, yvec, "y"); 237 238 // *** divergent fit *** 239 N = 0; 240 for (i = 0; i < Nimage; i++) { 241 if (mode[i] != 2) continue; 242 xvec[N] = Ro[i]; 243 yvec[N] = Do[i]; 244 N++; 245 } 246 graphdata.ptype = 2; 247 graphdata.color = KapaColorByName("blue"); 248 KapaPrepPlot (kapa, N, &graphdata); 249 KapaPlotVector (kapa, N, xvec, "x"); 250 KapaPlotVector (kapa, N, yvec, "y"); 251 252 free (xvec); 253 free (yvec); 254 255 return (TRUE); 256 } 257 258 // XXX if (!FindMosaicForImage (image, Nimage, i)) { }
Note:
See TracChangeset
for help on using the changeset viewer.
