IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 29, 2006, 8:36:33 AM (19 years ago)
Author:
eugene
Message:

extensive work to catch errors and clear leaks; implement mosaics

File:
1 edited

Legend:

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

    r10830 r10855  
    11# include "psastro.h"
     2
     3# define REQUIRED_RECIPE_VALUE(VALUE, NAME, TYPE, MESSAGE)\
     4  VALUE = psMetadataLookup##TYPE (&status, recipe, NAME); \
     5  if (!status) { \
     6   psError(PSASTRO_ERR_CONFIG, false, MESSAGE); \
     7   return false; }
    28
    39bool psastroOneChip (pmFPA *fpa, pmChip *chip, psArray *refstars, psArray *rawstars, psMetadata *recipe, psMetadata *updates) {
     
    511    bool status;
    612
     13    // supplied radius is in pixels
     14    REQUIRED_RECIPE_VALUE (double RADIUS, "PSASTRO.MATCH.RADIUS", F32, "Failed to lookup matching radius");
     15
     16    // correct radius to FP units (physical pixel scale in microns per pixel)
     17    REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32, "Failed to lookup pixel scale");
     18    RADIUS *= pixelScale;
     19
     20    // select the desired chip order
     21    REQUIRED_RECIPE_VALUE (int order, "PSASTRO.CHIP.ORDER", S32, "failed to find single-chip fit order\n");
     22
     23    // allowed limits for valid solutions
     24    REQUIRED_RECIPE_VALUE (float maxError, "PSASTRO.MAX.ERROR", F32, "failed to find single-chip max allowed error\n");
     25
     26    REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n");
     27
    728    // find initial offset / rotation
    829    pmAstromStats *gridStats = pmAstromGridMatch (rawstars, refstars, recipe);
    930    if (gridStats == NULL) {
    10         psError(PSASTRO_ERR_DATA, false, "failed to find a grid match solution\n");
     31        psLogMsg ("psastro", 3, "failed to find a grid match solution\n");
    1132        return false;
    1233    }
     
    1637    pmAstromStats *stats = pmAstromGridTweak (rawstars, refstars, recipe, gridStats);
    1738    if (stats == NULL) {
    18         psError(PSASTRO_ERR_DATA, false, "failed to measure tweaked grid solution\n");
     39        psLogMsg ("psastro", 3, "failed to measure tweaked grid solution\n");
    1940        return false;
    2041    }
     
    2546    psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    2647
    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");
     48    // use small radius to match stars
     49    psArray *match = pmAstromRadiusMatchFP (rawstars, refstars, RADIUS);
     50    if (match == NULL) {
     51        psLogMsg ("psastro", 3, "failed to find radius-matched sources\n");
     52        return false;
     53    }
     54
     55    // create the output fit model, modify the order to correspond to the actual number of
     56    // matched stars:
     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;
     60    if (order < 1) {
     61        psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n);
     62        psFree (match);
     63        psFree (stats);
     64        psFree (gridStats);
    3165        return false;
    3266    }
    3367
    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 
    42     // use small radius to match stars
    43     psArray *match = pmAstromRadiusMatchFP (rawstars, refstars, RADIUS);
    44     if (stats == NULL) {
    45         psError(PSASTRO_ERR_UNKNOWN, false, "failed to find radius-matched sources\n");
    46         return false;
    47     }
    48 
    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");
    53         return false;
    54     }
     68    // set masks appropriate to the Elixir DVO astrometry format
    5569    psFree (chip->toFPA);
    5670    chip->toFPA = psPlaneTransformAlloc (order, order);
     
    7286    pmAstromFitResults *results = pmAstromMatchFit (chip->toFPA, rawstars, refstars, match, fitStats);
    7387    if (!results) {
    74         psError(PSASTRO_ERR_DATA, false, "failed to perform the matched fit\n");
     88        psLogMsg ("psastro", 3, "failed to perform the matched fit\n");
    7589        return false;
    7690    }
    7791   
    78     // allowed limits for valid solutions
    79     float maxError = psMetadataLookupF32 (&status, recipe, "PSASTRO.MAX.ERROR");
    80     int minNstar = psMetadataLookupS32 (&status, recipe, "PSASTRO.MIN.NSTAR");
     92    // toTPA converts from FPA units (microns) to TPA units (linear degrees)
     93    float plateScale1 = hypot (fpa->toTPA->x->coeff[1][0], fpa->toTPA->x->coeff[0][1]);
     94    float plateScale2 = hypot (fpa->toTPA->y->coeff[1][0], fpa->toTPA->y->coeff[0][1]);
     95    float plateScale = 0.5*(plateScale1 + plateScale2)*3600.0;
    8196
    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;
     97    // pixError is the average 1D scatter in pixels ('results' are in FPA units = microns)
     98    float pixError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale;
     99
     100    // astError is the average 1D scatter in arcsec ('results' are in FPA units = microns)
     101    float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;
    84102    int astNstar = results->yStats->clippedNvalues;
    85103
     
    98116
    99117    // DVO expects NASTRO = 0 if we fail to find a solution
     118    psMetadataAddF32 (updates, PS_LIST_TAIL, "PERROR",   PS_META_REPLACE, "astrometry error (pixels)", pixError);
     119    psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR",   PS_META_REPLACE, "astrometry error (arcsec)", astError);
    100120    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));
     121        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));
     122        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", astNstar);
    103123    } else {
    104         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "", 0);
    105         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", 0.0);
     124        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);
     125        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", 0);
    106126    }
    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
     127    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
    109128
    110129// write results
Note: See TracChangeset for help on using the changeset viewer.