Changeset 35560 for trunk/psModules/src/objects/models/pmModel_TRAIL.c
- Timestamp:
- May 9, 2013, 12:19:21 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/models/pmModel_TRAIL.c
r35215 r35560 168 168 dPAR[PM_PAR_THETA] = PAR[PM_PAR_I0] * dPdT; 169 169 dPAR[PM_PAR_SIGMA] = 0; // we don't actually allow this to vary, so we do not need to calculate it 170 171 for (int i = 0; i < 7; i++) { 172 if (isnan(dPAR[i])) { 173 fprintf (stderr, "*"); 174 } 175 } 176 } 177 if (isnan(f)) { 178 fprintf (stderr, "!"); 170 179 } 171 180 return(f); … … 228 237 } 229 238 239 # define NA 21 240 # define NR 21 241 static float flux[NA][NR]; 242 static float npix[NA][NR]; 243 244 bool pmTrailGetAngle (float *To, float *Io, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal, float sigma) { 245 246 float Xo, Yo; 247 if (!pmModelSetPosition(&Xo, &Yo, source)) return false; 248 249 psImage *image = source->pixels; 250 psImage *mask = source->maskObj; 251 psF32 **imData = image->data.F32; 252 psImageMaskType **mkData = mask->data.PS_TYPE_IMAGE_MASK_DATA; 253 254 // do a loop over the pixels, generating (dX,dY) dot (cos(theta),sin(theta)) 255 int dP; 256 int dX = Xo - mask->col0; 257 dP = mask->numCols - dX; 258 int DX = PS_MAX(dP, dX); 259 int NX = mask->numCols; 260 261 int dY = Yo - mask->row0; 262 dP = mask->numRows - dY; 263 int DY = PS_MAX(dP, dY); 264 int NY = mask->numRows; 265 266 // just hard wire this for now... 267 float radius = 10.0; 268 float radius2 = PS_SQR(radius); 269 270 // we have an array of Angles x Radii 271 float dT = M_PI / NA; 272 for (int na = 0; na < NA; na++) { 273 memset (flux[na], 0, NR*sizeof(float)); 274 memset (npix[na], 0, NR*sizeof(float)); 275 } 276 277 // we skip any pixels [real or virtual] outside of the specified radius (nominally the aperture radius) 278 // ix and iy track pixels relative to the centroid 279 for (int ix = -DX; ix < DX + 1; ix++) { 280 if (ix > radius) continue; 281 int mx = ix + dX; 282 for (int iy = -DY; iy < DY + 1; iy++) { 283 if (iy > radius) continue; 284 if (ix*ix + iy*iy > radius2) continue; 285 int my = iy + dY; 286 287 // include count only the unmasked pixels within the image area 288 if (mx < 0) continue; 289 if (my < 0) continue; 290 if (mx >= NX) continue; 291 if (my >= NY) continue; 292 293 // count pixels which are masked only with bad pixels 294 if (mkData[my][mx] & maskVal)continue; 295 296 // we have defined NA to be 21 297 int na = 0; 298 for (float angle = 0.0; na < NA; angle += dT, na ++) { 299 300 // XXX optimization : pre-compute the angle sines and cosines 301 float Rad = (ix * cos(angle)) + (iy * sin(angle)); 302 int nr = PS_MAX (PS_MIN (NR, Rad + 0.5*NR), 0); 303 304 flux[na][nr] += imData[my][mx]; 305 npix[na][nr] ++; 306 } 307 } 308 } 309 310 // generate a psf model (with integral of 1.0) 311 float Ao = 1.0 / sqrt(2*M_PI) / sigma; 312 float psf[NR]; 313 for (int nr = 0; nr < NR; nr++) { 314 psf[nr] = Ao*exp(-0.5*PS_SQR((nr - 0.5*NR)/sigma)); 315 } 316 317 float fangle[NA]; 318 for (int na = 0; na < NA; na++) { 319 float fpsf = 0.0; 320 for (int nr = 0; nr < NR; nr++) { 321 fpsf += psf[nr]*flux[na][nr]; 322 } 323 fangle[na] = fpsf; 324 // fprintf (stderr, "fpsf: %f, theta = %f\n", fpsf, PS_DEG_RAD*dT*na); 325 } 326 327 float peak = fangle[0]; 328 int pbin = 0; 329 for (int na = 0; na < NA; na++) { 330 if (fangle[na] > peak) { 331 peak = fangle[na]; 332 pbin = na; 333 } 334 } 335 336 // result is peak, pbin -> angle 337 *To = dT * pbin; 338 *Io = peak * Ao; 339 340 return true; 341 } 342 230 343 // make an initial guess for parameters 231 344 // 0.5 PIX: moments and peaks are in pixel coords, thus so are model parameters 232 bool PM_MODEL_GUESS (pmModel *model, pmSource *source )345 bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) 233 346 { 234 347 psF32 *PAR = model->params->data.F32; … … 260 373 //else { size = psfAxes.major; } 261 374 375 float theta, peak; 376 pmTrailGetAngle (&theta, &peak, source, maskVal, markVal, psfAxes.major); 377 262 378 // axes.major is a sigma in the major direction; scale to 263 379 PAR[PM_PAR_LENGTH] = 1.5*2.35*size; // a tophat of length L has L = 1.5 * 2.35 * sigma … … 266 382 267 383 // set the model normalization 268 if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) { 269 return false; 270 } 384 // if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) { 385 // return false; 386 // } 387 PAR[PM_PAR_I0] = peak; 271 388 272 389 // set the model position
Note:
See TracChangeset
for help on using the changeset viewer.
