- Timestamp:
- Oct 18, 2008, 2:26:45 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branch_20081011/psastro/src/psastroOneChipFit.c
r16070 r20263 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 if ((match->n < 11) && (order >= 3)) order = 2;54 if ((match->n < 7) && (order >= 2)) order = 1;55 if ((match->n < 4) && (order >= 1)) order = 0;56 if (order < 1) {57 psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 58 psFree (match);59 return false; 60 } 52 // modify the order to correspond to the actual number of matched stars: 53 if ((match->n < 11) && (order >= 3)) order = 2; 54 if ((match->n < 7) && (order >= 2)) order = 1; 55 if ((match->n < 4) && (order >= 1)) order = 0; 56 if (order < 1) { 57 psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 58 psFree (match); 59 return false; 60 } 61 61 62 // create output toFPA; set masks appropriate to the Elixir DVO astrometry format63 psFree (chip->toFPA);64 chip->toFPA = psPlaneTransformAlloc (order, order);65 for (int i = 0; i <= chip->toFPA->x->nX; i++) {66 for (int j = 0; j <= chip->toFPA->x->nY; j++) {67 if (i + j > order) {68 chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET;69 chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET;70 }71 }72 }62 // create output toFPA; set masks appropriate to the Elixir DVO astrometry format 63 psFree (chip->toFPA); 64 chip->toFPA = psPlaneTransformAlloc (order, order); 65 for (int i = 0; i <= chip->toFPA->x->nX; i++) { 66 for (int j = 0; j <= chip->toFPA->x->nY; j++) { 67 if (i + j > order) { 68 chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET; 69 chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET; 70 } 71 } 72 } 73 73 74 // XXX allow statitic to be set by the user75 // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);76 fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);77 fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");78 fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");74 // XXX allow statitic to be set by the user 75 // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 76 fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 77 fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA"); 78 fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER"); 79 79 80 // improved fit for astrometric terms 81 results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats); 82 if (!results) { 83 psLogMsg ("psastro", 3, "failed to perform the matched fit\n"); 84 psFree (match); 85 psFree (fitStats); 86 return false; 87 } 88 89 // determine fromFPA transformation and apply new transformation to raw & ref stars 90 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 91 92 // toSky converts from FPA & TPA units (microns) to sky units (radians) 93 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 94 // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 95 float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale; 96 int astNstar = results->yStats->clippedNvalues; 97 psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar); 80 // improved fit for astrometric terms 81 results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats); 82 if (!results) { 83 psLogMsg ("psastro", 3, "failed to perform the matched fit\n"); 84 psFree (match); 85 psFree (fitStats); 86 return false; 87 } 98 88 99 if (iter < nIter - 1) { 100 psFree (fitStats); 101 psFree (results); 102 psFree (match); 103 } 89 // determine fromFPA transformation and apply new transformation to raw & ref stars 90 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 91 92 // toSky converts from FPA & TPA units (microns) to sky units (radians) 93 float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD; 94 // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 95 float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale; 96 int astNstar = results->yStats->clippedNvalues; 97 psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar); 98 99 if (iter < nIter - 1) { 100 psFree (fitStats); 101 psFree (results); 102 psFree (match); 103 } 104 104 } 105 105 … … 122 122 if (astError > maxError) { 123 123 psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError); 124 validSolution = false;124 validSolution = false; 125 125 } 126 126 if (astNstar < minNstar) { 127 127 psLogMsg("psastro", PS_LOG_INFO, "solution uses too few stars: %d < %d", astNstar, minNstar); 128 validSolution = false;128 validSolution = false; 129 129 } 130 130 … … 133 133 psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR", PS_META_REPLACE, "astrometry error (arcsec)", astError); 134 134 if (validSolution) { 135 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));136 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", astNstar);135 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar)); 136 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", astNstar); 137 137 } else { 138 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);139 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0);138 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0); 139 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0); 140 140 } 141 141 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 … … 143 143 // XXX drop from here : determine fromFPA transformation and apply new transformation to raw & ref stars 144 144 // psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 145 145 146 146 // XXX check if we correctly applied the new transformation: 147 147 if (psTraceGetLevel("psastro.dump") > 0) { 148 psastroDumpRawstars (rawstars, fpa, chip);149 psastroDumpMatchedStars ("match.dat", rawstars, refstars, match);150 psastroDumpStars (refstars, "refstars.cal.dat");148 psastroDumpRawstars (rawstars, fpa, chip); 149 psastroDumpMatchedStars ("match.dat", rawstars, refstars, match); 150 psastroDumpStars (refstars, "refstars.cal.dat"); 151 151 } 152 152 153 psastroVisualPlotOneChipFit (rawstars, refstars, match, recipe); 154 153 155 if (psTraceGetLevel("psastro.plot") > 0) { 154 psastroPlotOneChipFit (rawstars, refstars, match, recipe);156 psastroPlotOneChipFit (rawstars, refstars, match, recipe); 155 157 } 156 158
Note:
See TracChangeset
for help on using the changeset viewer.
