IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 18, 2007, 12:05:43 PM (19 years ago)
Author:
magnier
Message:

fixed adjustment to coordinate center when applying a common f.p. scale; get chip and fpa dimensions from concepts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmAstrometryWCS.c

    r11687 r12483  
    77 *  @author EAM, IfA
    88 *
    9  *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-02-07 23:58:17 $
     9 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-03-18 22:05:43 $
    1111 *
    1212 *  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    2020#include <pslib.h>
    2121#include "pmFPA.h"
     22#include "pmFPAExtent.h"
    2223#include "pmAstrometryWCS.h"
    2324#include "pmAstrometryUtils.h"
     
    8283
    8384// convert toFPA / toSky components to traditional WCS
    84 bool pmAstromReadBilevelMosaic (pmFPA *fpa, const psMetadata *header)
     85bool pmAstromReadBilevelMosaic (pmFPA *fpa, const psMetadata *header, double pixelScale)
    8586{
    8687    pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
     
    8990    }
    9091
    91     bool status = pmAstromWCSBileveltoFPA (fpa, wcs);
     92    bool status = pmAstromWCSBileveltoFPA (fpa, wcs, pixelScale);
    9293
    9394    psFree (wcs);
     
    404405        double rX = toSky->Xs / fpa->toSky->Xs;
    405406        double rY = toSky->Ys / fpa->toSky->Ys;
     407
    406408        for (int i = 0; i <= fpa->toTPA->x->nX; i++) {
    407409            for (int j = 0; j <= fpa->toTPA->x->nY; j++) {
     
    411413        }
    412414
    413         // adjust for common toSky, toTPA for mosaic:
     415        // adjust reference pixel for new toSky reference coordinate
    414416        // find the FPA coordinate of 0,0 for this chip.
    415         psPlane *chip = psPlaneAlloc();
    416         psPlane *fp = psPlaneAlloc();
     417        psPlane *fpOld = psPlaneAlloc();
     418        psPlane *fpNew = psPlaneAlloc();
    417419        psPlane *tp = psPlaneAlloc();
    418420        psSphere *sky = psSphereAlloc();
    419         chip->x = chip->y = 0;
    420 
    421         psPlaneTransformApply (fp, toFPA, chip); // find the focal-plane coordinate of this chip's 0,0 coordinate
    422         psPlaneTransformApply (tp, fpa->toTPA, fp);
    423         psDeproject (sky, tp, toSky); // find the RA,DEC coord of the focal-plane coordinate
     421
     422        sky->r = toSky->R;
     423        sky->d = toSky->D;
    424424        psProject (tp, sky, fpa->toSky); // find the focal-plane coord of this RA,DEC coord using the ref chip projection
    425         psPlaneTransformApply (fp, fpa->fromTPA, tp);
    426 
    427         toFPA->x->coeff[0][0] = fp->x;
    428         toFPA->y->coeff[0][0] = fp->y;
     425        psPlaneTransformApply (fpOld, fpa->fromTPA, tp);
     426
     427        sky->r = fpa->toSky->R;
     428        sky->d = fpa->toSky->D;
     429        psProject (tp, sky, fpa->toSky); // find the focal-plane coord of this RA,DEC coord using the ref chip projection
     430        psPlaneTransformApply (fpNew, fpa->fromTPA, tp);
     431
     432        toFPA->x->coeff[0][0] -= fpNew->x - fpOld->x;
     433        toFPA->y->coeff[0][0] -= fpNew->y - fpOld->y;
    429434
    430435        psFree (sky);
    431436        psFree (tp);
    432         psFree (fp);
    433         psFree (chip);
     437        psFree (fpOld);
     438        psFree (fpNew);
     439
    434440        psFree (toSky);
    435441    }
     
    437443    // free an existing toFPA structure
    438444    chip->toFPA = toFPA;
    439     // XXX this needs to perform the full (non-linear) inversion
    440     // XXX we need to pull the region from the chip metadata
    441     // is chip trimsec defined?  do we need to ensure the
    442     // XXX should this function be defined for the CELL, not the CHIP?
    443     // psRegion region = psMetadataLookupXXX (chip->concepts, "CHIP.TRIMSEC");
    444     psRegion region = psRegionSet (0, 4000, 0, 4000);
    445     chip->fromFPA = psPlaneTransformInvert(NULL, toFPA, region, 50);
     445    // NOTE that region specifies the FP region in PIXELS covered by the chip
     446    psRegion *region = pmChipExtent (chip);
     447    region->x1 -= region->x0;
     448    region->y1 -= region->y0;
     449    region->x0 = 0;
     450    region->y0 = 0;
     451    psFree (chip->fromFPA);
     452    chip->fromFPA = psPlaneTransformInvert(NULL, toFPA, *region, 50);
     453    psFree (region);
    446454
    447455    // this can take a very long time...
     
    475483    // create transformation with 0,0 reference pixel and units of microns/pixel
    476484    chip->toFPA = psPlaneTransformSetCenter (NULL, wcs->trans, -wcs->crpix1, -wcs->crpix2);
    477 
    478     // XXX this needs to perform the full (non-linear) inversion
    479     // XXX we need to pull the region from the chip metadata
    480     // is chip trimsec defined?  do we need to ensure the
    481     // XXX should this function be defined for the CELL, not the CHIP?
    482     // psRegion region = psMetadataLookupXXX (chip->concepts, "CHIP.TRIMSEC");
    483     psRegion region = psRegionSet (0, 4000, 0, 4000);
    484     chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, region, 50);
     485    psRegion *region = pmChipExtent (chip);
     486    region->x1 -= region->x0;
     487    region->y1 -= region->y0;
     488    region->x0 = 0;
     489    region->y0 = 0;
     490    psFree (chip->fromFPA);
     491    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
     492    psFree (region);
    485493
    486494    return true;
     
    488496
    489497// convert a pmAstromWCS structure representing a bilevel mosaic into corresponding fpa elements
    490 bool pmAstromWCSBileveltoFPA (pmFPA *fpa, const pmAstromWCS *wcs)
     498bool pmAstromWCSBileveltoFPA (pmFPA *fpa, const pmAstromWCS *wcs, double pixelScale)
    491499{
    492500    // projection from TPA (microns) to SKY (radians)
     
    505513    }
    506514
    507     // XXX this needs to perform the full (non-linear) inversion
    508     // XXX we need to pull the region from the chip metadata
    509     // is chip trimsec defined?  do we need to ensure the
    510     // XXX should this function be defined for the CELL, not the CHIP?
    511     // psRegion region = psMetadataLookupXXX (chip->concepts, "CHIP.TRIMSEC");
    512     psRegion region = psRegionSet (0, 4000, 0, 4000);
    513     fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, region, 50);
     515    // XXX this is still wrong: the pmFPAExtent function returns the FP dimensions in pixel units
     516    // relative to the 0,0 corner of chip 0,0.  for now, just recenter...
     517    // XXX I need to have a function which loops over all cells, determines the pixel dimensions
     518    // for each cell, converts them to chip pixels, then uses the fpa astrometry structures
     519    // to get the total dimensions of the fpa in fpa units.  equivalent to pmFPAExtent
     520    psRegion *region = pmFPAExtent (fpa);
     521    region->x0 *= pixelScale;
     522    region->x1 *= pixelScale;
     523    region->y0 *= pixelScale;
     524    region->y1 *= pixelScale;
     525    int xCenter = 0.5*(region->x0 + region->x1);
     526    int yCenter = 0.5*(region->y0 + region->y1);
     527    region->x0 -= xCenter;
     528    region->x1 -= xCenter;
     529    region->y0 -= yCenter;
     530    region->y1 -= yCenter;
     531    psFree (fpa->fromTPA);
     532    fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, *region, 50);
     533    psFree (region);
    514534
    515535    return true;
Note: See TracChangeset for help on using the changeset viewer.