Changeset 21366
- Timestamp:
- Feb 5, 2009, 5:03:33 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 23 edited
-
ppStack/src/ppStack.h (modified) (2 diffs)
-
ppStack/src/ppStackArguments.c (modified) (4 diffs)
-
ppStack/src/ppStackCamera.c (modified) (6 diffs)
-
ppStack/src/ppStackLoop.c (modified) (28 diffs)
-
ppStack/src/ppStackMatch.c (modified) (6 diffs)
-
ppStack/src/ppStackThread.c (modified) (6 diffs)
-
psphot/src/psphot.h (modified) (1 diff)
-
psphot/src/psphotAnnuli.c (modified) (4 diffs)
-
psphot/src/psphotBlendFit.c (modified) (9 diffs)
-
psphot/src/psphotFindFootprints.c (modified) (1 diff)
-
psphot/src/psphotFitSourcesLinear.c (modified) (7 diffs)
-
psphot/src/psphotMakeResiduals.c (modified) (11 diffs)
-
psphot/src/psphotMaskReadout.c (modified) (4 diffs)
-
psphot/src/psphotModelWithPSF.c (modified) (17 diffs)
-
psphot/src/psphotOutput.c (modified) (5 diffs)
-
psphot/src/psphotRadialProfile.c (modified) (4 diffs)
-
psphot/src/psphotReadout.c (modified) (1 diff)
-
psphot/src/psphotReadoutFindPSF.c (modified) (1 diff)
-
psphot/src/psphotReadoutKnownSources.c (modified) (3 diffs)
-
psphot/src/psphotReadoutMinimal.c (modified) (3 diffs)
-
psphot/src/psphotSignificanceImage.c (modified) (5 diffs)
-
psphot/src/psphotSourceSize.c (modified) (11 diffs)
-
psphot/src/psphotVisual.c (modified) (73 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStack.h
r21092 r21366 38 38 psArray *imageFits; // FITS file pointers for images 39 39 psArray *maskFits; // FITS file pointers for masks 40 psArray * weightFits; // FITS file pointers for weights40 psArray *varianceFits; // FITS file pointers for variances 41 41 } ppStackThreadData; 42 42 … … 45 45 const psArray *imageNames, // Names of images to read 46 46 const psArray *maskNames, // Names of masks to read 47 const psArray * weightNames, // Names of weightmaps to read47 const psArray *varianceNames, // Names of variance maps to read 48 48 const pmConfig *config // Configuration 49 49 ); -
trunk/ppStack/src/ppStackArguments.c
r21199 r21366 24 24 "\tIMAGE(STR): Image filename\n" 25 25 "\tMASK(STR): Mask filename\n" 26 "\t WEIGHT(STR): Weightmap filename\n"26 "\tVARIANCE(STR): Variance map filename\n" 27 27 "\tPSF(STR): PSF filename\n" 28 28 "\tSOURCES(STR): Sources filename\n" … … 151 151 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask-poor", 0, "Mask value to give poor pixels", NULL); 152 152 psMetadataAddF32(arguments, PS_LIST_TAIL, "-threshold-mask", 0, "Threshold for mask deconvolution", NAN); 153 psMetadataAddF32(arguments, PS_LIST_TAIL, "-poor-frac", 0, "Fraction of weightfor poor pixels", NAN);153 psMetadataAddF32(arguments, PS_LIST_TAIL, "-poor-frac", 0, "Fraction of variance for poor pixels", NAN); 154 154 psMetadataAddF32(arguments, PS_LIST_TAIL, "-deconv-limit", 0, "Maximum deconvolution fraction limit", NAN); 155 155 psMetadataAddF32(arguments, PS_LIST_TAIL, "-image-rej", 0, … … 183 183 psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-image", 0, "Suffix for temporary images", NULL); 184 184 psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-mask", 0, "Suffix for temporary masks", NULL); 185 psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp- weight", 0, "Suffix for temporary weightmaps", NULL);185 psMetadataAddStr(arguments, PS_LIST_TAIL, "-temp-variance", 0, "Suffix for temporary variance maps", NULL); 186 186 psMetadataAddBool(arguments, PS_LIST_TAIL, "-temp-delete", 0, 187 187 "Delete temporary files on completion?", false); … … 283 283 VALUE_ARG_RECIPE_INT("-renorm-num", "RENORM.NUM", S32, 0); 284 284 VALUE_ARG_RECIPE_FLOAT("-renorm-width", "RENORM.WIDTH", F32); 285 valueArgRecipeStr(arguments, recipe, "-renorm-mean", "RENORM.MEAN", recipe);285 valueArgRecipeStr(arguments, recipe, "-renorm-mean", "RENORM.MEAN", recipe); 286 286 valueArgRecipeStr(arguments, recipe, "-renorm-stdev", "RENORM.STDEV", recipe); 287 287 288 valueArgRecipeStr(arguments, recipe, "-temp-image", "TEMP.IMAGE", recipe);289 valueArgRecipeStr(arguments, recipe, "-temp-mask", "TEMP.MASK", recipe);290 valueArgRecipeStr(arguments, recipe, "-temp- weight", "TEMP.WEIGHT", recipe);288 valueArgRecipeStr(arguments, recipe, "-temp-image", "TEMP.IMAGE", recipe); 289 valueArgRecipeStr(arguments, recipe, "-temp-mask", "TEMP.MASK", recipe); 290 valueArgRecipeStr(arguments, recipe, "-temp-variance", "TEMP.VARIANCE", recipe); 291 291 292 292 if (psMetadataLookupBool(NULL, arguments, "-temp-delete") || -
trunk/ppStack/src/ppStackCamera.c
r20995 r21366 71 71 bool ppStackCamera(pmConfig *config) 72 72 { 73 bool have Weights = false; // Do we have weightmaps?73 bool haveVariances = false; // Do we have variance maps? 74 74 bool havePSFs = false; // Do we have PSFs? 75 75 … … 97 97 bool mdok; 98 98 psString mask = psMetadataLookupStr(&mdok, input, "MASK"); // Name of mask 99 psString weight = psMetadataLookupStr(&mdok, input, "WEIGHT"); // Name of weightmap99 psString variance = psMetadataLookupStr(&mdok, input, "VARIANCE"); // Name of variance map 100 100 psString psf = psMetadataLookupStr(&mdok, input, "PSF"); // Name of PSF 101 101 psString sources = psMetadataLookupStr(&mdok, input, "SOURCES"); // Name of sources … … 140 140 } 141 141 142 // Optionally add the weightfile143 if ( weight && strlen(weight) > 0) {144 have Weights = true;145 psArray * weightFiles = psArrayAlloc(1); // Array of filenames for this FPA146 weightFiles->data[0] = psMemIncrRefCounter(weight);147 psMetadataAddArray(config->arguments, PS_LIST_TAIL, " WEIGHT.FILENAMES", PS_META_REPLACE,148 "Filenames of weight files", weightFiles);149 psFree( weightFiles);142 // Optionally add the variance file 143 if (variance && strlen(variance) > 0) { 144 haveVariances = true; 145 psArray *varianceFiles = psArrayAlloc(1); // Array of filenames for this FPA 146 varianceFiles->data[0] = psMemIncrRefCounter(variance); 147 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "VARIANCE.FILENAMES", PS_META_REPLACE, 148 "Filenames of variance files", varianceFiles); 149 psFree(varianceFiles); 150 150 151 151 bool status; 152 pmFPAfile * weightFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.WEIGHT",153 "WEIGHT.FILENAMES");152 pmFPAfile *varianceFile = pmFPAfileBindFromArgs(&status, imageFile, config, 153 "PPSTACK.INPUT.VARIANCE", "VARIANCE.FILENAMES"); 154 154 if (!status) { 155 psError(PS_ERR_UNKNOWN, false, "Unable to define file from weight %d (%s)", i, weight);156 return false; 157 } 158 if ( weightFile->type != PM_FPA_FILE_WEIGHT) {159 psError(PS_ERR_IO, true, "PPSTACK.INPUT. WEIGHT is not of type WEIGHT");155 psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance); 156 return false; 157 } 158 if (varianceFile->type != PM_FPA_FILE_VARIANCE) { 159 psError(PS_ERR_IO, true, "PPSTACK.INPUT.VARIANCE is not of type VARIANCE"); 160 160 return false; 161 161 } … … 217 217 #if 0 218 218 // Output convolved files 219 pmFPAfile *outconvImage = defineOutputConvolved("PPSTACK.OUTCONV", imageFile->fpa, config, 219 pmFPAfile *outconvImage = defineOutputConvolved("PPSTACK.OUTCONV", imageFile->fpa, config, 220 PM_FPA_FILE_IMAGE); 221 pmFPAfile *outconvMask = defineOutputConvolved("PPSTACK.OUTCONV.MASK", imageFile->fpa, config, 222 PM_FPA_FILE_MASK); 223 pmFPAfile *outconvVariance = defineOutputConvolved("PPSTACK.OUTCONV.VARIANCE", imageFile->fpa, config, 224 PM_FPA_FILE_VARIANCE); 225 if (!outconvImage || !outconvMask || !outconvVariance) { 226 return false; 227 } 228 229 // Input convolved files 230 pmFPAfile *inconvImage = defineInputConvolved("PPSTACK.INCONV", outconvImage, config, 220 231 PM_FPA_FILE_IMAGE); 221 pmFPAfile * outconvMask = defineOutputConvolved("PPSTACK.OUTCONV.MASK", imageFile->fpa, config,232 pmFPAfile *inconvMask = defineInputConvolved("PPSTACK.INCONV.MASK", outconvMask, config, 222 233 PM_FPA_FILE_MASK); 223 pmFPAfile *outconvWeight = defineOutputConvolved("PPSTACK.OUTCONV.WEIGHT", imageFile->fpa, config, 224 PM_FPA_FILE_WEIGHT); 225 if (!outconvImage || !outconvMask || !outconvWeight) { 226 return false; 227 } 228 229 // Input convolved files 230 pmFPAfile *inconvImage = defineInputConvolved("PPSTACK.INCONV", outconvImage, config, 231 PM_FPA_FILE_IMAGE); 232 pmFPAfile *inconvMask = defineInputConvolved("PPSTACK.INCONV.MASK", outconvMask, config, 233 PM_FPA_FILE_MASK); 234 pmFPAfile *inconvWeight = defineInputConvolved("PPSTACK.INCONV.WEIGHT", outconvWeight, config, 235 PM_FPA_FILE_WEIGHT); 236 if (!inconvImage || !inconvMask || !inconvWeight) { 234 pmFPAfile *inconvVariance = defineInputConvolved("PPSTACK.INCONV.VARIANCE", outconvVariance, config, 235 PM_FPA_FILE_VARIANCE); 236 if (!inconvImage || !inconvMask || !inconvVariance) { 237 237 return false; 238 238 } … … 246 246 psMetadataRemoveKey(config->arguments, "MASK.FILENAMES"); 247 247 } 248 if (psMetadataLookup(config->arguments, " WEIGHT.FILENAMES")) {249 psMetadataRemoveKey(config->arguments, " WEIGHT.FILENAMES");248 if (psMetadataLookup(config->arguments, "VARIANCE.FILENAMES")) { 249 psMetadataRemoveKey(config->arguments, "VARIANCE.FILENAMES"); 250 250 } 251 251 if (psMetadataLookup(config->arguments, "PSF.FILENAMES")) { … … 295 295 outMask->save = true; 296 296 297 // Output weight298 if (have Weights) {299 pmFPAfile *out Weight = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.OUTPUT.WEIGHT");300 if (!out Weight) {301 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT. WEIGHT"));302 return false; 303 } 304 if (out Weight->type != PM_FPA_FILE_WEIGHT) {305 psError(PS_ERR_IO, true, "PPSTACK.OUTPUT. WEIGHT is not of type WEIGHT");306 return false; 307 } 308 out Weight->save = true;297 // Output variance 298 if (haveVariances) { 299 pmFPAfile *outVariance = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.OUTPUT.VARIANCE"); 300 if (!outVariance) { 301 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.OUTPUT.VARIANCE")); 302 return false; 303 } 304 if (outVariance->type != PM_FPA_FILE_VARIANCE) { 305 psError(PS_ERR_IO, true, "PPSTACK.OUTPUT.VARIANCE is not of type VARIANCE"); 306 return false; 307 } 308 outVariance->save = true; 309 309 } 310 310 -
trunk/ppStack/src/ppStackLoop.c
r21258 r21366 24 24 25 25 // Files required for the convolution 26 static char *convolveFiles[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT. WEIGHT", NULL };26 static char *convolveFiles[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", NULL }; 27 27 28 28 // Output files for the combination 29 static char *combineFiles[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT. WEIGHT",29 static char *combineFiles[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.VARIANCE", 30 30 "PPSTACK.OUTPUT.JPEG1", "PPSTACK.OUTPUT.JPEG2", NULL }; 31 31 … … 204 204 const char *tempImage = psMetadataLookupStr(NULL, recipe, "TEMP.IMAGE"); // Suffix for temporary images 205 205 const char *tempMask = psMetadataLookupStr(NULL, recipe, "TEMP.MASK"); // Suffix for temporary masks 206 const char *temp Weight = psMetadataLookupStr(NULL, recipe, "TEMP.WEIGHT"); // Suffix for temp weightmaps207 if (!tempImage || !tempMask || !temp Weight) {206 const char *tempVariance = psMetadataLookupStr(NULL, recipe, "TEMP.VARIANCE"); // Suffix for temp variance maps 207 if (!tempImage || !tempMask || !tempVariance) { 208 208 psError(PS_ERR_BAD_PARAMETER_VALUE, false, 209 "Unable to find TEMP.IMAGE, TEMP.MASK and TEMP. WEIGHTin recipe");209 "Unable to find TEMP.IMAGE, TEMP.MASK and TEMP.VARIANCE in recipe"); 210 210 return false; 211 211 } … … 387 387 psArray *imageNames = psArrayAlloc(num); 388 388 psArray *maskNames = psArrayAlloc(num); 389 psArray * weightNames = psArrayAlloc(num);389 psArray *varianceNames = psArrayAlloc(num); 390 390 for (int i = 0; i < num; i++) { 391 psString imageName = NULL, maskName = NULL, weightName = NULL; // Names for convolved images391 psString imageName = NULL, maskName = NULL, varianceName = NULL; // Names for convolved images 392 392 psStringAppend(&imageName, "%s/%s.%d.%s", tempDir, tempName, i, tempImage); 393 393 psStringAppend(&maskName, "%s/%s.%d.%s", tempDir, tempName, i, tempMask); 394 psStringAppend(& weightName, "%s/%s.%d.%s", tempDir, tempName, i, tempWeight);395 psTrace("ppStack", 5, "Temporary files: %s %s %s\n", imageName, maskName, weightName);394 psStringAppend(&varianceName, "%s/%s.%d.%s", tempDir, tempName, i, tempVariance); 395 psTrace("ppStack", 5, "Temporary files: %s %s %s\n", imageName, maskName, varianceName); 396 396 imageNames->data[i] = imageName; 397 397 maskNames->data[i] = maskName; 398 weightNames->data[i] = weightName;398 varianceNames->data[i] = varianceName; 399 399 } 400 400 // Free the outputName that we grabbed above to set up tempName. … … 417 417 psList *fpaList = psListAlloc(NULL); // List of input FPAs, for concept averaging 418 418 psList *cellList = psListAlloc(NULL); // List of input cells, for concept averaging 419 psArray *covariances = psArrayAlloc(num); // Covariance matrices 419 420 for (int i = 0; i < num; i++) { 420 421 psTrace("ppStack", 2, "Convolving input %d of %d to target PSF....\n", i, num); … … 431 432 psFree(fpaList); 432 433 psFree(cellList); 434 psFree(covariances); 433 435 return false; 434 436 } … … 450 452 psFree(fpaList); 451 453 psFree(cellList); 454 psFree(covariances); 452 455 return false; 453 456 } … … 464 467 continue; 465 468 } 469 covariances->data[i] = psMemIncrRefCounter(readout->covariance); 466 470 467 471 if (stats) { … … 486 490 pmHDU *hdu = readout->parent->parent->parent->hdu; // HDU for convolved image 487 491 assert(hdu); 488 writeImage(imageNames->data[i], hdu->header, readout->image, config);489 492 psMetadata *maskHeader = psMetadataCopy(NULL, hdu->header); // Copy of header, for mask 490 493 pmConfigMaskWriteHeader(config, maskHeader); 491 writeImage(maskNames->data[i], maskHeader, readout->mask, config);494 writeImage(maskNames->data[i], maskHeader, readout->mask, config); 492 495 psFree(maskHeader); 493 writeImage( weightNames->data[i], hdu->header, readout->weight, config);496 writeImage(varianceNames->data[i], hdu->header, readout->variance, config); 494 497 495 498 pmCell *inCell = readout->parent; // Input cell … … 502 505 psFree(fpaList); 503 506 psFree(cellList); 507 psFree(covariances); 504 508 return false; 505 509 } … … 523 527 psFree(fpaList); 524 528 psFree(cellList); 529 psFree(covariances); 525 530 return false; 526 531 } … … 570 575 psFree(matchChi2); 571 576 psFree(values); 577 psFree(covariances); 572 578 return false; 573 579 } … … 611 617 psFree(inputMask); 612 618 psFree(matchChi2); 619 psFree(covariances); 613 620 return false; 614 621 } … … 622 629 // Start threading 623 630 ppStackThreadInit(); 624 ppStackThreadData *stack = ppStackThreadDataSetup(cells, imageNames, maskNames, weightNames, config);631 ppStackThreadData *stack = ppStackThreadDataSetup(cells, imageNames, maskNames, varianceNames, config); 625 632 626 633 psTimerStart("PPSTACK_INITIAL"); … … 645 652 psFree(matchChi2); 646 653 psFree(cells); 654 psFree(covariances); 647 655 return false; 648 656 } … … 658 666 psFree(matchChi2); 659 667 psFree(cells); 668 psFree(covariances); 660 669 return false; 661 670 } … … 676 685 psFree(outRO); 677 686 psFree(cells); 687 psFree(covariances); 678 688 return false; 679 689 } … … 695 705 psFree(view); 696 706 psFree(outRO); 707 psFree(covariances); 697 708 return false; 698 709 } … … 721 732 psFree(view); 722 733 psFree(outRO); 734 psFree(covariances); 723 735 return false; 724 736 } … … 735 747 psFree(view); 736 748 psFree(outRO); 749 psFree(covariances); 737 750 return false; 738 751 } … … 803 816 psFree(inspect); 804 817 psFree(rejected); 818 psFree(covariances); 805 819 return false; 806 820 } … … 818 832 psFree(inspect); 819 833 psFree(rejected); 834 psFree(covariances); 820 835 return false; 821 836 } … … 912 927 psFree(view); 913 928 psFree(outRO); 929 psFree(covariances); 914 930 return false; 915 931 } … … 941 957 psFree(view); 942 958 psFree(outRO); 959 psFree(covariances); 943 960 return false; 944 961 } … … 962 979 psFree(view); 963 980 psFree(outRO); 981 psFree(covariances); 964 982 return false; 965 983 } … … 974 992 psFree(view); 975 993 psFree(outRO); 994 psFree(covariances); 976 995 return false; 977 996 } … … 979 998 980 999 memDump("final"); 1000 1001 // Sum covariance matrices 1002 for (int i = 0; i < num; i++) { 1003 if (inputMask->data.U8[i]) { 1004 psFree(covariances->data[i]); 1005 covariances->data[i] = NULL; 1006 } 1007 } 1008 outRO->covariance = psImageCovarianceSum(covariances); 1009 psFree(covariances); 981 1010 982 1011 if (stats) { … … 1040 1069 psString imageResolved = pmConfigConvertFilename(imageNames->data[i], config, false, false); 1041 1070 psString maskResolved = pmConfigConvertFilename(maskNames->data[i], config, false, false); 1042 psString weightResolved = pmConfigConvertFilename(weightNames->data[i], config, false, false);1071 psString varianceResolved = pmConfigConvertFilename(varianceNames->data[i], config, false, false); 1043 1072 if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 || 1044 unlink( weightResolved) == -1) {1073 unlink(varianceResolved) == -1) { 1045 1074 psWarning("Unable to delete temporary files for image %d", i); 1046 1075 } 1047 1076 psFree(imageResolved); 1048 1077 psFree(maskResolved); 1049 psFree( weightResolved);1078 psFree(varianceResolved); 1050 1079 } 1051 1080 } 1052 1081 psFree(imageNames); 1053 1082 psFree(maskNames); 1054 psFree( weightNames);1083 psFree(varianceNames); 1055 1084 1056 1085 psFree(inputMask); … … 1092 1121 float renormWidth = psMetadataLookupS32(&mdok, recipe, "RENORM.WIDTH"); // Width of Gaussian phot 1093 1122 psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask 1094 if (!pmReadout WeightRenormPhot(outRO, maskValue, renormNum, renormWidth,1095 renormMean, renormStdev, NULL)) {1123 if (!pmReadoutVarianceRenormPhot(outRO, maskValue, renormNum, renormWidth, 1124 renormMean, renormStdev, NULL)) { 1096 1125 psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances."); 1097 1126 psFree(outRO); -
trunk/ppStack/src/ppStackMatch.c
r21199 r21366 16 16 PM_SOURCE_MODE_CR_LIMIT) // Mask to apply to input sources 17 17 #define FAINT_SOURCE_FRAC 1.0e-4 // Set minimum flux to this fraction of faintest source flux 18 #define COVAR_FRAC 0.01 // Truncation fraction for covariance matrix 18 19 19 20 //#define TESTING // Enable debugging output … … 233 234 } 234 235 235 // Read image, mask, weight236 // Read image, mask, variance 236 237 const char *tempImage = psMetadataLookupStr(NULL, recipe, "TEMP.IMAGE"); // Suffix for image 237 238 const char *tempMask = psMetadataLookupStr(NULL, recipe, "TEMP.MASK"); // Suffix for mask 238 const char *temp Weight = psMetadataLookupStr(NULL, recipe, "TEMP.WEIGHT"); // Suffix for weightmap239 psString imageName = NULL, maskName = NULL, weightName = NULL; // Names for convolved images239 const char *tempVariance = psMetadataLookupStr(NULL, recipe, "TEMP.VARIANCE"); // Suffix for variance map 240 psString imageName = NULL, maskName = NULL, varianceName = NULL; // Names for convolved images 240 241 psStringAppend(&imageName, "%s.%d.%s", outName, numInput, tempImage); 241 242 psStringAppend(&maskName, "%s.%d.%s", outName, numInput, tempMask); 242 psStringAppend(& weightName, "%s.%d.%s", outName, numInput, tempWeight);243 psStringAppend(&varianceName, "%s.%d.%s", outName, numInput, tempVariance); 243 244 244 245 if (!readImage(&readout->image, imageName, config) || !readImage(&readout->mask, maskName, config) || 245 !readImage(&readout-> weight, weightName, config)) {246 !readImage(&readout->variance, varianceName, config)) { 246 247 psError(PS_ERR_IO, false, "Unable to read previously produced image."); 247 248 psFree(imageName); 248 249 psFree(maskName); 249 psFree( weightName);250 psFree(varianceName); 250 251 return false; 251 252 } 252 253 psFree(imageName); 253 254 psFree(maskName); 254 psFree( weightName);255 psFree(varianceName); 255 256 256 257 psRegion *region = psMetadataLookupPtr(NULL, output->analysis, … … 374 375 "RENORM.STDEV")); 375 376 376 if (!pmReadout WeightRenormPixels(readout, maskBad, renormMean, renormStdev, rng)) {377 if (!pmReadoutVarianceRenormPixels(readout, maskBad, renormMean, renormStdev, rng)) { 377 378 psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances."); 378 379 psFree(output); … … 444 445 psFree(readout->image); 445 446 psFree(readout->mask); 446 psFree(readout->weight); 447 psFree(readout->variance); 448 psFree(readout->covariance); 447 449 readout->image = psMemIncrRefCounter(output->image); 448 450 readout->mask = psMemIncrRefCounter(output->mask); 449 readout->weight = psMemIncrRefCounter(output->weight); 451 readout->variance = psMemIncrRefCounter(output->variance); 452 readout->covariance = psImageCovarianceTruncate(output->covariance, COVAR_FRAC); 450 453 } else { 451 454 // Fake the convolution … … 559 562 "RENORM.STDEV")); 560 563 561 if (!pmReadout WeightRenormPixels(readout, maskBad, renormMean, renormStdev, rng)) {564 if (!pmReadoutVarianceRenormPixels(readout, maskBad, renormMean, renormStdev, rng)) { 562 565 psError(PS_ERR_UNKNOWN, false, "Unable to renormalise variances."); 563 566 psFree(output); … … 583 586 psFree(bg); 584 587 585 586 588 #if 0 587 589 #define RADIUS 10 // Radius of photometry -
trunk/ppStack/src/ppStackThread.c
r20711 r21366 38 38 psFitsClose(stack->imageFits->data[i]); 39 39 psFitsClose(stack->maskFits->data[i]); 40 psFitsClose(stack-> weightFits->data[i]);41 stack->imageFits->data[i] = stack->maskFits->data[i] = stack-> weightFits->data[i] = NULL;40 psFitsClose(stack->varianceFits->data[i]); 41 stack->imageFits->data[i] = stack->maskFits->data[i] = stack->varianceFits->data[i] = NULL; 42 42 } 43 43 psFree(stack->imageFits); 44 44 psFree(stack->maskFits); 45 psFree(stack-> weightFits);45 psFree(stack->varianceFits); 46 46 return; 47 47 } 48 48 49 49 ppStackThreadData *ppStackThreadDataSetup(const psArray *cells, const psArray *imageNames, 50 const psArray *maskNames, const psArray * weightNames,50 const psArray *maskNames, const psArray *varianceNames, 51 51 const pmConfig *config) 52 52 { … … 54 54 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, imageNames, NULL); 55 55 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, maskNames, NULL); 56 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, weightNames, NULL);56 PS_ASSERT_ARRAYS_SIZE_EQUAL(cells, varianceNames, NULL); 57 57 58 58 ppStackThreadData *stack = psAlloc(sizeof(ppStackThreadData)); // Thread data, to return … … 64 64 stack->imageFits = psArrayAlloc(numInputs); 65 65 stack->maskFits = psArrayAlloc(numInputs); 66 stack-> weightFits = psArrayAlloc(numInputs);66 stack->varianceFits = psArrayAlloc(numInputs); 67 67 for (int i = 0; i < numInputs; i++) { 68 68 if (!cells->data[i]) { … … 73 73 psString imageResolved = pmConfigConvertFilename(imageNames->data[i], config, false, false); 74 74 psString maskResolved = pmConfigConvertFilename(maskNames->data[i], config, false, false); 75 psString weightResolved = pmConfigConvertFilename(weightNames->data[i], config, false, false);75 psString varianceResolved = pmConfigConvertFilename(varianceNames->data[i], config, false, false); 76 76 stack->imageFits->data[i] = psFitsOpen(imageResolved, "r"); 77 77 stack->maskFits->data[i] = psFitsOpen(maskResolved, "r"); 78 stack-> weightFits->data[i] = psFitsOpen(weightResolved, "r");78 stack->varianceFits->data[i] = psFitsOpen(varianceResolved, "r"); 79 79 psFree(imageResolved); 80 80 psFree(maskResolved); 81 psFree( weightResolved);82 if (!stack->imageFits->data[i] || !stack->maskFits->data[i] || !stack-> weightFits->data[i]) {81 psFree(varianceResolved); 82 if (!stack->imageFits->data[i] || !stack->maskFits->data[i] || !stack->varianceFits->data[i]) { 83 83 psError(PS_ERR_UNKNOWN, false, "Unable to open convolved files %s, %s, %s", 84 (char*)imageNames->data[i], (char*)maskNames->data[i], (char*) weightNames->data[i]);84 (char*)imageNames->data[i], (char*)maskNames->data[i], (char*)varianceNames->data[i]); 85 85 return false; 86 86 } … … 156 156 // override the recorded last scan 157 157 ro->thisImageScan = thread->firstScan; 158 ro->this WeightScan = thread->firstScan;158 ro->thisVarianceScan = thread->firstScan; 159 159 ro->thisMaskScan = thread->firstScan; 160 160 ro->lastImageScan = thread->lastScan; 161 161 ro->lastMaskScan = thread->lastScan; 162 ro->last WeightScan = thread->lastScan;162 ro->lastVarianceScan = thread->lastScan; 163 163 ro->forceScan = true; 164 164 165 165 psFits *imageFits = stack->imageFits->data[i]; // FITS file for image 166 166 psFits *maskFits = stack->maskFits->data[i]; // FITS file for mask 167 psFits * weightFits = stack->weightFits->data[i]; // FITS file for weight167 psFits *varianceFits = stack->varianceFits->data[i]; // FITS file for variance 168 168 169 169 … … 189 189 } 190 190 191 if (pmReadoutMore Weight(ro, weightFits, 0, rows, config)) {191 if (pmReadoutMoreVariance(ro, varianceFits, 0, rows, config)) { 192 192 keepReading = true; 193 if (!pmReadoutReadChunkWeight(ro, weightFits, 0, rows, overlap, config)) { 194 psError(PS_ERR_IO, false, "Unable to read chunk %d for file PPSTACK.INPUT.WEIGHT %d", 193 if (!pmReadoutReadChunkVariance(ro, varianceFits, 0, rows, overlap, config)) { 194 psError(PS_ERR_IO, false, 195 "Unable to read chunk %d for file PPSTACK.INPUT.VARIANCE %d", 195 196 numChunk, i); 196 197 *status = false; -
trunk/psphot/src/psphot.h
r21255 r21366 90 90 void psphotModelClassInit (void); 91 91 bool psphotGrowthCurve (pmReadout *readout, pmPSF *psf, bool ignore, psImageMaskType maskVal); 92 bool psphotSetMaskAnd Weight(pmConfig *config, pmReadout *readout, psMetadata *recipe);92 bool psphotSetMaskAndVariance (pmConfig *config, pmReadout *readout, psMetadata *recipe); 93 93 void psphotSourceFreePixels (psArray *sources); 94 94 -
trunk/psphot/src/psphotAnnuli.c
r21183 r21366 11 11 12 12 psVector *radius = source->extpars->profile->radius; 13 psVector * weight = source->extpars->profile->weight;13 psVector *variance = source->extpars->profile->variance; 14 14 psVector *flux = source->extpars->profile->flux; 15 15 … … 22 22 psVector *fluxValues = psVectorAlloc (radialBinsLower->n, PS_TYPE_F32); 23 23 psVector *fluxSquare = psVectorAlloc (radialBinsLower->n, PS_TYPE_F32); 24 psVector *flux Weight= psVectorAlloc (radialBinsLower->n, PS_TYPE_F32);24 psVector *fluxVariance = psVectorAlloc (radialBinsLower->n, PS_TYPE_F32); 25 25 psVector *pixelCount = psVectorAlloc (radialBinsLower->n, PS_TYPE_F32); 26 26 psVectorInit (fluxValues, 0.0); 27 27 psVectorInit (fluxSquare, 0.0); 28 psVectorInit (flux Weight, 0.0);28 psVectorInit (fluxVariance, 0.0); 29 29 psVectorInit (pixelCount, 0.0); 30 30 31 31 // XXX this code assumes the radii are in pixels. convert from arcsec with plate scale 32 32 // XXX assume the annulii above are not overlapping? much faster... 33 // XXX this might be must faster in the reverse order: loop over annulii and use disection to 33 // XXX this might be must faster in the reverse order: loop over annulii and use disection to 34 34 // skip to the start of the annulus. 35 35 for (int i = 0; i < flux->n; i++) { … … 39 39 fluxValues->data.F32[j] += flux->data.F32[i]; 40 40 fluxSquare->data.F32[j] += PS_SQR(flux->data.F32[i]); 41 flux Weight->data.F32[j] += weight->data.F32[i];41 fluxVariance->data.F32[j] += variance->data.F32[i]; 42 42 pixelCount->data.F32[j] += 1.0; 43 43 } … … 49 49 fluxSquare->data.F32[j] -= PS_SQR(fluxValues->data.F32[j]); 50 50 } 51 51 52 52 source->extpars->annuli = pmSourceAnnuliAlloc (); 53 53 source->extpars->annuli->flux = fluxValues; 54 source->extpars->annuli->fluxErr = flux Weight;54 source->extpars->annuli->fluxErr = fluxVariance; 55 55 source->extpars->annuli->fluxVar = fluxSquare; 56 56 -
trunk/psphot/src/psphotBlendFit.c
r21359 r21366 21 21 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 22 22 if (!status) { 23 nThreads = 0;23 nThreads = 0; 24 24 } 25 25 … … 44 44 psphotInitRadiusPSF (recipe, psf->type); 45 45 46 // starts the timer, sets up the array of fitSets 46 // starts the timer, sets up the array of fitSets 47 47 psphotFitInit (nThreads); 48 48 … … 56 56 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 57 57 58 fprintf (stderr, "starting with %ld sources\n", sources->n);59 60 58 for (int i = 0; i < cellGroups->n; i++) { 61 59 62 psArray *cells = cellGroups->data[i];63 64 for (int j = 0; j < cells->n; j++) {65 66 if (nThreads) {67 // allocate a job -- if threads are not defined, this just runs the job68 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT");69 psArray *newSources = psArrayAllocEmpty(16);70 71 psArrayAdd(job->args, 1, readout);72 psArrayAdd(job->args, 1, recipe);73 psArrayAdd(job->args, 1, cells->data[j]); // sources74 psArrayAdd(job->args, 1, psf);75 psArrayAdd(job->args, 1, newSources); // return for new sources76 psFree (newSources);77 78 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit79 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf80 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next81 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail82 83 if (!psThreadJobAddPending(job)) {84 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");85 psFree (job);86 return NULL;87 }88 psFree(job);89 } else {90 int nfit = 0;91 int npsf = 0;92 int next = 0;93 int nfail = 0;94 psArray *newSources = psArrayAllocEmpty(16);95 96 if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) {97 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");98 return NULL;99 }100 Nfit += nfit;101 Npsf += npsf;102 Next += next;103 Nfail += nfail;104 105 // add these back onto sources106 for (int k = 0; k < newSources->n; k++) {107 psArrayAdd (sources, 16, newSources->data[k]);108 }109 psFree (newSources);110 }111 }112 113 if (nThreads) {114 // wait for the threads to finish and manage results115 if (!psThreadPoolWait (false)) {116 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");117 return NULL;118 }119 120 // we have only supplied one type of job, so we can assume the types here121 psThreadJob *job = NULL;122 while ((job = psThreadJobGetDone()) != NULL) {123 if (job->args->n < 1) {124 fprintf (stderr, "error with job\n");125 } else {126 psScalar *scalar = NULL;127 scalar = job->args->data[5];128 Nfit += scalar->data.S32;129 scalar = job->args->data[6];130 Npsf += scalar->data.S32;131 scalar = job->args->data[7];132 Next += scalar->data.S32;133 scalar = job->args->data[8];134 Nfail += scalar->data.S32;135 136 // add these back onto sources137 psArray *newSources = job->args->data[4];138 for (int j = 0; j < newSources->n; j++) {139 psArrayAdd (sources, 16, newSources->data[j]);140 }141 }142 psFree(job);143 }144 }60 psArray *cells = cellGroups->data[i]; 61 62 for (int j = 0; j < cells->n; j++) { 63 64 if (nThreads) { 65 // allocate a job -- if threads are not defined, this just runs the job 66 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 67 psArray *newSources = psArrayAllocEmpty(16); 68 69 psArrayAdd(job->args, 1, readout); 70 psArrayAdd(job->args, 1, recipe); 71 psArrayAdd(job->args, 1, cells->data[j]); // sources 72 psArrayAdd(job->args, 1, psf); 73 psArrayAdd(job->args, 1, newSources); // return for new sources 74 psFree (newSources); 75 76 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 77 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 78 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 79 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 80 81 if (!psThreadJobAddPending(job)) { 82 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 83 psFree (job); 84 return NULL; 85 } 86 psFree(job); 87 } else { 88 int nfit = 0; 89 int npsf = 0; 90 int next = 0; 91 int nfail = 0; 92 psArray *newSources = psArrayAllocEmpty(16); 93 94 if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) { 95 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 96 return NULL; 97 } 98 Nfit += nfit; 99 Npsf += npsf; 100 Next += next; 101 Nfail += nfail; 102 103 // add these back onto sources 104 for (int k = 0; k < newSources->n; k++) { 105 psArrayAdd (sources, 16, newSources->data[k]); 106 } 107 psFree (newSources); 108 } 109 } 110 111 if (nThreads) { 112 // wait for the threads to finish and manage results 113 if (!psThreadPoolWait (false)) { 114 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 115 return NULL; 116 } 117 118 // we have only supplied one type of job, so we can assume the types here 119 psThreadJob *job = NULL; 120 while ((job = psThreadJobGetDone()) != NULL) { 121 if (job->args->n < 1) { 122 fprintf (stderr, "error with job\n"); 123 } else { 124 psScalar *scalar = NULL; 125 scalar = job->args->data[5]; 126 Nfit += scalar->data.S32; 127 scalar = job->args->data[6]; 128 Npsf += scalar->data.S32; 129 scalar = job->args->data[7]; 130 Next += scalar->data.S32; 131 scalar = job->args->data[8]; 132 Nfail += scalar->data.S32; 133 134 // add these back onto sources 135 psArray *newSources = job->args->data[4]; 136 for (int j = 0; j < newSources->n; j++) { 137 psArrayAdd (sources, 16, newSources->data[j]); 138 } 139 } 140 psFree(job); 141 } 142 } 145 143 } 146 144 psFree (cellGroups); … … 207 205 if (source->peak->SN < FIT_SN_LIM) continue; 208 206 209 // exclude sources outside optional analysis region207 // exclude sources outside optional analysis region 210 208 if (source->peak->xf < AnalysisRegion.x0) continue; 211 209 if (source->peak->yf < AnalysisRegion.y0) continue; … … 216 214 if (source->modelPSF == NULL) continue; 217 215 218 // skip sources which are insignificant flux? 219 // XXX this is somewhat ad-hoc216 // skip sources which are insignificant flux? 217 // XXX this is somewhat ad-hoc 220 218 if (source->modelPSF->params->data.F32[1] < 0.1) { 221 219 psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n", … … 234 232 // try fitting PSFs or extended sources depending on source->mode 235 233 // these functions subtract the resulting fitted source 236 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {237 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {238 source->type = PM_SOURCE_TYPE_EXTENDED;239 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);240 Next ++;241 continue;242 }243 } else {244 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {245 source->type = PM_SOURCE_TYPE_STAR;246 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);247 Npsf ++;248 continue;249 }250 }234 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 235 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) { 236 source->type = PM_SOURCE_TYPE_EXTENDED; 237 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 238 Next ++; 239 continue; 240 } 241 } else { 242 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) { 243 source->type = PM_SOURCE_TYPE_STAR; 244 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 245 Npsf ++; 246 continue; 247 } 248 } 251 249 252 250 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); … … 317 315 if (source->peak->SN < FIT_SN_LIM) continue; 318 316 319 // exclude sources outside optional analysis region317 // exclude sources outside optional analysis region 320 318 if (source->peak->xf < AnalysisRegion.x0) continue; 321 319 if (source->peak->yf < AnalysisRegion.y0) continue; … … 326 324 if (source->modelPSF == NULL) continue; 327 325 328 // skip sources which are insignificant flux? 329 // XXX this is somewhat ad-hoc326 // skip sources which are insignificant flux? 327 // XXX this is somewhat ad-hoc 330 328 if (source->modelPSF->params->data.F32[1] < 0.1) { 331 329 psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n", … … 344 342 // try fitting PSFs or extended sources depending on source->mode 345 343 // these functions subtract the resulting fitted source 346 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {347 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {348 source->type = PM_SOURCE_TYPE_EXTENDED;349 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf);350 Next ++;351 continue;352 }353 } else {354 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {355 source->type = PM_SOURCE_TYPE_STAR;356 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf);357 Npsf ++;358 continue;359 }360 }344 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 345 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) { 346 source->type = PM_SOURCE_TYPE_EXTENDED; 347 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 348 Next ++; 349 continue; 350 } 351 } else { 352 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) { 353 source->type = PM_SOURCE_TYPE_STAR; 354 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 355 Npsf ++; 356 continue; 357 } 358 } 361 359 362 360 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); -
trunk/psphot/src/psphotFindFootprints.c
r21183 r21366 68 68 } 69 69 70 psphotCullPeaks(readout->image, readout-> weight, recipe, detections->footprints);70 psphotCullPeaks(readout->image, readout->variance, recipe, detections->footprints); 71 71 detections->peaks = pmFootprintArrayToPeaks(detections->footprints); 72 72 psLogMsg ("psphot", PS_LOG_INFO, "%ld peaks, %ld total footprints: %f sec\n", detections->peaks->n, detections->footprints->n, psTimerMark ("psphot.footprints")); -
trunk/psphot/src/psphotFitSourcesLinear.c
r21183 r21366 68 68 69 69 // if (source->type == PM_SOURCE_TYPE_STAR && 70 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;70 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 71 71 72 72 if (final) { … … 76 76 } 77 77 78 // generate model for sources without, or skip if we can't79 if (!source->modelFlux) {80 if (!pmSourceCacheModel (source, maskVal)) continue;81 }78 // generate model for sources without, or skip if we can't 79 if (!source->modelFlux) { 80 if (!pmSourceCacheModel (source, maskVal)) continue; 81 } 82 82 83 83 // save the original coords … … 96 96 97 97 // vectors to store stats for each object 98 // psVector * weight= psVectorAlloc (fitSources->n, PS_TYPE_F32);98 // psVector *variance = psVectorAlloc (fitSources->n, PS_TYPE_F32); 99 99 psVector *errors = psVectorAlloc (fitSources->n, PS_TYPE_F32); 100 100 … … 128 128 psSparseVectorElement (sparse, i, f); 129 129 130 // add the per-source weights (border region)130 // add the per-source variances (border region) 131 131 switch (SKY_FIT_ORDER) { 132 132 case 1: … … 208 208 pmSource *source = fitSources->data[i]; 209 209 pmModel *model = pmSourceGetModel (NULL, source); 210 pmSourceChisq (model, source->pixels, source->maskObj, source-> weight, maskVal);210 pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal); 211 211 } 212 212 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "get chisqs: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem); … … 253 253 // accumulate the image statistics from the masked regions 254 254 psF32 **image = readout->image->data.F32; 255 psF32 ** weight = readout->weight->data.F32;255 psF32 **variance = readout->variance->data.F32; 256 256 psImageMaskType **mask = readout->mask->data.PS_TYPE_IMAGE_MASK_DATA; 257 257 … … 268 268 wt = 1.0; 269 269 } else { 270 wt = weight[j][i];270 wt = variance[j][i]; 271 271 } 272 272 f = image[j][i]; -
trunk/psphot/src/psphotMakeResiduals.c
r21183 r21366 58 58 // for each input source: 59 59 // - construct a residual image, renormalized 60 // - construct a renormalized weightimage60 // - construct a renormalized variance image 61 61 // - construct a new mask image 62 62 63 63 // construct the output residual table (Nx*DX,Ny*DY) 64 64 // for each output pixel: 65 // - construct a histogram of the values & weights (interpolate to the common pixel coordinate)65 // - construct a histogram of the values & variances (interpolate to the common pixel coordinate) 66 66 // - measure the robust median & sigma 67 67 // - reject (mask) input pixels which are outliers 68 68 // - re-measure the robust median & sigma 69 // - set output pixel, weight, and mask69 // - set output pixel, variance, and mask 70 70 71 71 // these mask values do not correspond to the recipe values: they … … 76 76 // psVectorStats 77 77 78 const psImageMaskType badMask = 0x01; // mask bits79 const psImageMaskType poorMask = 0x02; // from psImageInterpolate80 const psImageMaskType clippedMask = 0x04; // mask bit set for clipped values78 const psImageMaskType badMask = 0x01; // mask bits 79 const psImageMaskType poorMask = 0x02; // from psImageInterpolate 80 const psImageMaskType clippedMask = 0x04; // mask bit set for clipped values 81 81 const psVectorMaskType fmaskVal = badMask | poorMask | clippedMask; 82 82 … … 101 101 102 102 psImage *image = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 103 psImage * weight = psImageCopy (NULL, source->weight, PS_TYPE_F32);103 psImage *variance = psImageCopy (NULL, source->variance, PS_TYPE_F32); 104 104 psImage *mask = psImageCopy (NULL, source->maskView, PS_TYPE_IMAGE_MASK); 105 105 pmModelSub (image, mask, model, PM_MODEL_OP_FUNC, maskVal); 106 106 107 // re-normalize image and weight107 // re-normalize image and variance 108 108 float Io = model->params->data.F32[PM_PAR_I0]; 109 109 psBinaryOp (image, image, "/", psScalarAlloc(Io, PS_TYPE_F32)); 110 psBinaryOp ( weight, weight, "/", psScalarAlloc(Io*Io, PS_TYPE_F32));111 112 // we interpolate the image and weight- include the mask or not?113 // XXX why not the mask?114 // psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, weight, mask, maskVal, 0.0, 0.0, badMask, poorMask, 0.0, 0);115 psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, weight, NULL, 0xff, 0.0, 0.0, badMask, poorMask, 0.0, 0);110 psBinaryOp (variance, variance, "/", psScalarAlloc(Io*Io, PS_TYPE_F32)); 111 112 // we interpolate the image and variance - include the mask or not? 113 // XXX why not the mask? 114 // psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, variance, mask, maskVal, 0.0, 0.0, badMask, poorMask, 0.0, 0); 115 psImageInterpolation *interp = psImageInterpolationAlloc(mode, image, variance, NULL, 0xff, 0.0, 0.0, badMask, poorMask, 0.0, 0); 116 116 psArrayAdd (input, 100, interp); 117 117 … … 128 128 psFree (mask); 129 129 psFree (image); 130 psFree ( weight);130 psFree (variance); 131 131 psFree (interp); 132 132 } … … 176 176 fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = badMask; 177 177 } else { 178 fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = mflux; // XXX is mflux IMAGE or VECTOR type?179 }180 fluxes->data.F32[i] = flux;181 dfluxes->data.F32[i] = dflux;178 fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = mflux; // XXX is mflux IMAGE or VECTOR type? 179 } 180 fluxes->data.F32[i] = flux; 181 dfluxes->data.F32[i] = dflux; 182 182 if (isnan(flux)) { 183 183 fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = badMask; … … 204 204 205 205 // mark input pixels which are more than N sigma from the median 206 int nKeep = 0;206 int nKeep = 0; 207 207 for (int i = 0; i < fluxes->n; i++) { 208 208 float delta = fluxes->data.F32[i] - fluxClip->robustMedian; … … 210 210 float swing = fabs(delta) / sigma; 211 211 212 // mask pixels which are out of range212 // mask pixels which are out of range 213 213 if (swing > nSigma) { 214 214 fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = clippedMask; 215 215 } 216 if (!fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) nKeep++;216 if (!fmasks->data.PS_TYPE_VECTOR_MASK_DATA[i]) nKeep++; 217 217 } 218 218 … … 225 225 resid->Ro->data.F32[oy][ox] = psStatsGetValue(fluxStats, statOption); 226 226 resid->Rx->data.F32[oy][ox] = resid->Ry->data.F32[oy][ox] = 0.0; 227 //resid-> weight->data.F32[oy][ox] = fluxStats->sampleStdev;227 //resid->variance->data.F32[oy][ox] = fluxStats->sampleStdev; 228 228 229 229 if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*fluxStats->sampleStdev/sqrt(nKeep)) { … … 231 231 } 232 232 233 // fprintf (stderr, "res: %2d %2d : %6.4f %6.4f %6.4f %3d %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], fluxStats->sampleStdev, fluxStats->sampleStdev/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]);233 // fprintf (stderr, "res: %2d %2d : %6.4f %6.4f %6.4f %3d %1d\n", ox, oy, resid->Ro->data.F32[oy][ox], fluxStats->sampleStdev, fluxStats->sampleStdev/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]); 234 234 235 235 } else { … … 268 268 269 269 float dRo = sqrt(A->data.F32[0][0]); 270 // fprintf (stderr, "res: %2d %2d : %6.4f %6.4f %6.4f %3d %1d\n", 271 // ox, oy, resid->Ro->data.F32[oy][ox], dRo, dRo/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]);270 // fprintf (stderr, "res: %2d %2d : %6.4f %6.4f %6.4f %3d %1d\n", 271 // ox, oy, resid->Ro->data.F32[oy][ox], dRo, dRo/sqrt(nKeep), nKeep, resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox]); 272 272 273 273 if (fabs(resid->Ro->data.F32[oy][ox]) < pixelSN*dRo/sqrt(nKeep)) { 274 274 resid->mask->data.PM_TYPE_RESID_MASK_DATA[oy][ox] = 1; 275 275 } 276 //resid-> weight->data.F32[oy][ox] = XXX;276 //resid->variance->data.F32[oy][ox] = XXX; 277 277 } 278 278 } … … 301 301 psphotSaveImage (NULL, resid->Rx, "resid.rx.fits"); 302 302 psphotSaveImage (NULL, resid->Ry, "resid.ry.fits"); 303 psphotSaveImage (NULL, resid-> weight, "resid.wt.fits");303 psphotSaveImage (NULL, resid->variance, "resid.wt.fits"); 304 304 psphotSaveImage (NULL, resid->mask, "resid.mk.fits"); 305 305 } -
trunk/psphot/src/psphotMaskReadout.c
r21183 r21366 1 1 # include "psphotInternal.h" 2 2 3 // generate mask and weight if not defined, additional mask for restricted subregion4 bool psphotSetMaskAnd Weight(pmConfig *config, pmReadout *readout, psMetadata *recipe) {3 // generate mask and variance if not defined, additional mask for restricted subregion 4 bool psphotSetMaskAndVariance (pmConfig *config, pmReadout *readout, psMetadata *recipe) { 5 5 6 6 bool status; … … 15 15 psMetadataAddImageMask (recipe, PS_LIST_TAIL, "MASK.BAD", PS_META_REPLACE, "user-defined mask", maskBad); 16 16 17 // generate mask & weightimages if they don't already exit17 // generate mask & variance images if they don't already exit 18 18 if (!readout->mask) { 19 19 if (!pmReadoutGenerateMask(readout, maskSat, maskBad)) { … … 22 22 } 23 23 } 24 if (!readout-> weight) {25 if (!pmReadoutGenerate Weight(readout, true)) {26 psError (PSPHOT_ERR_CONFIG, false, "trouble creating weight");24 if (!readout->variance) { 25 if (!pmReadoutGenerateVariance(readout, true)) { 26 psError (PSPHOT_ERR_CONFIG, false, "trouble creating variance"); 27 27 return false; 28 28 } … … 49 49 psphotSaveImage (NULL, readout->image, "image.fits"); 50 50 psphotSaveImage (NULL, readout->mask, "mask.fits"); 51 psphotSaveImage (NULL, readout-> weight, "weight.fits");51 psphotSaveImage (NULL, readout->variance, "variance.fits"); 52 52 } 53 53 -
trunk/psphot/src/psphotModelWithPSF.c
r21183 r21366 20 20 paramMask = constraint->paramMask; 21 21 if (paramMask != NULL) { 22 PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);22 PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false); 23 23 PS_ASSERT_VECTORS_SIZE_EQUAL(params, paramMask, false); 24 24 } … … 42 42 // Alpha & Beta only contain elements to represent the unmasked parameters 43 43 if (!psMinLM_AllocAB (&Alpha, &Beta, params, paramMask)) { 44 psAbort ("programming error: no unmasked parameters to be fit\n");45 } 46 44 psAbort ("programming error: no unmasked parameters to be fit\n"); 45 } 46 47 47 // allocate internal arrays (current vs Guess) 48 48 psImage *alpha = psImageAlloc(Alpha->numCols, Alpha->numRows, PS_TYPE_F32); … … 127 127 lambda *= 0.25; 128 128 129 // save the new convolved model image130 psFree (source->modelFlux);131 source->modelFlux = pmPCMDataSaveImage(pcm);129 // save the new convolved model image 130 psFree (source->modelFlux); 131 source->modelFlux = pmPCMDataSaveImage(pcm); 132 132 } else { 133 133 lambda *= 10.0; … … 142 142 psTrace ("psphot", 5, "failure to calculate covariance matrix\n"); 143 143 } 144 // set covar values which are not masked145 psImageInit (covar, 0.0);146 for (int j = 0, J = 0; j < params->n; j++) {147 if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {148 covar->data.F32[j][j] = 1.0;149 continue;150 }151 for (int k = 0, K = 0; k < params->n; k++) {152 if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue;153 covar->data.F32[j][k] = Alpha->data.F32[J][K];154 K++;155 }156 J++;157 }144 // set covar values which are not masked 145 psImageInit (covar, 0.0); 146 for (int j = 0, J = 0; j < params->n; j++) { 147 if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) { 148 covar->data.F32[j][j] = 1.0; 149 continue; 150 } 151 for (int k = 0, K = 0; k < params->n; k++) { 152 if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[k])) continue; 153 covar->data.F32[j][k] = Alpha->data.F32[J][K]; 154 K++; 155 } 156 J++; 157 } 158 158 } 159 159 … … 192 192 PS_ASSERT_PTR_NON_NULL(source, NAN); 193 193 PS_ASSERT_IMAGE_NON_NULL(source->pixels, NAN); 194 PS_ASSERT_IMAGE_NON_NULL(source-> weight, NAN);194 PS_ASSERT_IMAGE_NON_NULL(source->variance, NAN); 195 195 PS_ASSERT_IMAGE_NON_NULL(source->maskObj, NAN); 196 196 … … 210 210 psImageInit (pcm->model, 0.0); 211 211 for (int n = 0; n < params->n; n++) { 212 if (!pcm->dmodels->data[n]) continue;213 psImageInit (pcm->dmodels->data[n], 0.0);212 if (!pcm->dmodels->data[n]) continue; 213 psImageInit (pcm->dmodels->data[n], 0.0); 214 214 } 215 215 … … 218 218 for (psS32 j = 0; j < source->pixels->numCols; j++) { 219 219 220 // XXX can we skip some of the data points where the model221 // is not going to be fitted??220 // XXX can we skip some of the data points where the model 221 // is not going to be fitted?? 222 222 223 223 // skip masked points 224 // XXX probably should not skipped masked points: 225 // XXX skip if convolution of unmasked pixels will not see this pixel224 // XXX probably should not skipped masked points: 225 // XXX skip if convolution of unmasked pixels will not see this pixel 226 226 // if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) { 227 // continue;228 // }229 230 // skip zero- weightpoints231 // XXX why is this not masked?232 // if (source-> weight->data.F32[i][j] == 0) {233 // continue;234 // }227 // continue; 228 // } 229 230 // skip zero-variance points 231 // XXX why is this not masked? 232 // if (source->variance->data.F32[i][j] == 0) { 233 // continue; 234 // } 235 235 // skip nan value points 236 // XXX why is this not masked?236 // XXX why is this not masked? 237 237 // if (!isfinite(source->pixels->data.F32[i][j])) { 238 // continue;239 // }238 // continue; 239 // } 240 240 241 241 // Convert i/j to image space: … … 243 243 coord->data.F32[1] = (psF32) (i + source->pixels->row0); 244 244 245 pcm->model->data.F32[i][j] = func (deriv, params, coord);246 247 for (int n = 0; n < params->n; n++) {248 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }249 psImage *dmodel = pcm->dmodels->data[n];250 dmodel->data.F32[i][j] = deriv->data.F32[n];251 }245 pcm->model->data.F32[i][j] = func (deriv, params, coord); 246 247 for (int n = 0; n < params->n; n++) { 248 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 249 psImage *dmodel = pcm->dmodels->data[n]; 250 dmodel->data.F32[i][j] = deriv->data.F32[n]; 251 } 252 252 } 253 253 } … … 258 258 psImageConvolveDirect (pcm->modelConv, pcm->model, psf); 259 259 for (int n = 0; n < pcm->dmodels->n; n++) { 260 if (pcm->dmodels->data[n] == NULL) continue;261 psImage *dmodel = pcm->dmodels->data[n];262 psImage *dmodelConv = pcm->dmodelsConv->data[n];263 psImageConvolveDirect (dmodelConv, dmodel, psf);260 if (pcm->dmodels->data[n] == NULL) continue; 261 psImage *dmodel = pcm->dmodels->data[n]; 262 psImage *dmodelConv = pcm->dmodelsConv->data[n]; 263 psImageConvolveDirect (dmodelConv, dmodel, psf); 264 264 } 265 265 266 266 // XXX TEST : SAVE IMAGES 267 # if (SAVE_IMAGES) 267 # if (SAVE_IMAGES) 268 268 psphotSaveImage (NULL, psf->image, "psf.fits"); 269 269 psphotSaveImage (NULL, pcm->model, "model.fits"); … … 271 271 psphotSaveImage (NULL, source->pixels, "obj.fits"); 272 272 psphotSaveImage (NULL, source->maskObj, "mask.fits"); 273 psphotSaveImage (NULL, source-> weight, "weight.fits");273 psphotSaveImage (NULL, source->variance, "variance.fits"); 274 274 # endif 275 275 276 // 2 *** accumulate alpha & beta 276 // 2 *** accumulate alpha & beta 277 277 278 278 // zero alpha and beta for summing below … … 283 283 for (psS32 i = 0; i < source->pixels->numRows; i++) { 284 284 for (psS32 j = 0; j < source->pixels->numCols; j++) { 285 // XXX are we doing the right thing with the mask?285 // XXX are we doing the right thing with the mask? 286 286 // skip masked points 287 287 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) { 288 288 continue; 289 289 } 290 // skip zero- weightpoints291 if (source-> weight->data.F32[i][j] == 0) {290 // skip zero-variance points 291 if (source->variance->data.F32[i][j] == 0) { 292 292 continue; 293 293 } … … 297 297 } 298 298 299 float ymodel = pcm->modelConv->data.F32[i][j];300 float yweight = 1.0 / source->weight->data.F32[i][j];301 float delta = ymodel - source->pixels->data.F32[i][j];302 303 chisq += PS_SQR(delta) * yweight;304 305 if (isnan(delta)) psAbort("nan in delta");306 if (isnan(chisq)) psAbort("nan in chisq");307 308 // alpha & beta only contain unmasked elements 309 for (int n1 = 0, N1 = 0; n1 < params->n; n1++) {310 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n1])) continue;311 psImage *dmodel = pcm->dmodelsConv->data[n1];312 float weight = dmodel->data.F32[i][j] * yweight;313 for (int n2 = 0, N2 = 0; n2 <= n1; n2++) {314 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n2])) continue;315 dmodel = pcm->dmodelsConv->data[n2];316 alpha->data.F32[N1][N2] += weight * dmodel->data.F32[i][j];317 N2++;318 }319 beta->data.F32[N1] += weight * delta;320 N1++;321 }322 }299 float ymodel = pcm->modelConv->data.F32[i][j]; 300 float yweight = 1.0 / source->variance->data.F32[i][j]; 301 float delta = ymodel - source->pixels->data.F32[i][j]; 302 303 chisq += PS_SQR(delta) * yweight; 304 305 if (isnan(delta)) psAbort("nan in delta"); 306 if (isnan(chisq)) psAbort("nan in chisq"); 307 308 // alpha & beta only contain unmasked elements 309 for (int n1 = 0, N1 = 0; n1 < params->n; n1++) { 310 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n1])) continue; 311 psImage *dmodel = pcm->dmodelsConv->data[n1]; 312 float weight = dmodel->data.F32[i][j] * yweight; 313 for (int n2 = 0, N2 = 0; n2 <= n1; n2++) { 314 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n2])) continue; 315 dmodel = pcm->dmodelsConv->data[n2]; 316 alpha->data.F32[N1][N2] += weight * dmodel->data.F32[i][j]; 317 N2++; 318 } 319 beta->data.F32[N1] += weight * delta; 320 N1++; 321 } 322 } 323 323 } 324 324 … … 356 356 pcm->dmodels = psArrayAlloc (params->n); 357 357 for (psS32 n = 0; n < params->n; n++) { 358 pcm->dmodels->data[n] = NULL;359 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }360 pcm->dmodels->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32);358 pcm->dmodels->data[n] = NULL; 359 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 360 pcm->dmodels->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 361 361 } 362 362 … … 365 365 pcm->dmodelsConv = psArrayAlloc (params->n); 366 366 for (psS32 n = 0; n < params->n; n++) { 367 pcm->dmodelsConv->data[n] = NULL;368 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; }369 pcm->dmodelsConv->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32);367 pcm->dmodelsConv->data[n] = NULL; 368 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 369 pcm->dmodelsConv->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 370 370 } 371 371 … … 376 376 377 377 psImage *model = psImageCopy (NULL, pcm->modelConv, PS_TYPE_F32); 378 378 379 379 return model; 380 380 } … … 383 383 * 384 384 * we have a function func(param; value) 385 385 386 386 * basic LMM: 387 387 388 388 - fill in the data (x, y) 389 389 390 390 chisq = SetABX (alpha, beta, params, paramMask, x, y, dy, func) 391 391 392 392 while () { 393 393 GuessABP (Alpha, Beta, Params, alpha, beta, params, paramMask, checkLimits, lambda) … … 396 396 convergence tests... 397 397 } 398 399 398 399 400 400 401 401 ** GuessABP: -
trunk/psphot/src/psphotOutput.c
r21183 r21366 18 18 19 19 pmReadout *psphotSelectBackgroundStdev (pmConfig *config, 20 const pmFPAview *view) {20 const pmFPAview *view) { 21 21 22 22 bool status; … … 77 77 continue; 78 78 } 79 // skip zero- weightpoints80 if (source-> weight->data.F32[i][j] == 0) {79 // skip zero-variance points 80 if (source->variance->data.F32[i][j] == 0) { 81 81 continue; 82 82 } … … 86 86 (i + source->pixels->row0), 87 87 source->pixels->data.F32[i][j], 88 1.0 / source-> weight->data.F32[i][j],88 1.0 / source->variance->data.F32[i][j], 89 89 source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]); 90 90 } … … 124 124 if (model == NULL) 125 125 continue; 126 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {127 nEXT ++;128 }129 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) {130 nCR ++;131 }126 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 127 nEXT ++; 128 } 129 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) { 130 nCR ++; 131 } 132 132 nSrc ++; 133 133 } … … 242 242 243 243 for (int i = 0; i < try->sources->n; i++) { 244 // masked for: bad model fit, outlier in parameters245 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL)246 continue;247 248 pmSource *source = try->sources->data[i];249 float x = source->modelPSF->params->data.F32[PM_PAR_XPOS];250 float y = source->modelPSF->params->data.F32[PM_PAR_YPOS];251 252 // set the mask and subtract the PSF model253 // XXX should we be using maskObj? should we be unsetting the mask?254 // use pmModelSub because modelFlux has not been generated255 assert (source->maskObj);256 psImageKeepCircle (source->maskObj, x, y, radius, "OR", markVal);257 pmModelSub (source->pixels, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL, maskVal);258 psImageKeepCircle (source->maskObj, x, y, radius, "AND", PS_NOT_IMAGE_MASK(markVal));244 // masked for: bad model fit, outlier in parameters 245 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) 246 continue; 247 248 pmSource *source = try->sources->data[i]; 249 float x = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 250 float y = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 251 252 // set the mask and subtract the PSF model 253 // XXX should we be using maskObj? should we be unsetting the mask? 254 // use pmModelSub because modelFlux has not been generated 255 assert (source->maskObj); 256 psImageKeepCircle (source->maskObj, x, y, radius, "OR", markVal); 257 pmModelSub (source->pixels, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL, maskVal); 258 psImageKeepCircle (source->maskObj, x, y, radius, "AND", PS_NOT_IMAGE_MASK(markVal)); 259 259 } 260 260 261 261 FILE *f = fopen ("shapes.dat", "w"); 262 262 for (int i = 0; i < try->sources->n; i++) { 263 psF32 inPar[10]; // must be psF32 to pmPSF_FitToModel264 265 // masked for: bad model fit, outlier in parameters266 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue;267 268 pmSource *source = try->sources->data[i];269 psF32 *outPar = source->modelEXT->params->data.F32;270 271 psEllipseShape shape;272 273 shape.sx = outPar[PM_PAR_SXX] / M_SQRT2;274 shape.sy = outPar[PM_PAR_SYY] / M_SQRT2;275 shape.sxy = outPar[PM_PAR_SXY];276 277 psEllipsePol pol = pmPSF_ModelToFit (outPar);278 inPar[PM_PAR_E0] = pol.e0;279 inPar[PM_PAR_E1] = pol.e1;280 inPar[PM_PAR_E2] = pol.e2;281 pmPSF_FitToModel (inPar, 0.1);282 283 psEllipseAxes axes1 = psEllipseShapeToAxes (shape, 20.0);284 psEllipseAxes axes2 = psEllipsePolToAxes(pol, 0.1);285 286 psEllipsePol pol2 = psEllipseAxesToPol (axes1);287 288 fprintf (f, "%3d %7.2f %7.2f %7.4f %7.4f %7.4f -- %7.4f %7.4f %7.4f : %7.4f %7.4f %7.4f -- %7.4f %7.4f %7.4f : %7.4f %7.4f %6.1f : %7.4f %7.4f %6.1f\n",289 i, outPar[PM_PAR_XPOS], outPar[PM_PAR_YPOS],290 outPar[PM_PAR_SXX], outPar[PM_PAR_SXY], outPar[PM_PAR_SYY],291 pol.e0, pol.e1, pol.e2,292 pol2.e0, pol2.e1, pol2.e2,293 inPar[PM_PAR_SXX], inPar[PM_PAR_SXY], inPar[PM_PAR_SYY],294 axes1.major, axes1.minor, axes1.theta*PM_DEG_RAD,295 axes2.major, axes2.minor, axes2.theta*PM_DEG_RAD296 );263 psF32 inPar[10]; // must be psF32 to pmPSF_FitToModel 264 265 // masked for: bad model fit, outlier in parameters 266 if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue; 267 268 pmSource *source = try->sources->data[i]; 269 psF32 *outPar = source->modelEXT->params->data.F32; 270 271 psEllipseShape shape; 272 273 shape.sx = outPar[PM_PAR_SXX] / M_SQRT2; 274 shape.sy = outPar[PM_PAR_SYY] / M_SQRT2; 275 shape.sxy = outPar[PM_PAR_SXY]; 276 277 psEllipsePol pol = pmPSF_ModelToFit (outPar); 278 inPar[PM_PAR_E0] = pol.e0; 279 inPar[PM_PAR_E1] = pol.e1; 280 inPar[PM_PAR_E2] = pol.e2; 281 pmPSF_FitToModel (inPar, 0.1); 282 283 psEllipseAxes axes1 = psEllipseShapeToAxes (shape, 20.0); 284 psEllipseAxes axes2 = psEllipsePolToAxes(pol, 0.1); 285 286 psEllipsePol pol2 = psEllipseAxesToPol (axes1); 287 288 fprintf (f, "%3d %7.2f %7.2f %7.4f %7.4f %7.4f -- %7.4f %7.4f %7.4f : %7.4f %7.4f %7.4f -- %7.4f %7.4f %7.4f : %7.4f %7.4f %6.1f : %7.4f %7.4f %6.1f\n", 289 i, outPar[PM_PAR_XPOS], outPar[PM_PAR_YPOS], 290 outPar[PM_PAR_SXX], outPar[PM_PAR_SXY], outPar[PM_PAR_SYY], 291 pol.e0, pol.e1, pol.e2, 292 pol2.e0, pol2.e1, pol2.e2, 293 inPar[PM_PAR_SXX], inPar[PM_PAR_SXY], inPar[PM_PAR_SYY], 294 axes1.major, axes1.minor, axes1.theta*PM_DEG_RAD, 295 axes2.major, axes2.minor, axes2.theta*PM_DEG_RAD 296 ); 297 297 } 298 298 fclose (f); -
trunk/psphot/src/psphotRadialProfile.c
r21183 r21366 11 11 flux->data.F32[A] = flux->data.F32[B]; \ 12 12 flux->data.F32[B] = tmp; \ 13 tmp = weight->data.F32[A]; \14 weight->data.F32[A] = weight->data.F32[B]; \15 weight->data.F32[B] = tmp; \13 tmp = variance->data.F32[A]; \ 14 variance->data.F32[A] = variance->data.F32[B]; \ 15 variance->data.F32[B] = tmp; \ 16 16 } \ 17 17 } … … 31 31 source->extpars->profile->radius = psVectorAllocEmpty (nPts, PS_TYPE_F32); 32 32 source->extpars->profile->flux = psVectorAllocEmpty (nPts, PS_TYPE_F32); 33 source->extpars->profile-> weight= psVectorAllocEmpty (nPts, PS_TYPE_F32);33 source->extpars->profile->variance = psVectorAllocEmpty (nPts, PS_TYPE_F32); 34 34 35 35 psVector *radius = source->extpars->profile->radius; 36 36 psVector *flux = source->extpars->profile->flux; 37 psVector * weight = source->extpars->profile->weight;37 psVector *variance = source->extpars->profile->variance; 38 38 39 39 // XXX use the extended source model here for Xo, Yo? … … 41 41 42 42 int n = 0; 43 43 44 44 float Xo = 0.0; 45 45 float Yo = 0.0; … … 57 57 radius->data.F32[n] = hypot (ix - Xo, iy - Yo) ; 58 58 flux->data.F32[n] = source->pixels->data.F32[iy][ix]; 59 weight->data.F32[n] = source->weight->data.F32[iy][ix];59 variance->data.F32[n] = source->variance->data.F32[iy][ix]; 60 60 n++; 61 61 } 62 62 } 63 63 radius->n = n; 64 weight->n = n;64 variance->n = n; 65 65 flux->n = n; 66 66 -
trunk/psphot/src/psphotReadout.c
r21250 r21366 40 40 41 41 // Generate the mask and weight images, including the user-defined analysis region of interest 42 psphotSetMaskAnd Weight(config, readout, recipe);42 psphotSetMaskAndVariance (config, readout, recipe); 43 43 if (!strcasecmp (breakPt, "NOTHING")) { 44 44 return psphotReadoutCleanup(config, readout, recipe, NULL, NULL, NULL); -
trunk/psphot/src/psphotReadoutFindPSF.c
r21249 r21366 18 18 PS_ASSERT_PTR_NON_NULL (readout, false); 19 19 20 // Generate the mask and weightimages, including the user-defined analysis region of interest21 psphotSetMaskAnd Weight(config, readout, recipe);20 // Generate the mask and variance images, including the user-defined analysis region of interest 21 psphotSetMaskAndVariance (config, readout, recipe); 22 22 23 23 // display the image, weight, mask (ch 1,2,3) -
trunk/psphot/src/psphotReadoutKnownSources.c
r21248 r21366 19 19 20 20 // Generate the mask and weight images, including the user-defined analysis region of interest 21 psphotSetMaskAnd Weight(config, readout, recipe);21 psphotSetMaskAndVariance (config, readout, recipe); 22 22 23 23 // display the image, weight, mask (ch 1,2,3) … … 41 41 // use the peak measured in the moments analysis: 42 42 for (int i = 0; i < sources->n; i++) { 43 pmSource *source = sources->data[i];44 source->peak->flux = source->moments->Peak;43 pmSource *source = sources->data[i]; 44 source->peak->flux = source->moments->Peak; 45 45 } 46 46 47 47 // classify sources based on moments, brightness (psf is not known) 48 48 if (!psphotRoughClass (readout, sources, recipe, false)) { … … 53 53 pmPSF *psf = psphotChoosePSF (readout, sources, recipe); 54 54 if (!psf) { 55 psLogMsg ("psphot", 3, "failure to construct a psf model");56 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);55 psLogMsg ("psphot", 3, "failure to construct a psf model"); 56 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 57 57 } 58 58 psphotVisualShowPSFModel (readout, psf); -
trunk/psphot/src/psphotReadoutMinimal.c
r21248 r21366 5 5 // used by ppSub. 6 6 7 // NOTE: ppSub needs to perform extended source analysis for comets and trails. 7 // NOTE: ppSub needs to perform extended source analysis for comets and trails. 8 8 9 9 bool psphotReadoutMinimal(pmConfig *config, const pmFPAview *view) { … … 27 27 28 28 // Generate the mask and weight images, including the user-defined analysis region of interest 29 psphotSetMaskAnd Weight(config, readout, recipe);29 psphotSetMaskAndVariance (config, readout, recipe); 30 30 31 31 // display the image, weight, mask (ch 1,2,3) … … 78 78 79 79 // XXX eventually, add the extended source fits here 80 # if (0) 80 # if (0) 81 81 // measure source size for the remaining sources 82 82 psphotSourceSize (config, readout, sources, recipe, 0); -
trunk/psphot/src/psphotSignificanceImage.c
r21183 r21366 1 1 # include "psphotInternal.h" 2 2 3 // In this function, we smooth the image and weight, then generate the significance image :3 // In this function, we smooth the image and variance, then generate the significance image : 4 4 // (S/N)^2. If FWMH_X,Y have been recorded, use them, otherwise use PEAKS_SMOOTH_SIGMA for the 5 5 // smoothing kernel. … … 10 10 bool guess = false; 11 11 12 // smooth the image and weightmap12 // smooth the image and variance map 13 13 psTimerStart ("psphot.smooth"); 14 14 bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading in psImageConvolve … … 48 48 psLogMsg("psphot", PS_LOG_MINUTIA, "smooth image: %f sec\n", psTimerMark("psphot.smooth")); 49 49 50 // Smooth the weight, applying the mask as we go. The variance is smoothed by the PSF^2,50 // Smooth the variance, applying the mask as we go. The variance is smoothed by the PSF^2, 51 51 // renomalized to maintain the input level of the variance. We achieve this by smoothing 52 52 // with a Gaussian with sigma = SIGMA_SMTH/sqrt(2) with unity normalization. Note that … … 55 55 // measurements based on apertures comparable to or larger than the smoothing kernel, the 56 56 // effective per-pixel variance is maintained. 57 psImage *smooth_wt = psImageCopy(NULL, readout-> weight, PS_TYPE_F32);57 psImage *smooth_wt = psImageCopy(NULL, readout->variance, PS_TYPE_F32); 58 58 psImageSmoothMask_Threaded(smooth_wt, smooth_wt, readout->mask, maskVal, SIGMA_SMTH * M_SQRT1_2, 59 59 NSIGMA_SMTH, minGauss); 60 psLogMsg("psphot", PS_LOG_MINUTIA, "smooth weight: %f sec\n", psTimerMark("psphot.smooth"));60 psLogMsg("psphot", PS_LOG_MINUTIA, "smooth variance: %f sec\n", psTimerMark("psphot.smooth")); 61 61 62 62 psImage *mask = readout->mask; … … 100 100 101 101 float factor = guess ? 4.0 * M_PI * PS_SQR(SIGMA_SMTH) : 4.0 * M_PI * PS_SQR(SIGMA_SMTH); 102 103 // Correct the correction factor for the covariance produced by the (potentially multiple) smoothing 104 psKernel *kernel = psImageSmoothKernel(SIGMA_SMTH, NSIGMA_SMTH); // Kernel used for smoothing 105 psKernel *covar = psImageCovarianceCalculate(kernel, readout->covariance); // Covariance matrix 106 psFree(kernel); 107 factor /= psImageCovarianceFactor(covar); 108 psFree(covar); 109 102 110 // record the effective area and significance scaling factor 103 111 float effArea = 8.0 * M_PI * PS_SQR(SIGMA_SMTH); -
trunk/psphot/src/psphotSourceSize.c
r21183 r21366 2 2 # include <gsl/gsl_sf_gamma.h> 3 3 4 static float psphotModelContour(const psImage *image, const psImage * weight, const psImage *mask,4 static float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask, 5 5 psImageMaskType maskVal, const pmModel *model, float Ro); 6 6 … … 62 62 63 63 psF32 **resid = source->pixels->data.F32; 64 psF32 ** weight = source->weight->data.F32;64 psF32 **variance = source->variance->data.F32; 65 65 psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA; 66 66 67 67 // check for extendedness: measure the delta flux significance at the 1 sigma contour 68 source->extNsigma = psphotModelContour(source->pixels, source-> weight, source->maskObj, maskVal,68 source->extNsigma = psphotModelContour(source->pixels, source->variance, source->maskObj, maskVal, 69 69 source->modelPSF, 1.0); 70 70 … … 103 103 // Compare the central pixel with those on either side, for the four possible lines through it. 104 104 105 // Soften weights (add systematic error)106 float softening = soft * PS_SQR(source->peak->flux); // Softening for weights105 // Soften variances (add systematic error) 106 float softening = soft * PS_SQR(source->peak->flux); // Softening for variances 107 107 108 108 // Across the middle: y = 0 109 109 float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1]; 110 float dcX = 4* weight[yPeak][xPeak] + weight[yPeak+0][xPeak-1] + weight[yPeak+0][xPeak+1];110 float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1]; 111 111 float nX = cX / sqrtf(dcX + softening); 112 112 113 113 // Up the centre: x = 0 114 114 float cY = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak+0] - resid[yPeak+1][xPeak+0]; 115 float dcY = 4* weight[yPeak][xPeak] + weight[yPeak-1][xPeak+0] + weight[yPeak+1][xPeak+0];115 float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0]; 116 116 float nY = cY / sqrtf(dcY + softening); 117 117 118 118 // Diagonal: x = y 119 119 float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1]; 120 float dcL = 4* weight[yPeak][xPeak] + weight[yPeak-1][xPeak-1] + weight[yPeak+1][xPeak+1];120 float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1]; 121 121 float nL = cL / sqrtf(dcL + softening); 122 122 123 123 // Diagonal: x = - y 124 124 float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1]; 125 float dcR = 4* weight[yPeak][xPeak] + weight[yPeak+1][xPeak-1] + weight[yPeak-1][xPeak+1];125 float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1]; 126 126 float nR = cR / sqrtf(dcR + softening); 127 127 … … 160 160 // this source is thought to be a cosmic ray. flag the detection and mask the pixels 161 161 if (source->crNsigma > CR_NSIGMA_LIMIT) { 162 // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask);163 psphotMaskCosmicRay_Old (source, maskVal, crMask);162 // XXX still testing... : psphotMaskCosmicRay_New (readout->mask, source, maskVal, crMask); 163 psphotMaskCosmicRay_Old (source, maskVal, crMask); 164 164 } 165 165 } … … 190 190 // deviation in sigmas. This is measured on the residual image - should we ignore negative 191 191 // deviations? 192 static float psphotModelContour(const psImage *image, const psImage * weight, const psImage *mask,192 static float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask, 193 193 psImageMaskType maskVal, const pmModel *model, float Ro) 194 194 { … … 240 240 if (yPixM >= 0 && yPixM < image->numRows && 241 241 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) { 242 float dSigma = image->data.F32[yPixM][xPix] / sqrtf( weight->data.F32[yPixM][xPix]);242 float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]); 243 243 nSigma += dSigma; 244 244 nPts++; … … 251 251 if (yPixP >= 0 && yPixP < image->numRows && 252 252 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) { 253 float dSigma = image->data.F32[yPixP][xPix] / sqrtf( weight->data.F32[yPixP][xPix]);253 float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]); 254 254 nSigma += dSigma; 255 255 nPts++; … … 274 274 pmFootprint *footprint = peak->footprint; 275 275 if (!footprint) { 276 // if we have not footprint, use the old code to mask by isophot277 psphotMaskCosmicRay_Old (source, maskVal, crMask);278 return true;276 // if we have not footprint, use the old code to mask by isophot 277 psphotMaskCosmicRay_Old (source, maskVal, crMask); 278 return true; 279 279 } 280 280 281 281 if (!footprint->spans) { 282 // if we have not footprint, use the old code to mask by isophot283 psphotMaskCosmicRay_Old (source, maskVal, crMask);284 return true;282 // if we have not footprint, use the old code to mask by isophot 283 psphotMaskCosmicRay_Old (source, maskVal, crMask); 284 return true; 285 285 } 286 286 287 287 // mask all of the pixels covered by the spans of the footprint 288 288 for (int j = 1; j < footprint->spans->n; j++) { 289 pmSpan *span1 = footprint->spans->data[j];290 291 int iy = span1->y;292 int xs = span1->x0;293 int xe = span1->x1;294 295 for (int ix = xs; ix < xe; ix++) {296 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;297 }289 pmSpan *span1 = footprint->spans->data[j]; 290 291 int iy = span1->y; 292 int xs = span1->x0; 293 int xe = span1->x1; 294 295 for (int ix = xs; ix < xe; ix++) { 296 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 297 } 298 298 } 299 299 return true; … … 308 308 psImage *mask = source->maskView; 309 309 psImage *pixels = source->pixels; 310 psImage * weight = source->weight;310 psImage *variance = source->variance; 311 311 312 312 // XXX This should be a recipe variable … … 318 318 // mark the pixels in this row to the left, then the right 319 319 for (int ix = xo; ix >= 0; ix--) { 320 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);321 if (SN > SN_LIMIT) {322 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;323 }320 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]); 321 if (SN > SN_LIMIT) { 322 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask; 323 } 324 324 } 325 325 for (int ix = xo + 1; ix < pixels->numCols; ix++) { 326 float SN = pixels->data.F32[yo][ix] / sqrt(weight->data.F32[yo][ix]);327 if (SN > SN_LIMIT) {328 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;329 }326 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]); 327 if (SN > SN_LIMIT) { 328 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask; 329 } 330 330 } 331 331 … … 333 333 // first go up: 334 334 for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) { 335 // mark the pixels in this row to the left, then the right336 for (int ix = 0; ix < pixels->numCols; ix++) {337 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);338 if (SN < SN_LIMIT) continue;339 340 bool valid = false;341 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);342 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;343 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;344 345 if (!valid) continue;346 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;347 }335 // mark the pixels in this row to the left, then the right 336 for (int ix = 0; ix < pixels->numCols; ix++) { 337 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 338 if (SN < SN_LIMIT) continue; 339 340 bool valid = false; 341 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask); 342 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0; 343 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0; 344 345 if (!valid) continue; 346 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 347 } 348 348 } 349 349 // next go down: 350 350 for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) { 351 // mark the pixels in this row to the left, then the right352 for (int ix = 0; ix < pixels->numCols; ix++) {353 float SN = pixels->data.F32[iy][ix] / sqrt(weight->data.F32[iy][ix]);354 if (SN < SN_LIMIT) continue;355 356 bool valid = false;357 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);358 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;359 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;360 361 if (!valid) continue;362 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;363 }351 // mark the pixels in this row to the left, then the right 352 for (int ix = 0; ix < pixels->numCols; ix++) { 353 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 354 if (SN < SN_LIMIT) continue; 355 356 bool valid = false; 357 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask); 358 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0; 359 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0; 360 361 if (!valid) continue; 362 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 363 } 364 364 } 365 365 return true; -
trunk/psphot/src/psphotVisual.c
r21183 r21366 2 2 3 3 // this function displays representative images as the psphot analysis progresses: 4 // 0 : image, 1 : weight5 // 0 : backsub, 1 : weight, 2 : backgnd6 // 0 : backsub, 1 : weight, 2 : signif4 // 0 : image, 1 : variance 5 // 0 : backsub, 1 : variance, 2 : backgnd 6 // 0 : backsub, 1 : variance, 2 : signif 7 7 // (overlay peaks on images) 8 8 // (overlay footprints on images) 9 9 // (overlay moments on images) 10 // (overlay rough class on images) 10 // (overlay rough class on images) 11 11 // 0 : backsub, 1 : psfpos, 2: psfsub 12 12 // 0 : backsub, 1 : lin_resid, 2: psfsub … … 40 40 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); 41 41 if (!psImageBackground(stats, NULL, inImage, NULL, 0, rng)) { 42 fprintf (stderr, "failed to get background values\n");43 return false;42 fprintf (stderr, "failed to get background values\n"); 43 return false; 44 44 } 45 45 … … 49 49 ALLOCATE (image.data2d, float *, image.Ny); 50 50 for (int iy = 0; iy < image.Ny; iy++) { 51 ALLOCATE (image.data2d[iy], float, image.Nx);52 for (int ix = 0; ix < image.Nx; ix++) {53 image.data2d[iy][ix] = inImage->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix];54 }51 ALLOCATE (image.data2d[iy], float, image.Nx); 52 for (int ix = 0; ix < image.Nx; ix++) { 53 image.data2d[iy][ix] = inImage->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]; 54 } 55 55 } 56 56 … … 60 60 data.range = 32; 61 61 data.logflux = 0; 62 62 63 63 KiiSetChannel (kapaFD, channel); 64 64 KiiNewPicture2D (kapaFD, &image, &data, &coords); 65 65 66 66 for (int iy = 0; iy < image.Ny; iy++) { 67 free (image.data2d[iy]);67 free (image.data2d[iy]); 68 68 } 69 69 free (image.data2d); … … 86 86 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0); 87 87 if (!psImageBackground(stats, NULL, inImage, NULL, 0, rng)) { 88 fprintf (stderr, "failed to get background values\n");89 return false;88 fprintf (stderr, "failed to get background values\n"); 89 return false; 90 90 } 91 91 … … 99 99 data.range = 5*stats->robustStdev; 100 100 data.logflux = 0; 101 101 102 102 KiiSetChannel (kapaFD, channel); 103 103 KiiNewPicture2D (kapaFD, &image, &data, &coords); … … 126 126 data.range = max - min; 127 127 data.logflux = 0; 128 128 129 129 KiiSetChannel (kapaFD, channel); 130 130 KiiNewPicture2D (kapaFD, &image, &data, &coords); … … 139 139 if (kapa == -1) { 140 140 kapa = KapaOpenNamedSocket ("kapa", "psphot:images"); 141 if (kapa == -1) {142 fprintf (stderr, "failure to open kapa; visual mode disabled\n");143 isVisual = false;144 return false;145 }146 } 141 if (kapa == -1) { 142 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 143 isVisual = false; 144 return false; 145 } 146 } 147 147 148 148 // psphotVisualShowMask (kapa, readout->mask, "mask", 2); 149 psphotVisualScaleImage (kapa, readout-> weight, "weight", 1);149 psphotVisualScaleImage (kapa, readout->variance, "variance", 1); 150 150 psphotVisualScaleImage (kapa, readout->image, "image", 0); 151 151 … … 155 155 fprintf (stdout, "[c]ontinue? "); 156 156 if (!fgets(key, 8, stdin)) { 157 psWarning("Unable to read option");157 psWarning("Unable to read option"); 158 158 } 159 159 return true; … … 168 168 if (kapa == -1) { 169 169 kapa = KapaOpenNamedSocket ("kapa", "psphot:images"); 170 if (kapa == -1) {171 fprintf (stderr, "failure to open kapa; visual mode disabled\n");172 isVisual = false;173 return false;174 }175 } 170 if (kapa == -1) { 171 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 172 isVisual = false; 173 return false; 174 } 175 } 176 176 177 177 bool status = false; … … 179 179 180 180 if (file->mode == PM_FPA_MODE_INTERNAL) { 181 backgnd = file->readout;181 backgnd = file->readout; 182 182 } else { 183 backgnd = pmFPAviewThisReadout (view, file->fpa);183 backgnd = pmFPAviewThisReadout (view, file->fpa); 184 184 } 185 185 … … 192 192 fprintf (stdout, "[c]ontinue? "); 193 193 if (!fgets(key, 8, stdin)) { 194 psWarning("Unable to read option");194 psWarning("Unable to read option"); 195 195 } 196 196 return true; … … 203 203 if (kapa == -1) { 204 204 kapa = KapaOpenNamedSocket ("kapa", "psphot:images"); 205 if (kapa == -1) {206 fprintf (stderr, "failure to open kapa; visual mode disabled\n");207 isVisual = false;208 return false;209 }210 } 205 if (kapa == -1) { 206 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 207 isVisual = false; 208 return false; 209 } 210 } 211 211 212 212 // XXX test: image->data.F32[10][10] = 10000; … … 218 218 fprintf (stdout, "[c]ontinue? "); 219 219 if (!fgets(key, 8, stdin)) { 220 psWarning("Unable to read option");220 psWarning("Unable to read option"); 221 221 } 222 222 return true; … … 227 227 int Noverlay; 228 228 KiiOverlay *overlay; 229 229 230 230 if (!isVisual) return true; 231 231 232 232 if (kapa == -1) { 233 fprintf (stderr, "kapa not opened, skipping\n");234 return false;233 fprintf (stderr, "kapa not opened, skipping\n"); 234 return false; 235 235 } 236 236 … … 244 244 for (int i = 0; i < peaks->n; i++) { 245 245 246 pmPeak *peak = peaks->data[i];247 if (peak == NULL) continue;248 249 overlay[Noverlay].type = KII_OVERLAY_BOX;250 overlay[Noverlay].x = peak->xf;251 overlay[Noverlay].y = peak->yf;252 overlay[Noverlay].dx = 2.0;253 overlay[Noverlay].dy = 2.0;254 overlay[Noverlay].angle = 0.0;255 overlay[Noverlay].text = NULL;256 Noverlay ++;246 pmPeak *peak = peaks->data[i]; 247 if (peak == NULL) continue; 248 249 overlay[Noverlay].type = KII_OVERLAY_BOX; 250 overlay[Noverlay].x = peak->xf; 251 overlay[Noverlay].y = peak->yf; 252 overlay[Noverlay].dx = 2.0; 253 overlay[Noverlay].dy = 2.0; 254 overlay[Noverlay].angle = 0.0; 255 overlay[Noverlay].text = NULL; 256 Noverlay ++; 257 257 258 258 # if (0) 259 overlay[Noverlay].type = KII_OVERLAY_BOX;260 overlay[Noverlay].x = peak->x;261 overlay[Noverlay].y = peak->y;262 overlay[Noverlay].dx = 1.0;263 overlay[Noverlay].dy = 1.0;264 overlay[Noverlay].angle = 0.0;265 overlay[Noverlay].text = NULL;266 Noverlay ++;267 268 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;269 overlay[Noverlay].x = peak->xf;270 overlay[Noverlay].y = peak->yf;271 overlay[Noverlay].dx = 2.0;272 overlay[Noverlay].dy = 2.0;273 overlay[Noverlay].angle = 0.0;274 overlay[Noverlay].text = NULL;275 Noverlay ++;259 overlay[Noverlay].type = KII_OVERLAY_BOX; 260 overlay[Noverlay].x = peak->x; 261 overlay[Noverlay].y = peak->y; 262 overlay[Noverlay].dx = 1.0; 263 overlay[Noverlay].dy = 1.0; 264 overlay[Noverlay].angle = 0.0; 265 overlay[Noverlay].text = NULL; 266 Noverlay ++; 267 268 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 269 overlay[Noverlay].x = peak->xf; 270 overlay[Noverlay].y = peak->yf; 271 overlay[Noverlay].dx = 2.0; 272 overlay[Noverlay].dy = 2.0; 273 overlay[Noverlay].angle = 0.0; 274 overlay[Noverlay].text = NULL; 275 Noverlay ++; 276 276 # endif 277 277 } … … 296 296 fprintf (stdout, "[c]ontinue? "); 297 297 if (!fgets(key, 8, stdin)) { 298 psWarning("Unable to read option");298 psWarning("Unable to read option"); 299 299 } 300 300 return true; … … 305 305 int Noverlay; 306 306 KiiOverlay *overlay; 307 307 308 308 if (!isVisual) return true; 309 309 310 310 if (kapa == -1) { 311 fprintf (stderr, "kapa not opened, skipping\n");312 return false;311 fprintf (stderr, "kapa not opened, skipping\n"); 312 return false; 313 313 } 314 314 … … 323 323 for (int i = 0; i < footprints->n; i++) { 324 324 325 pmSpan *span = NULL;326 327 pmFootprint *footprint = footprints->data[i];328 if (footprint == NULL) continue;329 if (footprint->spans == NULL) continue;330 if (footprint->spans->n < 1) continue;331 332 // draw the top333 span = footprint->spans->data[0];334 overlay[Noverlay].type = KII_OVERLAY_LINE;335 overlay[Noverlay].x = span->x0;336 overlay[Noverlay].y = span->y;337 overlay[Noverlay].dx = span->x1 - span->x0;338 overlay[Noverlay].dy = 0;339 overlay[Noverlay].angle = 0.0;340 overlay[Noverlay].text = NULL;341 Noverlay ++;342 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);343 344 int ys = span->y;345 int x0s = span->x0;346 int x1s = span->x1;347 348 // draw the outer span edges349 for (int j = 1; j < footprint->spans->n; j++) {350 pmSpan *span1 = footprint->spans->data[j];351 352 int ye = span1->y;353 int x0e = span1->x0;354 int x1e = span1->x1;355 356 // we cannot have two discontinuous spans on the top or bottom, right? (no, probably not right)357 // find all of the spans in this row and generate x0e, x01:358 for (int k = j + 1; k < footprint->spans->n; k++) {359 pmSpan *span2 = footprint->spans->data[k];360 if (span2->y > span1->y) break;361 x0e = PS_MIN (x0e, span2->x0);362 x1e = PS_MAX (x1e, span2->x1);363 j++;364 }365 366 overlay[Noverlay].type = KII_OVERLAY_LINE;367 overlay[Noverlay].x = x0s;368 overlay[Noverlay].y = ys;369 overlay[Noverlay].dx = x0e - x0s;370 overlay[Noverlay].dy = ye - ys;371 overlay[Noverlay].angle = 0.0;372 overlay[Noverlay].text = NULL;373 Noverlay ++;374 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);375 376 overlay[Noverlay].type = KII_OVERLAY_LINE;377 overlay[Noverlay].x = x1s;378 overlay[Noverlay].y = ys;379 overlay[Noverlay].dx = x1e - x1s;380 overlay[Noverlay].dy = ye - ys;381 overlay[Noverlay].angle = 0.0;382 overlay[Noverlay].text = NULL;383 Noverlay ++;384 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);385 386 ys = ye;387 x0s = x0e;388 x1s = x1e;389 }390 391 // draw the bottom392 span = footprint->spans->data[footprint->spans->n - 1];393 overlay[Noverlay].type = KII_OVERLAY_LINE;394 overlay[Noverlay].x = span->x0;395 overlay[Noverlay].y = span->y;396 overlay[Noverlay].dx = span->x1 - span->x0;397 overlay[Noverlay].dy = 0;398 overlay[Noverlay].angle = 0.0;399 overlay[Noverlay].text = NULL;400 Noverlay ++;401 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);325 pmSpan *span = NULL; 326 327 pmFootprint *footprint = footprints->data[i]; 328 if (footprint == NULL) continue; 329 if (footprint->spans == NULL) continue; 330 if (footprint->spans->n < 1) continue; 331 332 // draw the top 333 span = footprint->spans->data[0]; 334 overlay[Noverlay].type = KII_OVERLAY_LINE; 335 overlay[Noverlay].x = span->x0; 336 overlay[Noverlay].y = span->y; 337 overlay[Noverlay].dx = span->x1 - span->x0; 338 overlay[Noverlay].dy = 0; 339 overlay[Noverlay].angle = 0.0; 340 overlay[Noverlay].text = NULL; 341 Noverlay ++; 342 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 343 344 int ys = span->y; 345 int x0s = span->x0; 346 int x1s = span->x1; 347 348 // draw the outer span edges 349 for (int j = 1; j < footprint->spans->n; j++) { 350 pmSpan *span1 = footprint->spans->data[j]; 351 352 int ye = span1->y; 353 int x0e = span1->x0; 354 int x1e = span1->x1; 355 356 // we cannot have two discontinuous spans on the top or bottom, right? (no, probably not right) 357 // find all of the spans in this row and generate x0e, x01: 358 for (int k = j + 1; k < footprint->spans->n; k++) { 359 pmSpan *span2 = footprint->spans->data[k]; 360 if (span2->y > span1->y) break; 361 x0e = PS_MIN (x0e, span2->x0); 362 x1e = PS_MAX (x1e, span2->x1); 363 j++; 364 } 365 366 overlay[Noverlay].type = KII_OVERLAY_LINE; 367 overlay[Noverlay].x = x0s; 368 overlay[Noverlay].y = ys; 369 overlay[Noverlay].dx = x0e - x0s; 370 overlay[Noverlay].dy = ye - ys; 371 overlay[Noverlay].angle = 0.0; 372 overlay[Noverlay].text = NULL; 373 Noverlay ++; 374 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 375 376 overlay[Noverlay].type = KII_OVERLAY_LINE; 377 overlay[Noverlay].x = x1s; 378 overlay[Noverlay].y = ys; 379 overlay[Noverlay].dx = x1e - x1s; 380 overlay[Noverlay].dy = ye - ys; 381 overlay[Noverlay].angle = 0.0; 382 overlay[Noverlay].text = NULL; 383 Noverlay ++; 384 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 385 386 ys = ye; 387 x0s = x0e; 388 x1s = x1e; 389 } 390 391 // draw the bottom 392 span = footprint->spans->data[footprint->spans->n - 1]; 393 overlay[Noverlay].type = KII_OVERLAY_LINE; 394 overlay[Noverlay].x = span->x0; 395 overlay[Noverlay].y = span->y; 396 overlay[Noverlay].dx = span->x1 - span->x0; 397 overlay[Noverlay].dy = 0; 398 overlay[Noverlay].angle = 0.0; 399 overlay[Noverlay].text = NULL; 400 Noverlay ++; 401 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 402 402 } 403 403 … … 410 410 fprintf (stdout, "[c]ontinue? "); 411 411 if (!fgets(key, 8, stdin)) { 412 psWarning("Unable to read option");412 psWarning("Unable to read option"); 413 413 } 414 414 return true; … … 419 419 int Noverlay; 420 420 KiiOverlay *overlay; 421 421 422 422 psEllipseMoments emoments; 423 423 psEllipseAxes axes; … … 426 426 427 427 if (kapa == -1) { 428 fprintf (stderr, "kapa not opened, skipping\n");429 return false;428 fprintf (stderr, "kapa not opened, skipping\n"); 429 return false; 430 430 } 431 431 … … 436 436 for (int i = 0; i < sources->n; i++) { 437 437 438 pmSource *source = sources->data[i];439 if (source == NULL) continue;440 441 pmMoments *moments = source->moments;442 if (moments == NULL) continue;443 444 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;445 overlay[Noverlay].x = moments->Mx;446 overlay[Noverlay].y = moments->My;447 448 emoments.x2 = moments->Mxx;449 emoments.xy = moments->Mxy;450 emoments.y2 = moments->Myy;451 452 axes = psEllipseMomentsToAxes (emoments, 20.0);453 454 overlay[Noverlay].dx = 2.0*axes.major;455 overlay[Noverlay].dy = 2.0*axes.minor;456 overlay[Noverlay].angle = -axes.theta * PS_DEG_RAD; // XXXXXXXX the axes angle is negative to display of object on kapa457 overlay[Noverlay].text = NULL;458 Noverlay ++;438 pmSource *source = sources->data[i]; 439 if (source == NULL) continue; 440 441 pmMoments *moments = source->moments; 442 if (moments == NULL) continue; 443 444 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 445 overlay[Noverlay].x = moments->Mx; 446 overlay[Noverlay].y = moments->My; 447 448 emoments.x2 = moments->Mxx; 449 emoments.xy = moments->Mxy; 450 emoments.y2 = moments->Myy; 451 452 axes = psEllipseMomentsToAxes (emoments, 20.0); 453 454 overlay[Noverlay].dx = 2.0*axes.major; 455 overlay[Noverlay].dy = 2.0*axes.minor; 456 overlay[Noverlay].angle = -axes.theta * PS_DEG_RAD; // XXXXXXXX the axes angle is negative to display of object on kapa 457 overlay[Noverlay].text = NULL; 458 Noverlay ++; 459 459 } 460 460 … … 467 467 fprintf (stdout, "[c]ontinue? "); 468 468 if (!fgets(key, 8, stdin)) { 469 psWarning("Unable to read option");469 psWarning("Unable to read option"); 470 470 } 471 471 … … 482 482 if (kapa3 == -1) { 483 483 kapa3 = KapaOpenNamedSocket ("kapa", "psphot:plots"); 484 if (kapa3 == -1) {485 fprintf (stderr, "failure to open kapa; visual mode disabled\n");486 isVisual = false;487 return false;488 }489 } 484 if (kapa3 == -1) { 485 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 486 isVisual = false; 487 return false; 488 } 489 } 490 490 491 491 KapaClearPlots (kapa3); … … 494 494 // there are N regions: use the first (guaranteed to exist) to get the overall limits 495 495 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, "PSF.CLUMP.REGION.000"); 496 496 497 497 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 498 498 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); … … 558 558 559 559 // XXX draw N circles to outline the clumps 560 { 561 // draw a circle centered on psfX,Y with size of the psf limit562 psVector *xLimit = psVectorAlloc (120, PS_TYPE_F32);563 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32);564 565 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");566 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");567 568 graphdata.color = KapaColorByName ("blue");569 graphdata.style = 0;570 571 for (int n = 0; n < nRegions; n++) {572 573 char regionName[64];574 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n);575 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);576 577 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");578 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y");579 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX");580 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY");581 float Rx = psfdX * PSF_CLUMP_NSIGMA;582 float Ry = psfdY * PSF_CLUMP_NSIGMA;583 584 for (int i = 0; i < xLimit->n; i++) {585 xLimit->data.F32[i] = Rx*cos(i*2.0*M_PI/120.0) + psfX;586 yLimit->data.F32[i] = Ry*sin(i*2.0*M_PI/120.0) + psfY;587 }588 KapaPrepPlot (kapa3, xLimit->n, &graphdata);589 KapaPlotVector (kapa3, xLimit->n, xLimit->data.F32, "x");590 KapaPlotVector (kapa3, yLimit->n, yLimit->data.F32, "y");591 }592 psFree (xLimit);593 psFree (yLimit);560 { 561 // draw a circle centered on psfX,Y with size of the psf limit 562 psVector *xLimit = psVectorAlloc (120, PS_TYPE_F32); 563 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32); 564 565 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS"); 566 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA"); 567 568 graphdata.color = KapaColorByName ("blue"); 569 graphdata.style = 0; 570 571 for (int n = 0; n < nRegions; n++) { 572 573 char regionName[64]; 574 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 575 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName); 576 577 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 578 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 579 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 580 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 581 float Rx = psfdX * PSF_CLUMP_NSIGMA; 582 float Ry = psfdY * PSF_CLUMP_NSIGMA; 583 584 for (int i = 0; i < xLimit->n; i++) { 585 xLimit->data.F32[i] = Rx*cos(i*2.0*M_PI/120.0) + psfX; 586 yLimit->data.F32[i] = Ry*sin(i*2.0*M_PI/120.0) + psfY; 587 } 588 KapaPrepPlot (kapa3, xLimit->n, &graphdata); 589 KapaPlotVector (kapa3, xLimit->n, xLimit->data.F32, "x"); 590 KapaPlotVector (kapa3, yLimit->n, yLimit->data.F32, "y"); 591 } 592 psFree (xLimit); 593 psFree (yLimit); 594 594 } 595 595 596 596 # if (0) 597 // *** make a histogram of the source counts in the x and y directions 597 // *** make a histogram of the source counts in the x and y directions 598 598 psHistogram *nX = psHistogramAlloc (graphdata.xmin, graphdata.xmax, 50.0); 599 599 psHistogram *nY = psHistogramAlloc (graphdata.ymin, graphdata.ymax, 50.0); … … 605 605 psVector *vY = psVectorAlloc (nY->nums->n, PS_TYPE_F32); 606 606 for (int i = 0; i < nX->nums->n; i++) { 607 dX->data.F32[i] = nX->nums->data.S32[i];608 vX->data.F32[i] = 0.5*(nX->bounds->data.F32[i] + nX->bounds->data.F32[i+1]);607 dX->data.F32[i] = nX->nums->data.S32[i]; 608 vX->data.F32[i] = 0.5*(nX->bounds->data.F32[i] + nX->bounds->data.F32[i+1]); 609 609 } 610 610 for (int i = 0; i < nY->nums->n; i++) { 611 dY->data.F32[i] = nY->nums->data.S32[i];612 vY->data.F32[i] = 0.5*(nY->bounds->data.F32[i] + nY->bounds->data.F32[i+1]);611 dY->data.F32[i] = nY->nums->data.S32[i]; 612 vY->data.F32[i] = 0.5*(nY->bounds->data.F32[i] + nY->bounds->data.F32[i+1]); 613 613 } 614 614 … … 640 640 fprintf (stdout, "[c]ontinue? "); 641 641 if (!fgets(key, 8, stdin)) { 642 psWarning("Unable to read option");642 psWarning("Unable to read option"); 643 643 } 644 644 return true; … … 650 650 int Noverlay; 651 651 KiiOverlay *overlay; 652 652 653 653 psEllipseMoments emoments; 654 654 psEllipseAxes axes; … … 660 660 for (int i = 0; i < sources->n; i++) { 661 661 662 pmSource *source = sources->data[i];663 if (source == NULL) continue;664 665 if (source->type != type) continue;666 if (mode && !(source->mode & mode)) continue;667 668 pmMoments *moments = source->moments;669 if (moments == NULL) continue;670 671 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;672 overlay[Noverlay].x = moments->Mx;673 overlay[Noverlay].y = moments->My;674 675 emoments.x2 = moments->Mxx;676 emoments.y2 = moments->Myy;677 emoments.xy = moments->Mxy;678 679 axes = psEllipseMomentsToAxes (emoments, 20.0);680 681 overlay[Noverlay].dx = 2.0*axes.major;682 overlay[Noverlay].dy = 2.0*axes.minor;683 overlay[Noverlay].angle = -axes.theta * PS_DEG_RAD;684 overlay[Noverlay].text = NULL;685 Noverlay ++;662 pmSource *source = sources->data[i]; 663 if (source == NULL) continue; 664 665 if (source->type != type) continue; 666 if (mode && !(source->mode & mode)) continue; 667 668 pmMoments *moments = source->moments; 669 if (moments == NULL) continue; 670 671 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 672 overlay[Noverlay].x = moments->Mx; 673 overlay[Noverlay].y = moments->My; 674 675 emoments.x2 = moments->Mxx; 676 emoments.y2 = moments->Myy; 677 emoments.xy = moments->Mxy; 678 679 axes = psEllipseMomentsToAxes (emoments, 20.0); 680 681 overlay[Noverlay].dx = 2.0*axes.major; 682 overlay[Noverlay].dy = 2.0*axes.minor; 683 overlay[Noverlay].angle = -axes.theta * PS_DEG_RAD; 684 overlay[Noverlay].text = NULL; 685 Noverlay ++; 686 686 } 687 687 … … 697 697 698 698 if (kapa == -1) { 699 fprintf (stderr, "kapa not opened, skipping\n");700 return false;699 fprintf (stderr, "kapa not opened, skipping\n"); 700 return false; 701 701 } 702 702 … … 716 716 fprintf (stdout, "[c]ontinue? "); 717 717 if (!fgets(key, 8, stdin)) { 718 psWarning("Unable to read option");718 psWarning("Unable to read option"); 719 719 } 720 720 return true; … … 727 727 if (kapa2 == -1) { 728 728 kapa2 = KapaOpenNamedSocket ("kapa", "psphot:psfstars"); 729 if (kapa2 == -1) {730 fprintf (stderr, "failure to open kapa; visual mode disabled\n");731 isVisual = false;732 return false;733 }734 } 729 if (kapa2 == -1) { 730 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 731 isVisual = false; 732 return false; 733 } 734 } 735 735 736 736 int DX = 64; … … 739 739 psImage *psfMosaic = psImageAlloc (5*DX, 5*DY, PS_TYPE_F32); 740 740 psImageInit (psfMosaic, 0.0); 741 741 742 742 psImage *funMosaic = psImageAlloc (5*DX, 5*DY, PS_TYPE_F32); 743 743 psImageInit (funMosaic, 0.0); … … 750 750 // generate a fake model at each of the 3x3 image grid positions 751 751 for (int x = -2; x <= +2; x ++) { 752 for (int y = -2; y <= +2; y ++) {753 // use the center of the center pixel of the image754 float xc = (int)((0.5 + 0.225*x)*readout->image->numCols) + readout->image->col0 + 0.5;755 float yc = (int)((0.5 + 0.225*y)*readout->image->numRows) + readout->image->row0 + 0.5;756 757 // assign the x and y coords to the image center758 // create an object with center intensity of 1000759 modelRef->params->data.F32[PM_PAR_SKY] = 0;760 modelRef->params->data.F32[PM_PAR_I0] = 1000;761 modelRef->params->data.F32[PM_PAR_XPOS] = xc;762 modelRef->params->data.F32[PM_PAR_YPOS] = yc;763 764 // create modelPSF from this model765 pmModel *model = pmModelFromPSF (modelRef, psf);766 if (!model) continue;767 768 // place the reference object in the image center769 // no need to mask the source here770 // XXX should we measure this for the analytical model only or the full model?771 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, x*DX, y*DY);772 pmModelAddWithOffset (funMosaic, NULL, model, PM_MODEL_OP_FUNC | PM_MODEL_OP_CENTER, 0, x*DX, y*DY);773 pmModelAddWithOffset (resMosaic, NULL, model, PM_MODEL_OP_RES0 | PM_MODEL_OP_RES1 | PM_MODEL_OP_CENTER, 0, x*DX, y*DY);774 psFree (model);775 }752 for (int y = -2; y <= +2; y ++) { 753 // use the center of the center pixel of the image 754 float xc = (int)((0.5 + 0.225*x)*readout->image->numCols) + readout->image->col0 + 0.5; 755 float yc = (int)((0.5 + 0.225*y)*readout->image->numRows) + readout->image->row0 + 0.5; 756 757 // assign the x and y coords to the image center 758 // create an object with center intensity of 1000 759 modelRef->params->data.F32[PM_PAR_SKY] = 0; 760 modelRef->params->data.F32[PM_PAR_I0] = 1000; 761 modelRef->params->data.F32[PM_PAR_XPOS] = xc; 762 modelRef->params->data.F32[PM_PAR_YPOS] = yc; 763 764 // create modelPSF from this model 765 pmModel *model = pmModelFromPSF (modelRef, psf); 766 if (!model) continue; 767 768 // place the reference object in the image center 769 // no need to mask the source here 770 // XXX should we measure this for the analytical model only or the full model? 771 pmModelAddWithOffset (psfMosaic, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_CENTER, 0, x*DX, y*DY); 772 pmModelAddWithOffset (funMosaic, NULL, model, PM_MODEL_OP_FUNC | PM_MODEL_OP_CENTER, 0, x*DX, y*DY); 773 pmModelAddWithOffset (resMosaic, NULL, model, PM_MODEL_OP_RES0 | PM_MODEL_OP_RES1 | PM_MODEL_OP_CENTER, 0, x*DX, y*DY); 774 psFree (model); 775 } 776 776 } 777 777 … … 792 792 fprintf (stdout, "[c]ontinue? "); 793 793 if (!fgets(key, 8, stdin)) { 794 psWarning("Unable to read option");794 psWarning("Unable to read option"); 795 795 } 796 796 return true; … … 805 805 if (kapa2 == -1) { 806 806 kapa2 = KapaOpenNamedSocket ("kapa", "psphot:psfstars"); 807 if (kapa2 == -1) {808 fprintf (stderr, "failure to open kapa; visual mode disabled\n");809 isVisual = false;810 return false;811 }812 } 807 if (kapa2 == -1) { 808 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 809 isVisual = false; 810 return false; 811 } 812 } 813 813 814 814 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 827 827 828 828 // counters to track the size of the image and area used in a row 829 int dX = 0; // starting corner of next box830 int dY = 0; // height of row so far831 int NX = 20*DX; // full width of output image832 int NY = 0; // total height of output image829 int dX = 0; // starting corner of next box 830 int dY = 0; // height of row so far 831 int NX = 20*DX; // full width of output image 832 int NY = 0; // total height of output image 833 833 834 834 // first, examine the PSF stars: … … 838 838 pmSource *source = sources->data[i]; 839 839 840 bool keep = false;840 bool keep = false; 841 841 keep |= (source->mode & PM_SOURCE_MODE_PSFSTAR); 842 if (!keep) continue;843 844 // how does this subimage get placed into the output image?845 // DX = source->pixels->numCols846 // DY = source->pixels->numRows847 848 if (dX + DX > NX) {849 // too wide for the rest of this row850 if (dX == 0) {851 // alone on this row852 NY += DY;853 dX = 0;854 dY = 0;855 } else {856 // start the next row857 NY += dY;858 dX = DX;859 dY = DY;860 }861 } else {862 // extend this row863 dX += DX;864 dY = PS_MAX (dY, DY);865 }842 if (!keep) continue; 843 844 // how does this subimage get placed into the output image? 845 // DX = source->pixels->numCols 846 // DY = source->pixels->numRows 847 848 if (dX + DX > NX) { 849 // too wide for the rest of this row 850 if (dX == 0) { 851 // alone on this row 852 NY += DY; 853 dX = 0; 854 dY = 0; 855 } else { 856 // start the next row 857 NY += dY; 858 dX = DX; 859 dY = DY; 860 } 861 } else { 862 // extend this row 863 dX += DX; 864 dY = PS_MAX (dY, DY); 865 } 866 866 } 867 867 NY += DY; … … 873 873 psImageInit (outsub, 0.0); 874 874 875 int Xo = 0; // starting corner of next box876 int Yo = 0; // starting corner of next box877 dY = 0; // height of row so far875 int Xo = 0; // starting corner of next box 876 int Yo = 0; // starting corner of next box 877 dY = 0; // height of row so far 878 878 879 879 int nPSF = 0; … … 885 885 pmSource *source = sources->data[i]; 886 886 887 bool keep = false;887 bool keep = false; 888 888 if (source->mode & PM_SOURCE_MODE_PSFSTAR) { 889 nPSF ++;890 keep = true;891 }892 if (!keep) continue;893 894 if (Xo + DX > NX) {895 // too wide for the rest of this row896 if (Xo == 0) {897 // place source alone on this row898 psphotAddWithTest (source, true, maskVal); // replace source if subtracted899 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);900 901 psphotSubWithTest (source, false, maskVal); // remove source (force)902 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);903 psphotSetState (source, false, maskVal); // reset source Add/Sub state to recorded904 905 Yo += DY;906 Xo = 0;907 dY = 0;908 } else {909 // start the next row910 Yo += dY;911 Xo = 0;912 913 psphotAddWithTest (source, true, maskVal); // replace source if subtracted914 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);915 916 psphotSubWithTest (source, false, maskVal); // remove source (force)917 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);918 psphotSetState (source, false, maskVal); // replace source (has been subtracted)919 920 Xo = DX;921 dY = DY;922 }923 } else {924 // extend this row925 psphotAddWithTest (source, true, maskVal); // replace source if subtracted926 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true);927 928 psphotSubWithTest (source, false, maskVal); // remove source (force)929 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true);930 psphotSetState (source, false, maskVal); // replace source (has been subtracted)931 932 Xo += DX;933 dY = PS_MAX (dY, DY);934 }889 nPSF ++; 890 keep = true; 891 } 892 if (!keep) continue; 893 894 if (Xo + DX > NX) { 895 // too wide for the rest of this row 896 if (Xo == 0) { 897 // place source alone on this row 898 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 899 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 900 901 psphotSubWithTest (source, false, maskVal); // remove source (force) 902 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 903 psphotSetState (source, false, maskVal); // reset source Add/Sub state to recorded 904 905 Yo += DY; 906 Xo = 0; 907 dY = 0; 908 } else { 909 // start the next row 910 Yo += dY; 911 Xo = 0; 912 913 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 914 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 915 916 psphotSubWithTest (source, false, maskVal); // remove source (force) 917 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 918 psphotSetState (source, false, maskVal); // replace source (has been subtracted) 919 920 Xo = DX; 921 dY = DY; 922 } 923 } else { 924 // extend this row 925 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 926 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 927 928 psphotSubWithTest (source, false, maskVal); // remove source (force) 929 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 930 psphotSetState (source, false, maskVal); // replace source (has been subtracted) 931 932 Xo += DX; 933 dY = PS_MAX (dY, DY); 934 } 935 935 } 936 936 … … 943 943 fprintf (stdout, "[c]ontinue? "); 944 944 if (!fgets(key, 8, stdin)) { 945 psWarning("Unable to read option");945 psWarning("Unable to read option"); 946 946 } 947 947 … … 965 965 if (kapa2 == -1) { 966 966 kapa2 = KapaOpenNamedSocket ("kapa", "psphot:images"); 967 if (kapa2 == -1) {968 fprintf (stderr, "failure to open kapa; visual mode disabled\n");969 isVisual = false;970 return false;971 }972 } 967 if (kapa2 == -1) { 968 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 969 isVisual = false; 970 return false; 971 } 972 } 973 973 974 974 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 987 987 988 988 // counters to track the size of the image and area used in a row 989 int dX = 0; // starting corner of next box990 int dY = 0; // height of row so far991 int NX = 10*DX; // full width of output image992 int NY = 0; // total height of output image989 int dX = 0; // starting corner of next box 990 int dY = 0; // height of row so far 991 int NX = 10*DX; // full width of output image 992 int NY = 0; // total height of output image 993 993 994 994 // first, examine the PSF and SAT stars: … … 998 998 pmSource *source = sources->data[i]; 999 999 1000 bool keep = false;1000 bool keep = false; 1001 1001 keep |= (source->mode & PM_SOURCE_MODE_SATSTAR); 1002 if (!keep) continue;1003 1004 // how does this subimage get placed into the output image?1005 // DX = source->pixels->numCols1006 // DY = source->pixels->numRows1007 1008 if (dX + DX > NX) {1009 // too wide for the rest of this row1010 if (dX == 0) {1011 // alone on this row1012 NY += DY;1013 dX = 0;1014 dY = 0;1015 } else {1016 // start the next row1017 NY += dY;1018 dX = DX;1019 dY = DY;1020 }1021 } else {1022 // extend this row1023 dX += DX;1024 dY = PS_MAX (dY, DY);1025 }1002 if (!keep) continue; 1003 1004 // how does this subimage get placed into the output image? 1005 // DX = source->pixels->numCols 1006 // DY = source->pixels->numRows 1007 1008 if (dX + DX > NX) { 1009 // too wide for the rest of this row 1010 if (dX == 0) { 1011 // alone on this row 1012 NY += DY; 1013 dX = 0; 1014 dY = 0; 1015 } else { 1016 // start the next row 1017 NY += dY; 1018 dX = DX; 1019 dY = DY; 1020 } 1021 } else { 1022 // extend this row 1023 dX += DX; 1024 dY = PS_MAX (dY, DY); 1025 } 1026 1026 } 1027 1027 NY += DY; … … 1031 1031 psImageInit (outsat, 0.0); 1032 1032 1033 int Xo = 0; // starting corner of next box1034 int Yo = 0; // starting corner of next box1035 dY = 0; // height of row so far1033 int Xo = 0; // starting corner of next box 1034 int Yo = 0; // starting corner of next box 1035 dY = 0; // height of row so far 1036 1036 1037 1037 int nSAT = 0; … … 1043 1043 pmSource *source = sources->data[i]; 1044 1044 1045 bool keep = false;1045 bool keep = false; 1046 1046 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 1047 nSAT ++;1048 keep = true;1049 } 1050 if (!keep) continue;1051 1052 if (Xo + DX > NX) {1053 // too wide for the rest of this row1054 if (Xo == 0) {1055 // place source alone on this row1056 psphotAddWithTest (source, true, maskVal); // replace source if subtracted1057 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);1058 psphotSetState (source, true, maskVal); // reset source Add/Sub state to recorded1059 1060 Yo += DY;1061 Xo = 0;1062 dY = 0;1063 } else {1064 // start the next row1065 Yo += dY;1066 Xo = 0;1067 psphotAddWithTest (source, true, maskVal); // replace source if subtracted1068 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);1069 psphotSetState (source, true, maskVal); // replace source (has been subtracted)1070 1071 Xo = DX;1072 dY = DY;1073 }1074 } else {1075 // extend this row1076 psphotAddWithTest (source, true, maskVal); // replace source if subtracted1077 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false);1078 psphotSetState (source, true, maskVal); // replace source (has been subtracted)1079 1080 Xo += DX;1081 dY = PS_MAX (dY, DY);1082 }1047 nSAT ++; 1048 keep = true; 1049 } 1050 if (!keep) continue; 1051 1052 if (Xo + DX > NX) { 1053 // too wide for the rest of this row 1054 if (Xo == 0) { 1055 // place source alone on this row 1056 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 1057 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1058 psphotSetState (source, true, maskVal); // reset source Add/Sub state to recorded 1059 1060 Yo += DY; 1061 Xo = 0; 1062 dY = 0; 1063 } else { 1064 // start the next row 1065 Yo += dY; 1066 Xo = 0; 1067 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 1068 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1069 psphotSetState (source, true, maskVal); // replace source (has been subtracted) 1070 1071 Xo = DX; 1072 dY = DY; 1073 } 1074 } else { 1075 // extend this row 1076 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 1077 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1078 psphotSetState (source, true, maskVal); // replace source (has been subtracted) 1079 1080 Xo += DX; 1081 dY = PS_MAX (dY, DY); 1082 } 1083 1083 } 1084 1084 … … 1090 1090 fprintf (stdout, "[c]ontinue? "); 1091 1091 if (!fgets(key, 8, stdin)) { 1092 psWarning("Unable to read option");1092 psWarning("Unable to read option"); 1093 1093 } 1094 1094 … … 1117 1117 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS] - source->pixels->row0; 1118 1118 for (int iy = 0; iy < source->pixels->numRows; iy++) { 1119 for (int ix = 0; ix < source->pixels->numCols; ix++) {1120 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) {1121 // rb->data.F32[nb] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ;1122 rb->data.F32[nb] = hypot (ix - Xo, iy - Yo) ;1123 Rb->data.F32[nb] = log10(rb->data.F32[nb]);1124 fb->data.F32[nb] = log10(source->pixels->data.F32[iy][ix]);1125 nb++;1126 } else {1127 // rg->data.F32[ng] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ;1128 rg->data.F32[ng] = hypot (ix - Xo, iy - Yo) ;1129 Rg->data.F32[ng] = log10(rg->data.F32[ng]);1130 fg->data.F32[ng] = log10(source->pixels->data.F32[iy][ix]);1131 ng++;1132 }1133 }1134 } 1135 1119 for (int ix = 0; ix < source->pixels->numCols; ix++) { 1120 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) { 1121 // rb->data.F32[nb] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ; 1122 rb->data.F32[nb] = hypot (ix - Xo, iy - Yo) ; 1123 Rb->data.F32[nb] = log10(rb->data.F32[nb]); 1124 fb->data.F32[nb] = log10(source->pixels->data.F32[iy][ix]); 1125 nb++; 1126 } else { 1127 // rg->data.F32[ng] = hypot (ix + 0.5 - Xo, iy + 0.5 - Yo) ; 1128 rg->data.F32[ng] = hypot (ix - Xo, iy - Yo) ; 1129 Rg->data.F32[ng] = log10(rg->data.F32[ng]); 1130 fg->data.F32[ng] = log10(source->pixels->data.F32[iy][ix]); 1131 ng++; 1132 } 1133 } 1134 } 1135 1136 1136 // reset source Add/Sub state to recorded 1137 psphotSetState (source, state, maskVal); 1137 psphotSetState (source, state, maskVal); 1138 1138 1139 1139 KapaInitGraph (&graphdata); … … 1148 1148 graphdata.ymax = +5.05; 1149 1149 KapaSetLimits (myKapa, &graphdata); 1150 1150 1151 1151 KapaSetFont (myKapa, "helvetica", 14); 1152 1152 KapaBox (myKapa, &graphdata); 1153 1153 KapaSendLabel (myKapa, "radius (pixels)", KAPA_LABEL_XM); 1154 1154 KapaSendLabel (myKapa, "log flux (counts)", KAPA_LABEL_YM); 1155 1155 1156 1156 graphdata.color = KapaColorByName ("black"); 1157 1157 graphdata.ptype = 2; … … 1169 1169 KapaPlotVector (myKapa, nb, rb->data.F32, "x"); 1170 1170 KapaPlotVector (myKapa, nb, fb->data.F32, "y"); 1171 1171 1172 1172 // ** loglog ** 1173 1173 KapaSelectSection (myKapa, "loglog"); … … 1179 1179 graphdata.ymax = +5.05; 1180 1180 KapaSetLimits (myKapa, &graphdata); 1181 1181 1182 1182 KapaSetFont (myKapa, "helvetica", 14); 1183 1183 KapaBox (myKapa, &graphdata); 1184 1184 KapaSendLabel (myKapa, "log radius (pixels)", KAPA_LABEL_XM); 1185 1185 KapaSendLabel (myKapa, "log flux (counts)", KAPA_LABEL_YM); 1186 1186 1187 1187 graphdata.color = KapaColorByName ("black"); 1188 1188 graphdata.ptype = 2; … … 1212 1212 bool psphotVisualPlotRadialProfiles (psMetadata *recipe, psArray *sources) { 1213 1213 1214 KapaSection section; // put the positive profile in one and the residuals in another? 1214 KapaSection section; // put the positive profile in one and the residuals in another? 1215 1215 1216 1216 if (!isVisual) return true; … … 1218 1218 if (kapa3 == -1) { 1219 1219 kapa3 = KapaOpenNamedSocket ("kapa", "psphot:plots"); 1220 if (kapa3 == -1) {1221 fprintf (stderr, "failure to open kapa; visual mode disabled\n");1222 isVisual = false;1223 return false;1224 }1225 } 1220 if (kapa3 == -1) { 1221 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 1222 isVisual = false; 1223 return false; 1224 } 1225 } 1226 1226 1227 1227 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 1257 1257 if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue; 1258 1258 1259 psphotVisualPlotRadialProfile (kapa3, source, maskVal);1260 1261 // pause and wait for user input:1262 // continue, save (provide name), ??1263 char key[10];1264 fprintf (stdout, "[e]rase and continue? [o]verplot and continue? [s]kip rest of stars? : ");1265 if (!fgets(key, 8, stdin)) {1266 psWarning("Unable to read option");1267 }1268 if (key[0] == 'e') {1269 KapaClearPlots (kapa3);1270 }1271 if (key[0] == 's') {1272 break;1273 }1274 } 1259 psphotVisualPlotRadialProfile (kapa3, source, maskVal); 1260 1261 // pause and wait for user input: 1262 // continue, save (provide name), ?? 1263 char key[10]; 1264 fprintf (stdout, "[e]rase and continue? [o]verplot and continue? [s]kip rest of stars? : "); 1265 if (!fgets(key, 8, stdin)) { 1266 psWarning("Unable to read option"); 1267 } 1268 if (key[0] == 'e') { 1269 KapaClearPlots (kapa3); 1270 } 1271 if (key[0] == 's') { 1272 break; 1273 } 1274 } 1275 1275 1276 1276 return true; … … 1282 1282 int NoverlayO, NOVERLAYO; 1283 1283 KiiOverlay *overlayE, *overlayO; 1284 1284 1285 1285 psEllipseMoments emoments; 1286 1286 psEllipseAxes axes; … … 1289 1289 1290 1290 if (kapa == -1) { 1291 fprintf (stderr, "kapa not opened, skipping\n");1292 return false;1291 fprintf (stderr, "kapa not opened, skipping\n"); 1292 return false; 1293 1293 } 1294 1294 … … 1304 1304 for (int i = 0; i < sources->n; i++) { 1305 1305 1306 float Xo, Yo, Rmaj, Rmin, cs, sn;1307 1308 pmSource *source = sources->data[i];1309 if (source == NULL) continue;1310 1311 pmMoments *moments = source->moments;1312 if (0) { 1313 emoments.x2 = moments->Mxx;1314 emoments.y2 = moments->Myy;1315 emoments.xy = moments->Mxy;1316 Xo = moments->Mx;1317 Yo = moments->My;1318 1319 axes = psEllipseMomentsToAxes (emoments, 20.0);1320 Rmaj = 2.0*axes.major;1321 Rmin = 2.0*axes.minor;1322 cs = cos(axes.theta);1323 sn = sin(axes.theta);1324 } else {1325 Rmaj = Rmin = 5.0;1326 cs = 1.0;1327 sn = 0.0;1328 Xo = source->peak->xf;1329 Yo = source->peak->yf;1330 }1331 1332 unsigned short int flagMask = 0x01;1333 for (int j = 0; j < 8; j++) {1334 if (source->mode & flagMask) {1335 overlayE[NoverlayE].type = KII_OVERLAY_LINE;1336 overlayE[NoverlayE].x = Xo;1337 overlayE[NoverlayE].y = Yo;1338 1339 float phi = j*M_PI/4.0;1340 overlayE[NoverlayE].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn;1341 overlayE[NoverlayE].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs;1342 overlayE[NoverlayE].angle = 0;1343 overlayE[NoverlayE].text = NULL;1344 NoverlayE ++;1345 CHECK_REALLOCATE (overlayE, KiiOverlay, NOVERLAYE, NoverlayE, 100);1346 }1347 flagMask <<= 1;1348 1349 if (source->mode & flagMask) {1350 overlayO[NoverlayO].type = KII_OVERLAY_LINE;1351 overlayO[NoverlayO].x = Xo + 1;1352 overlayO[NoverlayO].y = Yo;1353 1354 float phi = j*M_PI/4.0;1355 overlayO[NoverlayO].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn;1356 overlayO[NoverlayO].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs;1357 overlayO[NoverlayO].angle = 0;1358 overlayO[NoverlayO].text = NULL;1359 NoverlayO ++;1360 CHECK_REALLOCATE (overlayO, KiiOverlay, NOVERLAYO, NoverlayO, 100);1361 }1362 flagMask <<= 1;1363 }1306 float Xo, Yo, Rmaj, Rmin, cs, sn; 1307 1308 pmSource *source = sources->data[i]; 1309 if (source == NULL) continue; 1310 1311 pmMoments *moments = source->moments; 1312 if (0) { 1313 emoments.x2 = moments->Mxx; 1314 emoments.y2 = moments->Myy; 1315 emoments.xy = moments->Mxy; 1316 Xo = moments->Mx; 1317 Yo = moments->My; 1318 1319 axes = psEllipseMomentsToAxes (emoments, 20.0); 1320 Rmaj = 2.0*axes.major; 1321 Rmin = 2.0*axes.minor; 1322 cs = cos(axes.theta); 1323 sn = sin(axes.theta); 1324 } else { 1325 Rmaj = Rmin = 5.0; 1326 cs = 1.0; 1327 sn = 0.0; 1328 Xo = source->peak->xf; 1329 Yo = source->peak->yf; 1330 } 1331 1332 unsigned short int flagMask = 0x01; 1333 for (int j = 0; j < 8; j++) { 1334 if (source->mode & flagMask) { 1335 overlayE[NoverlayE].type = KII_OVERLAY_LINE; 1336 overlayE[NoverlayE].x = Xo; 1337 overlayE[NoverlayE].y = Yo; 1338 1339 float phi = j*M_PI/4.0; 1340 overlayE[NoverlayE].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn; 1341 overlayE[NoverlayE].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs; 1342 overlayE[NoverlayE].angle = 0; 1343 overlayE[NoverlayE].text = NULL; 1344 NoverlayE ++; 1345 CHECK_REALLOCATE (overlayE, KiiOverlay, NOVERLAYE, NoverlayE, 100); 1346 } 1347 flagMask <<= 1; 1348 1349 if (source->mode & flagMask) { 1350 overlayO[NoverlayO].type = KII_OVERLAY_LINE; 1351 overlayO[NoverlayO].x = Xo + 1; 1352 overlayO[NoverlayO].y = Yo; 1353 1354 float phi = j*M_PI/4.0; 1355 overlayO[NoverlayO].dx = +Rmaj*cos(phi)*cs - Rmin*sin(phi)*sn; 1356 overlayO[NoverlayO].dy = +Rmaj*cos(phi)*sn + Rmin*sin(phi)*cs; 1357 overlayO[NoverlayO].angle = 0; 1358 overlayO[NoverlayO].text = NULL; 1359 NoverlayO ++; 1360 CHECK_REALLOCATE (overlayO, KiiOverlay, NOVERLAYO, NoverlayO, 100); 1361 } 1362 flagMask <<= 1; 1363 } 1364 1364 } 1365 1365 … … 1376 1376 fprintf (stdout, "[c]ontinue? "); 1377 1377 if (!fgets(key, 8, stdin)) { 1378 psWarning("Unable to read option");1378 psWarning("Unable to read option"); 1379 1379 } 1380 1380 … … 1390 1390 1391 1391 if (kapa == -1) { 1392 fprintf (stderr, "kapa not opened, skipping\n");1393 return false;1392 fprintf (stderr, "kapa not opened, skipping\n"); 1393 return false; 1394 1394 } 1395 1395 … … 1402 1402 for (int i = 0; i < sources->n; i++) { 1403 1403 1404 pmSource *source = sources->data[i];1405 if (source == NULL) continue;1406 1407 if (!(source->mode & PM_SOURCE_MODE_CR_LIMIT)) continue;1408 1409 overlay[Noverlay].type = KII_OVERLAY_BOX;1410 overlay[Noverlay].x = source->peak->xf;1411 overlay[Noverlay].y = source->peak->yf;1412 1413 overlay[Noverlay].dx = 4;1414 overlay[Noverlay].dy = 4;1415 overlay[Noverlay].angle = 0;1416 overlay[Noverlay].text = NULL;1417 Noverlay ++;1418 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);1404 pmSource *source = sources->data[i]; 1405 if (source == NULL) continue; 1406 1407 if (!(source->mode & PM_SOURCE_MODE_CR_LIMIT)) continue; 1408 1409 overlay[Noverlay].type = KII_OVERLAY_BOX; 1410 overlay[Noverlay].x = source->peak->xf; 1411 overlay[Noverlay].y = source->peak->yf; 1412 1413 overlay[Noverlay].dx = 4; 1414 overlay[Noverlay].dy = 4; 1415 overlay[Noverlay].angle = 0; 1416 overlay[Noverlay].text = NULL; 1417 Noverlay ++; 1418 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 1419 1419 } 1420 1420 KiiLoadOverlay (kapa, overlay, Noverlay, "red"); … … 1424 1424 for (int i = 0; i < sources->n; i++) { 1425 1425 1426 pmSource *source = sources->data[i];1427 if (source == NULL) continue;1428 1429 // mark EXTs with yellow circles1430 if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue;1431 1432 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;1433 overlay[Noverlay].x = source->peak->xf;1434 overlay[Noverlay].y = source->peak->yf;1435 1436 overlay[Noverlay].dx = 10;1437 overlay[Noverlay].dy = 10;1438 overlay[Noverlay].angle = 0;1439 overlay[Noverlay].text = NULL;1440 Noverlay ++;1441 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100);1426 pmSource *source = sources->data[i]; 1427 if (source == NULL) continue; 1428 1429 // mark EXTs with yellow circles 1430 if (!(source->mode & PM_SOURCE_MODE_EXT_LIMIT)) continue; 1431 1432 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 1433 overlay[Noverlay].x = source->peak->xf; 1434 overlay[Noverlay].y = source->peak->yf; 1435 1436 overlay[Noverlay].dx = 10; 1437 overlay[Noverlay].dy = 10; 1438 overlay[Noverlay].angle = 0; 1439 overlay[Noverlay].text = NULL; 1440 Noverlay ++; 1441 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 1442 1442 } 1443 1443 … … 1453 1453 fprintf (stdout, "[c]ontinue? "); 1454 1454 if (!fgets(key, 8, stdin)) { 1455 psWarning("Unable to read option");1455 psWarning("Unable to read option"); 1456 1456 } 1457 1457 … … 1468 1468 if (kapa3 == -1) { 1469 1469 kapa3 = KapaOpenNamedSocket ("kapa", "psphot:plots"); 1470 if (kapa3 == -1) {1471 fprintf (stderr, "failure to open kapa; visual mode disabled\n");1472 isVisual = false;1473 return false;1474 }1475 } 1470 if (kapa3 == -1) { 1471 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 1472 isVisual = false; 1473 return false; 1474 } 1475 } 1476 1476 1477 1477 KapaClearPlots (kapa3); … … 1500 1500 for (int i = 0; i < sources->n; i++) { 1501 1501 pmSource *source = sources->data[i]; 1502 if (!source) continue;1502 if (!source) continue; 1503 1503 if (source->type != PM_SOURCE_TYPE_STAR) continue; 1504 if (!isfinite (source->crNsigma)) continue;1504 if (!isfinite (source->crNsigma)) continue; 1505 1505 1506 1506 x->data.F32[n] = -2.5*log10(source->peak->flux); … … 1555 1555 for (int i = 0; i < sources->n; i++) { 1556 1556 pmSource *source = sources->data[i]; 1557 if (!source) continue;1557 if (!source) continue; 1558 1558 if (source->type != PM_SOURCE_TYPE_STAR) continue; 1559 if (!isfinite (source->extNsigma)) continue;1559 if (!isfinite (source->extNsigma)) continue; 1560 1560 1561 1561 x->data.F32[n] = -2.5*log10(source->peak->flux); … … 1597 1597 fprintf (stdout, "[c]ontinue? "); 1598 1598 if (!fgets(key, 8, stdin)) { 1599 psWarning("Unable to read option");1599 psWarning("Unable to read option"); 1600 1600 } 1601 1601 return true; … … 1608 1608 if (kapa == -1) { 1609 1609 kapa = KapaOpenNamedSocket ("kapa", "psphot:images"); 1610 if (kapa == -1) {1611 fprintf (stderr, "failure to open kapa; visual mode disabled\n");1612 isVisual = false;1613 return false;1614 }1615 } 1610 if (kapa == -1) { 1611 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 1612 isVisual = false; 1613 return false; 1614 } 1615 } 1616 1616 1617 1617 psphotVisualScaleImage (kapa, readout->image, "resid", 1); … … 1622 1622 fprintf (stdout, "[c]ontinue? "); 1623 1623 if (!fgets(key, 8, stdin)) { 1624 psWarning("Unable to read option");1624 psWarning("Unable to read option"); 1625 1625 } 1626 1626 return true; … … 1635 1635 if (kapa3 == -1) { 1636 1636 kapa3 = KapaOpenNamedSocket ("kapa", "psphot:plots"); 1637 if (kapa3 == -1) {1638 fprintf (stderr, "failure to open kapa; visual mode disabled\n");1639 isVisual = false;1640 return false;1641 }1642 } 1637 if (kapa3 == -1) { 1638 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 1639 isVisual = false; 1640 return false; 1641 } 1642 } 1643 1643 1644 1644 KapaClearPlots (kapa3); … … 1657 1657 for (int i = 0; i < sources->n; i++) { 1658 1658 pmSource *source = sources->data[i]; 1659 if (!source) continue;1659 if (!source) continue; 1660 1660 if (source->type != PM_SOURCE_TYPE_STAR) continue; 1661 if (!isfinite (source->apMag)) continue;1662 if (!isfinite (source->psfMag)) continue;1661 if (!isfinite (source->apMag)) continue; 1662 if (!isfinite (source->psfMag)) continue; 1663 1663 1664 1664 x->data.F32[n] = source->psfMag; … … 1705 1705 fprintf (stdout, "[c]ontinue? "); 1706 1706 if (!fgets(key, 8, stdin)) { 1707 psWarning("Unable to read option");1707 psWarning("Unable to read option"); 1708 1708 } 1709 1709 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
