Changeset 10855 for trunk/psastro/src/psastroOneChip.c
- Timestamp:
- Dec 29, 2006, 8:36:33 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroOneChip.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroOneChip.c
r10830 r10855 1 1 # include "psastro.h" 2 3 # define REQUIRED_RECIPE_VALUE(VALUE, NAME, TYPE, MESSAGE)\ 4 VALUE = psMetadataLookup##TYPE (&status, recipe, NAME); \ 5 if (!status) { \ 6 psError(PSASTRO_ERR_CONFIG, false, MESSAGE); \ 7 return false; } 2 8 3 9 bool psastroOneChip (pmFPA *fpa, pmChip *chip, psArray *refstars, psArray *rawstars, psMetadata *recipe, psMetadata *updates) { … … 5 11 bool status; 6 12 13 // supplied radius is in pixels 14 REQUIRED_RECIPE_VALUE (double RADIUS, "PSASTRO.MATCH.RADIUS", F32, "Failed to lookup matching radius"); 15 16 // correct radius to FP units (physical pixel scale in microns per pixel) 17 REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32, "Failed to lookup pixel scale"); 18 RADIUS *= pixelScale; 19 20 // select the desired chip order 21 REQUIRED_RECIPE_VALUE (int order, "PSASTRO.CHIP.ORDER", S32, "failed to find single-chip fit order\n"); 22 23 // allowed limits for valid solutions 24 REQUIRED_RECIPE_VALUE (float maxError, "PSASTRO.MAX.ERROR", F32, "failed to find single-chip max allowed error\n"); 25 26 REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n"); 27 7 28 // find initial offset / rotation 8 29 pmAstromStats *gridStats = pmAstromGridMatch (rawstars, refstars, recipe); 9 30 if (gridStats == NULL) { 10 ps Error(PSASTRO_ERR_DATA, false, "failed to find a grid match solution\n");31 psLogMsg ("psastro", 3, "failed to find a grid match solution\n"); 11 32 return false; 12 33 } … … 16 37 pmAstromStats *stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats); 17 38 if (stats == NULL) { 18 ps Error(PSASTRO_ERR_DATA, false, "failed to measure tweaked grid solution\n");39 psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n"); 19 40 return false; 20 41 } … … 25 46 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 26 47 27 // supplied radius is in pixels 28 double RADIUS = psMetadataLookupF32 (&status, recipe, "PSASTRO.MATCH.RADIUS"); 29 if (!status) { 30 psError(PS_ERR_IO, false, "Failed to lookup matching radius"); 48 // use small radius to match stars 49 psArray *match = pmAstromRadiusMatchFP (rawstars, refstars, RADIUS); 50 if (match == NULL) { 51 psLogMsg ("psastro", 3, "failed to find radius-matched sources\n"); 52 return false; 53 } 54 55 // create the output fit model, modify the order to correspond to the actual number of 56 // matched stars: 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 if (order < 1) { 61 psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n); 62 psFree (match); 63 psFree (stats); 64 psFree (gridStats); 31 65 return false; 32 66 } 33 67 34 // correct to FP units (physical pixel scale in microns per pixel) 35 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE"); 36 if (!status) { 37 psError(PS_ERR_IO, false, "Failed to lookup pixel scale"); 38 return false; 39 } 40 RADIUS *= pixelScale; 41 42 // use small radius to match stars 43 psArray *match = pmAstromRadiusMatchFP (rawstars, refstars, RADIUS); 44 if (stats == NULL) { 45 psError(PSASTRO_ERR_UNKNOWN, false, "failed to find radius-matched sources\n"); 46 return false; 47 } 48 49 // create the output fit model 50 int order = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.ORDER"); 51 if (!status) { 52 psError(PSASTRO_ERR_UNKNOWN, false, "failed to find single-chip fit order\n"); 53 return false; 54 } 68 // set masks appropriate to the Elixir DVO astrometry format 55 69 psFree (chip->toFPA); 56 70 chip->toFPA = psPlaneTransformAlloc (order, order); … … 72 86 pmAstromFitResults *results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats); 73 87 if (!results) { 74 ps Error(PSASTRO_ERR_DATA, false, "failed to perform the matched fit\n");88 psLogMsg ("psastro", 3, "failed to perform the matched fit\n"); 75 89 return false; 76 90 } 77 91 78 // allowed limits for valid solutions 79 float maxError = psMetadataLookupF32 (&status, recipe, "PSASTRO.MAX.ERROR"); 80 int minNstar = psMetadataLookupS32 (&status, recipe, "PSASTRO.MIN.NSTAR"); 92 // toTPA converts from FPA units (microns) to TPA units (linear degrees) 93 float plateScale1 = hypot (fpa->toTPA->x->coeff[1][0], fpa->toTPA->x->coeff[0][1]); 94 float plateScale2 = hypot (fpa->toTPA->y->coeff[1][0], fpa->toTPA->y->coeff[0][1]); 95 float plateScale = 0.5*(plateScale1 + plateScale2)*3600.0; 81 96 82 // astError is the average 1D scatter in pixels ('results' are in FPA units = microns) 83 float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale; 97 // pixError is the average 1D scatter in pixels ('results' are in FPA units = microns) 98 float pixError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale; 99 100 // astError is the average 1D scatter in arcsec ('results' are in FPA units = microns) 101 float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale; 84 102 int astNstar = results->yStats->clippedNvalues; 85 103 … … 98 116 99 117 // DVO expects NASTRO = 0 if we fail to find a solution 118 psMetadataAddF32 (updates, PS_LIST_TAIL, "PERROR", PS_META_REPLACE, "astrometry error (pixels)", pixError); 119 psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR", PS_META_REPLACE, "astrometry error (arcsec)", astError); 100 120 if (validSolution) { 101 psMetadataAdd S32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "", astNstar);102 psMetadataAdd F32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", astError/sqrt(astNstar));121 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar)); 122 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", astNstar); 103 123 } else { 104 psMetadataAdd S32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "",0);105 psMetadataAdd F32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", 0.0);124 psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0); 125 psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO", PS_META_REPLACE, "number of astrometry stars", 0); 106 126 } 107 psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR", PS_META_REPLACE, "", astError); 108 psMetadataAddF32 (updates, PS_LIST_TAIL, "EQUINOX", PS_META_REPLACE, "", 2000.0); // XXX this is bogus: should be defined based on equinox of refstars 127 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 109 128 110 129 // write results
Note:
See TracChangeset
for help on using the changeset viewer.
