IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

-

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.