IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27461 for trunk/pstamp/src


Ignore:
Timestamp:
Mar 26, 2010, 11:21:55 AM (16 years ago)
Author:
bills
Message:

Improve fit to bi-level astrometry for postage stamps by making astrometry terms that are centered on the output chip center

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/ppstampMakeStamp.c

    r27117 r27461  
    1717
    1818static void skyToChip(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
     19static void chipToSky(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
    1920static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
    2021
    2122// convert the input chip's transforms to the output
    22 static bool convertWCS(pmHDU *outHDU, pmFPA *outFPA, pmChip *outChip, pmChip *inChip, psRegion *roi)
    23 {
    24     pmHDU *hdu = pmHDUFromChip(inChip);
    25     PS_ASSERT_PTR_NON_NULL(hdu, 1)
    26     PS_ASSERT_PTR_NON_NULL(hdu->header, 1)
    27 
    28     // Change the reference pixel to account for the change in origin between the stamp and
    29     // the original image
    30     // XXX: shouldn't we be using the center of the stamp instead of the corner?
    31     outChip->toFPA   = psPlaneTransformSetCenter(NULL, inChip->toFPA, (int) roi->x0, (int) roi->y0);
    32 
    33     outChip->fromFPA = psPlaneTransformInvert(NULL, outChip->toFPA, *roi, 50);
     23static bool convertWCS(pmHDU *outHDU, pmFPA *inFPA, pmChip *inChip, pmFPA *outFPA, pmChip *outChip, psRegion *roi)
     24{
     25    PS_ASSERT_PTR_NON_NULL(outHDU, 1);
     26    PS_ASSERT_PTR_NON_NULL(outHDU->header, 1);
     27
     28    // Center of stamp in chip coordinates
     29    double center_x = (roi->x0 + roi->x1) / 2;
     30    double center_y = (roi->y0 + roi->y1) / 2;
     31    pmAstromObj *check = pmAstromObjAlloc();
     32    check->chip->x = center_x;
     33    check->chip->y = center_y;
     34    chipToSky(check, inFPA, inChip);
     35    double r_before = check->sky->r;
     36    double d_before = check->sky->d;
     37    psLogMsg("ppstampMakeStamp", 2, "Before fit  Center Pixel RA: %f   DEC: %f (degrees)\n",
     38             r_before * PS_DEG_RAD, d_before * PS_DEG_RAD);
    3439
    3540    if (outFPA->toSky->type != PS_PROJ_TAN) {
    36         if (!pmAstromLinearizeTransforms(outFPA, outChip)) {
     41        // we need to make astrometry terms for the output which are centered on the output chip center,
     42        // but we keep the original plate scale
     43        psFree(outFPA->toSky);
     44        outFPA->toSky = psProjectionAlloc (r_before, d_before, inFPA->toSky->Xs, inFPA->toSky->Ys, PS_PROJ_TAN);
     45
     46        if (!pmAstromLinearizeToSky(inFPA, inChip, outFPA, outChip, roi)) {
     47            psFree(check);
    3748            psError(PS_ERR_UNKNOWN, false, "Failed to linearize astrometry\n");
    3849            return false;
    3950        }
    40     }
     51        check->chip->x = (roi->x1 - roi->x0) / 2;
     52        check->chip->y = (roi->y1 - roi->y0) / 2;
     53        chipToSky(check, outFPA, outChip);
     54        double r_after = check->sky->r;
     55        double d_after = check->sky->d;
     56
     57        psLogMsg("ppstampMakeStamp", 2, "After fit:  Center Pixel RA: %f   DEC: %f (degrees)\n",
     58                 r_after * PS_DEG_RAD, d_after * PS_DEG_RAD);
     59        psLogMsg("ppstampMakeStamp", 2, "Error in fit to astrometry %.2f    %.2f (arcseconds)\n",
     60                 (r_after - r_before) *  PS_DEG_RAD * 3600, (d_after - d_before) * PS_DEG_RAD * 3600);
     61
     62        // XXX: should we fail if the fit is bad ??
     63
     64    } else {
     65        outChip->toFPA     = psPlaneTransformSetCenter(NULL, inChip->toFPA, (int) roi->x0, (int) roi->y0);
     66        outChip->fromFPA   = psPlaneTransformInvert(NULL, outChip->toFPA, *roi, 50);
     67        if (!outChip->fromFPA) {
     68            psError(PS_ERR_UNKNOWN, false, "inversion of toFPA transform failed");
     69            return false;
     70        }
     71    }
     72    psFree(check);
    4173
    4274    if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_NONLIN_TOL)) {
     
    92124    // If input had WCS convert it for stamp
    93125    if (input->fpa->toSky) {
    94         // steal the input fpa's transforms
    95         output->fpa->toTPA   = input->fpa->toTPA;
    96         output->fpa->fromTPA = input->fpa->fromTPA;
    97         output->fpa->toSky   = input->fpa->toSky;
    98 
    99         // drop the references
    100         input->fpa->toTPA   = 0;
    101         input->fpa->fromTPA = 0;
    102         input->fpa->toSky   = 0;
    103 
    104         if (!convertWCS(outHDU, output->fpa, outChip, inChip, &options->roi)) {
     126        // copy the input fpa's transforms
     127        // XXX: if we change to making multiple stamps per process we'll need to copy
     128        // the transformations
     129        output->fpa->toTPA   = psMemIncrRefCounter(input->fpa->toTPA);
     130        output->fpa->fromTPA = psMemIncrRefCounter(input->fpa->fromTPA);
     131        output->fpa->toSky   = psMemIncrRefCounter(input->fpa->toSky);
     132
     133        if (!convertWCS(outHDU, input->fpa, inChip, output->fpa, outChip, &options->roi)) {
    105134            return false;
    106135        }
Note: See TracChangeset for help on using the changeset viewer.