IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12492


Ignore:
Timestamp:
Mar 18, 2007, 12:28:16 PM (19 years ago)
Author:
eugene
Message:

a variety of fixes to get psastro working in chip and mosaic mode

  • various memory leaks
  • when loading mosaic data, the modification of the WCS for the common focal-plane scale was getting the offset wrong (fixed in psModules)
  • added some debugging dump; more plots still needed
  • error handling in psastroMosaicAstrom
  • loading chip and fpa dimensions from concepts
  • now reading chip concepts when reading objects (in psModules)
  • now supplying region and subdivisions for gradient measurements
  • grid search is now optional

-

Location:
trunk/psastro/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psastro.c

    r11354 r12492  
    77
    88int main (int argc, char **argv) {
     9
     10    pmConfig *config = NULL;
     11    psArray *refs = NULL;
    912
    1013    psTimerStart ("complete");
     
    1720
    1821    // load configuration information
    19     pmConfig *config = psastroArguments (argc, argv);
     22    config = psastroArguments (argc, argv);
    2023    if (!config) usage ();
    2124
     
    4144
    4245    // load the reference stars overlapping the data stars
    43     psArray *refs = psastroLoadRefstars (config);
     46    refs = psastroLoadRefstars (config);
    4447    if (!refs) {
    4548        psErrorStackPrint(stderr, "failed to load reference data\n");
  • trunk/psastro/src/psastro.h

    r11551 r12492  
    7878bool psastroDumpRefstars (psArray *refstars, char *filename);
    7979bool psastroDumpMatches (pmFPA *fpa, char *filename);
     80bool psastroDumpStars (psArray *stars, char *filename);
    8081
    8182bool psastroMosaicSetAstrom_tmp (pmFPA *fpa);
  • trunk/psastro/src/psastroArguments.c

    r11009 r12492  
    3232    if ((N = psArgumentGet (argc, argv, "-chip"))) {
    3333        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]);
    3535        psArgumentRemove (N, &argc, argv);
    3636    }
  • trunk/psastro/src/psastroAstromGuess.c

    r12450 r12492  
    4040    double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
    4141    if (!status) {
    42         psError(PS_ERR_IO, false, "Failed to lookup pixel scale");
     42        psError(PS_ERR_IO, true, "Failed to lookup pixel scale");
    4343        return false;
    4444    }
  • trunk/psastro/src/psastroChipAstrom.c

    r10880 r12492  
    5252                }
    5353
     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
    5467                // save WCS and analysis metadata in update header
    5568                psMetadata *updates = psMetadataAlloc();
  • trunk/psastro/src/psastroCleanup.c

    r11273 r12492  
    1212    pmConceptsDone ();
    1313    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");
    1616
    1717    return;
  • trunk/psastro/src/psastroDemoDump.c

    r11467 r12492  
    11# include "psastro.h"
     2
     3// this function is used for test purposes (-trace psastro.dump.psastroAstromGuess 1)
     4bool 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}
    221
    322// this function is used for test purposes (-trace psastro.dump.psastroAstromGuess 1)
    423bool psastroDumpRawstars (psArray *rawstars, pmFPA *fpa, pmChip *chip) {
    524
    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;
    837
    938    for (int i = 0; i < rawstars->n; i++) {
  • trunk/psastro/src/psastroLoadRefstars.c

    r12352 r12492  
    5454    // XXX set getstar in config?
    5555    // 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);
    5757    psTrace ("psastro", 3, "%s\n", getstarLine);
    5858
  • trunk/psastro/src/psastroMosaicAstrom.c

    r10922 r12492  
    55bool psastroMosaicAstrom (pmConfig *config, psArray *refs) {
    66
     7    bool status;
     8
    79    // select the current recipe
    810    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSASTRO_RECIPE);
    911    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");
    1113        return false;
    1214    }
     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    }
    1322
    1423    // select the input data sources
    1524    pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
    1625    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");
    1827        return false;
    1928    }
     
    2736    // given the existing per-chip astrometry, determine matches between raw and ref stars
    2837    // 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    }
    3042    if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.0.dat"); }
    3143
     
    3345    // modify the chip->toFPA scaling to match knowledge about pixel scale,
    3446    // 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    }
    3651    if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.1.dat"); }
    3752
     
    3954    // apply the new distortion terms up and down
    4055    // 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    }
    4260    if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.2.dat"); }
    4361
    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    }
    4567    if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.3.dat"); }
    4668
    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"); }
    4984
    50     // do a second pass on the distortion with improved chip positions and rotations
    51     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
    5691    // now fit the chips under the common distortion with higher-order terms
    5792    // 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"); }
    59102
    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
    61115    // XXX also need to add DATE/TIME info and NAXIS1, NAXIS2
    62116    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);
    67120   
    68     pmAstromWriteBilevelMosaic (updates, fpa, NONLIN_TOL);
     121    if (!pmAstromWriteBilevelMosaic (updates, fpa, NONLIN_TOL)) {
     122        psAbort ("failed to save header terms");
     123    }
     124
    69125    psMetadataAddMetadata (fpa->analysis, PS_LIST_TAIL, "PSASTRO.HEADER",  PS_META_REPLACE, "psastro header stats", updates);
    70126    psFree (updates);
  • trunk/psastro/src/psastroMosaicGetGrads.c

    r9574 r12492  
    1515        if (!chip->process || !chip->file_exists) { continue; }
    1616       
     17        psRegion *region = pmChipExtent (chip);
     18
    1719        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    1820            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     
    3638
    3739                // 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 added
    39                 grads = pmAstromMeasureGradients (grads, rawstars, refstars, match, recipe);
     40                // the new elements are added to the incoming gradient structure
     41                grads = pmAstromMeasureGradients (grads, rawstars, refstars, match, region, 2, 2);
    4042            }
    4143        }
     44        psFree (region);
    4245    }
    4346    return (grads);
  • trunk/psastro/src/psastroMosaicGradients.c

    r10880 r12492  
    1616        if (!chip->process || !chip->file_exists) { continue; }
    1717       
     18        psRegion *region = pmChipExtent (chip);
     19
    1820        while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) {
    1921            psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     
    3739
    3840                // 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);
    4043            }
    4144        }
     45        psFree (region);
    4246    }
    4347
     
    5963    }
    6064
     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
    6172    // 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    }
    6486
    6587    psFree (gradients);
  • trunk/psastro/src/psastroMosaicRescaleChips.c

    r10815 r12492  
    11# include "psastro.h"
     2
     3// XXX this file is no longer used
    24
    35// XXX what is this doing?
  • trunk/psastro/src/psastroOneChip.c

    r11470 r12492  
    1010
    1111    bool status;
     12    pmAstromStats *gridStats = NULL;
     13    pmAstromStats *stats = NULL;
    1214
    1315    // supplied radius is in pixels
     
    2527    REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n");
    2628
    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);
    3253    }
    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 stars
    36     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 only
    44     pmAstromGridApply (chip->toFPA, stats);
    45     psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    4654
    4755    // use small radius to match stars
     
    4957    if (match == NULL) {
    5058        psLogMsg ("psastro", 3, "failed to find radius-matched sources\n");
     59        psFree (stats);
     60        psFree (gridStats);
    5161        return false;
    5262    }
     
    8595    if (!results) {
    8696        psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
     97        psFree (match);
     98        psFree (stats);
     99        psFree (fitStats);
     100        psFree (gridStats);
    87101        return false;
    88102    }
  • trunk/psastro/src/psastroRefstarSubset.c

    r11471 r12492  
    5656
    5757  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);
    5965  }
    6066
  • trunk/psastro/src/psastroUtils.c

    r11532 r12492  
    7979bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip, psArray *rawstars, psArray *refstars) {
    8080
    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;
    8586    psFree (chip->fromFPA);
    8687    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);
    9389
    9490    for (int i = 0; i < rawstars->n; i++) {
     
    105101    }
    106102
    107     psFree (region);
    108103    return true;
    109104}
Note: See TracChangeset for help on using the changeset viewer.