IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10855


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

extensive work to catch errors and clear leaks; implement mosaics

Location:
trunk/psastro/src
Files:
11 edited

Legend:

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

    r10833 r10855  
    5353    }
    5454
    55     if (!psastroChipAstrom (config, refs)) {
    56       psErrorStackPrint(stderr, "failed to perform single chip astrometry\n");
    57       exit (1);
     55    bool chipastro = psMetadataLookupBool (NULL, config->arguments, "PSASTRO.CHIP.MODE");
     56    if (chipastro) {
     57        if (!psastroChipAstrom (config, refs)) {
     58            psErrorStackPrint(stderr, "failed to perform single chip astrometry\n");
     59            exit (1);
     60        }
    5861    }
    5962
    60     bool mosastro = psMetadataLookupBool (NULL, config->arguments, "MOSAIC.MODE");
    61     if (!mosastro) {
     63    bool mosastro = psMetadataLookupBool (NULL, config->arguments, "PSASTRO.MOSAIC.MODE");
     64    if (mosastro) {
    6265        if (!psastroMosaicAstrom (config, refs)) {
    6366            psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry\n");
  • trunk/psastro/src/psastroArguments.c

    r10833 r10855  
    3333    if ((N = psArgumentGet (argc, argv, "-chip"))) {
    3434        psArgumentRemove (N, &argc, argv);
    35         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_DATA_STRING, "", psStringCopy(argv[N]));
     35        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_META_REPLACE, "", psStringCopy(argv[N]));
    3636        psArgumentRemove (N, &argc, argv);
    3737    }
    3838
    39     // mosastro mode also specifies output header file
     39    // apply mosastro mode?
    4040    if ((N = psArgumentGet (argc, argv, "-mosastro"))) {
    4141        psArgumentRemove (N, &argc, argv);
    42         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MOSAIC.MODE", PS_DATA_BOOL, "", psStringCopy(argv[N]));
     42        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.MOSAIC.MODE", PS_META_REPLACE, "", false);
     43    }
     44    if ((N = psArgumentGet (argc, argv, "+mosastro"))) {
    4345        psArgumentRemove (N, &argc, argv);
     46        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.MOSAIC.MODE", PS_META_REPLACE, "", true);
     47    }
     48
     49    // apply chipastro mode?
     50    if ((N = psArgumentGet (argc, argv, "-chipastro"))) {
     51        psArgumentRemove (N, &argc, argv);
     52        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.CHIP.MODE", PS_META_REPLACE, "", false);
     53    }
     54    if ((N = psArgumentGet (argc, argv, "+chipastro"))) {
     55        psArgumentRemove (N, &argc, argv);
     56        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.CHIP.MODE", PS_META_REPLACE, "", true);
    4457    }
    4558
  • trunk/psastro/src/psastroAstromGuess.c

    r10830 r10855  
    1111    bool newFPA = true;
    1212    bool status = false;
    13     double RAmin = NAN;
    14     double RAmax = NAN;
     13    double RAmin = FLT_MAX;
     14    double RAmax = FLT_MIN;
     15    double DECmin = FLT_MAX;
     16    double DECmax = FLT_MIN;
     17
    1518    double RAminSky = NAN;
    1619    double RAmaxSky = NAN;
    17     double DECmin = NAN;
    18     double DECmax = NAN;
    1920
    2021    pmChip *chip = NULL;
    2122    pmCell *cell = NULL;
    2223    pmReadout *readout = NULL;
    23 
    24     DECmin = DECmax = -90;
    25     RAmin = RAmax = RAminSky = RAmaxSky = 0;
    2624
    2725    // select the current recipe
     
    6361            RAminSky = fpa->toSky->R - M_PI;
    6462            RAmaxSky = fpa->toSky->R + M_PI;
    65             RAmin = RAmax = fpa->toSky->R;
    66             DECmin = DECmax = fpa->toSky->D;
    6763        }
    6864
     
    7975                if (rawstars == NULL) { continue; }
    8076
     77                FILE *f = fopen ("rawstars.dat", "w");
    8178                for (int i = 0; i < rawstars->n; i++) {
    8279                    pmAstromObj *raw = rawstars->data[i];
     
    8582                    psPlaneTransformApply (raw->TP, fpa->toTPA, raw->FP);
    8683                    psDeproject (raw->sky, raw->TP, fpa->toSky);
     84
     85                    fprintf (f, "%d  %f %f  %f %f  %f %f  %f %f\n", i,
     86                             raw->sky->r, raw->sky->d,
     87                             raw->TP->x, raw->TP->y,
     88                             raw->FP->x, raw->FP->y,
     89                             raw->chip->x, raw->chip->y);
    8790
    8891                    if (i < 10) {
     
    122125                    DECmax = PS_MAX (raw->sky->d, DECmax);
    123126                }
     127                fclose (f);
    124128            }
    125129        }
  • trunk/psastro/src/psastroChipAstrom.c

    r10785 r10855  
    4949                if (refstars == NULL) { continue; }
    5050
     51                // the absolute minimum number of stars is 4 (for order = 1)
     52                if ((rawstars->n < 4) || (refstars->n < 4)) {
     53                    psLogMsg ("psastro", 3, "insufficient rawstars (%ld) or refstars (%ld)",
     54                            rawstars->n, refstars->n);
     55                    continue;
     56                }
     57
    5158                // save WCS and analysis metadata in update header
    5259                psMetadata *updates = psMetadataAlloc();
    5360
     61                // XXX update the header with info to reflect the failure
    5462                if (!psastroOneChip (fpa, chip, refstars, rawstars, recipe, updates)) {
    55                     psError (PSASTRO_ERR_DATA, false, "failed to find a solution\n");
    56                     return false;
     63                    psLogMsg ("psastro", 3, "failed to find a solution\n");
     64                    psFree (updates);
     65                    continue;
    5766                }
    5867                pmAstromWriteWCS (updates, fpa, chip, NONLIN_TOL);
  • trunk/psastro/src/psastroChooseRefstars.c

    r10830 r10855  
    5656                psArray *refstars = psArrayAllocEmpty (100);
    5757
     58                FILE *f = fopen ("refstars.dat", "w");
     59
    5860                // select the reference objects within range of this readout
    5961                // project the reference objects to this chip
     
    6466                    psPlaneTransformApply (ref->FP, fpa->fromTPA, ref->TP);
    6567                    psPlaneTransformApply (ref->chip, chip->fromFPA, ref->FP);
     68
     69                    fprintf (f, "%d  %f %f  %f %f  %f %f  %f %f\n", i,
     70                             ref->sky->r, ref->sky->d,
     71                             ref->TP->x, ref->TP->y,
     72                             ref->FP->x, ref->FP->y,
     73                             ref->chip->x, ref->chip->y);
    6674
    6775                    // limit the X,Y range of the refs to the selected chip
     
    7583                    psFree (ref);
    7684                }
     85                fclose (f);
    7786                psTrace ("psastro", 4, "Added %ld refstars\n", refstars->n);
    7887
  • trunk/psastro/src/psastroConvert.c

    r9732 r10855  
    3939
    4040    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSASTRO.RAWSTARS", PS_DATA_ARRAY, "astrometry objects", rawstars);
     41    psLogMsg ("psastro", 4, "loaded %ld sources\n", rawstars->n);
     42
    4143    psFree (rawstars);
    4244
  • trunk/psastro/src/psastroLuminosityFunction.c

    r10787 r10855  
    109109  }
    110110
    111   psLogMsg ("psastro", 4, "logN %f + %f mag\n", line->coeff[0], line->coeff[1]);
     111  psLogMsg ("psastro", 4, "logN = %f + %f mag\n", line->coeff[0], line->coeff[1]);
    112112  psLogMsg ("psastro", 4, "logN vs mag residuals: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
    113113
  • 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
  • trunk/psastro/src/psastroParseCamera.c

    r10438 r10855  
    2222    pmFPAfileDefineOutput (config, input->fpa, "PSASTRO.OUTPUT");
    2323
    24     // Chip selection: turn on only the chips specified
     24    // Chip selection: turn on only the chips specified (option is not required)
    2525    char *chipLine = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS");
     26    if (chipLine == NULL) psErrorClear();
     27
    2628    psArray *chips = psStringSplitArray (chipLine, ",", false);
    2729    if (chips->n > 0) {
  • trunk/psastro/src/psastroRefstarSubset.c

    r10790 r10855  
    6161  return true;
    6262}
     63
     64/* this test is a bit sensitive to the total number of refstars or rawstars available
     65   watch out if:
     66   - the fitted slopes are extremely different
     67   - the average number of stars per bin is ~1
     68   
     69   skip the cut in these cases?
     70*/
  • trunk/psastro/src/psastroUtils.c

    r10830 r10855  
    3737        for (int i = 0; i < fpa->chips->n; i++) {
    3838            pmChip *chip = fpa->chips->data[i];
     39            if (!chip->process || !chip->file_exists) { continue; }
    3940           
    4041            pixelScale1 = hypot (chip->toFPA->x->coeff[1][0], chip->toFPA->x->coeff[0][1]);
     
    5051    for (int i = 0; i < fpa->chips->n; i++) {
    5152        pmChip *chip = fpa->chips->data[i];
     53        if (!chip->process || !chip->file_exists) { continue; }
    5254
    5355        psPlaneTransform *toFPA = chip->toFPA;
Note: See TracChangeset for help on using the changeset viewer.