Changeset 5560 for trunk/psastro/src/pmAstrom.c
- Timestamp:
- Nov 21, 2005, 11:03:53 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/pmAstrom.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/pmAstrom.c
r5510 r5560 1 1 # include "pmAstrom.h" 2 2 3 // sort by mag (descending) 4 int pmAstromObjSortByFPX (const void **a, const void **b) 5 { 6 pmAstromObj *A = *(pmAstromObj **)a; 7 pmAstromObj *B = *(pmAstromObj **)b; 8 9 psF32 diff = A->FP.x - B->FP.x; 10 if (diff > FLT_EPSILON) return (+1); 11 if (diff < FLT_EPSILON) return (-1); 12 return (0); 13 } 14 15 psPlane *psCoordReadoutToCell (psPlane *cellpix, psPlane *readpix, pmReadout *readout) { 16 17 if (cellpix == NULL) { 18 cellpix = psPlaneAlloc (); 19 } 20 21 cellpix->x = readpix->x*readout->colBins + readout->col0; 22 cellpix->y = readpix->y*readout->rowBins + readout->row0; 23 24 return (cellpix); 25 } 26 27 psPlane *psCoordCellToReadout (psPlane *readpix, psPlane *cellpix, pmReadout *readout) { 28 29 if (readpix == NULL) { 30 readpix = psPlaneAlloc (); 31 } 32 33 readpix->x = (cellpix->x - readout->col0) / readout->colBins; 34 readpix->y = (cellpix->y - readout->row0) / readout->rowBins; 35 36 return (readpix); 37 } 38 39 psPlane* psCoordChipToCell_EAM(psPlane* cellCoord, 40 const psPlane* chipCoord, 41 const pmCell* cell) 42 { 43 PS_ASSERT_PTR_NON_NULL(chipCoord, NULL); 44 PS_ASSERT_PTR_NON_NULL(cell, NULL); 45 PS_ASSERT_PTR_NON_NULL(cell->parent, NULL); 46 47 // XXX EAM : why was this being done? 48 // pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent); 49 PS_ASSERT_PTR_NON_NULL(cell->toChip, NULL); 50 psPlaneTransform *tmpChipToCell = p_psPlaneTransformLinearInvert(cell->toChip); 51 PS_ASSERT_PTR_NON_NULL(tmpChipToCell, NULL); 52 cellCoord = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord); 53 psFree(tmpChipToCell); 54 return(cellCoord); 55 } 56 57 bool psastroProjectFPA (pmFPA *fpa, char *starlist, bool toSky) { 58 59 bool status; 60 61 for (int i = 0; i < fpa->chips->n; i++) { 62 pmChip *chip = fpa->chips->data[i]; 63 for (int j = 0; j < chip->cells->n; j++) { 64 pmCell *cell = chip->cells->data[j]; 65 for (int k = 0; k < cell->readouts->n; k++) { 66 pmReadout *readout = cell->readouts->data[k]; 67 psArray *stars = psMetadataLookupPtr (&status, readout->analysis, starlist); 68 if (toSky) { 69 psastroProjectRawstars (stars, readout); 70 } else { 71 psastroProjectRefstars (stars, readout); 72 } 73 } 74 } 75 } 76 return true; 77 } 78 79 bool psastroProjectRawstars (psArray *stars, pmReadout *readout) { 80 81 pmCell *cell = readout->parent; 82 pmChip *chip = cell->parent; 83 pmFPA *fpa = chip->parent; 84 85 for (int i = 0; i < stars->n; i++) { 86 pmAstromObj *star = stars->data[i]; 87 psCoordReadoutToCell (&star->cell, &star->pix, readout); 88 psCoordCellToChip (&star->chip, &star->cell, cell); 89 psCoordChipToFPA (&star->FP, &star->chip, chip); 90 psCoordFPAToTP (&star->TP, &star->FP, 0.0, 0.0, fpa); 91 psCoordTPToSky (&star->sky, &star->TP, fpa->projection); 92 } 93 return true; 94 } 95 96 bool psastroProjectRefstars (psArray *stars, pmReadout *readout) { 97 98 pmCell *cell = readout->parent; 99 pmChip *chip = cell->parent; 100 pmFPA *fpa = chip->parent; 101 102 for (int i = 0; i < stars->n; i++) { 103 pmAstromObj *star = stars->data[i]; 104 psCoordSkyToTP (&star->TP, &star->sky, fpa->projection); 105 psCoordTPToFPA (&star->FP, &star->TP, 0.0, 0.0, fpa); 106 psCoordFPAToChip (&star->chip, &star->FP, chip); 107 psCoordChipToCell_EAM (&star->cell, &star->chip, cell); 108 psCoordCellToReadout (&star->pix, &star->cell, readout); 109 } 110 return true; 111 } 112 3 113 psArray *pmAstromRadiusMatch (psArray *st1, psArray *st2, psMetadata *config) { 4 114 5 // assume the lists are sorted, or sort in place? 6 // sort st1 by P 7 // sort st2 by P 8 9 double dX, dY; 115 bool status; 116 int jStart; 117 double dX, dY, dR; 118 119 double RADIUS = psMetadataLookupF32 (&status, config, "PSASTRO.MATCH.RADIUS"); 120 double RADIUS_SQR = PS_SQR (RADIUS); 121 122 // sort both lists by Focal Plane X coord 123 st1 = psArraySort (st1, pmAstromObjSortByFPX); 124 st2 = psArraySort (st2, pmAstromObjSortByFPX); 125 126 psArray *matches = psArrayAlloc (100); 127 matches->n = 0; 10 128 11 129 int i = 0; 12 130 int j = 0; 13 14 double RADIUS = psMetadataLookupR32 (&status, myHeader, "ASTROM_MATCH_RADIUS");15 double RADIUS_SQR = PS_SQR (RADIUS);16 17 psArray *matches = psArrayAlloc (100);18 matches->n = 0;19 20 131 while ((i < st1->n) && (j < st2->n)) { 21 132 … … 34 145 35 146 dX = ((pmAstromObj *)st1->data[i])->FP.x - ((pmAstromObj *)st2->data[j])->FP.x; 36 d Q= ((pmAstromObj *)st1->data[i])->FP.y - ((pmAstromObj *)st2->data[j])->FP.y;37 dR = dX*dX + d Q*dQ;147 dY = ((pmAstromObj *)st1->data[i])->FP.y - ((pmAstromObj *)st2->data[j])->FP.y; 148 dR = dX*dX + dY*dY; 38 149 39 150 if (dR > RADIUS_SQR) { … … 44 155 // got a match; add to output list 45 156 pmAstromMatch *match = pmAstromMatchAlloc (i, j); 46 psArrayAdd (matches, match, 100);157 psArrayAdd (matches, 100, match); 47 158 48 159 j++; … … 51 162 i++; 52 163 } 53 return (match );164 return (matches); 54 165 } 55 166 56 167 // take two matched star lists and fit a psPlaneTransform between them 57 168 // 58 psPlaneTransform *pmAstromMatchedListFit (psPlaneTransform *map, psArray *st1, psArray *st2, psArray *match, psMetadata *config) { 169 psPlaneTransform *pmAstromMatchFit (psPlaneTransform *map, psArray *raw, psArray *ref, psArray *match, psMetadata *config) { 170 171 bool status; 172 pmAstromObj *rawStar, *refStar; 173 pmAstromMatch *pair; 59 174 60 175 if (map == NULL) { 61 // int nX = psMetadataLookupS32 (&status, myHeader, "CHIP.NX"); 62 // int nY = psMetadataLookupS32 (&status, myHeader, "CHIP.NY"); 63 map = psPlaneTransform (2, 2); 64 } 65 66 psStats *stats = psStatsAlloc (CLIPPED_MEAN); 67 stats->nSigma = psMetadataLookupS32 (&status, myHeader, "CHIP.NITER"); 68 stats->nSigma = psMetadataLookupS32 (&status, myHeader, "CHIP.NSIGMA"); 69 70 psVector *X = psVectorAlloc (match->n); 71 psVector *Y = psVectorAlloc (match->n); 72 psVector *x = psVectorAlloc (match->n); 73 psVector *y = psVectorAlloc (match->n); 176 int nX = psMetadataLookupS32 (&status, config, "PSASTRO.CHIP.NX"); 177 if (!status) nX = 1; 178 int nY = psMetadataLookupS32 (&status, config, "PSASTRO.CHIP.NY"); 179 if (!status) nY = 1; 180 map = psPlaneTransformAlloc (nX, nY); 181 // XXX EAM : not clear that we are allowed to use orders > 1 182 } 183 184 psStats *stats = psStatsAlloc (PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 185 stats->clipSigma = psMetadataLookupF32 (&status, config, "PSASTRO.CHIP.NSIGMA"); 186 stats->clipIter = psMetadataLookupS32 (&status, config, "PSASTRO.CHIP.NITER"); 187 188 // XXX EAM : clip fit seems to only work for F32! 189 // XXX EAM : clip fit fails to handle NULL error 190 psVector *X = psVectorAlloc (match->n, PS_TYPE_F32); 191 psVector *Y = psVectorAlloc (match->n, PS_TYPE_F32); 192 psVector *x = psVectorAlloc (match->n, PS_TYPE_F32); 193 psVector *y = psVectorAlloc (match->n, PS_TYPE_F32); 194 psVector *wt = psVectorAlloc (match->n, PS_TYPE_F32); 74 195 75 196 // take the matched stars, first fit 76 197 for (int i = 0; i < match->n; i++) { 77 198 78 pair = match->data[i]; 79 ob1 = st1->data[pair->i1]; 80 ob2 = st2->data[pair->i2]; 81 82 X->data.F64[i] = ob1->chip.x; 83 Y->data.F64[i] = ob1->chip.y; 84 85 x->data.F64[i] = ob2->FP.x; 86 y->data.F64[i] = ob2->FP.y; 199 pair = match->data[i]; 200 rawStar = raw->data[pair->i1]; 201 refStar = ref->data[pair->i2]; 202 203 X->data.F32[i] = rawStar->chip.x; 204 Y->data.F32[i] = rawStar->chip.y; 205 206 x->data.F32[i] = refStar->FP.x; 207 y->data.F32[i] = refStar->FP.y; 208 209 wt->data.F32[i] = 1.0; 87 210 } 88 211 89 212 // no masking, no errors 90 psVectorClipFitPolynomial2D (map->x, stats, NULL, 0, X, NULL, x, y);91 psVectorClipFitPolynomial2D (map->y, stats, NULL, 0, Y, NULL, x, y);213 psVectorClipFitPolynomial2D (map->x, stats, NULL, 0, X, wt, x, y); 214 psVectorClipFitPolynomial2D (map->y, stats, NULL, 0, Y, wt, x, y); 92 215 psFree (x); 93 216 psFree (y); 94 217 psFree (X); 95 218 psFree (Y); 219 psFree (wt); 96 220 psFree (stats); 97 221 … … 103 227 psArray *pmAstromRotateObj (psArray *old, psPlane center, double angle) { 104 228 229 double X, Y; 105 230 pmAstromObj *newObj; 231 pmAstromObj *oldObj; 106 232 107 233 psArray *new = psArrayAlloc (old->n); 108 234 109 cs = cos(angle);110 sn = sin(angle);111 xCenter = center.x;112 yCenter = center.y;235 double cs = cos(angle); 236 double sn = sin(angle); 237 double xCenter = center.x; 238 double yCenter = center.y; 113 239 114 240 for (int i = 0; i < old->n; i++) { … … 120 246 Y = oldObj->FP.y - yCenter; 121 247 122 newObj->FP.x = X*cs + Y*sn ;123 newObj->FP.y = Y*cs - X*sn ;248 newObj->FP.x = X*cs + Y*sn + xCenter; 249 newObj->FP.y = Y*cs - X*sn + yCenter; 124 250 125 251 new->data[i] = newObj; … … 148 274 obj->TP.y = 0; 149 275 150 obj->sky.x = 0; 151 obj->sky.y = 0; 152 153 obj->mag = 0; 276 obj->sky.r = 0; 277 obj->sky.d = 0; 278 279 obj->Mag = 0; 280 obj->dMag = 0; 154 281 155 282 return (obj);
Note:
See TracChangeset
for help on using the changeset viewer.
