Changeset 39926 for trunk/psastro/src/psastroMosaicAstrom.c
- Timestamp:
- Jan 6, 2017, 11:30:10 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psastro/src/psastroMosaicAstrom.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to
/branches/czw_branch/20160809 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/psastro/src/psastroMosaicAstrom.c
r27558 r39926 15 15 16 16 bool psastroMosaicFit (pmFPA *fpa, psMetadata *recipe, const char *rootname, int pass); 17 bool psastroProjectionRefit (pmFPA *fpa, psMetadata *recipe); 17 18 18 19 // XXX require this fpa to have multiple chip extensions and a PHU? … … 43 44 if (!status) psAbort ("missing config value"); 44 45 46 // if projection is not TAN, fit the measured projection here and combine toTPA/fromTPA functions 47 bool fitMosaicDistortion = true; 48 if ((fpa->toSky->type != PS_PROJ_TAN) && (fpa->toSky->type != PS_PROJ_DIS)) { 49 if (!psastroProjectionRefit (fpa, recipe)) psAbort ("failed to refit distortion"); 50 fitMosaicDistortion = false; 51 } 52 45 53 // this should be in a loop with nIter = 46 for (int iter = 0; iter < nIter; iter++) {54 for (int iter = 0; fitMosaicDistortion && (iter < nIter); iter++) { 47 55 if (!psastroMosaicFit (fpa, recipe, outroot, iter)) return false; 48 56 } 49 57 50 // now fit the chips under the common distortion with higher-order terms 51 // first, re-perform the match with a slightly tighter circle 52 if (!psastroMosaicSetMatch (fpa, recipe, nIter)) { 53 psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (4th pass)"); 54 return false; 55 } 56 if (!psastroMosaicChipAstrom (fpa, recipe, nIter)) { 57 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (4th pass)"); 58 return false; 59 } 60 61 if (psTraceGetLevel("psastro.dump") > 0) { 58 for (int iter = 0; (iter < nIter); iter++) { 59 // now fit the chips under the common distortion with higher-order terms 60 // first, re-perform the match with a slightly tighter circle 61 if (!psastroMosaicSetMatch (fpa, recipe, iter)) { 62 psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (4th pass %d)", iter); 63 return false; 64 } 65 if (!psastroMosaicChipAstrom (fpa, recipe, iter)) { 66 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (pass %d)", iter); 67 return false; 68 } 69 70 if (psTraceGetLevel("psastro.dump") > 0) { 62 71 // the last filename (see filenames in psastroMosaicFit) 63 72 char filename[256]; 64 73 snprintf (filename, 256, "%s.%d.dat", outroot, 2*nIter + 2); 65 74 psastroDumpMatches (fpa, filename); 66 } 67 75 } 76 } 77 68 78 // save WCS and analysis metadata in update header. 69 79 // (pull or create local view to entry on readout->analysis) … … 154 164 return true; 155 165 } 166 167 // we have a fpa->toSky projection which is NOT of type TAN along with a toTPA which is 168 // the Identity transform. we want to convert this to TAN projection plus a non-identity 169 // transformation to take the non-TAN components. 170 171 // we are going to generate a set of FP->(x,y) using the current projection + fromTPA 172 // transformations along with a set of TP->(x,y) values using the desired TAN projection, 173 // then we will fit TP vs FP 174 175 bool psastroProjectionRefit (pmFPA *fpa, psMetadata *recipe) { 176 177 bool status; 178 179 // allocate mosaic-level polynomial transformation and set masks needed by DVO 180 int order = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.ORDER"); 181 if (!status) { 182 psError(PSASTRO_ERR_UNKNOWN, false, "failed to find mosaic distortion fit order\n"); 183 return false; 184 } 185 186 pmChip *chip = NULL; 187 pmCell *cell = NULL; 188 pmReadout *readout = NULL; 189 pmFPAview *view = pmFPAviewAlloc (0); 190 191 psVector *L = psVectorAllocEmpty (1000, PS_TYPE_F32); 192 psVector *M = psVectorAllocEmpty (1000, PS_TYPE_F32); 193 194 psVector *P = psVectorAllocEmpty (1000, PS_TYPE_F32); 195 psVector *Q = psVectorAllocEmpty (1000, PS_TYPE_F32); 196 197 psProjection *toSkyTan = psProjectionAlloc (fpa->toSky->R, fpa->toSky->D, fpa->toSky->Xs, fpa->toSky->Ys, PS_PROJ_TAN); 198 199 float xMin = NAN; 200 float xMax = NAN; 201 float yMin = NAN; 202 float yMax = NAN; 203 204 bool firstObject = true; 205 206 // this loop selects the matched stars for all chips 207 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 208 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 209 if (!chip->process || !chip->file_exists) continue; 210 211 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 212 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 213 if (!cell->process || !cell->file_exists) continue; 214 215 // process each of the readouts 216 // XXX there can only be one readout per chip, right? 217 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 218 if (! readout->data_exists) continue; 219 220 // select the raw objects for this readout 221 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS.SUBSET"); 222 if (refstars == NULL) continue; 223 psTrace ("psastro", 4, "Trying %ld refstars\n", refstars->n); 224 225 psArray *matches = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.MATCH"); 226 if (matches == NULL) continue; 227 228 // we are looking over the matched refstars only to be sure we are 229 // covering the valid space of the projection + transformation, and not 230 // beyond 231 232 for (int i = 0; i < matches->n; i++) { 233 pmAstromMatch *match = matches->data[i]; 234 pmAstromObj *ref = refstars->data[match->ref]; 235 236 psPlane fpOld, tpNew, tpOld; 237 238 psProject (&tpOld, ref->sky, fpa->toSky); // find the focal-plane coord of this RA,DEC coord using the ref chip projection 239 psPlaneTransformApply (&fpOld, fpa->fromTPA, &tpOld); 240 241 psProject (&tpNew, ref->sky, toSkyTan); // find the focal-plane coord of this RA,DEC coord using the ref chip projection 242 243 psVectorAppend (L, fpOld.x); 244 psVectorAppend (M, fpOld.y); 245 246 psVectorAppend (P, tpNew.x); 247 psVectorAppend (Q, tpNew.y); 248 249 if (firstObject) { 250 xMin = xMax = fpOld.x; 251 yMin = yMax = fpOld.y; 252 firstObject = false; 253 } 254 255 xMin = PS_MIN (xMin, fpOld.x); 256 xMax = PS_MAX (xMax, fpOld.x); 257 yMin = PS_MIN (yMin, fpOld.y); 258 yMax = PS_MAX (yMax, fpOld.y); 259 } 260 } 261 } 262 } 263 264 // the original transforms are (1, 1), but we will need higher order to fit the distortions 265 psFree (fpa->toTPA); 266 267 // the original transforms are (1, 1), but we will need higher order to fit the distortions 268 fpa->toTPA = psPlaneTransformAlloc (order, order); 269 for (int i = 0; i <= fpa->toTPA->x->nX; i++) { 270 for (int j = 0; j <= fpa->toTPA->x->nY; j++) { 271 if (i + j > order) { 272 fpa->toTPA->x->coeffMask[i][j] = PS_POLY_MASK_SET; 273 fpa->toTPA->y->coeffMask[i][j] = PS_POLY_MASK_SET; 274 } 275 } 276 } 277 278 psVectorFitPolynomial2D (fpa->toTPA->x, NULL, 0, P, NULL, L, M); 279 psVectorFitPolynomial2D (fpa->toTPA->y, NULL, 0, Q, NULL, L, M); 280 281 psRegion fitRegion = psRegionSet (xMin, xMax, yMin, yMax); 282 283 // psPlaneTransformInvert will generate a new fromTPA with order to match toTPA 284 psFree (fpa->fromTPA); 285 psPlaneTransform *myPT = psPlaneTransformAlloc(fpa->toTPA->x->nX+4, fpa->toTPA->x->nY+4); 286 fpa->fromTPA = psPlaneTransformInvert (myPT, fpa->toTPA, fitRegion, 100); 287 psFree (myPT); 288 289 psFree (fpa->toSky); 290 fpa->toSky = toSkyTan; 291 292 psFree (L); 293 psFree (M); 294 psFree (P); 295 psFree (Q); 296 297 psFree (view); 298 299 if (!psastroMosaicSetAstrom (fpa)) { 300 psError(PSASTRO_ERR_UNKNOWN, false, "failed to apply mosaic distortion terms\n"); 301 return false; 302 } 303 304 return true; 305 } 306
Note:
See TracChangeset
for help on using the changeset viewer.
