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