- Timestamp:
- Jan 28, 2009, 1:36:37 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
