Changeset 36835 for trunk/pswarp/src/pswarpLoop.c
- Timestamp:
- Jun 7, 2014, 6:38:38 AM (12 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpLoop.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpLoop.c
r36083 r36835 156 156 157 157 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; 160 160 } 161 161 … … 163 163 return true; 164 164 165 FAIL:165 FAIL: 166 166 psFree (view); 167 167 return false; 168 168 } 169 170 bool pswarpGetBackTransform (pmReadout *tgt, pmReadout *src); 169 171 170 172 // once the output fpa elements have been built, loop over the fpa and generate stats … … 188 190 while ((readout = pmFPAviewNextReadout(view, output, 1)) != NULL) { 189 191 pswarpTransformReadout (readout, input, config, backgroundWarp); 192 193 // determine a (rough) linear WCS from readout to input 194 pswarpGetBackTransform (readout, input); 190 195 } 191 196 } … … 194 199 } 195 200 201 bool 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 }
Note:
See TracChangeset
for help on using the changeset viewer.
