Changeset 37066 for branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCM_MinimizeChisq.c
- Timestamp:
- Jul 17, 2014, 12:30:45 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-ops-20130712/psModules
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
src/objects (modified) (1 prop)
-
src/objects/pmPCM_MinimizeChisq.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-ops-20130712/psModules
- Property svn:mergeinfo deleted
-
branches/eam_branches/ipp-ops-20130712/psModules/src/objects
- Property svn:ignore
-
old new 12 12 pmSourceIO_CMF_PS1_V1.v1.c 13 13 pmSourceIO_CMF_PS1_V4.c 14 pmSourceIO_CMF_PS1_V5.c 14 15 pmSourceIO_CMF_PS1_SV1.c 15 16 pmSourceIO_CMF_PS1_SV2.c 17 pmSourceIO_CMF_PS1_SV3.c 16 18 pmSourceIO_CMF_PS1_DV1.c 17 19 pmSourceIO_CMF_PS1_DV2.c 18 20 pmSourceIO_CMF_PS1_DV3.c 19 21 pmSourceIO_CMF_PS1_DV4.c
-
- Property svn:ignore
-
branches/eam_branches/ipp-ops-20130712/psModules/src/objects/pmPCM_MinimizeChisq.c
r35768 r37066 31 31 #include "pmMoments.h" 32 32 #include "pmModelFuncs.h" 33 #include "pmModelClass.h" 33 34 #include "pmModel.h" 34 35 #include "pmModelUtils.h" 35 #include "pmModelClass.h"36 36 #include "pmSourceMasks.h" 37 37 #include "pmSourceExtendedPars.h" 38 38 #include "pmSourceDiffStats.h" 39 39 #include "pmSourceSatstar.h" 40 #include "pmSourceLensing.h" 40 41 #include "pmSource.h" 41 42 #include "pmSourceFitModel.h" 42 43 #include "pmPCMdata.h" 44 45 # define SAVE_IMAGES 0 46 # if (SAVE_IMAGES) 47 int psphotSaveImage (psMetadata *header, psImage *image, char *filename); 48 # endif 43 49 44 50 # define FACILITY "psModules.objects" … … 91 97 psF32 lambda = 0.001; 92 98 psF32 dLinear = 0.0; 93 psF32 nu = 2.0;99 psF32 nu = 3.0; 94 100 95 101 # if (USE_FFT && PRE_CONVOLVE) … … 130 136 } 131 137 138 if (min->isInteractive) { 139 fprintf (stderr, "%d : ", min->iter); 140 for (int ti = 0; ti < params->n; ti++) { 141 fprintf (stderr, "%f ", params->data.F32[ti]); 142 } 143 fprintf (stderr, " : %f\n", min->value); 144 } 145 146 char key[10]; // used for interactive responses 147 bool testValue = false; 148 132 149 // set a new guess for Alpha, Beta, Params 133 150 if (!psMinLM_GuessABP(Alpha, Beta, Params, alpha, beta, params, paramMask, checkLimits, lambda, &dLinear)) { 151 if (false && min->isInteractive) { 152 fprintf (stdout, "guess failed (singular matrix or NaN values), continue? [Y,n] "); 153 if (!fgets(key, 8, stdin)) { 154 psWarning("Unable to read option"); 155 } 156 switch (key[0]) { 157 case 'n': 158 case 'N': 159 done = true; 160 break; 161 case 'y': 162 case 'Y': 163 case '\n': 164 lambda *= 10.0; 165 continue; 166 default: 167 lambda *= 10.0; 168 continue; 169 } 170 if (done) break; 171 } 134 172 min->iter ++; 135 173 if (min->iter >= min->maxIter) break; … … 138 176 } 139 177 178 if (false && min->isInteractive) { 179 p_psVectorPrint(psTraceGetDestination(), Params, "current parameters: "); 180 fprintf (stdout, "last chisq : %f\n", min->value); 181 bool getOptions = true; 182 while (getOptions) { 183 fprintf (stdout, "options: (m)odify, (g)o, (q)uit: "); 184 if (!fgets(key, 8, stdin)) { 185 psWarning("Unable to read option"); 186 } 187 switch (key[0]) { 188 case 'm': 189 case 'M': 190 testValue = TRUE; 191 fprintf (stdout, "enter (Npar) (value): "); 192 int Npar = 0; 193 float value= 0; 194 int Nscan = fscanf (stdin, "%d %f", &Npar, &value); 195 if (Nscan != 2) { 196 fprintf (stderr, "scan failure\n"); 197 } 198 Params->data.F32[Npar] = value; 199 break; 200 case 'g': 201 case 'G': 202 case '\n': 203 getOptions = false; 204 break; 205 default: 206 done = true; 207 break; 208 } 209 fprintf (stderr, "foo\n"); 210 } 211 if (done) break; 212 } 213 140 214 // dump some useful info if trace is defined 141 215 if (psTraceGetLevel(FACILITY) >= 6) { … … 202 276 // XXX : Madsen gives suggestion for better use of rho 203 277 // rho is positive if the new chisq is smaller 204 if ( rho >= -1e-6) {278 if (testValue || (rho >= -1e-6)) { 205 279 min->value = Chisq; 206 280 alpha = psImageCopy(alpha, Alpha, PS_TYPE_F32); … … 215 289 case 0: 216 290 if (rho >= -1e-6) { 217 lambda *= 0. 25;291 lambda *= 0.1; 218 292 } else { 219 293 lambda *= 10.0; … … 234 308 if (rho > 0.0) { 235 309 lambda *= PS_MAX(0.33, (1.0 - pow(2.0*rho - 1.0, 3.0))); 236 nu = 2.0;310 nu = 3.0; 237 311 } else { 238 312 lambda *= nu; 239 nu *= 2.0;313 nu *= 3.0; 240 314 } 241 315 break; … … 381 455 coord->data.F32[1] = (psF32) (i + 0.5 + source->pixels->row0); 382 456 383 pcm->modelFlux->data.F32[i][j] = pcm->modelConv-> modelFunc (deriv, params, coord);457 pcm->modelFlux->data.F32[i][j] = pcm->modelConv->class->modelFunc (deriv, params, coord); 384 458 385 459 for (int n = 0; n < params->n; n++) { … … 408 482 # else 409 483 if (pcm->use1Dgauss) { 410 // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread): 411 // * the model flux is not masked 412 // * threading takes place above this level 413 pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type); 414 psImageSmooth_PreAlloc_F32 (pcm->modelConvFlux, pcm->smdata); 415 // psImageSmooth (pcm->modelConvFlux, pcm->sigma, pcm->nsigma); 484 485 if (USE_1D_CACHE) { 486 // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread): 487 // * the model flux is not masked 488 // * threading takes place above this level 489 pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type); 490 psImageSmoothCache_F32 (pcm->modelConvFlux, pcm->smdata); 491 } else { 492 pcm->modelConvFlux = psImageCopy (pcm->modelConvFlux, pcm->modelFlux, pcm->modelFlux->type.type); 493 psImageSmooth2dCache_F32 (pcm->modelConvFlux, pcm->smdata2d); 494 } 416 495 } else { 417 496 psImageConvolveKernel (pcm->modelConvFlux, pcm->modelFlux, NULL, 0, pcm->psfFFT); … … 428 507 # else 429 508 if (pcm->use1Dgauss) { 430 // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread): 431 // * the model flux is not masked 432 // * threading takes place above this level 433 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 434 psImageSmooth_PreAlloc_F32 (dmodelConv, pcm->smdata); 435 // psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma); 509 if (USE_1D_CACHE) { 510 // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread): 511 // * the model flux is not masked 512 // * threading takes place above this level 513 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 514 psImageSmoothCache_F32 (dmodelConv, pcm->smdata); 515 } else { 516 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 517 psImageSmooth2dCache_F32 (dmodelConv, pcm->smdata2d); 518 } 436 519 } else { 437 520 psImageConvolveKernel (dmodelConv, dmodel, NULL, 0, pcm->psfFFT); … … 449 532 450 533 if (pcm->use1Dgauss) { 451 // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread): 452 // * the model flux is not masked 453 // * threading takes place above this level 454 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 455 psImageSmooth_PreAlloc_F32 (dmodelConv, pcm->smdata); 456 // psImageSmooth (dmodelConv, pcm->sigma, pcm->nsigma); 534 if (USE_1D_CACHE) { 535 // do not use the threaded, mask-aware version of this code (psImageSmoothMaskPixelsThread): 536 // * the model flux is not masked 537 // * threading takes place above this level 538 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 539 psImageSmoothCache_F32 (dmodelConv, pcm->smdata); 540 } else { 541 dmodelConv = psImageCopy (dmodelConv, dmodel, dmodel->type.type); 542 psImageSmooth2dCache_F32 (dmodelConv, pcm->smdata2d); 543 } 457 544 } else { 458 545 psImageConvolveFFT (dmodelConv, dmodel, NULL, 0, pcm->psf); … … 474 561 // XXX TEST : SAVE IMAGES 475 562 # if (SAVE_IMAGES) 476 psphotSaveImage (NULL, pcm->psf->image, "psf.fits"); 477 psphotSaveImage (NULL, pcm->modelFlux, "model.fits"); 478 psphotSaveImage (NULL, pcm->modelConvFlux, "modelConv.fits"); 479 psphotSaveImage (NULL, source->pixels, "obj.fits"); 480 psphotSaveImage (NULL, source->maskObj, "mask.fits"); 481 psphotSaveImage (NULL, source->variance, "variance.fits"); 563 static int Npass = 0; 564 char name[128]; 565 if (!pcm->use1Dgauss) { 566 snprintf (name, 128, "psf.%03d.fits", Npass); psphotSaveImage (NULL, pcm->psf->image, name); 567 } 568 snprintf (name, 128, "mod.%03d.fits", Npass); psphotSaveImage (NULL, pcm->modelFlux, name); 569 snprintf (name, 128, "cnv.%03d.fits", Npass); psphotSaveImage (NULL, pcm->modelConvFlux, name); 570 snprintf (name, 128, "obj.%03d.fits", Npass); psphotSaveImage (NULL, source->pixels, name); 571 snprintf (name, 128, "msk.%03d.fits", Npass); psphotSaveImage (NULL, source->maskObj, name); 572 snprintf (name, 128, "var.%03d.fits", Npass); psphotSaveImage (NULL, source->variance, name); 573 for (int n = 0; n < pcm->dmodelsFlux->n; n++) { 574 psImage *dmodelConv = pcm->dmodelsConvFlux->data[n]; 575 if (!dmodelConv) continue; 576 snprintf (name, 128, "dpar.%01d.%03d.fits", n, Npass); psphotSaveImage (NULL, dmodelConv, name); 577 } 578 Npass ++; 482 579 # endif 483 580 … … 506 603 507 604 float ymodel = pcm->modelConvFlux->data.F32[i][j]; 508 float yweight = 1.0 / source->variance->data.F32[i][j]; 605 606 // XXXX note this point here::: 607 float yweight = pcm->poissonErrors ? 1.0 / source->variance->data.F32[i][j] : 1.0; 509 608 float delta = ymodel - source->pixels->data.F32[i][j]; 510 609
Note:
See TracChangeset
for help on using the changeset viewer.
