IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36835


Ignore:
Timestamp:
Jun 7, 2014, 6:38:38 AM (12 years ago)
Author:
eugene
Message:

add pswarp backwards transformations so we can map warp pixels to chip pixels

Location:
trunk/pswarp/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarp.h

    r35563 r36835  
    3030#define PSASTRO_RECIPE "PSASTRO" ///< Name of the recipe to use
    3131
    32 #define PSWARP_ANALYSIS_GOODPIX   "PSWARP.GOODPIX" ///< Name for number of good pixels in analysis metadata
     32#define PSWARP_ANALYSIS_GOODPIX     "PSWARP.GOODPIX" ///< Name for number of good pixels in analysis metadata
    3333#define PSWARP_ANALYSIS_COVARIANCES "PSWARP.COVARIANCES" ///< Name for covariance matrices on analysis MD
    34 #define PSWARP_ANALYSIS_JACOBIAN "PSWARP.JACOBIAN" ///< Name for Jacobian on analysis MD
     34#define PSWARP_ANALYSIS_JACOBIAN    "PSWARP.JACOBIAN" ///< Name for Jacobian on analysis MD
     35#define PSWARP_ANALYSIS_BACKMAPS    "PSWARP.BACKMAPS" ///< Name for array of backwarps maps on analysis MD
     36#define PSWARP_ANALYSIS_CHIPNAMES   "PSWARP.CHIPNAMES" ///< Name for array of input chipnames on analysis MD
     37#define PSWARP_ANALYSIS_CHIPREGIONS "PSWARP.CHIPREGIONS" ///< Name for array of input chipnames on analysis MD
    3538
    3639/**
  • trunk/pswarp/src/pswarpLoop.c

    r36083 r36835  
    156156
    157157    if (!pswarpMakePSF (config, output, stats)) {
    158       psError(psErrorCodeLast(), false, "problem generating PSF.");
    159       goto FAIL;
     158        psError(psErrorCodeLast(), false, "problem generating PSF.");
     159        goto FAIL;
    160160    }
    161161
     
    163163    return true;
    164164
    165  FAIL:
     165FAIL:
    166166    psFree (view);
    167167    return false;
    168168}
     169
     170bool pswarpGetBackTransform (pmReadout *tgt, pmReadout *src);
    169171
    170172// once the output fpa elements have been built, loop over the fpa and generate stats
     
    188190            while ((readout = pmFPAviewNextReadout(view, output, 1)) != NULL) {
    189191                pswarpTransformReadout (readout, input, config, backgroundWarp);
     192
     193                // determine a (rough) linear WCS from readout to input
     194                pswarpGetBackTransform (readout, input);
    190195            }
    191196        }
     
    194199}
    195200
     201bool pswarpGetBackTransform (pmReadout *tgt, pmReadout *src) {
     202
     203    bool status;
     204
     205    // tgt is the pswarp output target image, src is the input source image
     206    // here we are generating a linear transformation from tgt -> src
     207
     208    // the map is defined for coordinates in the image parent frame.
     209    psRegion imageRegion = psRegionSet (0,0,0,0);
     210    imageRegion = psRegionForImage (src->image, imageRegion);
     211    psString imageRegionString = psRegionToString (imageRegion);
     212 
     213    // generate a set of points (X,Y)_tgt = (X,Y)_src and do the 2D fit?
     214    // save a 2D polynomial, not WCS?
     215
     216    // use a map with only linear terms in x,y
     217    psPlaneTransform *map = psPlaneTransformAlloc(1,1);
     218    map->x->coeffMask[1][1] = PS_POLY_MASK_BOTH;
     219    map->y->coeffMask[1][1] = PS_POLY_MASK_BOTH;
     220
     221    pmCell *cell = NULL;
     222
     223    cell = src->parent;
     224    pmChip *chipSrc = cell->parent;
     225    pmFPA *fpaSrc = chipSrc->parent;
     226
     227    cell = tgt->parent;
     228    pmChip *chipTgt = cell->parent;
     229    pmFPA *fpaTgt = chipTgt->parent;
     230
     231    psPlane *srcPos = psPlaneAlloc();
     232    psPlane *tgtPos = psPlaneAlloc();
     233
     234    psPlane *FP = psPlaneAlloc();
     235    psPlane *TP = psPlaneAlloc();
     236    psSphere *sky = psSphereAlloc();
     237
     238    psVector *tgtX = psVectorAllocEmpty (121, PS_TYPE_F32);
     239    psVector *tgtY = psVectorAllocEmpty (121, PS_TYPE_F32);
     240    psVector *srcX = psVectorAllocEmpty (121, PS_TYPE_F32);
     241    psVector *srcY = psVectorAllocEmpty (121, PS_TYPE_F32);
     242
     243    int dX = src->image->numCols / 10.0;
     244    int dY = src->image->numRows / 10.0;
     245    for (int ix = 0; ix < src->image->numCols; ix += dX) {
     246        for (int iy = 0; iy < src->image->numRows; iy += dY) {
     247
     248            srcPos->x = ix;
     249            srcPos->y = iy;
     250
     251            psPlaneTransformApply(FP, chipSrc->toFPA, srcPos);
     252            psPlaneTransformApply (TP, fpaSrc->toTPA, FP);
     253            psDeproject (sky, TP, fpaSrc->toSky);
     254
     255            psProject (TP, sky, fpaTgt->toSky);
     256            psPlaneTransformApply (FP, fpaTgt->fromTPA, TP);
     257            psPlaneTransformApply (tgtPos, chipTgt->fromFPA, FP);
     258
     259            psVectorAppend (srcX, srcPos->x);
     260            psVectorAppend (srcY, srcPos->y);
     261            psVectorAppend (tgtX, tgtPos->x);
     262            psVectorAppend (tgtY, tgtPos->y);
     263        }
     264    }
     265
     266    psVectorFitPolynomial2D(map->x, NULL, 0, srcX, NULL, tgtX, tgtY);
     267    psVectorFitPolynomial2D(map->y, NULL, 0, srcY, NULL, tgtX, tgtY);
     268
     269    // for each output image, we want to add headers corresponding to all input images
     270    // save an array of the transformations on the tgt analysis and an array of the input chip names
     271    psArray *backmaps = psMetadataLookupPtr (&status, tgt->analysis, PSWARP_ANALYSIS_BACKMAPS);
     272    if (!backmaps) {
     273        backmaps = psArrayAllocEmpty (4);
     274        psMetadataAddArray (tgt->analysis, PS_LIST_TAIL, PSWARP_ANALYSIS_BACKMAPS, 0, "backwards maps", backmaps);
     275        psFree (backmaps); // can free here since we put a copy on tgt->analysis
     276    }
     277    psArrayAdd (backmaps, 4, map);
     278   
     279    // we also need to save the corresponding chip name for this map
     280    char *chipname = psMetadataLookupStr (&status, chipSrc->concepts, "CHIP.NAME");
     281    psArray *chipnames = psMetadataLookupPtr (&status, tgt->analysis, PSWARP_ANALYSIS_CHIPNAMES);
     282    if (!chipnames) {
     283        chipnames = psArrayAllocEmpty (4);
     284        psMetadataAddArray (tgt->analysis, PS_LIST_TAIL, PSWARP_ANALYSIS_CHIPNAMES, 0, "source images", chipnames);
     285        psFree (chipnames); // can free here since we put a copy on tgt->analysis
     286    }
     287    psArrayAdd (chipnames, 4, chipname);
     288
     289    // we also need to save the corresponding chip name for this map
     290    psArray *chipRegions = psMetadataLookupPtr (&status, tgt->analysis, PSWARP_ANALYSIS_CHIPREGIONS);
     291    if (!chipRegions) {
     292        chipRegions = psArrayAllocEmpty (4);
     293        psMetadataAddArray (tgt->analysis, PS_LIST_TAIL, PSWARP_ANALYSIS_CHIPREGIONS, 0, "source images", chipRegions);
     294        psFree (chipRegions); // can free here since we put a copy on tgt->analysis
     295    }
     296    psArrayAdd (chipRegions, 4, imageRegionString);
     297
     298    fprintf (stderr, "warp to %s X = %f + %f x + %f y\n", chipname, map->x->coeff[0][0], map->x->coeff[1][0], map->x->coeff[0][1]);
     299    fprintf (stderr, "warp to %s Y = %f + %f x + %f y\n", chipname, map->y->coeff[0][0], map->y->coeff[1][0], map->y->coeff[0][1]);
     300   
     301    psFree (map);
     302    psFree (tgtX);
     303    psFree (tgtY);
     304    psFree (srcX);
     305    psFree (srcY);
     306
     307    psFree (srcPos);
     308    psFree (tgtPos);
     309    psFree (FP);
     310    psFree (TP);
     311    psFree (sky);
     312
     313    psFree (imageRegionString);
     314
     315    return true;
     316}
  • trunk/pswarp/src/pswarpUpdateMetadata.c

    r35563 r36835  
    7878                psFree(md5string);
    7979                psFree(headerName);
     80
     81                bool status;
     82                psString keyword = NULL;
     83                psString mapstring = NULL;
     84
     85                // we (should) have an array of chipnames on the analysis
     86                psArray *chipnames = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_CHIPNAMES);
     87                for (int i = 0; chipnames && (i < chipnames->n); i++) {
     88                  psStringAppend (&keyword, "SRC_%04d", i);
     89                  psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", chipnames->data[i]);
     90                  psFree (keyword);
     91                }
     92
     93                // we (should) have an array of chipnames on the analysis
     94                psArray *chipRegions = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_CHIPREGIONS);
     95                for (int i = 0; chipRegions && (i < chipRegions->n); i++) {
     96                  psStringAppend (&keyword, "SEC_%04d", i);
     97                  psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "input image", chipRegions->data[i]);
     98                  psFree (keyword);
     99                }
     100
     101                // we (should) also have an array of backwards maps (warp->chip) for the above chips
     102                psArray *backmaps  = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_BACKMAPS); //
     103                for (int i = 0; backmaps && (i < backmaps->n); i++) {
     104                  psPlaneTransform *map = backmaps->data[i];             
     105                  psStringAppend (&keyword, "MPX_%04d", i);
     106                  psStringAppend (&mapstring, "[%8.2f,%8.4f,%8.4f]", map->x->coeff[0][0], map->x->coeff[1][0], map->x->coeff[0][1]);
     107                  psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "warp to image map", mapstring);
     108                  psFree (keyword);
     109                  psFree (mapstring);
     110                  psStringAppend (&keyword, "MPY_%04d", i);
     111                  psStringAppend (&mapstring, "[%8.2f,%8.4f,%8.4f]", map->y->coeff[0][0], map->y->coeff[1][0], map->y->coeff[0][1]);
     112                  psMetadataAddStr(hdu->header, PS_LIST_TAIL, keyword, PS_META_REPLACE, "warp to image map", mapstring);
     113                  psFree (keyword);
     114                  psFree (mapstring);
     115                }
    80116            }
    81117
Note: See TracChangeset for help on using the changeset viewer.