Changeset 19200 for trunk/pswarp/src/pswarpTransformSources.c
- Timestamp:
- Aug 25, 2008, 3:04:38 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpTransformSources.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpTransformSources.c
r18839 r19200 24 24 psArray *outSources = psMemIncrRefCounter(psMetadataLookupPtr(&mdok, output->analysis, "PSPHOT.SOURCES")); // Target sources 25 25 if (!outSources) { 26 outSources = psArrayAllocEmpty(SOURCE_ARRAY_BUFFER);27 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY,28 "Warped sources", outSources);26 outSources = psArrayAllocEmpty(SOURCE_ARRAY_BUFFER); 27 psMetadataAddPtr(output->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, 28 "Warped sources", outSources); 29 29 } 30 30 … … 33 33 // this does not cost us so much time. 34 34 for (int i = 0; i < inSources->n; i++) { 35 pmSource *source = inSources->data[i]; // Source of interest36 pmModel *model = source->modelPSF; // Model for this source37 float xIn, yIn; // Coordinates of source38 xIn = model->params->data.F32[PM_PAR_XPOS] - input->image->col0;39 yIn = model->params->data.F32[PM_PAR_YPOS] - input->image->row0;35 pmSource *source = inSources->data[i]; // Source of interest 36 pmModel *model = source->modelPSF; // Model for this source 37 float xIn, yIn; // Coordinates of source 38 xIn = model->params->data.F32[PM_PAR_XPOS] - input->image->col0; 39 yIn = model->params->data.F32[PM_PAR_YPOS] - input->image->row0; 40 40 41 int xGrid, yGrid; // Grid coordinates for local map42 if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) {43 psError(PS_ERR_UNKNOWN, false, "Unable to get grid coordinates for source at %f,%f\n",44 xIn, yIn);45 psFree(outSources);46 psFree(sourceGrid);47 return false;48 }49 if (xGrid < 0 || xGrid >= sourceGrid->nXpts || yGrid < 0 || yGrid >= sourceGrid->nYpts) {50 // It's not even on the grid51 // XXX how can this happen?52 continue;53 }41 int xGrid, yGrid; // Grid coordinates for local map 42 if (!pswarpMapGridSetGrid(sourceGrid, xIn + 0.5, yIn + 0.5, &xGrid, &yGrid)) { 43 psError(PS_ERR_UNKNOWN, false, "Unable to get grid coordinates for source at %f,%f\n", 44 xIn, yIn); 45 psFree(outSources); 46 psFree(sourceGrid); 47 return false; 48 } 49 if (xGrid < 0 || xGrid >= sourceGrid->nXpts || yGrid < 0 || yGrid >= sourceGrid->nYpts) { 50 // It's not even on the grid 51 // XXX how can this happen? 52 continue; 53 } 54 54 55 pswarpMap *map = sourceGrid->maps[xGrid][yGrid]; // Locally linear transformation56 double xOut, yOut; // Output coordinates57 if (!pswarpMapApply(&xOut, &yOut, map, xIn + 0.5, yIn + 0.5)) {58 psError(PS_ERR_UNKNOWN, false, "Unable to transform coordinates for source at %f,%f\n",59 xIn, yIn);60 psFree(outSources);61 psFree(sourceGrid);62 return false;63 }64 xOut += output->image->col0 - 0.5;65 yOut += output->image->row0 - 0.5;66 if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) {67 // It's not in the output image68 continue;69 }55 pswarpMap *map = sourceGrid->maps[xGrid][yGrid]; // Locally linear transformation 56 double xOut, yOut; // Output coordinates 57 if (!pswarpMapApply(&xOut, &yOut, map, xIn + 0.5, yIn + 0.5)) { 58 psError(PS_ERR_UNKNOWN, false, "Unable to transform coordinates for source at %f,%f\n", 59 xIn, yIn); 60 psFree(outSources); 61 psFree(sourceGrid); 62 return false; 63 } 64 xOut += output->image->col0 - 0.5; 65 yOut += output->image->row0 - 0.5; 66 if (xOut < minX || xOut > maxX || yOut < minY || yOut > maxY) { 67 // It's not in the output image 68 continue; 69 } 70 70 71 // Generate the new source in the output frame 72 pmSource *new = pmSourceAlloc(); // New source 73 new->peak = pmPeakAlloc(xOut, yOut, source->peak->flux, PM_PEAK_LONE); 74 new->peak->flux = source->peak->flux; 75 new->type = PM_SOURCE_TYPE_STAR; 76 new->psfMag = source->psfMag; 77 new->errMag = source->errMag; 78 new->sky = source->sky; 79 new->skyErr = source->skyErr; 80 new->pixWeight = source->pixWeight; 81 new->modelPSF = pmModelAlloc(source->modelPSF->type); 71 // Generate the new source in the output frame 72 // 73 // Magnitudes will be off if there's any change in scale, but for our purposes (mainly x,y and 74 // relative flux) that's OK. 75 pmSource *new = pmSourceAlloc(); // New source 76 new->peak = pmPeakAlloc(xOut, yOut, source->peak->flux, PM_PEAK_LONE); 77 new->peak->flux = source->peak->flux; 78 new->type = source->type; 79 new->mode = source->mode; 80 new->psfMag = source->psfMag; 81 new->extMag = source->extMag; 82 new->errMag = source->errMag; 83 new->apMag = source->apMag; 84 new->pixWeight = source->pixWeight; 85 new->psfChisq = source->psfChisq; 86 new->crNsigma = source->crNsigma; 87 new->extNsigma = source->extNsigma; 88 new->sky = source->sky; 89 new->skyErr = source->skyErr; 90 91 new->modelPSF = pmModelAlloc(source->modelPSF->type); 82 92 83 93 #if 0 84 // XXX Note that this will not set the correct axes85 pmPSF_AxesToModel(new->modelPSF->params->data.F32,86 pmPSF_ModelToAxes(source->modelPSF->params->data.F32, 20.0));94 // XXX Note that this will not set the correct axes 95 pmPSF_AxesToModel(new->modelPSF->params->data.F32, 96 pmPSF_ModelToAxes(source->modelPSF->params->data.F32, 20.0)); 87 97 #endif 88 98 89 // Propagate the position erorrs90 float dxIn, dyIn; // Errors in input coordinates91 dxIn = model->dparams->data.F32[PM_PAR_XPOS];92 dyIn = model->dparams->data.F32[PM_PAR_YPOS];99 // Propagate the position erorrs 100 float dxIn, dyIn; // Errors in input coordinates 101 dxIn = model->dparams->data.F32[PM_PAR_XPOS]; 102 dyIn = model->dparams->data.F32[PM_PAR_YPOS]; 93 103 94 float dxOut, dyOut; // Errors in output coordinates95 dxOut = sqrt(PS_SQR(map->Xx * dxIn) + PS_SQR(map->Xy * dyIn));96 dyOut = sqrt(PS_SQR(map->Yx * dxIn) + PS_SQR(map->Yy * dyIn));104 float dxOut, dyOut; // Errors in output coordinates 105 dxOut = sqrt(PS_SQR(map->Xx * dxIn) + PS_SQR(map->Xy * dyIn)); 106 dyOut = sqrt(PS_SQR(map->Yx * dxIn) + PS_SQR(map->Yy * dyIn)); 97 107 98 new->modelPSF->params->data.F32[PM_PAR_XPOS] = xOut;99 new->modelPSF->params->data.F32[PM_PAR_YPOS] = yOut;100 new->modelPSF->dparams->data.F32[PM_PAR_XPOS] = dxOut;101 new->modelPSF->dparams->data.F32[PM_PAR_YPOS] = dyOut;108 new->modelPSF->params->data.F32[PM_PAR_XPOS] = xOut; 109 new->modelPSF->params->data.F32[PM_PAR_YPOS] = yOut; 110 new->modelPSF->dparams->data.F32[PM_PAR_XPOS] = dxOut; 111 new->modelPSF->dparams->data.F32[PM_PAR_YPOS] = dyOut; 102 112 103 psArrayAdd(outSources, SOURCE_ARRAY_BUFFER, new);104 psFree(new); // Drop reference113 psArrayAdd(outSources, SOURCE_ARRAY_BUFFER, new); 114 psFree(new); // Drop reference 105 115 } 106 116 psFree(sourceGrid);
Note:
See TracChangeset
for help on using the changeset viewer.
