- Timestamp:
- Jan 11, 2012, 6:57:13 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/psphot/src/psphotFitSourcesLinear.c
r33071 r33086 12 12 static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal); 13 13 14 bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, int index, psMetadata *recipe, pmReadout *readout, psArray *sources); 15 pmSourceFitVarMode psphotGetFitVarMode (psMetadata *recipe); 16 bool psphotFreeModelVariance (pmReadout *readout, psArray *sources); 17 14 18 // for now, let's store the detections on the readout->analysis for each readout 15 19 bool psphotFitSourcesLinear (pmConfig *config, const pmFPAview *view, const char *filerule, bool final) … … 29 33 return false; 30 34 } 35 // MODEL_VAR requires 2 passes -- in the first, we get the rough fluxes; in the second, we 36 // use the flux to define the model variance before fitting the objects. Other modes only 37 // do a single pass. 31 38 pmSourceFitVarMode fitVarModePass1 = (fitVarMode == PM_SOURCE_PHOTFIT_MODEL_VAR) ? PM_SOURCE_PHOTFIT_CONST : fitVarMode; 32 39 … … 66 73 // re-run the fit against that variance. 67 74 if (fitVarMode == PM_SOURCE_PHOTFIT_MODEL_VAR) { 68 // generate the model variance image 69 if (!psphotGenerateModelVariance ( recipe, readout, sources, psf, final, fitVarMode)) {75 // generate the model variance image & source pointers 76 if (!psphotGenerateModelVariance (config, view, i, recipe, readout, sources)) { 70 77 psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i); 71 78 return false; 72 79 } 80 81 // replace all sources (use TMPF_SUBTRACTED as test) 82 psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe, false); 73 83 74 84 // rerun fit with correct fitVarMode … … 77 87 return false; 78 88 } 89 90 // free the model variance image & source pointers 91 if (!psphotFreeModelVariance (readout, sources)) { 92 psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for %s entry %d", filerule, i); 93 return false; 94 } 79 95 } 80 96 … … 86 102 } 87 103 104 // look up the fit variance mode from the recipe; older recipes do not have the value 105 // 'LINEAR_FIT_VARIANCE_MODE'; in those cases, look for 'CONSTANT_PHOTOMETRIC_WEIGHTS' as a boolean and 106 // set the value to either CONST or IMAGE_VAR 88 107 pmSourceFitVarMode psphotGetFitVarMode (psMetadata *recipe) { 89 108 … … 96 115 psAbort("You must provide a value for LINEAR_FIT_VARIANCE_MODE or CONSTANT_PHOTOMETRIC_WEIGHTS"); 97 116 } 98 pm sourceFitVarMode fitVarMode = CONSTANT_PHOTOMETRIC_WEIGHTS ? PM_SOURCE_PHOTFIT_CONST : PM_SOURCE_PHOTFIT_IMAGE_VAR;117 pmSourceFitVarMode fitVarMode = CONSTANT_PHOTOMETRIC_WEIGHTS ? PM_SOURCE_PHOTFIT_CONST : PM_SOURCE_PHOTFIT_IMAGE_VAR; 99 118 return fitVarMode; 100 119 } … … 109 128 } 110 129 psError (PSPHOT_ERR_CONFIG, false, "Invalid value for LINEAR_FIT_VARIANCE_MODE (%s)", fitVarModeString); 111 return PM_SOURCE_PHOTFIT_ MODEL_NONE;130 return PM_SOURCE_PHOTFIT_NONE; 112 131 } 113 132 … … 182 201 // psAssert (source->peak, "source without peak??"); 183 202 // psAssert (source->peak->footprint, "peak without footprint??"); 184 185 // XXX TEST186 if (source->mode2 & PM_SOURCE_MODE2_MATCHED) {187 fprintf (stderr, "forced photometry on supplied source\n");188 }189 203 190 204 // turn this bit off and turn it on again if we pass this test … … 381 395 382 396 // set the sky, sky_x, sky_y components of border matrix 383 SetBorderMatrixElements (border, readout, fitSources, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER, markVal);397 SetBorderMatrixElements (border, readout, fitSources, (fitVarMode == PM_SOURCE_PHOTFIT_CONST), SKY_FIT_ORDER, markVal); 384 398 385 399 psSparseConstraint constraint; … … 540 554 } 541 555 542 bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 556 bool psphotGenerateModelVariance (pmConfig *config, const pmFPAview *view, int index, psMetadata *recipe, pmReadout *readout, psArray *sources) { 557 558 bool status = false; 559 psRegion fullRegion = psRegionSet (0, 0, 0, 0); 560 561 // bit-masks to test for good/bad pixels 562 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 563 assert (maskVal); 564 565 // bit-mask to mark pixels not used in analysis 566 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 567 assert (markVal); 568 569 // maskVal is used to test for rejected pixels, and must include markVal 570 maskVal |= markVal; 543 571 544 572 // create a model variance image 545 573 psImage *modelVar = psImageCopy (NULL, readout->variance, PS_TYPE_F32); 546 574 547 // find the pmFPAfile for the readout (background model is saved on PSPHOT.BACKMDL regardless of 'file name')548 pmFPAfile *backModel lFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL", index); // File of interest575 // find the pmFPAfile for the readout (background model is saved on PSPHOT.BACKMDL regardless of 'filerule') 576 pmFPAfile *backModelFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL", index); // File of interest 549 577 assert (backModelFile); 550 578 … … 554 582 555 583 // find the binning information 556 psImageBinning *backBinning = psMetadataLookupPtr(&status, model->analysis, "PSPHOT.BACKGROUND.BINNING");584 psImageBinning *backBinning = psMetadataLookupPtr(&status, backModel->analysis, "PSPHOT.BACKGROUND.BINNING"); 557 585 assert (backBinning); 558 586 … … 572 600 pmSource *source = sources->data[i]; 573 601 574 // XXX which sources need to be injected? 575 // skip non-astronomical objects (very likely defects) 576 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 577 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 578 579 // do not include CRs in the full ensemble fit 580 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 581 582 // do not include MOMENTS_FAILURES in the fit 583 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 584 585 // XXX need to identify the region appropriate for the source 602 // skip sources which were not fitted already 603 if (!(source->mode & PM_SOURCE_MODE_LINEAR_FIT)) continue; 604 605 // pixel region appropriate for the source 606 psRegion region = psRegionForImage (source->pixels, fullRegion); 586 607 587 608 // define the source->modelVar pixels (view on modelVar image) 588 609 psAssert (!source->modelVar, "programming error : modelVar should be NULL here"); 610 psAssert (source->modelFlux, "programming error : modelFlux should not be NULL here"); 589 611 source->modelVar = psImageSubset(readout->image, region); 590 612 591 613 // add the source model to the model variance image 592 pmSourceAdd (source, PM_MODEL_OP_ XXX, maskVal);614 pmSourceAdd (source, PM_MODEL_OP_MODELVAR, maskVal); 593 615 } 594 616 … … 599 621 // XXX for a test: 600 622 psphotSaveImage (NULL, modelVar, "model.var.fits"); 623 psphotSaveImage (NULL, readout->image, "image.var.fits"); 624 625 // we save the model variance for future reference 626 psMetadataAddImage(readout->analysis, PS_LIST_TAIL, "PSPHOT.MODEL.VAR", PS_META_REPLACE, "model variance", modelVar); 627 psFree (modelVar); 601 628 602 629 return true; 603 630 } 604 631 605 bool psphotFreeModelVariance (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 632 bool psphotFreeModelVariance (pmReadout *readout, psArray *sources) { 633 634 bool status = false; 606 635 607 636 // find the binning information 608 psImage *modelVar = psMetadataLookupPtr(&status, model->analysis, "PSPHOT.MODEL.VAR");637 psImage *modelVar = psMetadataLookupPtr(&status, readout->analysis, "PSPHOT.MODEL.VAR"); 609 638 assert (modelVar); 610 639
Note:
See TracChangeset
for help on using the changeset viewer.
