Changeset 39783
- Timestamp:
- Oct 20, 2016, 12:11:12 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20160809/Ohana/src/relastro/src/UpdateObjects.c
r39747 r39783 5 5 # define PAR_MIN_NPTS 7 6 6 # define PAR_MIN_NPTS_BOOT 6 7 # define PM_MIN_NPTS 48 # define PM_MIN_NPTS_BOOT 39 # define POS_MIN_NPTS 310 # define POS_MIN_NPTS_BOOT 27 # define PM_MIN_NPTS 5 8 # define PM_MIN_NPTS_BOOT 4 9 # define POS_MIN_NPTS 4 10 # define POS_MIN_NPTS_BOOT 4 11 11 12 12 typedef enum { … … 183 183 if (Trange < PM_DT_MIN) { 184 184 // not enough baseline for proper motion, only set mean position 185 mode = FIT_AVERAGE;186 185 goto justPosition; 187 186 } 188 187 if (parRange < PAR_FACTOR_MIN) { 189 188 // not enough parallax factor range, skip parallax 190 mode = FIT_PM_ONLY;191 189 goto skipParallax; 192 190 } 193 191 if (fitStats->Npoints < PAR_MIN_NPTS) { 194 192 // not enough data, skip parallax 195 mode = FIT_PM_ONLY;196 193 goto skipParallax; 197 194 } 198 195 199 196 // we are going to use the IRLS analysis to calculate the mean solution and the masking 200 // then run N_BOOTSTRAP_SAMPLES to measure the errors 201 fitStats->fitdataPar->getError = !N_BOOTSTRAP_SAMPLES; 197 // then run N_BOOTSTRAP_SAMPLES to measure the errors. We first measure the OLS error, 198 // and choose the max of the OLS and bootstrap errors 199 fitStats->fitdataPar->getError = TRUE; 202 200 if (USE_IRLS) { 203 201 if (!FitPMandPar_IRLS (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) { 204 mode = FIT_PM_ONLY;205 202 goto skipParallax; 206 203 } 207 204 } else { 208 205 if (!FitPMandPar_Basic (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) { 209 mode = FIT_PM_ONLY;210 206 goto skipParallax; 211 207 } … … 217 213 fitStats->Nfit = 0; 218 214 int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints); 219 if (Nnomask < PAR_MIN_NPTS_BOOT) { 220 // if we do not have enough points to assess parallax error, we cannot dothe bootstrap analysis.221 mode = FIT_PM_ONLY; 222 goto skipParallax;223 } 215 216 // if we do not have enough points to assess parallax error, skip the bootstrap analysis. 217 // (I think the test above means we never do this skip) 218 if (Nnomask < PAR_MIN_NPTS_BOOT) goto skipParallaxBootstrap; 219 224 220 for (k = 0; k < fitStats->NfitAlloc; k++) { 225 221 BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask); … … 227 223 fitStats->Nfit ++; 228 224 } 225 229 226 // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above) 230 227 // this call expects the fitted parameters to have the formal error set: it will apply the … … 237 234 } 238 235 236 skipParallaxBootstrap: 239 237 // project Ro, Do back to RA,DEC 240 238 XY_to_RD (&fitPar.Ro, &fitPar.Do, fitPar.Ro, fitPar.Do, &fitStats->coords); … … 255 253 valid = valid && (fabs(fitPar.uD) < 4.0); 256 254 valid = valid && (fabs(fitPar.p) < 2.0); 257 if (!valid) { 258 mode = FIT_PM_ONLY; 259 } else { 255 if (valid) { 260 256 average[0].flags |= ID_OBJ_USE_PAR; 261 257 } … … 267 263 if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) { 268 264 if (Trange < PM_DT_MIN) { 269 mode = FIT_AVERAGE;270 265 goto justPosition; 271 266 } 272 267 if (fitStats->Npoints < PM_MIN_NPTS) { 273 mode = FIT_AVERAGE;274 268 goto justPosition; 275 269 } 276 270 277 271 // if we have fitted (and accepted) a parallax model, get the best pm fit and chisq 278 // given the set of points (mask is respected) 279 if (average[0].flags & ID_OBJ_USE_PAR) { 272 // given the set of points (mask is respected). Alternatively, if we do not request 273 // IRLS fitting, the just use OLS fitting (skip bootstrap) 274 if ((average[0].flags & ID_OBJ_USE_PAR) || !USE_IRLS) { 280 275 if (!FitPM_Basic (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) { 281 276 average[0].flags |= ID_OBJ_BAD_PM; 282 277 goto justPosition; 283 278 } 284 } else { 285 fitStats->fitdataPM->getError = !N_BOOTSTRAP_SAMPLES; 286 if (USE_IRLS) { 287 if (!FitPM_IRLS (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) { 288 mode = FIT_AVERAGE; 289 goto justPosition; 290 } 291 } else { 292 if (!FitPM_Basic (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) { 293 mode = FIT_AVERAGE; 294 goto justPosition; 295 } 296 } 279 goto skipProperMotionBootstrap; 280 } 281 282 // we are going to use the IRLS analysis to calculate the mean solution and the masking 283 // then run N_BOOTSTRAP_SAMPLES to measure the errors. We first measure the OLS error, 284 // and choose the max of the OLS and bootstrap errors 285 fitStats->fitdataPM->getError = TRUE; 286 if (!FitPM_IRLS (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) { 287 goto justPosition; 288 } 297 289 298 290 // in the fits above, we have saved the formal error for the unmasked points. 299 291 // if we do not have enough points for bootstrap, we will keep those errors 300 if (N_BOOTSTRAP_SAMPLES && (fitPM.Nfit >= PM_MIN_NPTS_BOOT)) { 301 fitStats->Nfit = 0; 302 int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints); 303 if (Nnomask < PM_MIN_NPTS_BOOT) { 304 mode = FIT_AVERAGE; 305 goto justPosition; 306 } 307 for (k = 0; k < fitStats->NfitAlloc; k++) { 308 BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask); 309 if (!FitPM_Basic (&fitStats->fit[k], fitStats->fitdataPM, fitStats->sample, Nnomask)) continue; 310 fitStats->Nfit ++; 311 } 292 if (N_BOOTSTRAP_SAMPLES && (fitPM.Nfit >= PM_MIN_NPTS_BOOT)) { 293 fitStats->Nfit = 0; 294 int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints); 295 296 // if we do not have enough points to assess p.m. error, skip the bootstrap analysis. 297 // (I think the test above means we never do this skip) 298 if (Nnomask < PM_MIN_NPTS_BOOT) goto skipProperMotionBootstrap; 299 300 for (k = 0; k < fitStats->NfitAlloc; k++) { 301 BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask); 302 if (!FitPM_Basic (&fitStats->fit[k], fitStats->fitdataPM, fitStats->sample, Nnomask)) continue; 303 fitStats->Nfit ++; 304 } 305 312 306 // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above) 313 307 // this call expects the fitted parameters to have the formal error set: it will apply the 314 308 // max of the formal and bootstrap errors 315 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);316 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);317 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uR);318 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uD);319 }320 } 321 309 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA); 310 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC); 311 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uR); 312 BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uD); 313 } 314 315 skipProperMotionBootstrap: 322 316 // project Ro, Do back to RA,DEC 323 317 XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &fitStats->coords); … … 326 320 fitStats->Npm ++; 327 321 322 // XXX a hard-wired hack... 328 323 // unless there is a clear problems (below) with the proper-motion fit or we have a parallax fit, we will use pm fit 329 324 int valid = TRUE; … … 335 330 valid = valid && (fabs(fitPM.uD) < 4.0); 336 331 if (!valid) { 337 mode = FIT_AVERAGE;338 332 average[0].flags |= ID_OBJ_BAD_PM; 339 333 } else { … … 349 343 // if we only have one point, this is silly... 350 344 345 // set the proper motion (to the galaxy model or average value, if desired; else to 0,0) 351 346 FitAstromResultSetPM (&fitPos, 1, average); 352 // fprintf (stderr, "fit 1: %f %f : %f %f\n", fitPos.Ro, fitPos.Do, fitPos.uR, fitPos.uD); 353 if (average[0].flags & (ID_OBJ_USE_PAR | ID_OBJ_USE_PM)) { 347 348 // if we already have a valid fit (pm or par), use OLS to fit the position 349 // alternatively, if we do not request IRLS, use OLS 350 // alternatively, if we do not have enough points, use OLS 351 if ((average[0].flags & (ID_OBJ_USE_PAR | ID_OBJ_USE_PM)) || (fitStats->Npoints < POS_MIN_NPTS) || !USE_IRLS) { 354 352 if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 355 // if this fails, stick with the PM and/or PAR fit from above 353 // if this fails, stick with the PM and/or PAR fit from above, or use a single value 356 354 goto doneWithFit; 357 355 } 358 } else { 359 if (fitStats->Npoints < POS_MIN_NPTS) { 360 // I will not try to outlier-reject, just calculate the weighted average 361 if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 362 // if we have tried this, we have not masked any points; we will find a single unmasked point below 363 goto doneWithFit; 364 } 356 // if we have not already gotten a good fit, use this fit 357 if (!(average[0].flags & (ID_OBJ_USE_PAR | ID_OBJ_USE_PM))) { 365 358 average[0].flags |= ID_OBJ_USE_AVE; 366 359 average[0].flags |= ID_OBJ_RAW_AVE; 367 goto useBasic; 368 } 369 if (USE_IRLS) { 370 if (!FitPosPMfixed_IRLS (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 371 // if the above fails, we need to clear the masks and try again below 372 FitPointsClearMasks (fitStats->points, fitStats->Npoints); 373 // just calculate the weighted average 374 if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 375 // if this fails, find a single unmasked point below 376 goto doneWithFit; 377 } 378 average[0].flags |= ID_OBJ_USE_AVE; 379 average[0].flags |= ID_OBJ_RAW_AVE; 380 goto useBasic; 381 } 382 } else { 383 if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 384 // if this fails, find a single unmasked point below 385 goto doneWithFit; 386 } 387 average[0].flags |= ID_OBJ_USE_AVE; 388 average[0].flags |= ID_OBJ_RAW_AVE; 389 goto useBasic; 390 } 391 // fprintf (stderr, "fit 2: %f %f : %f %f\n", fitPos.Ro, fitPos.Do, fitPos.uR, fitPos.uD); 392 if (N_BOOTSTRAP_SAMPLES) { 393 fitStats->Nfit = 0; 394 int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints); 395 if (Nnomask < POS_MIN_NPTS_BOOT) { 396 // XXX if the above fails, accept the formal error from unmasked points? 397 FitPointsClearMasks (fitStats->points, fitStats->Npoints); 398 if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 399 // if this fails, find a single unmasked point below 400 goto doneWithFit; 401 } 402 average[0].flags |= ID_OBJ_USE_AVE; 403 average[0].flags |= ID_OBJ_RAW_AVE; 404 goto useBasic; 405 } 406 FitAstromResultSetPM (fitStats->fit, fitStats->NfitAlloc, average); 407 for (k = 0; k < fitStats->NfitAlloc; k++) { 408 BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask); 409 if (!FitPosPMfixed_Basic (&fitStats->fit[k], fitStats->fitdataPos, fitStats->sample, Nnomask)) continue; 410 fitStats->Nfit ++; 411 } 412 BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA); 413 BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC); 360 } 361 goto useBasic; 362 } 363 364 // try the IRLS fitting, otherwise give up and use OLS 365 if (!FitPosPMfixed_IRLS (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 366 // if the above fails, we need to clear the masks and try again below 367 FitPointsClearMasks (fitStats->points, fitStats->Npoints); 368 // just calculate the weighted average 369 if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 370 // if this fails, find a single unmasked point below 371 goto doneWithFit; 414 372 } 415 373 average[0].flags |= ID_OBJ_USE_AVE; 374 average[0].flags |= ID_OBJ_RAW_AVE; 375 goto useBasic; 376 } 377 average[0].flags |= ID_OBJ_USE_AVE; 378 379 if (N_BOOTSTRAP_SAMPLES && (fitPos.Nfit >= POS_MIN_NPTS_BOOT)) { 380 fitStats->Nfit = 0; 381 int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints); 382 383 if (Nnomask < POS_MIN_NPTS_BOOT) goto useBasic; 384 385 FitAstromResultSetPM (fitStats->fit, fitStats->NfitAlloc, average); 386 for (k = 0; k < fitStats->NfitAlloc; k++) { 387 BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask); 388 if (!FitPosPMfixed_Basic (&fitStats->fit[k], fitStats->fitdataPos, fitStats->sample, Nnomask)) continue; 389 fitStats->Nfit ++; 390 } 391 392 // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above) 393 // this call expects the fitted parameters to have the formal error set: it will apply the 394 // max of the formal and bootstrap errors 395 BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA); 396 BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC); 416 397 } 417 398 … … 580 561 average[0].dP = fit.dp; // parallax error in arcsec 581 562 563 582 564 average[0].ChiSqAve = fitPos.chisq; 583 565 average[0].ChiSqPM = fitPM.chisq; … … 873 855 int i; 874 856 857 myAbort ("this should not be called anymore"); 858 875 859 // add up the chi square for the fit 876 860 double chisq = 0.0;
Note:
See TracChangeset
for help on using the changeset viewer.
