Changeset 12492
- Timestamp:
- Mar 18, 2007, 12:28:16 PM (19 years ago)
- Location:
- trunk/psastro/src
- Files:
-
- 15 edited
-
psastro.c (modified) (3 diffs)
-
psastro.h (modified) (1 diff)
-
psastroArguments.c (modified) (1 diff)
-
psastroAstromGuess.c (modified) (1 diff)
-
psastroChipAstrom.c (modified) (1 diff)
-
psastroCleanup.c (modified) (1 diff)
-
psastroDemoDump.c (modified) (1 diff)
-
psastroLoadRefstars.c (modified) (1 diff)
-
psastroMosaicAstrom.c (modified) (4 diffs)
-
psastroMosaicGetGrads.c (modified) (2 diffs)
-
psastroMosaicGradients.c (modified) (3 diffs)
-
psastroMosaicRescaleChips.c (modified) (1 diff)
-
psastroOneChip.c (modified) (4 diffs)
-
psastroRefstarSubset.c (modified) (1 diff)
-
psastroUtils.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastro.c
r11354 r12492 7 7 8 8 int main (int argc, char **argv) { 9 10 pmConfig *config = NULL; 11 psArray *refs = NULL; 9 12 10 13 psTimerStart ("complete"); … … 17 20 18 21 // load configuration information 19 pmConfig *config = psastroArguments (argc, argv);22 config = psastroArguments (argc, argv); 20 23 if (!config) usage (); 21 24 … … 41 44 42 45 // load the reference stars overlapping the data stars 43 psArray *refs = psastroLoadRefstars (config);46 refs = psastroLoadRefstars (config); 44 47 if (!refs) { 45 48 psErrorStackPrint(stderr, "failed to load reference data\n"); -
trunk/psastro/src/psastro.h
r11551 r12492 78 78 bool psastroDumpRefstars (psArray *refstars, char *filename); 79 79 bool psastroDumpMatches (pmFPA *fpa, char *filename); 80 bool psastroDumpStars (psArray *stars, char *filename); 80 81 81 82 bool psastroMosaicSetAstrom_tmp (pmFPA *fpa); -
trunk/psastro/src/psastroArguments.c
r11009 r12492 32 32 if ((N = psArgumentGet (argc, argv, "-chip"))) { 33 33 psArgumentRemove (N, &argc, argv); 34 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_META_REPLACE, "", psStringCopy(argv[N]));34 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_META_REPLACE, "", argv[N]); 35 35 psArgumentRemove (N, &argc, argv); 36 36 } -
trunk/psastro/src/psastroAstromGuess.c
r12450 r12492 40 40 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE"); 41 41 if (!status) { 42 psError(PS_ERR_IO, false, "Failed to lookup pixel scale");42 psError(PS_ERR_IO, true, "Failed to lookup pixel scale"); 43 43 return false; 44 44 } -
trunk/psastro/src/psastroChipAstrom.c
r10880 r12492 52 52 } 53 53 54 char *filename = NULL; 55 char *chipname = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME"); 56 57 psStringAppend (&filename, "rawstars.ch.%s.dat", chipname); 58 psastroDumpStars (rawstars, filename); 59 psFree (filename); 60 filename = NULL; 61 62 psStringAppend (&filename, "refstars.ch.%s.dat", chipname); 63 psastroDumpStars (refstars, filename); 64 psFree (filename); 65 filename = NULL; 66 54 67 // save WCS and analysis metadata in update header 55 68 psMetadata *updates = psMetadataAlloc(); -
trunk/psastro/src/psastroCleanup.c
r11273 r12492 12 12 pmConceptsDone (); 13 13 pmConfigDone (); 14 //fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psastro");15 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psastro");14 fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psastro"); 15 // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psastro"); 16 16 17 17 return; -
trunk/psastro/src/psastroDemoDump.c
r11467 r12492 1 1 # include "psastro.h" 2 3 // this function is used for test purposes (-trace psastro.dump.psastroAstromGuess 1) 4 bool psastroDumpStars (psArray *stars, char *filename) { 5 6 FILE *f = fopen (filename, "w"); 7 8 for (int i = 0; i < stars->n; i++) { 9 pmAstromObj *obj = stars->data[i]; 10 11 // write out the upward projections 12 fprintf (f, "%d %f %f %f %f %f %f %f %f %f\n", i, 13 obj->sky->r, obj->sky->d, obj->Mag, 14 obj->TP->x, obj->TP->y, 15 obj->FP->x, obj->FP->y, 16 obj->chip->x, obj->chip->y); 17 } 18 fclose (f); 19 return true; 20 } 2 21 3 22 // this function is used for test purposes (-trace psastro.dump.psastroAstromGuess 1) 4 23 bool psastroDumpRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip) { 5 24 6 FILE *f1 = fopen ("rawstars.dat", "w"); 7 FILE *f2 = fopen ("rawstars.down.dat", "w"); 25 char *filename = NULL; 26 char *chipname = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME"); 27 28 psStringAppend (&filename, "rawstars.up.%s.dat", chipname); 29 FILE *f1 = fopen (filename, "w"); 30 psFree (filename); 31 filename = NULL; 32 33 psStringAppend (&filename, "rawstars.dn.%s.dat", chipname); 34 FILE *f2 = fopen (filename, "w"); 35 psFree (filename); 36 filename = NULL; 8 37 9 38 for (int i = 0; i < rawstars->n; i++) { -
trunk/psastro/src/psastroLoadRefstars.c
r12352 r12492 54 54 // XXX set getstar in config? 55 55 // psStringAppend (&getstarLine, "/home/kiawe/eugene/psconfig/dev.lin64/bin/getstar %s -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", catformat, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile); 56 psStringAppend (&getstarLine, " getstar %s -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", catformat, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile);56 psStringAppend (&getstarLine, "/home/kiawe/eugene/psconfig/dev.lin64/bin/getstar %s -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", catformat, MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile); 57 57 psTrace ("psastro", 3, "%s\n", getstarLine); 58 58 -
trunk/psastro/src/psastroMosaicAstrom.c
r10922 r12492 5 5 bool psastroMosaicAstrom (pmConfig *config, psArray *refs) { 6 6 7 bool status; 8 7 9 // select the current recipe 8 10 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE); 9 11 if (!recipe) { 10 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe!\n");12 psError(PSASTRO_ERR_CONFIG, false, "Can't find PSASTRO recipe!\n"); 11 13 return false; 12 14 } 15 16 // physical pixel scale in microns per pixel 17 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE"); 18 if (!status) { 19 psError(PS_ERR_IO, false, "Failed to lookup pixel scale"); 20 return false; 21 } 13 22 14 23 // select the input data sources 15 24 pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 16 25 if (!input) { 17 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data!\n");26 psError(PSASTRO_ERR_CONFIG, false, "Can't find input data!\n"); 18 27 return false; 19 28 } … … 27 36 // given the existing per-chip astrometry, determine matches between raw and ref stars 28 37 // is this needed? yes, if we didn't do SingleChip astrometry first 29 psastroMosaicSetMatch (fpa, recipe, 0); 38 if (!psastroMosaicSetMatch (fpa, recipe, 0)) { 39 psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic"); 40 return false; 41 } 30 42 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.0.dat"); } 31 43 … … 33 45 // modify the chip->toFPA scaling to match knowledge about pixel scale, 34 46 // then recalculate raw and ref positions 35 psastroMosaicCommonScale (fpa, recipe); 47 if (!psastroMosaicCommonScale (fpa, recipe)) { 48 psError(PSASTRO_ERR_UNKNOWN, false, "failed to set a common scale for the chips"); 49 return false; 50 } 36 51 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.1.dat"); } 37 52 … … 39 54 // apply the new distortion terms up and down 40 55 // refit the per-chip terms with linear fits only 41 psastroMosaicGradients (fpa, recipe); 56 if (!psastroMosaicGradients (fpa, recipe)) { 57 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure mosaic gradients"); 58 return false; 59 } 42 60 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.2.dat"); } 43 61 44 psastroMosaicChipAstrom (fpa, recipe, false); 62 // measure the astrometry for the chips under the distortion term 63 if (!psastroMosaicChipAstrom (fpa, recipe, false)) { 64 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode"); 65 return false; 66 } 45 67 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.3.dat"); } 46 68 47 // re-perform the match with a slightly tighter circle 48 psastroMosaicSetMatch (fpa, recipe, 1); 69 // do a second pass on the distortion with improved chip positions and rotations 70 // first, re-perform the match with a slightly tighter circle 71 if (!psastroMosaicSetMatch (fpa, recipe, 1)) { 72 psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (2nd pass)"); 73 return false; 74 } 75 if (!psastroMosaicCommonScale (fpa, recipe)) { 76 psError(PSASTRO_ERR_UNKNOWN, false, "failed to set a common scale for the chips (2nd pass)"); 77 return false; 78 } 79 if (!psastroMosaicGradients (fpa, recipe)) { 80 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure mosaic gradients (2nd pass)"); 81 return false; 82 } 83 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.4.dat"); } 49 84 50 // do a second pass on the distortion with improved chip positions and rotations51 psastroMosaicCommonScale (fpa, recipe);52 psastroMosaicGradients (fpa, recipe);53 psastroMosaicChipAstrom (fpa, recipe, false);54 psastroMosaicSetMatch (fpa, recipe, 1);55 85 if (!psastroMosaicChipAstrom (fpa, recipe, false)) { 86 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (2nd pass)"); 87 return false; 88 } 89 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.5.dat"); } 90 56 91 // now fit the chips under the common distortion with higher-order terms 57 92 // first, re-perform the match with a slightly tighter circle 58 psastroMosaicChipAstrom (fpa, recipe, true); 93 if (!psastroMosaicSetMatch (fpa, recipe, 1)) { 94 psError(PSASTRO_ERR_UNKNOWN, false, "failed to match raw and ref stars for mosaic (3rd pass)"); 95 return false; 96 } 97 if (!psastroMosaicChipAstrom (fpa, recipe, true)) { 98 psError(PSASTRO_ERR_UNKNOWN, false, "failed to measure chip astrometry in mosaic mode (3rd pass)"); 99 return false; 100 } 101 if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.6.dat"); } 59 102 60 // save WCS and analysis metadata in update header 103 // save WCS and analysis metadata in update header XXX this is still wrong: the pmFPAExtent 104 // function returns the FP dimensions in pixel units relative to the 0,0 corner of chip 105 // 0,0. I need to have a function which loops over all cells, determines the pixel 106 // dimensions for each cell, converts them to chip pixels, then uses the fpa astrometry 107 // structures to get the total dimensions of the fpa in fpa units. equivalent to 108 // pmFPAExtent 109 psRegion *region = pmFPAExtent (fpa); 110 region->x0 *= pixelScale; 111 region->x1 *= pixelScale; 112 region->y0 *= pixelScale; 113 region->y1 *= pixelScale; 114 61 115 // XXX also need to add DATE/TIME info and NAXIS1, NAXIS2 62 116 psMetadata *updates = psMetadataAlloc(); 63 psMetadataAddS32 (updates, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "fpa dimensions (um)", 30000); 64 psMetadataAddS32 (updates, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "fpa dimensions (um)", 30000); 65 psMetadataAddStr (updates, PS_LIST_TAIL, "DATE-OBS", PS_META_REPLACE, "date", "2003-08-28"); 66 psMetadataAddStr (updates, PS_LIST_TAIL, "UTC-OBS", PS_META_REPLACE, "date", "7:15:46.47"); 117 psMetadataAddS32 (updates, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "fpa dimensions (mm)", region->x1 - region->x0); 118 psMetadataAddS32 (updates, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "fpa dimensions (mm)", region->y1 - region->y0); 119 psFree (region); 67 120 68 pmAstromWriteBilevelMosaic (updates, fpa, NONLIN_TOL); 121 if (!pmAstromWriteBilevelMosaic (updates, fpa, NONLIN_TOL)) { 122 psAbort ("failed to save header terms"); 123 } 124 69 125 psMetadataAddMetadata (fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER", PS_META_REPLACE, "psastro header stats", updates); 70 126 psFree (updates); -
trunk/psastro/src/psastroMosaicGetGrads.c
r9574 r12492 15 15 if (!chip->process || !chip->file_exists) { continue; } 16 16 17 psRegion *region = pmChipExtent (chip); 18 17 19 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 18 20 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); … … 36 38 37 39 // measure the local gradients for this set of stars 38 // XXX update the function prototype to accept an incoming gradient structure to which the new elements are added39 grads = pmAstromMeasureGradients (grads, rawstars, refstars, match, re cipe);40 // the new elements are added to the incoming gradient structure 41 grads = pmAstromMeasureGradients (grads, rawstars, refstars, match, region, 2, 2); 40 42 } 41 43 } 44 psFree (region); 42 45 } 43 46 return (grads); -
trunk/psastro/src/psastroMosaicGradients.c
r10880 r12492 16 16 if (!chip->process || !chip->file_exists) { continue; } 17 17 18 psRegion *region = pmChipExtent (chip); 19 18 20 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 19 21 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); … … 37 39 38 40 // measure the local gradients for this set of stars 39 gradients = pmAstromMeasureGradients (gradients, rawstars, refstars, match, recipe); 41 // XXX 2,2 are the number of test boxes on the chip. put this in the recipe 42 gradients = pmAstromMeasureGradients (gradients, rawstars, refstars, match, region, 2, 2); 40 43 } 41 44 } 45 psFree (region); 42 46 } 43 47 … … 59 63 } 60 64 65 // physical pixel scale in microns per pixel (FP is in physical units, chip is in pixels) 66 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE"); 67 if (!status) { 68 psError(PS_ERR_IO, false, "Failed to lookup pixel scale"); 69 return false; 70 } 71 61 72 // fit the measured gradients with the telescope distortion model (polynomial order based on toTPA) 62 pmAstromFitDistortion (fpa, gradients, recipe); 63 psastroMosaicSetAstrom (fpa); 73 if (!pmAstromFitDistortion (fpa, gradients, pixelScale)) { 74 psError(PSASTRO_ERR_UNKNOWN, false, "failed to fit the distortion terms\n"); 75 psFree (gradients); 76 psFree (view); 77 return false; 78 } 79 80 if (!psastroMosaicSetAstrom (fpa)) { 81 psError(PSASTRO_ERR_UNKNOWN, false, "failed to apply mosaic distortion terms\n"); 82 psFree (gradients); 83 psFree (view); 84 return false; 85 } 64 86 65 87 psFree (gradients); -
trunk/psastro/src/psastroMosaicRescaleChips.c
r10815 r12492 1 1 # include "psastro.h" 2 3 // XXX this file is no longer used 2 4 3 5 // XXX what is this doing? -
trunk/psastro/src/psastroOneChip.c
r11470 r12492 10 10 11 11 bool status; 12 pmAstromStats *gridStats = NULL; 13 pmAstromStats *stats = NULL; 12 14 13 15 // supplied radius is in pixels … … 25 27 REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n"); 26 28 27 // find initial offset / rotation 28 pmAstromStats *gridStats = pmAstromGridMatch (rawstars, refstars, recipe); 29 if (gridStats == NULL) { 30 psLogMsg ("psastro", 3, "failed to find a grid match solution\n"); 31 return false; 29 // do we need to get a rough initial match? 30 REQUIRED_RECIPE_VALUE (bool gridSearch, "PSASTRO.GRID.SEARCH", Bool, "failed to find chip grid-search option\n"); 31 32 if (gridSearch) { 33 // find initial offset / rotation 34 gridStats = pmAstromGridMatch (rawstars, refstars, recipe); 35 if (gridStats == NULL) { 36 psLogMsg ("psastro", 3, "failed to find a grid match solution\n"); 37 return false; 38 } 39 psLogMsg ("psastro", 3, "basic grid search result - offset: %f,%f pixels, rotation: %f deg\n", gridStats->offset.x, gridStats->offset.y, DEG_RAD*gridStats->angle); 40 41 // tweak the position by finding peak of matches stars 42 stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats); 43 if (stats == NULL) { 44 psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n"); 45 psFree (gridStats); 46 return false; 47 } 48 psLogMsg ("psastro", 3, "tweak grid search result - offset: %f,%f pixels, rotation: %f deg\n", stats->offset.x, stats->offset.y, DEG_RAD*stats->angle); 49 50 // adjust the chip.toFPA terms only 51 pmAstromGridApply (chip->toFPA, stats); 52 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars); 32 53 } 33 psLogMsg ("psastro", 3, "basic grid search result - offset: %f,%f pixels, rotation: %f deg\n", gridStats->offset.x, gridStats->offset.y, DEG_RAD*gridStats->angle);34 35 // tweak the position by finding peak of matches stars36 pmAstromStats *stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats);37 if (stats == NULL) {38 psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n");39 return false;40 }41 psLogMsg ("psastro", 3, "tweak grid search result - offset: %f,%f pixels, rotation: %f deg\n", stats->offset.x, stats->offset.y, DEG_RAD*stats->angle);42 43 // adjust the chip.toFPA terms only44 pmAstromGridApply (chip->toFPA, stats);45 psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);46 54 47 55 // use small radius to match stars … … 49 57 if (match == NULL) { 50 58 psLogMsg ("psastro", 3, "failed to find radius-matched sources\n"); 59 psFree (stats); 60 psFree (gridStats); 51 61 return false; 52 62 } … … 85 95 if (!results) { 86 96 psLogMsg ("psastro", 3, "failed to perform the matched fit\n"); 97 psFree (match); 98 psFree (stats); 99 psFree (fitStats); 100 psFree (gridStats); 87 101 return false; 88 102 } -
trunk/psastro/src/psastroRefstarSubset.c
r11471 r12492 56 56 57 57 if (psTraceGetLevel("psastro.dump") > 0) { 58 psastroDumpRefstars (subset, "refstars.subset.dat"); 58 pmChip *chip = readout->parent->parent; 59 60 char *filename = NULL; 61 char *chipname = psMetadataLookupStr (NULL, chip->concepts, "CHIP.NAME"); 62 psStringAppend (&filename, "refstars.%s.dat", chipname); 63 psastroDumpRefstars (subset, filename); 64 psFree (filename); 59 65 } 60 66 -
trunk/psastro/src/psastroUtils.c
r11532 r12492 79 79 bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip, psArray *rawstars, psArray *refstars) { 80 80 81 // XXX this region needs to be defined more intelligently 82 // psRegion *region = pmChipExtent (chip); 83 psRegion *region = psRegionAlloc (0, 2000, 0, 2000); 84 81 psRegion *region = pmChipExtent (chip); 82 region->x1 -= region->x0; 83 region->y1 -= region->y0; 84 region->x0 = 0; 85 region->y0 = 0; 85 86 psFree (chip->fromFPA); 86 87 chip->fromFPA = psPlaneTransformInvert (NULL, chip->toFPA, *region, 20); 87 88 // PS_POLY_PRINT_2D(chip->toFPA->x); 89 // PS_POLY_PRINT_2D(chip->toFPA->y); 90 91 // PS_POLY_PRINT_2D(chip->fromFPA->x); 92 // PS_POLY_PRINT_2D(chip->fromFPA->y); 88 psFree (region); 93 89 94 90 for (int i = 0; i < rawstars->n; i++) { … … 105 101 } 106 102 107 psFree (region);108 103 return true; 109 104 }
Note:
See TracChangeset
for help on using the changeset viewer.
