IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 28, 2009, 1:36:37 PM (18 years ago)
Author:
beaumont
Message:

Added QA plots to ppSub. Migrated psastro QA plots to psModules/extras.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branch_20090113/psastro/src/psastroOneChipFit.c

    r20805 r21208  
    1111
    1212    // default value for match/fit : radius is in pixels
    13     REQUIRED_RECIPE_VALUE (double RADIUS, "PSASTRO.MATCH.RADIUS", F32); 
     13    REQUIRED_RECIPE_VALUE (double RADIUS, "PSASTRO.MATCH.RADIUS", F32);
    1414
    1515    // run the match/fit sequence NITER times
    16     REQUIRED_RECIPE_VALUE (int nIter, "PSASTRO.MATCH.FIT.NITER", S32); 
     16    REQUIRED_RECIPE_VALUE (int nIter, "PSASTRO.MATCH.FIT.NITER", S32);
    1717
    1818    // correct radius to FP units (physical pixel scale in microns per pixel)
    19     REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32); 
     19    REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32);
    2020    RADIUS *= pixelScale;
    2121
     
    3232
    3333    for (int iter = 0; iter < nIter; iter++) {
    34        
    35         char name[128];
    3634
    37         sprintf (name, "PSASTRO.MATCH.RADIUS.N%d", iter);
    38         float radius = psMetadataLookupF32 (&status, recipe, name);
    39         radius *= pixelScale;
    40         if (!status || (radius == 0.0)) {
    41             radius = RADIUS;
    42         }
     35        char name[128];
     36
     37        sprintf (name, "PSASTRO.MATCH.RADIUS.N%d", iter);
     38        float radius = psMetadataLookupF32 (&status, recipe, name);
     39        radius *= pixelScale;
     40        if (!status || (radius == 0.0)) {
     41            radius = RADIUS;
     42        }
    4343
    4444
    45         // use small radius to match stars
    46         match = pmAstromRadiusMatchFP (rawstars, refstars, radius);
    47         if (match == NULL) {
    48             psLogMsg ("psastro", 3, "failed to find radius-matched sources\n");
    49             return false;
    50         }
     45        // use small radius to match stars
     46        match = pmAstromRadiusMatchFP (rawstars, refstars, radius);
     47        if (match == NULL) {
     48            psLogMsg ("psastro", 3, "failed to find radius-matched sources\n");
     49            return false;
     50        }
    5151
    52         // modify the order to correspond to the actual number of matched stars:
    53         int Ndof_min = 3;
    54         int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1));
    55         order = PS_MIN (order, order_max);
     52        // modify the order to correspond to the actual number of matched stars:
     53        int Ndof_min = 3;
     54        int order_max = 0.5*(3 + sqrt(4*match->n - 4*Ndof_min + 1));
     55        order = PS_MIN (order, order_max);
    5656
    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;
     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;
    6060
    61         if (order < 1) {
    62             psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n);
    63             psFree (match);
    64             return false;
    65         }
     61        if (order < 1) {
     62            psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n);
     63            psFree (match);
     64            return false;
     65        }
    6666
    67         // create output toFPA; set masks appropriate to the Elixir DVO astrometry format
    68         psFree (chip->toFPA);
    69         chip->toFPA = psPlaneTransformAlloc (order, order);
    70         for (int i = 0; i <= chip->toFPA->x->nX; i++) {
    71             for (int j = 0; j <= chip->toFPA->x->nY; j++) {
    72                 if (i + j > order) {
    73                     chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET;
    74                     chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET;
    75                 }
    76             }
    77         }
     67        // create output toFPA; set masks appropriate to the Elixir DVO astrometry format
     68        psFree (chip->toFPA);
     69        chip->toFPA = psPlaneTransformAlloc (order, order);
     70        for (int i = 0; i <= chip->toFPA->x->nX; i++) {
     71            for (int j = 0; j <= chip->toFPA->x->nY; j++) {
     72                if (i + j > order) {
     73                    chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET;
     74                    chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET;
     75                }
     76            }
     77        }
    7878
    79         // XXX allow statitic to be set by the user
    80         // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    81         fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    82         fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");
    83         fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");
     79        // XXX allow statitic to be set by the user
     80        // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     81        fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     82        fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");
     83        fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");
    8484
    85         // improved fit for astrometric terms
    86         results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats);
    87         if (!results) {
    88             psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
    89             psFree (match);
    90             psFree (fitStats);
    91             return false;
    92         }
    93    
    94         // determine fromFPA transformation and apply new transformation to raw & ref stars
    95         psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    96    
    97         // toSky converts from FPA & TPA units (microns) to sky units (radians)
    98         float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD;
    99         // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;
    100         float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale;
    101         int astNstar = results->yStats->clippedNvalues;
    102         psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar);
     85        // improved fit for astrometric terms
     86        results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats);
     87        if (!results) {
     88            psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
     89            psFree (match);
     90            psFree (fitStats);
     91            return false;
     92        }
    10393
    104         if (iter < nIter - 1) {
    105             psFree (fitStats);
    106             psFree (results);
    107             psFree (match);
    108         }
     94        // determine fromFPA transformation and apply new transformation to raw & ref stars
     95        psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
     96
     97        // toSky converts from FPA & TPA units (microns) to sky units (radians)
     98        float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD;
     99        // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;
     100        float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale;
     101        int astNstar = results->yStats->clippedNvalues;
     102        psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar);
     103
     104        if (iter < nIter - 1) {
     105            psFree (fitStats);
     106            psFree (results);
     107            psFree (match);
     108        }
    109109    }
    110110
     
    127127    if (astError > maxError) {
    128128        psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError);
    129         validSolution = false;
     129        validSolution = false;
    130130    }
    131131    if (astNstar < minNstar) {
    132132        psLogMsg("psastro", PS_LOG_INFO, "solution uses too few stars: %d < %d", astNstar, minNstar);
    133         validSolution = false;
     133        validSolution = false;
    134134    }
    135135
     
    138138    psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR",   PS_META_REPLACE, "astrometry error (arcsec)", astError);
    139139    if (validSolution) {
    140         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));
    141         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", astNstar);
     140        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));
     141        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", astNstar);
    142142    } else {
    143         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);
    144         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", 0);
     143        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);
     144        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", 0);
    145145    }
    146146    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
     
    148148    // XXX drop from here : determine fromFPA transformation and apply new transformation to raw & ref stars
    149149    // psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    150    
     150
    151151    // XXX check if we correctly applied the new transformation:
    152152    if (psTraceGetLevel("psastro.dump") > 0) {
    153         psastroDumpRawstars (rawstars, fpa, chip);
    154         psastroDumpMatchedStars ("match.dat", rawstars, refstars, match);
    155         psastroDumpStars (refstars, "refstars.cal.dat");
     153        psastroDumpRawstars (rawstars, fpa, chip);
     154        psastroDumpMatchedStars ("match.dat", rawstars, refstars, match);
     155        psastroDumpStars (refstars, "refstars.cal.dat");
    156156    }
    157157
    158     psastroVisualPlotOneChipFit (rawstars, refstars, match, recipe);
     158    pmAstromVisualPlotOneChipFit (rawstars, refstars, match, recipe);
    159159
    160160    if (psTraceGetLevel("psastro.plot") > 0) {
    161         psastroPlotOneChipFit (rawstars, refstars, match, recipe);
     161        psastroPlotOneChipFit (rawstars, refstars, match, recipe);
    162162    }
    163163
Note: See TracChangeset for help on using the changeset viewer.