IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 2, 2007, 3:26:52 PM (20 years ago)
Author:
eugene
Message:

fixed mosaic analysis; cleaned up test code (some in traces, some removed), general output cleanups

File:
1 edited

Legend:

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

    r10830 r10880  
    11# include "psastro.h"
    22
    3 bool psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, int iteration) {
     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; }
     8
     9bool psastroMosaicOneChip (pmChip *chip, pmReadout *readout, psMetadata *recipe, psMetadata *updates, bool nonlinear) {
    410
    511    bool status;
     
    2026    if (match == NULL) return false;
    2127
    22     if ((iteration < 1) || (iteration > 2)) {
    23         psError(PSASTRO_ERR_UNKNOWN, false, "invalid iteration number %d\n", iteration);
    24         return false;
     28    // correct radius to FP units (physical pixel scale in microns per pixel)
     29    REQUIRED_RECIPE_VALUE (double pixelScale, "PSASTRO.PIXEL.SCALE", F32, "Failed to lookup pixel scale");
     30
     31    // allowed limits for valid solutions
     32    REQUIRED_RECIPE_VALUE (float maxError, "PSASTRO.MOSAIC.MAX.ERROR", F32, "failed to find single-chip max allowed error\n");
     33    REQUIRED_RECIPE_VALUE (int minNstar, "PSASTRO.MOSAIC.MIN.NSTAR", S32, "failed to find single-chip min allowed stars\n");
     34
     35    // set the order of the per-chip fit (higher order only if nonlinear == true)
     36    int order = 1;
     37    if (nonlinear) {
     38        // select the desired chip order
     39        REQUIRED_RECIPE_VALUE (order, "PSASTRO.MOSAIC.CHIP.ORDER", S32, "failed to find mosaic chip-level fit order\n");
     40
     41        // modify the order to correspond to the actual number of matched stars:
     42        if ((match->n < 11) && (order >= 3)) order = 2;
     43        if ((match->n <  7) && (order >= 2)) order = 1;
     44        if ((match->n <  4) && (order >= 1)) order = 0;
     45        if (order < 1) {
     46            psLogMsg ("psastro", 3, "insufficient stars or invalid order: %ld stars", match->n);
     47            return false;
     48        }
    2549    }
    2650
    27     // correct to FP units (physical pixel scale in microns per pixel)
    28     double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
    29     if (!status) {
    30         psError(PS_ERR_IO, false, "Failed to lookup pixel scale");
    31         return false;
    32     }
    33 
    34     // set the order of the per-chip fit (iteration 1: 1, iteration 2: from recipe)
    35     int order = 1;
    36     if (iteration == 2) {
    37         order = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.CHIP.ORDER");
    38         if (!status) {
    39             psError(PSASTRO_ERR_UNKNOWN, false, "failed to find mosaic chip-level fit order\n");
    40             return false;
    41         }
    42     }
     51    // create output toFPA; set masks appropriate to the Elixir DVO astrometry format
    4352    psFree (chip->toFPA);
    4453    chip->toFPA = psPlaneTransformAlloc (order, order);
     
    6473    }
    6574
    66     // allowed limits for valid solutions
    67     // XXX have these values depend on the iteration?
    68     float maxError = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.MAX.ERROR");
    69     int minNstar = psMetadataLookupS32 (&status, recipe, "PSASTRO.MOSAIC.MIN.NSTAR");
     75    // toSky converts from FPA & TPA units (microns) to sky units (radians)
     76    pmFPA *fpa = chip->parent;
     77    float plateScale = 0.5*(fpa->toSky->Xs + fpa->toSky->Ys)*3600.0*PM_DEG_RAD;
    7078
    71     // astError is the average 1D scatter in pixels ('results' are in FPA units = microns)
    72     // XXX currently using supplied pixel scale: use toFPA->x->coeff[1][0], etc?
    73     float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale;
     79    // pixError is the average 1D scatter in pixels ('results' are in FPA units = microns)
     80    float pixError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) / pixelScale;
     81
     82    // astError is the average 1D scatter in arcsec ('results' are in FPA units = microns)
     83    float astError = 0.5*(results->xStats->clippedStdev + results->yStats->clippedStdev) * plateScale;
    7484    int astNstar = results->yStats->clippedNvalues;
    7585
     
    7787
    7888    // XXX should these result in errors or be handled another way?
    79     psLogMsg ("psastro", PS_LOG_INFO, "astrometry solution: error: %f, Nstars: %d", astError, astNstar);
     89    psLogMsg ("psastro", PS_LOG_INFO, "astrometry solution: error: %f arcsec, Nstars: %d", astError, astNstar);
    8090    if (astError > maxError) {
    8191        psLogMsg("psastro", PS_LOG_INFO, "residual error is too large, failed to find a solution: %f > %f", astError, maxError);
     
    8898
    8999    // DVO expects NASTRO = 0 if we fail to find a solution
     100    psMetadataAddF32 (updates, PS_LIST_TAIL, "PERROR",   PS_META_REPLACE, "astrometry error (pixels)", pixError);
     101    psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR",   PS_META_REPLACE, "astrometry error (arcsec)", astError);
    90102    if (validSolution) {
    91         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "", astNstar);
    92         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", astError/sqrt(astNstar));
     103        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", astError/sqrt(astNstar));
     104        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", astNstar);
    93105    } else {
    94         psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "", 0);
    95         psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "", 0.0);
     106        psMetadataAddF32 (updates, PS_LIST_TAIL, "CPRECISE", PS_META_REPLACE, "astrometry precision (arcsec)", 0.0);
     107        psMetadataAddS32 (updates, PS_LIST_TAIL, "NASTRO",   PS_META_REPLACE, "number of astrometry stars", 0);
    96108    }
    97     psMetadataAddF32 (updates, PS_LIST_TAIL, "CERROR",   PS_META_REPLACE, "", astError);
    98109    psMetadataAddF32 (updates, PS_LIST_TAIL, "EQUINOX",  PS_META_REPLACE, "", 2000.0); // XXX this is bogus: should be defined based on equinox of refstars
     110
     111    // determine fromFPA transformation and apply new transformation to raw & ref stars
     112    psastroUpdateChipToFPA (fpa, chip, rawstars, refstars);
    99113
    100114    psFree (fitStats);
Note: See TracChangeset for help on using the changeset viewer.