Changeset 21208 for branches/cnb_branch_20090113/psastro
- Timestamp:
- Jan 28, 2009, 1:36:37 PM (18 years ago)
- Location:
- branches/cnb_branch_20090113/psastro/src
- Files:
-
- 1 deleted
- 13 edited
-
Makefile.am (modified) (1 diff)
-
psastro.h (modified) (3 diffs)
-
psastroArguments.c (modified) (1 diff)
-
psastroAstromGuess.c (modified) (20 diffs)
-
psastroCleanup.c (modified) (2 diffs)
-
psastroFixChips.c (modified) (6 diffs)
-
psastroLoadRefstars.c (modified) (5 diffs)
-
psastroLuminosityFunction.c (modified) (1 diff)
-
psastroMosaicOneChip.c (modified) (1 diff)
-
psastroMosaicSetMatch.c (modified) (1 diff)
-
psastroOneChipFit.c (modified) (5 diffs)
-
psastroRemoveClumps.c (modified) (1 diff)
-
psastroUtils.c (modified) (2 diffs)
-
psastroVisual.c (deleted)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branch_20090113/psastro/src/Makefile.am
r20805 r21208 53 53 psastroErrorCodes.c \ 54 54 psastroVersion.c \ 55 psastroVisual.c \56 55 psastroDefineFiles.c \ 57 56 psastroAnalysis.c \ -
branches/cnb_branch_20090113/psastro/src/psastro.h
r20805 r21208 14 14 # define SIGN(X) (((X) == 0) ? 0 : ((fabs((double)(X))) / (X))) 15 15 16 #if 0 16 17 // this structure represents a fit to the logN / logS curve for a set of stars 17 18 // logN = offset + slope * logS … … 25 26 int sPeak; // sum of stars to peak bin 26 27 } pmLumFunc; 28 #endif 27 29 28 30 bool psastroDataSave (pmConfig *config); … … 77 79 psString psastroVersionLong(void); 78 80 79 // psastroVisual functions80 bool psastroSetVisual (bool mode);81 bool psastroVisualClose();82 bool psastroVisualPlotLuminosityFunction (psVector *lnMag, psVector *Mag, pmLumFunc *lumFunc, pmLumFunc *rawFunc);83 bool psastroVisualPlotRawStars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe);84 bool psastroVisualPlotRefStars (psArray *refstars, psMetadata *recipe);85 bool psastroVisualPlotRemoveClumps (psArray *input, psImage *count, int scale, float limit);86 bool psastroVisualPlotFixChips (pmFPAfile *input, psVector *xOld, psVector *yOld);87 bool psastroVisualPlotOneChipFit (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);88 bool psastroVisualPlotAstromGuessCheck (psVector *cornerPo, psVector *cornerQo, psVector *cornerPn, psVector *cornerQn, psVector *cornerPd, psVector *cornerQd);89 bool psastroVisualPlotMosaicOneChip (psArray *rawstars, psArray *refstars, psArray *match, psMetadata *recipe);90 bool psastroVisualPlotCommonScale (pmFPA *fpa, psVector *oldScale);91 bool psastroVisualPlotMosaicMatches (psArray *rawstars, psArray *refstars, psArray *match, int iteration, psMetadata *recipe);92 93 81 // demo plots 94 82 bool psastroPlotRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip, psMetadata *recipe); -
branches/cnb_branch_20090113/psastro/src/psastroArguments.c
r20805 r21208 88 88 if ((N = psArgumentGet (argc, argv, "-visual"))) { 89 89 psArgumentRemove (N, &argc, argv); 90 psastroSetVisual (true);91 90 pmAstromSetVisual (true); 92 91 } -
branches/cnb_branch_20090113/psastro/src/psastroAstromGuess.c
r20805 r21208 29 29 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE); 30 30 if (!recipe) { 31 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!");32 return false;31 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!"); 32 return false; 33 33 } 34 34 … … 36 36 bool useModel = psMetadataLookupBool (&status, config->arguments, "PSASTRO.USE.MODEL"); 37 37 if (!status) { 38 useModel = psMetadataLookupBool (&status, recipe, "PSASTRO.USE.MODEL");38 useModel = psMetadataLookupBool (&status, recipe, "PSASTRO.USE.MODEL"); 39 39 } 40 40 … … 42 42 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 43 43 if (!input) { 44 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");45 return false;44 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 45 return false; 46 46 } 47 47 … … 49 49 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE"); 50 50 if (!status) { 51 psError(PS_ERR_IO, true, "Failed to lookup pixel scale"); 52 return false; 53 } 51 psError(PS_ERR_IO, true, "Failed to lookup pixel scale"); 52 return false; 53 } 54 54 55 55 psVector *cornerL = psVectorAllocEmpty (100, PS_TYPE_F32); … … 67 67 bool bilevelAstrometry = false; 68 68 if (!useModel) { 69 psastroAstromGuessSetFPA (fpa, &bilevelAstrometry);69 psastroAstromGuessSetFPA (fpa, &bilevelAstrometry); 70 70 } 71 71 … … 75 75 if (!chip->process || !chip->file_exists || !chip->data_exists) { continue; } 76 76 77 if (!useModel) {78 if (!psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry)) continue;79 }77 if (!useModel) { 78 if (!psastroAstromGuessSetChip (fpa, chip, view, pixelScale, bilevelAstrometry)) continue; 79 } 80 80 81 81 if (newFPA) { 82 82 newFPA = false; 83 while (fpa->toSky->R < 0) fpa->toSky->R += 2.0*M_PI;84 while (fpa->toSky->R > 2.0*M_PI) fpa->toSky->R -= 2.0*M_PI;83 while (fpa->toSky->R < 0) fpa->toSky->R += 2.0*M_PI; 84 while (fpa->toSky->R > 2.0*M_PI) fpa->toSky->R -= 2.0*M_PI; 85 85 RAminSky = fpa->toSky->R - M_PI; 86 86 RAmaxSky = fpa->toSky->R + M_PI; 87 87 } 88 88 89 // report and save the current best guess for the chip 0,0 pixel coordinates90 { 91 psPlane ptCH, ptFP, ptTP;92 psSphere ptSky;93 94 ptCH.x = 0;95 ptCH.y = 0;96 psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);97 psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);98 psDeproject (&ptSky, &ptTP, fpa->toSky);99 psLogMsg ("psastro", 3, "0,0 pix for chip %3d = %f,%f\n", view->chip, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d);100 101 psVectorAppend (cornerL, ptFP.x);102 psVectorAppend (cornerM, ptFP.y);103 psVectorAppend (cornerP, ptTP.x);104 psVectorAppend (cornerQ, ptTP.y);105 psVectorAppend (cornerR, ptSky.r);106 psVectorAppend (cornerD, ptSky.d);107 }89 // report and save the current best guess for the chip 0,0 pixel coordinates 90 { 91 psPlane ptCH, ptFP, ptTP; 92 psSphere ptSky; 93 94 ptCH.x = 0; 95 ptCH.y = 0; 96 psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH); 97 psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP); 98 psDeproject (&ptSky, &ptTP, fpa->toSky); 99 psLogMsg ("psastro", 3, "0,0 pix for chip %3d = %f,%f\n", view->chip, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d); 100 101 psVectorAppend (cornerL, ptFP.x); 102 psVectorAppend (cornerM, ptFP.y); 103 psVectorAppend (cornerP, ptTP.x); 104 psVectorAppend (cornerQ, ptTP.y); 105 psVectorAppend (cornerR, ptSky.r); 106 psVectorAppend (cornerD, ptSky.d); 107 } 108 108 109 109 // apply the new WCS guess data to all of the data in the readouts … … 119 119 if (rawstars == NULL) { continue; } 120 120 121 *nStars += rawstars->n;121 *nStars += rawstars->n; 122 122 for (int i = 0; i < rawstars->n; i++) { 123 123 pmAstromObj *raw = rawstars->data[i]; … … 138 138 } 139 139 140 // dump or plot the resulting projected positions141 if (psTraceGetLevel("psastro.dump") > 0) {142 psastroDumpRawstars (rawstars, fpa, chip);143 }144 145 p sastroVisualPlotRawStars(rawstars, fpa, chip, recipe);146 147 if (psTraceGetLevel("psastro.plot") > 0) {148 psastroPlotRawstars (rawstars, fpa, chip, recipe);149 }140 // dump or plot the resulting projected positions 141 if (psTraceGetLevel("psastro.dump") > 0) { 142 psastroDumpRawstars (rawstars, fpa, chip); 143 } 144 145 pmAstromVisualPlotRawStars(rawstars, fpa, chip, recipe); 146 147 if (psTraceGetLevel("psastro.plot") > 0) { 148 psastroPlotRawstars (rawstars, fpa, chip, recipe); 149 } 150 150 } 151 151 } … … 157 157 psMetadataAddS32 (recipe, PS_LIST_TAIL, "NTOTSTAR", PS_META_REPLACE, "", *nStars); 158 158 if (*nStars == 0) { 159 psLogMsg ("psastro", 2, "no sources available for astrometry\n");160 psFree (view);161 return true;162 } 163 164 psLogMsg ("psastro", 2, "loaded raw data from %f,%f to %f,%f\n", 165 DEG_RAD*RAmin, DEG_RAD*DECmin, 166 DEG_RAD*RAmax, DEG_RAD*DECmax);159 psLogMsg ("psastro", 2, "no sources available for astrometry\n"); 160 psFree (view); 161 return true; 162 } 163 164 psLogMsg ("psastro", 2, "loaded raw data from %f,%f to %f,%f\n", 165 DEG_RAD*RAmin, DEG_RAD*DECmin, 166 DEG_RAD*RAmax, DEG_RAD*DECmax); 167 167 168 168 psMetadataAddF32 (recipe, PS_LIST_TAIL, "RA_MIN", PS_META_REPLACE, "", RAmin); … … 203 203 pmHDU *hdu = pmFPAviewThisHDU (view, fpa); 204 204 if (bilevelAstrometry) { 205 if (!pmAstromReadBilevelChip (chip, hdu->header)) {206 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 207 return false;208 } 205 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 206 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 207 return false; 208 } 209 209 } else { 210 if (!pmAstromReadWCS (fpa, chip, hdu->header, pixelScale)) {211 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 212 return false;213 } 210 if (!pmAstromReadWCS (fpa, chip, hdu->header, pixelScale)) { 211 psWarning("Could not get WCS information from header for chip %d, skipping", view->chip); 212 return false; 213 } 214 214 } 215 215 return true; … … 225 225 // load mosaic-level astrometry? 226 226 if (phu) { 227 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");228 if (ctype) {229 *bilevelAstrometry = !strcmp (&ctype[4], "-DIS");230 }227 char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1"); 228 if (ctype) { 229 *bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 230 } 231 231 } 232 232 if (*bilevelAstrometry) { 233 pmAstromReadBilevelMosaic (fpa, phu->header);234 } 233 pmAstromReadBilevelMosaic (fpa, phu->header); 234 } 235 235 psFree (view); 236 236 return true; … … 245 245 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 246 246 if (!input) { 247 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");248 return false;247 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 248 return false; 249 249 } 250 250 … … 277 277 if (!chip->process || !chip->file_exists || !chip->data_exists) { continue; } 278 278 279 // XXX we are currently inconsistent with marking the good vs the bad data280 // psastroChipAstrom sets data_exists to false if the fit is bad. this is281 // probably wrong since it implies there is no data!282 283 // skip chips for which the astrometry failed (NASTRO == 0)284 if (!chip->cells->n) goto skip_chip;285 pmCell *cell = chip->cells->data[0];286 if (!cell) goto skip_chip;287 288 if (!cell->readouts->n) goto skip_chip;289 pmReadout *readout = cell->readouts->data[0];290 if (!readout) goto skip_chip;291 292 psMetadata *updates = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER");293 if (!updates) goto skip_chip;294 295 int nAstro = psMetadataLookupS32 (&status, updates, "NASTRO");296 if (!nAstro) goto skip_chip;297 298 float astError = psMetadataLookupF32 (&status, updates, "CERROR");299 if (fabs(astError) < 1e-6) goto skip_chip;300 301 psPlane ptCH, ptFP, ptTP;302 psSphere ptSky;303 304 ptCH.x = 0;305 ptCH.y = 0;306 psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH);307 psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP);308 psDeproject (&ptSky, &ptTP, fpa->toSky);309 psLogMsg ("psastro", 3, "0,0 pix for chip %3d = %f,%f\n", view->chip, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d);310 311 // new corner locations based on the calibrated astrometry312 psVectorAppend (cornerLn, ptFP.x);313 psVectorAppend (cornerMn, ptFP.y);314 psVectorAppend (cornerPn, ptTP.x);315 psVectorAppend (cornerQn, ptTP.y);316 psVectorAppend (cornerRn, ptSky.r);317 psVectorAppend (cornerDn, ptSky.d);318 psVectorAppend (cornerMK, 0);319 continue;279 // XXX we are currently inconsistent with marking the good vs the bad data 280 // psastroChipAstrom sets data_exists to false if the fit is bad. this is 281 // probably wrong since it implies there is no data! 282 283 // skip chips for which the astrometry failed (NASTRO == 0) 284 if (!chip->cells->n) goto skip_chip; 285 pmCell *cell = chip->cells->data[0]; 286 if (!cell) goto skip_chip; 287 288 if (!cell->readouts->n) goto skip_chip; 289 pmReadout *readout = cell->readouts->data[0]; 290 if (!readout) goto skip_chip; 291 292 psMetadata *updates = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER"); 293 if (!updates) goto skip_chip; 294 295 int nAstro = psMetadataLookupS32 (&status, updates, "NASTRO"); 296 if (!nAstro) goto skip_chip; 297 298 float astError = psMetadataLookupF32 (&status, updates, "CERROR"); 299 if (fabs(astError) < 1e-6) goto skip_chip; 300 301 psPlane ptCH, ptFP, ptTP; 302 psSphere ptSky; 303 304 ptCH.x = 0; 305 ptCH.y = 0; 306 psPlaneTransformApply (&ptFP, chip->toFPA, &ptCH); 307 psPlaneTransformApply (&ptTP, fpa->toTPA, &ptFP); 308 psDeproject (&ptSky, &ptTP, fpa->toSky); 309 psLogMsg ("psastro", 3, "0,0 pix for chip %3d = %f,%f\n", view->chip, DEG_RAD*ptSky.r, DEG_RAD*ptSky.d); 310 311 // new corner locations based on the calibrated astrometry 312 psVectorAppend (cornerLn, ptFP.x); 313 psVectorAppend (cornerMn, ptFP.y); 314 psVectorAppend (cornerPn, ptTP.x); 315 psVectorAppend (cornerQn, ptTP.y); 316 psVectorAppend (cornerRn, ptSky.r); 317 psVectorAppend (cornerDn, ptSky.d); 318 psVectorAppend (cornerMK, 0); 319 continue; 320 320 321 321 skip_chip: 322 // new corner locations based on the calibrated astrometry323 psVectorAppend (cornerLn, 0.0);324 psVectorAppend (cornerMn, 0.0);325 psVectorAppend (cornerPn, 0.0);326 psVectorAppend (cornerQn, 0.0);327 psVectorAppend (cornerRn, 0.0);328 psVectorAppend (cornerDn, 0.0);329 psVectorAppend (cornerMK, 1);322 // new corner locations based on the calibrated astrometry 323 psVectorAppend (cornerLn, 0.0); 324 psVectorAppend (cornerMn, 0.0); 325 psVectorAppend (cornerPn, 0.0); 326 psVectorAppend (cornerQn, 0.0); 327 psVectorAppend (cornerRn, 0.0); 328 psVectorAppend (cornerDn, 0.0); 329 psVectorAppend (cornerMK, 1); 330 330 } 331 331 … … 336 336 337 337 for (int i = 0; i < cornerRo->n; i++) { 338 339 psPlane ptTP;340 psSphere ptSky;341 342 ptSky.r = cornerRo->data.F32[i];343 ptSky.d = cornerDo->data.F32[i];344 345 psProject (&ptTP, &ptSky, fpa->toSky);346 psVectorAppend (cornerPs, ptTP.x);347 psVectorAppend (cornerQs, ptTP.y);338 339 psPlane ptTP; 340 psSphere ptSky; 341 342 ptSky.r = cornerRo->data.F32[i]; 343 ptSky.d = cornerDo->data.F32[i]; 344 345 psProject (&ptTP, &ptSky, fpa->toSky); 346 psVectorAppend (cornerPs, ptTP.x); 347 psVectorAppend (cornerQs, ptTP.y); 348 348 } 349 349 … … 351 351 map->x->coeffMask[1][1] = PS_POLY_MASK_SET; 352 352 map->y->coeffMask[1][1] = PS_POLY_MASK_SET; 353 353 354 354 // fit the valid chips, mask the invalid chips 355 355 psVectorFitPolynomial2D (map->x, cornerMK, 1, cornerPn, NULL, cornerPs, cornerQs); 356 356 psVectorFitPolynomial2D (map->y, cornerMK, 1, cornerQn, NULL, cornerPs, cornerQs); 357 357 358 358 // apply the linear fit... 359 359 psVector *cornerPf = psPolynomial2DEvalVector (map->x, cornerPs, cornerQs); … … 364 364 psVector *cornerQd = (psVector *) psBinaryOp (NULL, cornerQn, "-", cornerQf); 365 365 366 p sastroVisualPlotAstromGuessCheck (cornerPo, cornerQo, cornerPn, cornerQn, cornerPd, cornerQd);366 pmAstromVisualPlotAstromGuessCheck (cornerPo, cornerQo, cornerPn, cornerQn, cornerPd, cornerQd); 367 367 368 368 psStats *statsP = psStatsAlloc (PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); … … 374 374 float angle = atan2 (map->y->coeff[1][0], map->x->coeff[1][0]); 375 375 float scale = hypot (map->y->coeff[1][0], map->x->coeff[1][0]); 376 376 377 377 psLogMsg ("psastro", 3, "boresite offset : %f,%f\n", map->x->coeff[0][0], map->y->coeff[0][0]); 378 378 psLogMsg ("psastro", 3, "boresite angle : %f, scale: %f", angle*PS_DEG_RAD, scale); … … 382 382 psMetadata *header = psMetadataLookupMetadata (&status, input->fpa->analysis, "PSASTRO.HEADER"); 383 383 if (!header) { 384 header = psMetadataAlloc();385 psMetadataAddMetadata (input->fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", header);386 psFree (header); // drop this reference384 header = psMetadataAlloc(); 385 psMetadataAddMetadata (input->fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", header); 386 psFree (header); // drop this reference 387 387 } 388 388 … … 395 395 396 396 if (DEBUG) { 397 FILE *f = fopen ("corners.dat", "w");398 for (int i = 0; i < cornerRo->n; i++) {399 fprintf (f, "%10.6f %10.6f %9.2f %9.2f %9.2f %9.2f | %10.6f %10.6f %9.2f %9.2f %9.2f %9.2f\n",400 cornerRn->data.F32[i], cornerDn->data.F32[i], cornerPn->data.F32[i], cornerQn->data.F32[i], cornerLn->data.F32[i], cornerMn->data.F32[i], 401 cornerRo->data.F32[i], cornerDo->data.F32[i], cornerPo->data.F32[i], cornerQo->data.F32[i], cornerLo->data.F32[i], cornerMo->data.F32[i]);402 }403 fclose (f);397 FILE *f = fopen ("corners.dat", "w"); 398 for (int i = 0; i < cornerRo->n; i++) { 399 fprintf (f, "%10.6f %10.6f %9.2f %9.2f %9.2f %9.2f | %10.6f %10.6f %9.2f %9.2f %9.2f %9.2f\n", 400 cornerRn->data.F32[i], cornerDn->data.F32[i], cornerPn->data.F32[i], cornerQn->data.F32[i], cornerLn->data.F32[i], cornerMn->data.F32[i], 401 cornerRo->data.F32[i], cornerDo->data.F32[i], cornerPo->data.F32[i], cornerQo->data.F32[i], cornerLo->data.F32[i], cornerMo->data.F32[i]); 402 } 403 fclose (f); 404 404 } 405 405 … … 424 424 psFree (map); 425 425 psFree (view); 426 426 427 427 428 428 return true; -
branches/cnb_branch_20090113/psastro/src/psastroCleanup.c
r20805 r21208 4 4 5 5 psFree (config); 6 pmAstromVisualClose (); 6 7 7 8 psTimerStop (); … … 11 12 pmConceptsDone (); 12 13 pmConfigDone (); 13 psastroVisualClose ();14 pmAstromVisualClose ();15 14 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psastro"); 16 15 // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psastro"); -
branches/cnb_branch_20090113/psastro/src/psastroFixChips.c
r20805 r21208 13 13 bool fixChips = psMetadataLookupBool (&status, config->arguments, "PSASTRO.FIX.CHIPS"); 14 14 if (!status) { 15 fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.FIX.CHIPS");15 fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.FIX.CHIPS"); 16 16 } 17 17 if (!fixChips) return true; … … 25 25 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 26 26 if (!input) { 27 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data");28 return false;27 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 28 return false; 29 29 } 30 30 … … 48 48 // files associated with the science image 49 49 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 50 psError (PS_ERR_IO, false, "Can't load the astrometry model file");51 return false;50 psError (PS_ERR_IO, false, "Can't load the astrometry model file"); 51 return false; 52 52 } 53 53 … … 64 64 65 65 if (DEBUG) { 66 f = fopen ("corners.raw.dat", "w");67 chipName = NULL;66 f = fopen ("corners.raw.dat", "w"); 67 chipName = NULL; 68 68 } 69 69 70 70 pmChip *obsChip = NULL; 71 71 while ((obsChip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 72 if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; }73 74 // XXX we are currently inconsistent with marking the good vs the bad data75 // psastroChipAstrom sets data_exists to false if the fit is bad. this is76 // probably wrong since it implies there is no data!77 78 // skip chips for which the astrometry failed (NASTRO == 0)79 if (!obsChip->cells->n) continue;80 pmCell *cell = obsChip->cells->data[0];81 if (!cell) continue;82 83 if (!cell->readouts->n) continue;84 pmReadout *readout = cell->readouts->data[0];85 if (!readout) continue;86 87 psMetadata *updates = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER");88 if (!updates) continue;89 90 int nAstro = psMetadataLookupS32 (&status, updates, "NASTRO");91 if (!nAstro) continue;92 93 // set the chip astrometry using the astrom file94 pmChip *refChip = pmFPAviewThisChip (view, astrom->fpa);95 96 psRegion *region = pmChipPixels (obsChip);97 psPlane ptCP, ptFP;98 99 ptCP.x = region->x0; ptCP.y = region->y0;100 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);101 xObs->data.F32[nPts] = ptFP.x;102 yObs->data.F32[nPts] = ptFP.y;103 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP);104 xRef->data.F32[nPts] = ptFP.x;105 yRef->data.F32[nPts] = ptFP.y;106 107 if (DEBUG) {108 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME");109 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]);110 }111 nPts ++;112 113 ptCP.x = region->x0; ptCP.y = region->y1;114 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);115 xObs->data.F32[nPts] = ptFP.x;116 yObs->data.F32[nPts] = ptFP.y;117 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP);118 xRef->data.F32[nPts] = ptFP.x;119 yRef->data.F32[nPts] = ptFP.y;120 121 if (DEBUG) {122 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME");123 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]);124 }125 nPts ++;126 127 ptCP.x = region->x1; ptCP.y = region->y1;128 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);129 xObs->data.F32[nPts] = ptFP.x;130 yObs->data.F32[nPts] = ptFP.y;131 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP);132 xRef->data.F32[nPts] = ptFP.x;133 yRef->data.F32[nPts] = ptFP.y;134 135 if (DEBUG) {136 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME");137 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]);138 }139 nPts ++;140 141 ptCP.x = region->x1; ptCP.y = region->y0;142 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP);143 xObs->data.F32[nPts] = ptFP.x;144 yObs->data.F32[nPts] = ptFP.y;145 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP);146 xRef->data.F32[nPts] = ptFP.x;147 yRef->data.F32[nPts] = ptFP.y;148 149 if (DEBUG) {150 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME");151 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]);152 }153 nPts ++;154 155 psFree (region);72 if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; } 73 74 // XXX we are currently inconsistent with marking the good vs the bad data 75 // psastroChipAstrom sets data_exists to false if the fit is bad. this is 76 // probably wrong since it implies there is no data! 77 78 // skip chips for which the astrometry failed (NASTRO == 0) 79 if (!obsChip->cells->n) continue; 80 pmCell *cell = obsChip->cells->data[0]; 81 if (!cell) continue; 82 83 if (!cell->readouts->n) continue; 84 pmReadout *readout = cell->readouts->data[0]; 85 if (!readout) continue; 86 87 psMetadata *updates = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER"); 88 if (!updates) continue; 89 90 int nAstro = psMetadataLookupS32 (&status, updates, "NASTRO"); 91 if (!nAstro) continue; 92 93 // set the chip astrometry using the astrom file 94 pmChip *refChip = pmFPAviewThisChip (view, astrom->fpa); 95 96 psRegion *region = pmChipPixels (obsChip); 97 psPlane ptCP, ptFP; 98 99 ptCP.x = region->x0; ptCP.y = region->y0; 100 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP); 101 xObs->data.F32[nPts] = ptFP.x; 102 yObs->data.F32[nPts] = ptFP.y; 103 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP); 104 xRef->data.F32[nPts] = ptFP.x; 105 yRef->data.F32[nPts] = ptFP.y; 106 107 if (DEBUG) { 108 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME"); 109 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]); 110 } 111 nPts ++; 112 113 ptCP.x = region->x0; ptCP.y = region->y1; 114 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP); 115 xObs->data.F32[nPts] = ptFP.x; 116 yObs->data.F32[nPts] = ptFP.y; 117 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP); 118 xRef->data.F32[nPts] = ptFP.x; 119 yRef->data.F32[nPts] = ptFP.y; 120 121 if (DEBUG) { 122 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME"); 123 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]); 124 } 125 nPts ++; 126 127 ptCP.x = region->x1; ptCP.y = region->y1; 128 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP); 129 xObs->data.F32[nPts] = ptFP.x; 130 yObs->data.F32[nPts] = ptFP.y; 131 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP); 132 xRef->data.F32[nPts] = ptFP.x; 133 yRef->data.F32[nPts] = ptFP.y; 134 135 if (DEBUG) { 136 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME"); 137 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]); 138 } 139 nPts ++; 140 141 ptCP.x = region->x1; ptCP.y = region->y0; 142 psPlaneTransformApply (&ptFP, obsChip->toFPA, &ptCP); 143 xObs->data.F32[nPts] = ptFP.x; 144 yObs->data.F32[nPts] = ptFP.y; 145 psPlaneTransformApply (&ptFP, refChip->toFPA, &ptCP); 146 xRef->data.F32[nPts] = ptFP.x; 147 yRef->data.F32[nPts] = ptFP.y; 148 149 if (DEBUG) { 150 chipName = psMetadataLookupStr(NULL, obsChip->concepts, "CHIP.NAME"); 151 fprintf (f, "%s %f %f %f %f\n", chipName, xObs->data.F32[nPts], yObs->data.F32[nPts], xRef->data.F32[nPts], yRef->data.F32[nPts]); 152 } 153 nPts ++; 154 155 psFree (region); 156 156 } 157 157 xObs->n = yObs->n = xRef->n = yRef->n = nPts; 158 158 if (DEBUG) fclose (f); 159 159 160 160 psPlaneTransform *map = psPlaneTransformAlloc (1, 1); 161 161 162 162 psVector *mask = psVectorAlloc (nPts, PS_TYPE_U8); 163 163 psVectorInit (mask, 0); … … 167 167 168 168 for (int i = 0; i < 3; i++) { 169 psVectorClipFitPolynomial2D (map->x, stats, mask, 0xff, xObs, NULL, xRef, yRef);170 psTrace ("psModules.astrom", 3, "x resid: %f +/- %f (%ld of %ld)\n", stats->clippedMean, stats->clippedStdev, stats->clippedNvalues, xObs->n);171 172 psVectorClipFitPolynomial2D (map->y, stats, mask, 0xff, yObs, NULL, xRef, yRef);173 psTrace ("psModules.astrom", 3, "y resid: %f +/- %f (%ld of %ld)\n", stats->clippedMean, stats->clippedStdev, stats->clippedNvalues, yObs->n);169 psVectorClipFitPolynomial2D (map->x, stats, mask, 0xff, xObs, NULL, xRef, yRef); 170 psTrace ("psModules.astrom", 3, "x resid: %f +/- %f (%ld of %ld)\n", stats->clippedMean, stats->clippedStdev, stats->clippedNvalues, xObs->n); 171 172 psVectorClipFitPolynomial2D (map->y, stats, mask, 0xff, yObs, NULL, xRef, yRef); 173 psTrace ("psModules.astrom", 3, "y resid: %f +/- %f (%ld of %ld)\n", stats->clippedMean, stats->clippedStdev, stats->clippedNvalues, yObs->n); 174 174 } 175 175 176 176 // loop over all chips, select the outliers, and replace the measured astrometry with the model 177 // the measured transformation above must be applied to make the comparison, and also then applied to the 177 // the measured transformation above must be applied to make the comparison, and also then applied to the 178 178 // model transformation 179 179 180 180 if (DEBUG) { 181 f = fopen ("corners.fit.dat", "w");182 for (int i = 0; i < xObs->n; i++) {183 psPlane obsCoord, refCoord;184 refCoord.x = xRef->data.F32[i];185 refCoord.y = yRef->data.F32[i];186 psPlaneTransformApply (&obsCoord, map, &refCoord);187 fprintf (f, "%f %f %f %f %f %f\n", xObs->data.F32[i], yObs->data.F32[i], xRef->data.F32[i], yRef->data.F32[i], obsCoord.x, obsCoord.y);188 }189 fclose (f);181 f = fopen ("corners.fit.dat", "w"); 182 for (int i = 0; i < xObs->n; i++) { 183 psPlane obsCoord, refCoord; 184 refCoord.x = xRef->data.F32[i]; 185 refCoord.y = yRef->data.F32[i]; 186 psPlaneTransformApply (&obsCoord, map, &refCoord); 187 fprintf (f, "%f %f %f %f %f %f\n", xObs->data.F32[i], yObs->data.F32[i], xRef->data.F32[i], yRef->data.F32[i], obsCoord.x, obsCoord.y); 188 } 189 fclose (f); 190 190 } 191 191 … … 199 199 200 200 while ((obsChip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 201 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, obsChip->file_exists, obsChip->process);202 if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; }203 204 // set the chip astrometry using the astrom file205 pmChip *refChip = pmFPAviewThisChip (view, astrom->fpa);206 207 // bad Astrometry test: ref pixel or angle outside nominal208 209 psPlane refPixel = {0.0, 0.0, 0.0, 0.0};210 psPlane obsCoord, refCoord, tmpCoord;211 212 // find location of 0,0 pixel in focal plane coords for this chip213 psPlaneTransformApply (&obsCoord, obsChip->toFPA, &refPixel);214 215 // find location of 0,0 pixel in focal plane coords for ref chip216 // apply the global field rotation and offset before comparing217 psPlaneTransformApply (&tmpCoord, refChip->toFPA, &refPixel);218 psPlaneTransformApply (&refCoord, map, &tmpCoord);219 220 psPlane offPixel = {100.0, 0.0, 100.0, 0.0};221 psPlane obsOffPt, refOffPt;222 223 // find location of 0,0 pixel in focal plane coords for this chip224 psPlaneTransformApply (&obsOffPt, obsChip->toFPA, &offPixel);225 226 // find location of 0,0 pixel in focal plane coords for ref chip227 psPlaneTransformApply (&tmpCoord, refChip->toFPA, &offPixel);228 psPlaneTransformApply (&refOffPt, map, &tmpCoord);229 230 double obsAngle = PM_DEG_RAD*atan2 (obsOffPt.y - obsCoord.y, obsOffPt.x - obsCoord.x);231 double refAngle = PM_DEG_RAD*atan2 (refOffPt.y - refCoord.y, refOffPt.x - refCoord.x);232 233 bool badAstrom = false;234 badAstrom |= fabs(obsCoord.x - refCoord.x) > pixelTol;235 badAstrom |= fabs(obsCoord.y - refCoord.y) > pixelTol;236 badAstrom |= fabs(obsAngle - refAngle) > angleTol;237 238 fprintf (stderr, "chip %d, angle: %f, pixel: %f,%f\n", view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y);239 240 // XXX for now, just use first readout241 pmCell *cell = obsChip->cells->data[0];242 pmReadout *readout = cell->readouts->data[0];243 244 // update the header (pull or create local view to entry on readout->analysis)245 psMetadata *updates = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER");246 if (!updates) {247 updates = psMetadataAlloc ();248 psMetadataAddMetadata (readout->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", updates);249 psFree (updates);250 }251 252 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DX", PS_META_REPLACE, "chip x offset wrt model", obsCoord.x - refCoord.x);253 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DY", PS_META_REPLACE, "chip y offset wrt model", obsCoord.y - refCoord.y);254 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DT", PS_META_REPLACE, "chip rot offset wrt model", obsAngle - refAngle);255 256 // for successful chips, save the measured offsets in the header257 if (!badAstrom) continue;258 259 // XXX for now, let's just fail on the bad chips. In the future, let's try to recover, but we still need to 260 // catch the failures relative to the model261 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0);262 continue;263 264 psLogMsg ("psastro", PS_LOG_INFO, "fixing chip %d, angle: %f, pixel: %f,%f\n",265 view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y);266 267 psFree (obsChip->toFPA);268 psFree (obsChip->fromFPA);269 270 // apply the exiting fromTPA transformation to make the new toFPA consistent with the toTPA layter271 // XXX this only works if toTPA is at most a linear transformation272 psPlaneTransform *toFPA = psPlaneTransformAlloc(refChip->toFPA->x->nX, refChip->toFPA->x->nY);273 for (int i = 0; i <= refChip->toFPA->x->nX; i++) {274 for (int j = 0; j <= refChip->toFPA->x->nY; j++) {275 double f1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->x->coeff[1][0]*refChip->toFPA->x->coeff[i][j];276 double f2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->x->coeff[0][1]*refChip->toFPA->y->coeff[i][j];277 toFPA->x->coeff[i][j] = f1 + f2;278 279 double g1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->y->coeff[1][0]*refChip->toFPA->x->coeff[i][j];280 double g2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->y->coeff[0][1]*refChip->toFPA->y->coeff[i][j];281 toFPA->y->coeff[i][j] = g1 + g2;282 }283 }284 toFPA->x->coeff[0][0] += map->x->coeff[0][0];285 toFPA->y->coeff[0][0] += map->y->coeff[0][0];286 287 psRegion *region = pmChipPixels (obsChip);288 obsChip->toFPA = toFPA;289 obsChip->fromFPA = psPlaneTransformInvert(NULL, obsChip->toFPA, *region, 50);290 psFree (region);291 292 // use the new position to re-try the match fit293 // select the raw objects for this readout294 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS");295 if (rawstars == NULL) { continue; }296 297 // select the raw objects for this readout298 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS");299 if (refstars == NULL) { continue; }300 301 // the absolute minimum number of stars is 4 (for order = 1)302 if ((rawstars->n < 4) || (refstars->n < 4)) {303 readout->data_exists = false;304 psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)", 305 rawstars->n, refstars->n);306 continue;307 } 308 309 psastroUpdateChipToFPA (input->fpa, obsChip, rawstars, refstars);310 311 // XXX update the header with info to reflect the failure312 if (!psastroOneChipFit (input->fpa, obsChip, refstars, rawstars, recipe, updates)) {313 readout->data_exists = false;314 psLogMsg ("psastro", 3, "failed to find a solution\n");315 continue;316 }317 318 pmAstromWriteWCS (updates, input->fpa, obsChip, NONLIN_TOL);319 } 320 321 p sastroVisualPlotFixChips (input, xObs, yObs);201 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, obsChip->file_exists, obsChip->process); 202 if (!obsChip->process || !obsChip->file_exists || !obsChip->data_exists) { continue; } 203 204 // set the chip astrometry using the astrom file 205 pmChip *refChip = pmFPAviewThisChip (view, astrom->fpa); 206 207 // bad Astrometry test: ref pixel or angle outside nominal 208 209 psPlane refPixel = {0.0, 0.0, 0.0, 0.0}; 210 psPlane obsCoord, refCoord, tmpCoord; 211 212 // find location of 0,0 pixel in focal plane coords for this chip 213 psPlaneTransformApply (&obsCoord, obsChip->toFPA, &refPixel); 214 215 // find location of 0,0 pixel in focal plane coords for ref chip 216 // apply the global field rotation and offset before comparing 217 psPlaneTransformApply (&tmpCoord, refChip->toFPA, &refPixel); 218 psPlaneTransformApply (&refCoord, map, &tmpCoord); 219 220 psPlane offPixel = {100.0, 0.0, 100.0, 0.0}; 221 psPlane obsOffPt, refOffPt; 222 223 // find location of 0,0 pixel in focal plane coords for this chip 224 psPlaneTransformApply (&obsOffPt, obsChip->toFPA, &offPixel); 225 226 // find location of 0,0 pixel in focal plane coords for ref chip 227 psPlaneTransformApply (&tmpCoord, refChip->toFPA, &offPixel); 228 psPlaneTransformApply (&refOffPt, map, &tmpCoord); 229 230 double obsAngle = PM_DEG_RAD*atan2 (obsOffPt.y - obsCoord.y, obsOffPt.x - obsCoord.x); 231 double refAngle = PM_DEG_RAD*atan2 (refOffPt.y - refCoord.y, refOffPt.x - refCoord.x); 232 233 bool badAstrom = false; 234 badAstrom |= fabs(obsCoord.x - refCoord.x) > pixelTol; 235 badAstrom |= fabs(obsCoord.y - refCoord.y) > pixelTol; 236 badAstrom |= fabs(obsAngle - refAngle) > angleTol; 237 238 fprintf (stderr, "chip %d, angle: %f, pixel: %f,%f\n", view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y); 239 240 // XXX for now, just use first readout 241 pmCell *cell = obsChip->cells->data[0]; 242 pmReadout *readout = cell->readouts->data[0]; 243 244 // update the header (pull or create local view to entry on readout->analysis) 245 psMetadata *updates = psMetadataLookupMetadata (&status, readout->analysis, "PSASTRO.HEADER"); 246 if (!updates) { 247 updates = psMetadataAlloc (); 248 psMetadataAddMetadata (readout->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", updates); 249 psFree (updates); 250 } 251 252 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DX", PS_META_REPLACE, "chip x offset wrt model", obsCoord.x - refCoord.x); 253 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DY", PS_META_REPLACE, "chip y offset wrt model", obsCoord.y - refCoord.y); 254 psMetadataAddF32 (updates, PS_LIST_TAIL, "AST_DT", PS_META_REPLACE, "chip rot offset wrt model", obsAngle - refAngle); 255 256 // for successful chips, save the measured offsets in the header 257 if (!badAstrom) continue; 258 259 // XXX for now, let's just fail on the bad chips. In the future, let's try to recover, but we still need to 260 // catch the failures relative to the model 261 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0); 262 continue; 263 264 psLogMsg ("psastro", PS_LOG_INFO, "fixing chip %d, angle: %f, pixel: %f,%f\n", 265 view->chip, obsAngle - refAngle, obsCoord.x - refCoord.x, obsCoord.y - refCoord.y); 266 267 psFree (obsChip->toFPA); 268 psFree (obsChip->fromFPA); 269 270 // apply the exiting fromTPA transformation to make the new toFPA consistent with the toTPA layter 271 // XXX this only works if toTPA is at most a linear transformation 272 psPlaneTransform *toFPA = psPlaneTransformAlloc(refChip->toFPA->x->nX, refChip->toFPA->x->nY); 273 for (int i = 0; i <= refChip->toFPA->x->nX; i++) { 274 for (int j = 0; j <= refChip->toFPA->x->nY; j++) { 275 double f1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->x->coeff[1][0]*refChip->toFPA->x->coeff[i][j]; 276 double f2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->x->coeff[0][1]*refChip->toFPA->y->coeff[i][j]; 277 toFPA->x->coeff[i][j] = f1 + f2; 278 279 double g1 = refChip->toFPA->x->coeffMask[i][j] ? 0.0 : map->y->coeff[1][0]*refChip->toFPA->x->coeff[i][j]; 280 double g2 = refChip->toFPA->y->coeffMask[i][j] ? 0.0 : map->y->coeff[0][1]*refChip->toFPA->y->coeff[i][j]; 281 toFPA->y->coeff[i][j] = g1 + g2; 282 } 283 } 284 toFPA->x->coeff[0][0] += map->x->coeff[0][0]; 285 toFPA->y->coeff[0][0] += map->y->coeff[0][0]; 286 287 psRegion *region = pmChipPixels (obsChip); 288 obsChip->toFPA = toFPA; 289 obsChip->fromFPA = psPlaneTransformInvert(NULL, obsChip->toFPA, *region, 50); 290 psFree (region); 291 292 // use the new position to re-try the match fit 293 // select the raw objects for this readout 294 psArray *rawstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.RAWSTARS"); 295 if (rawstars == NULL) { continue; } 296 297 // select the raw objects for this readout 298 psArray *refstars = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.REFSTARS"); 299 if (refstars == NULL) { continue; } 300 301 // the absolute minimum number of stars is 4 (for order = 1) 302 if ((rawstars->n < 4) || (refstars->n < 4)) { 303 readout->data_exists = false; 304 psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)", 305 rawstars->n, refstars->n); 306 continue; 307 } 308 309 psastroUpdateChipToFPA (input->fpa, obsChip, rawstars, refstars); 310 311 // XXX update the header with info to reflect the failure 312 if (!psastroOneChipFit (input->fpa, obsChip, refstars, rawstars, recipe, updates)) { 313 readout->data_exists = false; 314 psLogMsg ("psastro", 3, "failed to find a solution\n"); 315 continue; 316 } 317 318 pmAstromWriteWCS (updates, input->fpa, obsChip, NONLIN_TOL); 319 } 320 321 pmAstromVisualPlotFixChips (input, xObs, yObs); 322 322 psFree (xObs); 323 323 psFree (yObs); -
branches/cnb_branch_20090113/psastro/src/psastroLoadRefstars.c
r20805 r21208 138 138 } 139 139 140 p sastroVisualPlotRefStars (refstars, recipe);140 pmAstromVisualPlotRefStars (refstars, recipe); 141 141 142 142 if (psTraceGetLevel("psastro.plot") > 0) { … … 239 239 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 240 240 if (!input) { 241 psLogMsg ("psastro", PS_LOG_DETAIL, "no supplied reference header data");242 photcode = psStringCopy ("NONE");243 return photcode;241 psLogMsg ("psastro", PS_LOG_DETAIL, "no supplied reference header data"); 242 photcode = psStringCopy ("NONE"); 243 return photcode; 244 244 } 245 245 assert (input->fpa); … … 247 247 *maxRho = psMetadataLookupF32(&status, recipe, "DVO.GETSTAR.MAX.RHO"); 248 248 if (!status) { 249 psError(PSASTRO_ERR_CONFIG, false, "DVO.GETSTAR.MAX.RHO missing from recipe");250 return NULL;249 psError(PSASTRO_ERR_CONFIG, false, "DVO.GETSTAR.MAX.RHO missing from recipe"); 250 return NULL; 251 251 } 252 252 … … 266 266 if (!status) ESCAPE ("missing DVO.GETSTAR.MIN.MAG.INST"); 267 267 268 // PHOTCODE.DATA is a multi of metadata items 268 // PHOTCODE.DATA is a multi of metadata items 269 269 psListIterator *iter = psListIteratorAlloc(item->data.list, PS_LIST_HEAD, false); 270 270 271 271 psMetadataItem *refItem = NULL; 272 272 while ((refItem = psListGetAndIncrement (iter))) { 273 if (refItem->type != PS_DATA_METADATA) ESCAPE ("PHOTCODE.DATA entry is not a metadata folder");274 275 char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER");276 if (!status) {277 psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");278 continue;279 }280 281 // does this entry match the current filter?282 if (strcmp (refFilter, filter)) continue;283 284 psLogMsg ("psastro", PS_LOG_DETAIL, "PHOTCODE.DATA found for filter %s", filter);285 286 float zeropt = psMetadataLookupF32 (&status, refItem->data.md, "ZEROPT");287 if (!status) {288 psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");289 continue;290 }291 photcode = psMetadataLookupStr (&status, refItem->data.md, "PHOTCODE");292 if (!status) {293 psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER");294 continue;295 }296 297 // convert the minInst to a calibrated minimum magnitude298 *minMag = minInst + 2.5*log10(exptime) + zeropt;299 300 psFree (iter);301 return photcode;302 } 273 if (refItem->type != PS_DATA_METADATA) ESCAPE ("PHOTCODE.DATA entry is not a metadata folder"); 274 275 char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER"); 276 if (!status) { 277 psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER"); 278 continue; 279 } 280 281 // does this entry match the current filter? 282 if (strcmp (refFilter, filter)) continue; 283 284 psLogMsg ("psastro", PS_LOG_DETAIL, "PHOTCODE.DATA found for filter %s", filter); 285 286 float zeropt = psMetadataLookupF32 (&status, refItem->data.md, "ZEROPT"); 287 if (!status) { 288 psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER"); 289 continue; 290 } 291 photcode = psMetadataLookupStr (&status, refItem->data.md, "PHOTCODE"); 292 if (!status) { 293 psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER"); 294 continue; 295 } 296 297 // convert the minInst to a calibrated minimum magnitude 298 *minMag = minInst + 2.5*log10(exptime) + zeropt; 299 300 psFree (iter); 301 return photcode; 302 } 303 303 psFree (iter); 304 304 … … 306 306 photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE"); 307 307 PS_ASSERT (photcode, NULL); 308 308 309 309 // give up and use fixed value 310 310 *minMag = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MIN.MAG"); -
branches/cnb_branch_20090113/psastro/src/psastroLuminosityFunction.c
r20805 r21208 129 129 lumFunc->sPeak = sPeak; 130 130 131 p sastroVisualPlotLuminosityFunction(lnMag, Mag, lumFunc, rawFunc);131 pmAstromVisualPlotLuminosityFunction(lnMag, Mag, lumFunc, rawFunc); 132 132 133 133 psFree (lnMag); -
branches/cnb_branch_20090113/psastro/src/psastroMosaicOneChip.c
r20803 r21208 148 148 149 149 //plot results 150 p sastroVisualPlotMosaicOneChip(rawstars, refstars, match, recipe);150 pmAstromVisualPlotMosaicOneChip(rawstars, refstars, match, recipe); 151 151 152 152 psFree (fitStats); -
branches/cnb_branch_20090113/psastro/src/psastroMosaicSetMatch.c
r20805 r21208 57 57 psTrace ("psastro", 4, "Matched %ld refstars\n", matches->n); 58 58 59 p sastroVisualPlotMosaicMatches(rawstars, refstars, matches, iteration, recipe);59 pmAstromVisualPlotMosaicMatches(rawstars, refstars, matches, iteration, recipe); 60 60 61 61 // XXX drop the old one -
branches/cnb_branch_20090113/psastro/src/psastroOneChipFit.c
r20805 r21208 11 11 12 12 // default value for match/fit : radius is in pixels 13 REQUIRED_RECIPE_VALUE (double RADIUS, "PSASTRO.MATCH.RADIUS", F32); 13 REQUIRED_RECIPE_VALUE (double RADIUS, "PSASTRO.MATCH.RADIUS", F32); 14 14 15 15 // run the match/fit sequence NITER times 16 REQUIRED_RECIPE_VALUE (int nIter, "PSASTRO.MATCH.FIT.NITER", S32); 16 REQUIRED_RECIPE_VALUE (int nIter, "PSASTRO.MATCH.FIT.NITER", S32); 17 17 18 18 // correct radius to FP units (physical pixel scale in microns per pixel) 19 REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32); 19 REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32); 20 20 RADIUS *= pixelScale; 21 21 … … 32 32 33 33 for (int iter = 0; iter < nIter; iter++) { 34 35 char name[128];36 34 37 sprintf (name, "PSASTRO.MATCH.RADIUS.N%d", iter); 38 float radius = psMetadataLookupF32 (&status, recipe, name); 39 radius *= pixelScale; 40 if (!status || (radius == 0.0)) { 41 radius = RADIUS; 42 } 35 char name[128]; 36 37 sprintf (name, "PSASTRO.MATCH.RADIUS.N%d", iter); 38 float radius = psMetadataLookupF32 (&status, recipe, name); 39 radius *= pixelScale; 40 if (!status || (radius == 0.0)) { 41 radius = RADIUS; 42 } 43 43 44 44 45 // use small radius to match stars46 match = pmAstromRadiusMatchFP (rawstars, refstars, radius);47 if (match == NULL) {48 psLogMsg ("psastro", 3, "failed to find radius-matched sources\n");49 return false;50 }45 // use small radius to match stars 46 match = pmAstromRadiusMatchFP (rawstars, refstars, radius); 47 if (match == NULL) { 48 psLogMsg ("psastro", 3, "failed to find radius-matched sources\n"); 49 return false; 50 } 51 51 52 // modify the order to correspond to the actual number of matched stars:53 int Ndof_min = 3;54 int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1));55 order = PS_MIN (order, order_max);52 // modify the order to correspond to the actual number of matched stars: 53 int Ndof_min = 3; 54 int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1)); 55 order = PS_MIN (order, order_max); 56 56 57 // if ((match->n < 11) && (order >= 3)) order = 2;58 // if ((match->n < 7) && (order >= 2)) order = 1;59 // if ((match->n < 4) && (order >= 1)) order = 0;57 // if ((match->n < 11) && (order >= 3)) order = 2; 58 // if ((match->n < 7) && (order >= 2)) order = 1; 59 // if ((match->n < 4) && (order >= 1)) order = 0; 60 60 61 if (order < 1) {62 psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 63 psFree (match);64 return false; 65 } 61 if (order < 1) { 62 psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 63 psFree (match); 64 return false; 65 } 66 66 67 // create output toFPA; set masks appropriate to the Elixir DVO astrometry format68 psFree (chip->toFPA);69 chip->toFPA = psPlaneTransformAlloc (order, order);70 for (int i = 0; i <= chip->toFPA->x->nX; i++) {71 for (int j = 0; j <= chip->toFPA->x->nY; j++) {72 if (i + j > order) {73 chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET;74 chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET;75 }76 }77 }67 // create output toFPA; set masks appropriate to the Elixir DVO astrometry format 68 psFree (chip->toFPA); 69 chip->toFPA = psPlaneTransformAlloc (order, order); 70 for (int i = 0; i <= chip->toFPA->x->nX; i++) { 71 for (int j = 0; j <= chip->toFPA->x->nY; j++) { 72 if (i + j > order) { 73 chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET; 74 chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET; 75 } 76 } 77 } 78 78 79 // XXX allow statitic to be set by the user80 // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);81 fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);82 fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");83 fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");79 // XXX allow statitic to be set by the user 80 // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 81 fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 82 fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA"); 83 fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER"); 84 84 85 // improved fit for astrometric terms 86 results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats); 87 if (!results) { 88 psLogMsg ("psastro", 3, "failed to perform the matched fit\n"); 89 psFree (match); 90 psFree (fitStats); 91 return false; 92 } 93 94 // determine fromFPA transformation and apply new transformation to raw & ref stars 95 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 96 97 // toSky converts from FPA & TPA units (microns) to sky units (radians) 98 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 99 // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 100 float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale; 101 int astNstar = results->yStats->clippedNvalues; 102 psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar); 85 // improved fit for astrometric terms 86 results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats); 87 if (!results) { 88 psLogMsg ("psastro", 3, "failed to perform the matched fit\n"); 89 psFree (match); 90 psFree (fitStats); 91 return false; 92 } 103 93 104 if (iter < nIter - 1) { 105 psFree (fitStats); 106 psFree (results); 107 psFree (match); 108 } 94 // determine fromFPA transformation and apply new transformation to raw & ref stars 95 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 96 97 // toSky converts from FPA & TPA units (microns) to sky units (radians) 98 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 99 // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 100 float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale; 101 int astNstar = results->yStats->clippedNvalues; 102 psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar); 103 104 if (iter < nIter - 1) { 105 psFree (fitStats); 106 psFree (results); 107 psFree (match); 108 } 109 109 } 110 110 … … 127 127 if (astError > maxError) { 128 128 psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError); 129 validSolution = false;129 validSolution = false; 130 130 } 131 131 if (astNstar < minNstar) { 132 132 psLogMsg("psastro", PS_LOG_INFO, "solution uses too few stars: %d < %d", astNstar, minNstar); 133 validSolution = false;133 validSolution = false; 134 134 } 135 135 … … 138 138 psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR", PS_META_REPLACE, "astrometry error (arcsec)", astError); 139 139 if (validSolution) { 140 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));141 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", astNstar);140 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar)); 141 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", astNstar); 142 142 } else { 143 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);144 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0);143 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0); 144 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0); 145 145 } 146 146 psMetadataAddF32 (updates, PS_LIST_TAIL, "EQUINOX", PS_META_REPLACE, "equinox of ref catalog", 2000.0); // XXX this is bogus: should be defined based on equinox of refstars … … 148 148 // XXX drop from here : determine fromFPA transformation and apply new transformation to raw & ref stars 149 149 // psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 150 150 151 151 // XXX check if we correctly applied the new transformation: 152 152 if (psTraceGetLevel("psastro.dump") > 0) { 153 psastroDumpRawstars (rawstars, fpa, chip);154 psastroDumpMatchedStars ("match.dat", rawstars, refstars, match);155 psastroDumpStars (refstars, "refstars.cal.dat");153 psastroDumpRawstars (rawstars, fpa, chip); 154 psastroDumpMatchedStars ("match.dat", rawstars, refstars, match); 155 psastroDumpStars (refstars, "refstars.cal.dat"); 156 156 } 157 157 158 p sastroVisualPlotOneChipFit (rawstars, refstars, match, recipe);158 pmAstromVisualPlotOneChipFit (rawstars, refstars, match, recipe); 159 159 160 160 if (psTraceGetLevel("psastro.plot") > 0) { 161 psastroPlotOneChipFit (rawstars, refstars, match, recipe);161 psastroPlotOneChipFit (rawstars, refstars, match, recipe); 162 162 } 163 163 -
branches/cnb_branch_20090113/psastro/src/psastroRemoveClumps.c
r20805 r21208 55 55 psTrace ("psastro", 4, "skipping stars in cells with more than %f stars\n", limit); 56 56 57 p sastroVisualPlotRemoveClumps (input, count, scale, limit);57 pmAstromVisualPlotRemoveClumps (input, count, scale, limit); 58 58 59 59 // find and exclude objects in bad pixels -
branches/cnb_branch_20090113/psastro/src/psastroUtils.c
r20804 r21208 42 42 if (!chip->toFPA) { continue; } 43 43 44 if (chip->cells->n == 0) { continue; }45 pmCell *cell = chip->cells->data[0];44 if (chip->cells->n == 0) { continue; } 45 pmCell *cell = chip->cells->data[0]; 46 46 if (!cell->process || !cell->file_exists) { continue; } 47 47 48 if (cell->readouts->n == 0) { continue; }49 pmReadout *readout = cell->readouts->data[0];50 if (! readout->data_exists) { continue; }48 if (cell->readouts->n == 0) { continue; } 49 pmReadout *readout = cell->readouts->data[0]; 50 if (! readout->data_exists) { continue; } 51 51 52 52 pixelScale1 = hypot (chip->toFPA->x->coeff[1][0], chip->toFPA->x->coeff[0][1]); … … 88 88 psastroMosaicSetAstrom (fpa); 89 89 if (!useExternal) { 90 p sastroVisualPlotCommonScale (fpa, oldScale);90 pmAstromVisualPlotCommonScale (fpa, oldScale); 91 91 } 92 92 psFree (oldScale);
Note:
See TracChangeset
for help on using the changeset viewer.
