IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 21, 2007, 12:00:49 PM (19 years ago)
Author:
magnier
Message:

fixed the source of the focal-plane region; added astrometric extent functions

File:
1 edited

Legend:

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

    r12483 r12519  
    77 *  @author EAM, IfA
    88 *
    9  *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-03-18 22:05:43 $
     9 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-03-21 22:00:49 $
    1111 *
    1212 *  Copyright 2006 Institute for Astronomy, University of Hawaii
     
    2323#include "pmAstrometryWCS.h"
    2424#include "pmAstrometryUtils.h"
     25#include "pmAstrometryRegions.h"
    2526
    2627// the following functions support coordinate transformations direcly related to the FITS WCS
     
    8384
    8485// convert toFPA / toSky components to traditional WCS
    85 bool pmAstromReadBilevelMosaic (pmFPA *fpa, const psMetadata *header, double pixelScale)
     86// we require the header to have NAXIS1,NAXIS2, the field of the FPA
     87// the center of the TPA/Sky projection is 0.5*(NAXIS1,NAXIS2)
     88bool pmAstromReadBilevelMosaic (pmFPA *fpa, const psMetadata *header)
    8689{
    8790    pmAstromWCS *wcs = pmAstromWCSfromHeader (header);
    8891    if (!wcs) {
    89         return false;
    90     }
    91 
    92     bool status = pmAstromWCSBileveltoFPA (fpa, wcs, pixelScale);
     92        psError(PS_ERR_UNKNOWN, false, "failure to determine WCS terms from header");
     93        return false;
     94    }
     95
     96    bool status1 = false;
     97    bool status2 = false;
     98    int Nx = psMetadataLookupS32 (&status1, header, "NAXIS1");
     99    int Ny = psMetadataLookupS32 (&status2, header, "NAXIS2");
     100    if (!status1 || !status2) {
     101        psFree (wcs);
     102        psError(PS_ERR_UNKNOWN, false, "missing required FPA size in header");
     103        return false;
     104    }
     105
     106    psRegion region = psRegionSet (-0.5*Nx, +0.5*Nx, -0.5*Ny, +0.5*Ny);
     107    bool status = pmAstromWCSBileveltoFPA (fpa, wcs, region);
    93108
    94109    psFree (wcs);
     
    113128    pmAstromWCS *wcs = pmAstromWCSBilevelMosaicFromFPA (fpa, tol);
    114129
     130    // we need to specify the dimensions of the FPA
     131    // if we have chips defined, we can do
     132    psRegion *region = pmAstromFPAExtent (fpa);
     133    int Nx = region->x1 - region->x0;
     134    int Ny = region->y1 - region->y0;
     135    psMetadataAddS32 (header, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "Mosaic Dimensions", Nx);
     136    psMetadataAddS32 (header, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "Mosaic Dimensions", Ny);
     137
    115138    pmAstromWCStoHeader (header, wcs);
    116139
     140    psFree (region);
    117141    psFree (wcs);
    118142    return true;
     
    442466
    443467    // free an existing toFPA structure
     468    psFree (chip->toFPA);
    444469    chip->toFPA = toFPA;
    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;
     470
     471    // determine the inverse transformation: we need the chip pixels covered by this transform
     472    psRegion *region = pmChipPixels (chip);
     473
    451474    psFree (chip->fromFPA);
    452     chip->fromFPA = psPlaneTransformInvert(NULL, toFPA, *region, 50);
     475    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
    453476    psFree (region);
    454477
     
    482505
    483506    // create transformation with 0,0 reference pixel and units of microns/pixel
     507    psFree (chip->toFPA);
    484508    chip->toFPA = psPlaneTransformSetCenter (NULL, wcs->trans, -wcs->crpix1, -wcs->crpix2);
    485     psRegion *region = pmChipExtent (chip);
    486     region->x1 -= region->x0;
    487     region->y1 -= region->y0;
    488     region->x0 = 0;
    489     region->y0 = 0;
     509
     510    // determine the inverse transformation: we need the chip pixels covered by this transform
     511    psRegion *region = pmChipPixels (chip);
     512
    490513    psFree (chip->fromFPA);
    491514    chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *region, 50);
     
    496519
    497520// convert a pmAstromWCS structure representing a bilevel mosaic into corresponding fpa elements
    498 bool pmAstromWCSBileveltoFPA (pmFPA *fpa, const pmAstromWCS *wcs, double pixelScale)
     521bool pmAstromWCSBileveltoFPA (pmFPA *fpa, const pmAstromWCS *wcs, psRegion region)
    499522{
    500523    // projection from TPA (microns) to SKY (radians)
     
    513536    }
    514537
    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;
     538    // the transformation used the region to define the inversion grid
     539    // the region defines the FPA pixels covered by the tranformation
    531540    psFree (fpa->fromTPA);
    532     fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, *region, 50);
    533     psFree (region);
    534 
     541    fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, region, 50);
    535542    return true;
    536543}
Note: See TracChangeset for help on using the changeset viewer.