IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 18, 2008, 2:26:45 PM (18 years ago)
Author:
beaumont
Message:

Updates to psastro to include plotting calls

File:
1 edited

Legend:

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

    r16070 r20263  
    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         if ((match->n < 11) && (order >= 3)) order = 2;
    54         if ((match->n <  7) && (order >= 2)) order = 1;
    55         if ((match->n <  4) && (order >= 1)) order = 0;
    56         if (order < 1) {
    57             psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n);
    58             psFree (match);
    59             return false;
    60         }
     52        // modify the order to correspond to the actual number of matched stars:
     53        if ((match->n < 11) && (order >= 3)) order = 2;
     54        if ((match->n <  7) && (order >= 2)) order = 1;
     55        if ((match->n <  4) && (order >= 1)) order = 0;
     56        if (order < 1) {
     57            psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n);
     58            psFree (match);
     59            return false;
     60        }
    6161
    62         // create output toFPA; set masks appropriate to the Elixir DVO astrometry format
    63         psFree (chip->toFPA);
    64         chip->toFPA = psPlaneTransformAlloc (order, order);
    65         for (int i = 0; i <= chip->toFPA->x->nX; i++) {
    66             for (int j = 0; j <= chip->toFPA->x->nY; j++) {
    67                 if (i + j > order) {
    68                     chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET;
    69                     chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET;
    70                 }
    71             }
    72         }
     62        // create output toFPA; set masks appropriate to the Elixir DVO astrometry format
     63        psFree (chip->toFPA);
     64        chip->toFPA = psPlaneTransformAlloc (order, order);
     65        for (int i = 0; i <= chip->toFPA->x->nX; i++) {
     66            for (int j = 0; j <= chip->toFPA->x->nY; j++) {
     67                if (i + j > order) {
     68                    chip->toFPA->x->coeffMask[i][j] = PS_POLY_MASK_SET;
     69                    chip->toFPA->y->coeffMask[i][j] = PS_POLY_MASK_SET;
     70                }
     71            }
     72        }
    7373
    74         // XXX allow statitic to be set by the user
    75         // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    76         fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
    77         fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");
    78         fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");
     74        // XXX allow statitic to be set by the user
     75        // fitStats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
     76        fitStats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
     77        fitStats->clipSigma = psMetadataLookupF32 (&status, recipe, "PSASTRO.CHIP.NSIGMA");
     78        fitStats->clipIter = psMetadataLookupS32 (&status, recipe, "PSASTRO.CHIP.NITER");
    7979
    80         // improved fit for astrometric terms
    81         results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats);
    82         if (!results) {
    83             psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
    84             psFree (match);
    85             psFree (fitStats);
    86             return false;
    87         }
    88    
    89         // determine fromFPA transformation and apply new transformation to raw & ref stars
    90         psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    91    
    92         // toSky converts from FPA & TPA units (microns) to sky units (radians)
    93         float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD;
    94         // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;
    95         float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale;
    96         int astNstar = results->yStats->clippedNvalues;
    97         psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar);
     80        // improved fit for astrometric terms
     81        results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats);
     82        if (!results) {
     83            psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
     84            psFree (match);
     85            psFree (fitStats);
     86            return false;
     87        }
    9888
    99         if (iter < nIter - 1) {
    100             psFree (fitStats);
    101             psFree (results);
    102             psFree (match);
    103         }
     89        // determine fromFPA transformation and apply new transformation to raw & ref stars
     90        psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
     91
     92        // toSky converts from FPA & TPA units (microns) to sky units (radians)
     93        float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD;
     94        // float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;
     95        float astError = 0.5*(results->xStats->robustStdev + results->yStats->robustStdev) * plateScale;
     96        int astNstar = results->yStats->clippedNvalues;
     97        psLogMsg ("psastro", PS_LOG_INFO, "pass %d, error: %f arcsec, Nstars: %d", iter, astError, astNstar);
     98
     99        if (iter < nIter - 1) {
     100            psFree (fitStats);
     101            psFree (results);
     102            psFree (match);
     103        }
    104104    }
    105105
     
    122122    if (astError > maxError) {
    123123        psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError);
    124         validSolution = false;
     124        validSolution = false;
    125125    }
    126126    if (astNstar < minNstar) {
    127127        psLogMsg("psastro", PS_LOG_INFO, "solution uses too few stars: %d < %d", astNstar, minNstar);
    128         validSolution = false;
     128        validSolution = false;
    129129    }
    130130
     
    133133    psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR",   PS_META_REPLACE, "astrometry error (arcsec)", astError);
    134134    if (validSolution) {
    135         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));
    136         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", astNstar);
     135        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));
     136        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", astNstar);
    137137    } else {
    138         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);
    139         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", 0);
     138        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);
     139        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", 0);
    140140    }
    141141    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
     
    143143    // XXX drop from here : determine fromFPA transformation and apply new transformation to raw & ref stars
    144144    // psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    145    
     145
    146146    // XXX check if we correctly applied the new transformation:
    147147    if (psTraceGetLevel("psastro.dump") > 0) {
    148         psastroDumpRawstars (rawstars, fpa, chip);
    149         psastroDumpMatchedStars ("match.dat", rawstars, refstars, match);
    150         psastroDumpStars (refstars, "refstars.cal.dat");
     148        psastroDumpRawstars (rawstars, fpa, chip);
     149        psastroDumpMatchedStars ("match.dat", rawstars, refstars, match);
     150        psastroDumpStars (refstars, "refstars.cal.dat");
    151151    }
    152152
     153    psastroVisualPlotOneChipFit (rawstars, refstars, match, recipe);
     154
    153155    if (psTraceGetLevel("psastro.plot") > 0) {
    154         psastroPlotOneChipFit (rawstars, refstars, match, recipe);
     156        psastroPlotOneChipFit (rawstars, refstars, match, recipe);
    155157    }
    156158
Note: See TracChangeset for help on using the changeset viewer.