IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 24, 2006, 3:56:53 PM (20 years ago)
Author:
eugene
Message:

finished up the mosaic astrometry code

File:
1 edited

Legend:

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

    r10789 r10830  
    2525    psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    2626
     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");
     31        return false;
     32    }
     33
     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
    2742    // use small radius to match stars
    28     psArray *match = pmAstromRadiusMatch (rawstars, refstars, recipe);
     43    psArray *match = pmAstromRadiusMatchFP (rawstars, refstars, RADIUS);
    2944    if (stats == NULL) {
    3045        psError(PSASTRO_ERR_UNKNOWN, false, "failed to find radius-matched sources\n");
     
    3247    }
    3348
    34     int nX = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NX");
    35     if (!status) nX = 1;
    36 
    37     int nY = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NY");
    38     if (!status) nY = 1;
    39 
    40     psPlaneTransform *toFPAout = psPlaneTransformAlloc (nX, nY);
    41 
    42     // improved fit for astrometric terms
    43     if (!pmAstromMatchFit (toFPAout, rawstars, refstars, match, recipe, updates)) {
    44         psError(PSASTRO_ERR_DATA, false, "failed to find a valid fitted match solution\n");
     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");
    4553        return false;
    4654    }
    4755    psFree (chip->toFPA);
    48     chip->toFPA = toFPAout;
     56    chip->toFPA = psPlaneTransformAlloc (order, order);
     57    for (int i = 0; i <= chip->toFPA->x->nX; i++) {
     58        for (int j = 0; j <= chip->toFPA->x->nY; j++) {
     59            if (i + j > order) {
     60                chip->toFPA->x->mask[i][j] = 1;
     61                chip->toFPA->y->mask[i][j] = 1;
     62            }
     63        }
     64    }
    4965
    50     // write results
     66    // XXX allow statitic to be set by the user
     67    psStats *fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     68    fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");
     69    fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");
     70
     71    // improved fit for astrometric terms
     72    pmAstromFitResults *results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats);
     73    if (!results) {
     74        psError(PSASTRO_ERR_DATA, false, "failed to perform the matched fit\n");
     75        return false;
     76    }
     77   
     78    // allowed limits for valid solutions
     79    float maxError = psMetadataLookupF32 (&status, recipe, "PSASTRO.MAX.ERROR");
     80    int minNstar = psMetadataLookupS32 (&status, recipe, "PSASTRO.MIN.NSTAR");
     81
     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;
     84    int astNstar = results->yStats->clippedNvalues;
     85
     86    bool validSolution = true;
     87
     88    // XXX should these result in errors or be handled another way?
     89    psLogMsg ("psastro", PS_LOG_INFO, "astrometry solution: error: %f, Nstars: %d", astError, astNstar);
     90    if (astError > maxError) {
     91        psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError);
     92        validSolution = false;
     93    }
     94    if (astNstar < minNstar) {
     95        psLogMsg("psastro", PS_LOG_INFO, "solution uses too few stars: %d < %d", astNstar, minNstar);
     96        validSolution = false;
     97    }
     98
     99    // DVO expects NASTRO = 0 if we fail to find a solution
     100    if (validSolution) {
     101        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "", astNstar);
     102        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", astError/sqrt(astNstar));
     103    } else {
     104        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "", 0);
     105        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", 0.0);
     106    }
     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
     109
     110// write results
    51111    psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    52112
    53113    psFree (match);
    54114    psFree (stats);
     115    psFree (results);
     116    psFree (fitStats);
    55117    psFree (gridStats);
    56118    return true;
Note: See TracChangeset for help on using the changeset viewer.