Changeset 25852
- Timestamp:
- Oct 15, 2009, 12:10:16 PM (17 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 5 edited
-
psphot.h (modified) (3 diffs)
-
psphotRoughClass.c (modified) (6 diffs)
-
psphotSourceSize.c (modified) (15 diffs)
-
psphotSourceStats.c (modified) (6 diffs)
-
psphotVisual.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphot.h
r25755 r25852 182 182 bool psphotVisualShowFootprints (pmDetections *detections); 183 183 bool psphotVisualShowMoments (psArray *sources); 184 bool psphotVisualPlotMoments (psMetadata *recipe, ps Array *sources);184 bool psphotVisualPlotMoments (psMetadata *recipe, psMetadata *analysis, psArray *sources); 185 185 bool psphotVisualShowRoughClass (psArray *sources); 186 186 bool psphotVisualShowPSFStars (psMetadata *recipe, pmPSF *psf, psArray *sources); … … 193 193 bool psphotVisualShowResidualImage (pmReadout *readout); 194 194 bool psphotVisualPlotApResid (psArray *sources, float mean, float error); 195 bool psphotVisualPlotSourceSize (psMetadata *recipe, ps Array *sources);195 bool psphotVisualPlotSourceSize (psMetadata *recipe, psMetadata *analysis, psArray *sources); 196 196 bool psphotVisualShowPetrosians (psArray *sources); 197 197 … … 212 212 // bool psphotPetrosianVisualProfileRadii (psVector *radius, psVector *flux, psVector *radiusBin, psVector *fluxBin, float peakFlux, float RadiusRef); 213 213 // bool psphotPetrosianVisualEllipticalContour (pmPetrosian *petrosian); 214 // bool psphotPetrosianVisualStats (psVector *radBin, psVector *fluxBin, 215 // psVector *refRadius, psVector *meanSB,216 // psVector *petRatio, psVector *petRatioErr, psVector *fluxSum,217 // float petRadius, float ratioForRadius,218 // float petFlux, float radiusForFlux);214 // bool psphotPetrosianVisualStats (psVector *radBin, psVector *fluxBin, 215 // psVector *refRadius, psVector *meanSB, 216 // psVector *petRatio, psVector *petRatioErr, psVector *fluxSum, 217 // float petRadius, float ratioForRadius, 218 // float petFlux, float radiusForFlux); 219 219 220 220 bool psphotImageQuality (psMetadata *recipe, psArray *sources); -
trunk/psphot/src/psphotRoughClass.c
r25755 r25852 1 1 # include "psphotInternal.h" 2 2 3 # define CHECK_STATUS(S,MSG) { \4 if (!status) {\5 psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \6 return false;\7 } }3 # define CHECK_STATUS(S,MSG) { \ 4 if (!status) { \ 5 psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \ 6 return false; \ 7 } } 8 8 9 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata * recipe, const bool havePSF);9 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *target, psMetadata *recipe, const bool havePSF); 10 10 11 11 // 2006.02.02 : no leaks … … 24 24 int nRegion = 0; 25 25 for (int ix = 0; ix < NX; ix ++) { 26 for (int iy = 0; iy < NY; iy ++) {26 for (int iy = 0; iy < NY; iy ++) { 27 27 28 psRegion *region = psRegionAlloc (ix*dX, (ix + 1)*dX, iy*dY, (iy + 1)*dY);29 if (!psphotRoughClassRegion (nRegion, region, sources, recipe, havePSF)) {30 psLogMsg ("psphot", 4, "Failed to determine rough classification for region %f,%f - %f,%f\n", 31 region->x0, region->y0, region->x1, region->y1);32 psFree (region);33 continue;34 }35 psFree (region);36 nRegion ++;37 }28 psRegion *region = psRegionAlloc (ix*dX, (ix + 1)*dX, iy*dY, (iy + 1)*dY); 29 if (!psphotRoughClassRegion (nRegion, region, sources, readout->analysis, recipe, havePSF)) { 30 psLogMsg ("psphot", 4, "Failed to determine rough classification for region %f,%f - %f,%f\n", 31 region->x0, region->y0, region->x1, region->y1); 32 psFree (region); 33 continue; 34 } 35 psFree (region); 36 nRegion ++; 37 } 38 38 } 39 39 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", nRegion); … … 44 44 psLogMsg ("psphot.roughclass", PS_LOG_INFO, "rough classification: %f sec\n", psTimerMark ("psphot.rough")); 45 45 46 psphotVisualPlotMoments (recipe, sources);46 psphotVisualPlotMoments (recipe, readout->analysis, sources); 47 47 psphotVisualShowRoughClass (sources); 48 48 // XXX better visualization: psphotVisualShowFlags (sources); … … 51 51 } 52 52 53 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata * recipe, const bool havePSF) {53 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *target, psMetadata *recipe, const bool havePSF) { 54 54 55 55 bool status; … … 62 62 63 63 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", nRegion); 64 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);64 psMetadata *regionMD = psMetadataLookupPtr (&status, target, regionName); 65 65 if (!regionMD) { 66 // allocate the region metadata folder and add this region to it.67 regionMD = psMetadataAlloc();68 psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD);69 psFree (regionMD);66 // allocate the region metadata folder and add this region to it. 67 regionMD = psMetadataAlloc(); 68 psMetadataAddMetadata (target, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD); 69 psFree (regionMD); 70 70 } 71 71 psMetadataAddPtr (regionMD, PS_LIST_TAIL, "REGION", PS_DATA_REGION | PS_META_REPLACE, "psf clump region", region); 72 72 73 73 if (!havePSF) { 74 // determine the PSF parameters from the source moment values75 // XXX why not save the psfClump as a PTR?76 psfClump = pmSourcePSFClump (region, sources, recipe);77 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X);78 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y);79 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);80 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);74 // determine the PSF parameters from the source moment values 75 // XXX why not save the psfClump as a PTR? 76 psfClump = pmSourcePSFClump (region, sources, target); 77 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X); 78 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y); 79 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX); 80 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY); 81 81 } else { 82 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y83 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 84 if (!status) {85 psLogMsg ("psphot", 4, "No PSF clump defined for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);86 return false;87 } 88 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); psAssert (status, "missing PSF.CLUMP.Y");89 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); psAssert (status, "missing PSF.CLUMP.DX");90 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); psAssert (status, "missing PSF.CLUMP.DY");82 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y 83 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 84 if (!status) { 85 psLogMsg ("psphot", 4, "No PSF clump defined for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1); 86 return false; 87 } 88 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); psAssert (status, "missing PSF.CLUMP.Y"); 89 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); psAssert (status, "missing PSF.CLUMP.DX"); 90 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); psAssert (status, "missing PSF.CLUMP.DY"); 91 91 } 92 92 93 93 if (psfClump.X < 0) { 94 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourcePSFClump");95 return false;94 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourcePSFClump"); 95 return false; 96 96 } 97 97 if (!psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) { 98 psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);99 return false;98 psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1); 99 return false; 100 100 } 101 101 psLogMsg ("psphot", 3, "psf clump X, Y: %f, %f\n", psfClump.X, psfClump.Y); … … 104 104 // group into STAR, COSMIC, EXTENDED, SATURATED, etc. 105 105 if (!pmSourceRoughClass (region, sources, recipe, psfClump, maskSat)) { 106 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourceRoughClass");107 return false;106 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourceRoughClass"); 107 return false; 108 108 } 109 109 -
trunk/psphot/src/psphotSourceSize.c
r25755 r25852 83 83 psLogMsg ("psphot.size", PS_LOG_INFO, "measure source sizes for %ld sources: %f sec\n", sources->n - first, psTimerMark ("psphot.size")); 84 84 85 psphotVisualPlotSourceSize (recipe, sources);85 psphotVisualPlotSourceSize (recipe, readout->analysis, sources); 86 86 psphotVisualShowSourceSize (readout, sources); 87 87 psphotVisualPlotApResid (sources, options.ApResid, options.ApSysErr); … … 103 103 pmFootprint *footprint = peak->footprint; 104 104 if (!footprint) { 105 // if we have not footprint, use the old code to mask by isophot106 psphotMaskCosmicRayIsophot (source, maskVal, crMask);107 return true;105 // if we have not footprint, use the old code to mask by isophot 106 psphotMaskCosmicRayIsophot (source, maskVal, crMask); 107 return true; 108 108 } 109 109 110 110 if (!footprint->spans) { 111 // if we have no footprint, use the old code to mask by isophot112 psphotMaskCosmicRayIsophot (source, maskVal, crMask);113 return true;111 // if we have no footprint, use the old code to mask by isophot 112 psphotMaskCosmicRayIsophot (source, maskVal, crMask); 113 return true; 114 114 } 115 115 116 116 // mask all of the pixels covered by the spans of the footprint 117 117 for (int j = 1; j < footprint->spans->n; j++) { 118 pmSpan *span1 = footprint->spans->data[j];119 120 int iy = span1->y;121 int xs = span1->x0;122 int xe = span1->x1;123 124 for (int ix = xs; ix < xe; ix++) {125 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;126 }118 pmSpan *span1 = footprint->spans->data[j]; 119 120 int iy = span1->y; 121 int xs = span1->x0; 122 int xe = span1->x1; 123 124 for (int ix = xs; ix < xe; ix++) { 125 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 126 } 127 127 } 128 128 return true; … … 147 147 // mark the pixels in this row to the left, then the right 148 148 for (int ix = xo; ix >= 0; ix--) { 149 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);150 if (SN > SN_LIMIT) {151 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;152 }149 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]); 150 if (SN > SN_LIMIT) { 151 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask; 152 } 153 153 } 154 154 for (int ix = xo + 1; ix < pixels->numCols; ix++) { 155 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]);156 if (SN > SN_LIMIT) {157 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask;158 }155 float SN = pixels->data.F32[yo][ix] / sqrt(variance->data.F32[yo][ix]); 156 if (SN > SN_LIMIT) { 157 mask->data.PS_TYPE_IMAGE_MASK_DATA[yo][ix] |= crMask; 158 } 159 159 } 160 160 … … 162 162 // first go up: 163 163 for (int iy = PS_MIN(yo, mask->numRows-2); iy >= 0; iy--) { 164 // mark the pixels in this row to the left, then the right165 for (int ix = 0; ix < pixels->numCols; ix++) {166 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);167 if (SN < SN_LIMIT) continue;168 169 bool valid = false;170 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask);171 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0;172 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0;173 174 if (!valid) continue;175 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;176 }164 // mark the pixels in this row to the left, then the right 165 for (int ix = 0; ix < pixels->numCols; ix++) { 166 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 167 if (SN < SN_LIMIT) continue; 168 169 bool valid = false; 170 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix] & crMask); 171 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix-1] & crMask) : 0; 172 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+1][ix+1] & crMask) : 0; 173 174 if (!valid) continue; 175 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 176 } 177 177 } 178 178 // next go down: 179 179 for (int iy = PS_MIN(yo+1, mask->numRows-1); iy < pixels->numRows; iy++) { 180 // mark the pixels in this row to the left, then the right181 for (int ix = 0; ix < pixels->numCols; ix++) {182 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);183 if (SN < SN_LIMIT) continue;184 185 bool valid = false;186 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask);187 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0;188 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0;189 190 if (!valid) continue;191 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask;192 }180 // mark the pixels in this row to the left, then the right 181 for (int ix = 0; ix < pixels->numCols; ix++) { 182 float SN = pixels->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 183 if (SN < SN_LIMIT) continue; 184 185 bool valid = false; 186 valid |= (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix] & crMask); 187 valid |= (ix > 0) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix-1] & crMask) : 0; 188 valid |= (ix <= mask->numCols) ? (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy-1][ix+1] & crMask) : 0; 189 190 if (!valid) continue; 191 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] |= crMask; 192 } 193 193 } 194 194 return true; … … 201 201 psVector *Ap = psVectorAllocEmpty (100, PS_TYPE_F32); 202 202 psVector *ApErr = psVectorAllocEmpty (100, PS_TYPE_F32); 203 203 204 204 psImageMaskType maskVal = options->maskVal | options->markVal; 205 205 … … 208 208 209 209 for (int i = 0; i < sources->n; i++) { 210 pmSource *source = sources->data[i];211 if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;210 pmSource *source = sources->data[i]; 211 if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue; 212 212 213 213 // replace object in image … … 216 216 } 217 217 218 // clear the mask bit and set the circular mask pixels219 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));220 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);221 222 // XXX can we test if psfMag is set and calculate only if needed?223 pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal224 225 // clear the mask bit 226 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));218 // clear the mask bit and set the circular mask pixels 219 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 220 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal); 221 222 // XXX can we test if psfMag is set and calculate only if needed? 223 pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal 224 225 // clear the mask bit 226 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 227 227 228 228 // re-subtract the object, leave local sky 229 229 pmSourceSub (source, PM_MODEL_OP_FULL, options->maskVal); 230 230 231 float apMag = -2.5*log10(source->moments->Sum);232 float dMag = source->psfMag - apMag;233 234 psVectorAppend (Ap, 100, dMag);235 psVectorAppend (ApErr, 100, source->errMag);231 float apMag = -2.5*log10(source->moments->Sum); 232 float dMag = source->psfMag - apMag; 233 234 psVectorAppend (Ap, 100, dMag); 235 psVectorAppend (ApErr, 100, source->errMag); 236 236 } 237 237 … … 242 242 psVector *dAp = psVectorAlloc (Ap->n, PS_TYPE_F32); 243 243 for (int i = 0; i < Ap->n; i++) { 244 dAp->data.F32[i] = Ap->data.F32[i] - stats->robustMedian;244 dAp->data.F32[i] = Ap->data.F32[i] - stats->robustMedian; 245 245 } 246 246 … … 266 266 psLogMsg("psModules.objects", PS_LOG_INFO, "Source Size classifications: %4s %4s %4s %4s %4s %4s", "Npsf", "Next", "Nsat", "Ncr", "Nmiss", "Nskip"); 267 267 268 int nRegions = psMetadataLookupS32 (&status, re cipe, "PSF.CLUMP.NREGIONS");268 int nRegions = psMetadataLookupS32 (&status, readout->analysis, "PSF.CLUMP.NREGIONS"); 269 269 for (int i = 0; i < nRegions; i ++) { 270 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i);271 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);272 psAssert (regionMD, "regions must be defined by earlier call to psphotRoughClassRegion");273 274 psRegion *region = psMetadataLookupPtr (&status, regionMD, "REGION");275 psAssert (region, "regions must be defined by earlier call to psphotRoughClassRegion");276 277 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y278 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); psAssert (status, "missing PSF.CLUMP.X");279 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); psAssert (status, "missing PSF.CLUMP.Y");280 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); psAssert (status, "missing PSF.CLUMP.DX");281 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); psAssert (status, "missing PSF.CLUMP.DY");282 283 if ((psfClump.X < 0) || (psfClump.Y < 0) || !psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) {284 psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);285 continue;286 }287 288 if (!psphotSourceClassRegion (region, &psfClump, sources, recipe, psf, options)) {289 psLogMsg ("psphot", 4, "Failed to determine source classification for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1);290 continue;291 }292 } 270 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", i); 271 psMetadata *regionMD = psMetadataLookupPtr (&status, readout->analysis, regionName); 272 psAssert (regionMD, "regions must be defined by earlier call to psphotRoughClassRegion"); 273 274 psRegion *region = psMetadataLookupPtr (&status, regionMD, "REGION"); 275 psAssert (region, "regions must be defined by earlier call to psphotRoughClassRegion"); 276 277 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y 278 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); psAssert (status, "missing PSF.CLUMP.X"); 279 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); psAssert (status, "missing PSF.CLUMP.Y"); 280 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); psAssert (status, "missing PSF.CLUMP.DX"); 281 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); psAssert (status, "missing PSF.CLUMP.DY"); 282 283 if ((psfClump.X < 0) || (psfClump.Y < 0) || !psfClump.X || !psfClump.Y || isnan(psfClump.X) || isnan(psfClump.Y)) { 284 psLogMsg ("psphot", 4, "Failed to find a valid PSF clump for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1); 285 continue; 286 } 287 288 if (!psphotSourceClassRegion (region, &psfClump, sources, recipe, psf, options)) { 289 psLogMsg ("psphot", 4, "Failed to determine source classification for region %f,%f - %f,%f\n", region->x0, region->y0, region->x1, region->y1); 290 continue; 291 } 292 } 293 293 294 294 return true; … … 314 314 for (psS32 i = 0 ; i < sources->n ; i++) { 315 315 316 pmSource *source = (pmSource *) sources->data[i];317 318 // psfClumps are found for image subregions:319 // skip sources not in this region320 if (source->peak->x < region->x0) continue;321 if (source->peak->x >= region->x1) continue;322 if (source->peak->y < region->y0) continue;323 if (source->peak->y >= region->y1) continue;324 325 // skip source if it was already measured326 if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {327 psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");328 continue;329 }330 331 // source must have been subtracted332 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {333 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;334 psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");335 continue;336 }337 338 // we are basically classifying by moments; use the default if not found339 psAssert (source->moments, "why is this source missing moments?");340 if (source->mode & noMoments) { 341 Nskip ++;342 continue;343 }344 345 psF32 Mxx = source->moments->Mxx;346 psF32 Myy = source->moments->Myy;316 pmSource *source = (pmSource *) sources->data[i]; 317 318 // psfClumps are found for image subregions: 319 // skip sources not in this region 320 if (source->peak->x < region->x0) continue; 321 if (source->peak->x >= region->x1) continue; 322 if (source->peak->y < region->y0) continue; 323 if (source->peak->y >= region->y1) continue; 324 325 // skip source if it was already measured 326 if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) { 327 psTrace("psphot", 7, "Not calculating source size since it has already been measured\n"); 328 continue; 329 } 330 331 // source must have been subtracted 332 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) { 333 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED; 334 psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n"); 335 continue; 336 } 337 338 // we are basically classifying by moments; use the default if not found 339 psAssert (source->moments, "why is this source missing moments?"); 340 if (source->mode & noMoments) { 341 Nskip ++; 342 continue; 343 } 344 345 psF32 Mxx = source->moments->Mxx; 346 psF32 Myy = source->moments->Myy; 347 347 348 348 // replace object in image … … 351 351 } 352 352 353 // clear the mask bit and set the circular mask pixels354 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));355 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal);356 357 // XXX can we test if psfMag is set and calculate only if needed?358 pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal359 360 // clear the mask bit 361 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal));353 // clear the mask bit and set the circular mask pixels 354 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 355 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", options->markVal); 356 357 // XXX can we test if psfMag is set and calculate only if needed? 358 pmSourceMagnitudes (source, psf, photMode, maskVal); // maskVal includes markVal 359 360 // clear the mask bit 361 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(options->markVal)); 362 362 363 363 // re-subtract the object, leave local sky 364 364 pmSourceSub (source, PM_MODEL_OP_FULL, options->maskVal); 365 365 366 float apMag = -2.5*log10(source->moments->Sum);367 float dMag = source->psfMag - apMag;368 float nSigma = (dMag - options->ApResid) / hypot(source->errMag, options->ApSysErr);369 370 source->extNsigma = nSigma;371 source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;372 373 // Anything within this region is a probably PSF-like object. Saturated stars may land374 // in this region, but are detected elsewhere on the basis of their peak value.375 bool isPSF = (fabs(nSigma) < options->nSigmaApResid) && (fabs(Mxx - psfClump->X) < options->nSigmaMoments*psfClump->dX) && (fabs(Myy - psfClump->Y) < options->nSigmaMoments*psfClump->dY);376 if (isPSF) {377 Npsf ++;378 continue;379 }380 381 // Defects may not always match CRs from peak curvature analysis382 // Defects may also be marked as SATSTAR -- XXX deactivate this flag?383 // XXX this rule is not great384 if ((Mxx < psfClump->X) || (Myy < psfClump->Y)) {385 source->mode |= PM_SOURCE_MODE_DEFECT;386 Ncr ++;387 continue;388 }389 390 // saturated star (determined in PSF fit). These may also be saturated galaxies, or391 // just large saturated regions.392 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 393 Nsat ++;394 continue;395 }396 397 // XXX allow the Mxx, Myy to be less than psfClump->X,Y (by some nSigma)?398 bool isEXT = (nSigma > options->nSigmaApResid) || ((Mxx > psfClump->X) && (Myy > psfClump->Y));399 if (isEXT) {400 source->mode |= PM_SOURCE_MODE_EXT_LIMIT;401 Next ++;402 continue;403 }404 405 psWarning ("sourse size was missed for %f,%f : %f %f -- %f\n", source->peak->xf, source->peak->yf, Mxx, Myy, nSigma);406 Nmiss ++;366 float apMag = -2.5*log10(source->moments->Sum); 367 float dMag = source->psfMag - apMag; 368 float nSigma = (dMag - options->ApResid) / hypot(source->errMag, options->ApSysErr); 369 370 source->extNsigma = nSigma; 371 source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED; 372 373 // Anything within this region is a probably PSF-like object. Saturated stars may land 374 // in this region, but are detected elsewhere on the basis of their peak value. 375 bool isPSF = (fabs(nSigma) < options->nSigmaApResid) && (fabs(Mxx - psfClump->X) < options->nSigmaMoments*psfClump->dX) && (fabs(Myy - psfClump->Y) < options->nSigmaMoments*psfClump->dY); 376 if (isPSF) { 377 Npsf ++; 378 continue; 379 } 380 381 // Defects may not always match CRs from peak curvature analysis 382 // Defects may also be marked as SATSTAR -- XXX deactivate this flag? 383 // XXX this rule is not great 384 if ((Mxx < psfClump->X) || (Myy < psfClump->Y)) { 385 source->mode |= PM_SOURCE_MODE_DEFECT; 386 Ncr ++; 387 continue; 388 } 389 390 // saturated star (determined in PSF fit). These may also be saturated galaxies, or 391 // just large saturated regions. 392 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 393 Nsat ++; 394 continue; 395 } 396 397 // XXX allow the Mxx, Myy to be less than psfClump->X,Y (by some nSigma)? 398 bool isEXT = (nSigma > options->nSigmaApResid) || ((Mxx > psfClump->X) && (Myy > psfClump->Y)); 399 if (isEXT) { 400 source->mode |= PM_SOURCE_MODE_EXT_LIMIT; 401 Next ++; 402 continue; 403 } 404 405 psWarning ("sourse size was missed for %f,%f : %f %f -- %f\n", source->peak->xf, source->peak->yf, Mxx, Myy, nSigma); 406 Nmiss ++; 407 407 } 408 408 … … 417 417 // no longer used by psphot. 418 418 float psphotModelContour(const psImage *image, const psImage *variance, const psImage *mask, 419 psImageMaskType maskVal, const pmModel *model, float Ro)419 psImageMaskType maskVal, const pmModel *model, float Ro) 420 420 { 421 421 psF32 *PAR = model->params->data.F32; // Model parameters … … 432 432 float Q = Ro * PS_SQR(sxx) / (1.0 - PS_SQR(sxx * syy * sxy) / 4.0); 433 433 if (Q < 0.0) { 434 // ellipse is imaginary435 return NAN;434 // ellipse is imaginary 435 return NAN; 436 436 } 437 437 … … 441 441 442 442 for (int x = -radius; x <= radius; x++) { 443 // Polynomial coefficients444 // XXX Should we be using the centre of the pixel as x or x+0.5?445 float A = PS_SQR (1.0 / syy);446 float B = x * sxy;447 float C = PS_SQR (x / sxx) - Ro;448 float T = PS_SQR(B) - 4*A*C;449 if (T < 0.0) {450 continue;451 }452 453 // y position in source frame454 float yP = (-B + sqrt (T)) / (2.0 * A);455 float yM = (-B - sqrt (T)) / (2.0 * A);456 457 // Get the closest pixel positions (image frame)458 int xPix = x + PAR[PM_PAR_XPOS] - image->col0 + 0.5;459 int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5;460 int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5;461 462 if (xPix < 0 || xPix >= image->numCols) {463 continue;464 }465 466 if (yPixM >= 0 && yPixM < image->numRows &&467 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) {468 float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]);469 nSigma += dSigma;470 nPts++;471 }472 473 if (yPixM == yPixP) {474 continue;475 }476 477 if (yPixP >= 0 && yPixP < image->numRows &&478 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) {479 float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]);480 nSigma += dSigma;481 nPts++;482 }443 // Polynomial coefficients 444 // XXX Should we be using the centre of the pixel as x or x+0.5? 445 float A = PS_SQR (1.0 / syy); 446 float B = x * sxy; 447 float C = PS_SQR (x / sxx) - Ro; 448 float T = PS_SQR(B) - 4*A*C; 449 if (T < 0.0) { 450 continue; 451 } 452 453 // y position in source frame 454 float yP = (-B + sqrt (T)) / (2.0 * A); 455 float yM = (-B - sqrt (T)) / (2.0 * A); 456 457 // Get the closest pixel positions (image frame) 458 int xPix = x + PAR[PM_PAR_XPOS] - image->col0 + 0.5; 459 int yPixM = yM + PAR[PM_PAR_YPOS] - image->row0 + 0.5; 460 int yPixP = yP + PAR[PM_PAR_YPOS] - image->row0 + 0.5; 461 462 if (xPix < 0 || xPix >= image->numCols) { 463 continue; 464 } 465 466 if (yPixM >= 0 && yPixM < image->numRows && 467 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixM][xPix] & maskVal))) { 468 float dSigma = image->data.F32[yPixM][xPix] / sqrtf(variance->data.F32[yPixM][xPix]); 469 nSigma += dSigma; 470 nPts++; 471 } 472 473 if (yPixM == yPixP) { 474 continue; 475 } 476 477 if (yPixP >= 0 && yPixP < image->numRows && 478 !(mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPixP][xPix] & maskVal))) { 479 float dSigma = image->data.F32[yPixP][xPix] / sqrtf(variance->data.F32[yPixP][xPix]); 480 nSigma += dSigma; 481 nPts++; 482 } 483 483 } 484 484 nSigma /= nPts; … … 491 491 // XXX use an internal flag to mark sources which have already been measured 492 492 for (int i = 0; i < sources->n; i++) { 493 pmSource *source = sources->data[i];494 495 // skip source if it was already measured496 if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) {497 psTrace("psphot", 7, "Not calculating source size since it has already been measured\n");498 continue;499 }500 501 // source must have been subtracted502 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) {503 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED;504 psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n");505 continue;506 }507 508 psF32 **resid = source->pixels->data.F32;509 psF32 **variance = source->variance->data.F32;510 psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;511 512 // Integer position of peak513 int xPeak = source->peak->xf - source->pixels->col0 + 0.5;514 int yPeak = source->peak->yf - source->pixels->row0 + 0.5;515 516 // Skip sources which are too close to a boundary. These are mostly caught as DEFECT517 if (xPeak < 1 || xPeak > source->pixels->numCols - 2 ||518 yPeak < 1 || yPeak > source->pixels->numRows - 2) {519 psTrace("psphot", 7, "Not calculating crNsigma due to edge\n");520 continue;521 }522 523 // Skip sources with masked pixels. These are mostly caught as DEFECT524 bool keep = true;525 for (int iy = -1; (iy <= +1) && keep; iy++) {526 for (int ix = -1; (ix <= +1) && keep; ix++) {527 if (mask[yPeak+iy][xPeak+ix] & options->maskVal) {528 keep = false;529 }530 }531 }532 if (!keep) {533 psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n");534 continue;535 }536 537 // Compare the central pixel with those on either side, for the four possible lines through it.538 539 // Soften variances (add systematic error)540 float softening = options->soft * PS_SQR(source->peak->flux); // Softening for variances541 542 // Across the middle: y = 0543 float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1];544 float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1];545 float nX = cX / sqrtf(dcX + softening);546 547 // Up the centre: x = 0548 float cY = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak+0] - resid[yPeak+1][xPeak+0];549 float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0];550 float nY = cY / sqrtf(dcY + softening);551 552 // Diagonal: x = y553 float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1];554 float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1];555 float nL = cL / sqrtf(dcL + softening);556 557 // Diagonal: x = - y558 float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1];559 float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1];560 float nR = cR / sqrtf(dcR + softening);561 562 // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2)563 // Ndof = 4 ? (four measurements, no free parameters)564 // XXX this value is going to be biased low because of systematic errors.565 // we need to calibrate it somehow566 // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq);567 568 // not strictly accurate: overcounts the chisq contribution from the center pixel (by569 // factor of 4); also biases a bit low if any pixels are masked570 // XXX I am not sure I want to keep this value...571 source->psfChisq = PS_SQR(nX) + PS_SQR(nY) + PS_SQR(nL) + PS_SQR(nR);572 573 float fCR = 0.0;574 int nCR = 0;575 if (nX > 0.0) {576 fCR += nX;577 nCR ++;578 }579 if (nY > 0.0) {580 fCR += nY;581 nCR ++;582 }583 if (nL > 0.0) {584 fCR += nL;585 nCR ++;586 }587 if (nR > 0.0) {588 fCR += nR;589 nCR ++;590 }591 source->crNsigma = (nCR > 0) ? fCR / nCR : 0.0;592 source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED;593 594 if (!isfinite(source->crNsigma)) {595 continue;596 }597 598 // this source is thought to be a cosmic ray. flag the detection and mask the pixels599 if (source->crNsigma > options->nSigmaCR) {600 source->mode |= PM_SOURCE_MODE_CR_LIMIT;601 // XXX still testing... : psphotMaskCosmicRay (readout->mask, source, maskVal, crMask);602 // XXX acting strange... psphotMaskCosmicRay_Old (source, maskVal, crMask);603 }493 pmSource *source = sources->data[i]; 494 495 // skip source if it was already measured 496 if (source->tmpFlags & PM_SOURCE_TMPF_SIZE_MEASURED) { 497 psTrace("psphot", 7, "Not calculating source size since it has already been measured\n"); 498 continue; 499 } 500 501 // source must have been subtracted 502 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) { 503 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED; 504 psTrace("psphot", 7, "Not calculating source size since source is not subtracted\n"); 505 continue; 506 } 507 508 psF32 **resid = source->pixels->data.F32; 509 psF32 **variance = source->variance->data.F32; 510 psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA; 511 512 // Integer position of peak 513 int xPeak = source->peak->xf - source->pixels->col0 + 0.5; 514 int yPeak = source->peak->yf - source->pixels->row0 + 0.5; 515 516 // Skip sources which are too close to a boundary. These are mostly caught as DEFECT 517 if (xPeak < 1 || xPeak > source->pixels->numCols - 2 || 518 yPeak < 1 || yPeak > source->pixels->numRows - 2) { 519 psTrace("psphot", 7, "Not calculating crNsigma due to edge\n"); 520 continue; 521 } 522 523 // Skip sources with masked pixels. These are mostly caught as DEFECT 524 bool keep = true; 525 for (int iy = -1; (iy <= +1) && keep; iy++) { 526 for (int ix = -1; (ix <= +1) && keep; ix++) { 527 if (mask[yPeak+iy][xPeak+ix] & options->maskVal) { 528 keep = false; 529 } 530 } 531 } 532 if (!keep) { 533 psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n"); 534 continue; 535 } 536 537 // Compare the central pixel with those on either side, for the four possible lines through it. 538 539 // Soften variances (add systematic error) 540 float softening = options->soft * PS_SQR(source->peak->flux); // Softening for variances 541 542 // Across the middle: y = 0 543 float cX = 2*resid[yPeak][xPeak] - resid[yPeak+0][xPeak-1] - resid[yPeak+0][xPeak+1]; 544 float dcX = 4*variance[yPeak][xPeak] + variance[yPeak+0][xPeak-1] + variance[yPeak+0][xPeak+1]; 545 float nX = cX / sqrtf(dcX + softening); 546 547 // Up the centre: x = 0 548 float cY = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak+0] - resid[yPeak+1][xPeak+0]; 549 float dcY = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak+0] + variance[yPeak+1][xPeak+0]; 550 float nY = cY / sqrtf(dcY + softening); 551 552 // Diagonal: x = y 553 float cL = 2*resid[yPeak][xPeak] - resid[yPeak-1][xPeak-1] - resid[yPeak+1][xPeak+1]; 554 float dcL = 4*variance[yPeak][xPeak] + variance[yPeak-1][xPeak-1] + variance[yPeak+1][xPeak+1]; 555 float nL = cL / sqrtf(dcL + softening); 556 557 // Diagonal: x = - y 558 float cR = 2*resid[yPeak][xPeak] - resid[yPeak+1][xPeak-1] - resid[yPeak-1][xPeak+1]; 559 float dcR = 4*variance[yPeak][xPeak] + variance[yPeak+1][xPeak-1] + variance[yPeak-1][xPeak+1]; 560 float nR = cR / sqrtf(dcR + softening); 561 562 // P(chisq > chisq_obs; Ndof) = gamma_Q (Ndof/2, chisq/2) 563 // Ndof = 4 ? (four measurements, no free parameters) 564 // XXX this value is going to be biased low because of systematic errors. 565 // we need to calibrate it somehow 566 // source->psfProb = gsl_sf_gamma_inc_Q (2, 0.5*chisq); 567 568 // not strictly accurate: overcounts the chisq contribution from the center pixel (by 569 // factor of 4); also biases a bit low if any pixels are masked 570 // XXX I am not sure I want to keep this value... 571 source->psfChisq = PS_SQR(nX) + PS_SQR(nY) + PS_SQR(nL) + PS_SQR(nR); 572 573 float fCR = 0.0; 574 int nCR = 0; 575 if (nX > 0.0) { 576 fCR += nX; 577 nCR ++; 578 } 579 if (nY > 0.0) { 580 fCR += nY; 581 nCR ++; 582 } 583 if (nL > 0.0) { 584 fCR += nL; 585 nCR ++; 586 } 587 if (nR > 0.0) { 588 fCR += nR; 589 nCR ++; 590 } 591 source->crNsigma = (nCR > 0) ? fCR / nCR : 0.0; 592 source->tmpFlags |= PM_SOURCE_TMPF_SIZE_MEASURED; 593 594 if (!isfinite(source->crNsigma)) { 595 continue; 596 } 597 598 // this source is thought to be a cosmic ray. flag the detection and mask the pixels 599 if (source->crNsigma > options->nSigmaCR) { 600 source->mode |= PM_SOURCE_MODE_CR_LIMIT; 601 // XXX still testing... : psphotMaskCosmicRay (readout->mask, source, maskVal, crMask); 602 // XXX acting strange... psphotMaskCosmicRay_Old (source, maskVal, crMask); 603 } 604 604 } 605 605 606 606 // now that we have masked pixels associated with CRs, we can grow the mask 607 607 if (options->grow > 0) { 608 bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolveMask609 psImage *newMask = psImageConvolveMask(NULL, readout->mask, options->crMask, options->crMask, -options->grow, options->grow, -options->grow, options->grow);610 psImageConvolveSetThreads(oldThreads);611 if (!newMask) {612 psError(PS_ERR_UNKNOWN, false, "Unable to grow CR mask");613 return false;614 }615 psFree(readout->mask);616 readout->mask = newMask;608 bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolveMask 609 psImage *newMask = psImageConvolveMask(NULL, readout->mask, options->crMask, options->crMask, -options->grow, options->grow, -options->grow, options->grow); 610 psImageConvolveSetThreads(oldThreads); 611 if (!newMask) { 612 psError(PS_ERR_UNKNOWN, false, "Unable to grow CR mask"); 613 return false; 614 } 615 psFree(readout->mask); 616 readout->mask = newMask; 617 617 } 618 618 return true; -
trunk/psphot/src/psphotSourceStats.c
r25755 r25852 1 1 # include "psphotInternal.h" 2 2 3 bool psphotSetMomentsWindow (psMetadata *recipe, ps Array *sources);3 bool psphotSetMomentsWindow (psMetadata *recipe, psMetadata *analysis, psArray *sources); 4 4 5 5 psArray *psphotSourceStats (pmConfig *config, pmReadout *readout, pmDetections *detections, bool setWindow) { … … 68 68 69 69 if (setWindow) { 70 if (!psphotSetMomentsWindow(recipe, sources)) {71 psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!");72 return NULL;73 }70 if (!psphotSetMomentsWindow(recipe, readout->analysis, sources)) { 71 psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!"); 72 return NULL; 73 } 74 74 } 75 75 … … 242 242 243 243 // this function attempts to iteratively determine the best value for sigma of the moments weighting Gaussian 244 bool psphotSetMomentsWindow (psMetadata *recipe, ps Array *sources) {244 bool psphotSetMomentsWindow (psMetadata *recipe, psMetadata *analysis, psArray *sources) { 245 245 246 246 bool status; … … 259 259 for (int i = 0; i < 4; i++) { 260 260 261 // XXX move max source number to config262 for (int j = 0; (j < sources->n) && (j < 400); j++) {263 264 pmSource *source = sources->data[j];265 psAssert (source->moments, "force moments to exist");266 source->moments->nPixels = 0;267 268 // skip faint sources for moments measurement269 if (source->peak->SN < MIN_SN) {270 continue;271 }272 273 // measure basic source moments (no S/N clipping on input pixels)274 status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0);275 }276 277 // choose a grid scale that is a fixed fraction of the psf sigma^2278 psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(sigma[i]));279 psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SX_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));280 psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SY_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i]));281 282 // determine the PSF parameters from the source moment values283 pmPSFClump psfClump = pmSourcePSFClump (NULL, sources, recipe);284 psLogMsg ("psphot", 3, "radius %.1f, nStars: %d, nSigma: %5.2f, X, Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]);285 286 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", 1);287 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, "PSF.CLUMP.REGION.000");288 if (!regionMD) {289 regionMD = psMetadataAlloc();290 psMetadataAddMetadata (recipe, PS_LIST_TAIL, "PSF.CLUMP.REGION.000", PS_META_REPLACE, "psf clump region", regionMD);291 psFree (regionMD);292 }293 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X);294 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y);295 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);296 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);297 298 // psphotVisualPlotMoments (recipe, sources);299 300 Sout[i] = sqrt(0.5*(psfClump.X + psfClump.Y)) / sigma[i];261 // XXX move max source number to config 262 for (int j = 0; (j < sources->n) && (j < 400); j++) { 263 264 pmSource *source = sources->data[j]; 265 psAssert (source->moments, "force moments to exist"); 266 source->moments->nPixels = 0; 267 268 // skip faint sources for moments measurement 269 if (source->peak->SN < MIN_SN) { 270 continue; 271 } 272 273 // measure basic source moments (no S/N clipping on input pixels) 274 status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0); 275 } 276 277 // choose a grid scale that is a fixed fraction of the psf sigma^2 278 psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(sigma[i])); 279 psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SX_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i])); 280 psMetadataAddF32(recipe, PS_LIST_TAIL, "MOMENTS_SY_MAX", PS_META_REPLACE, "moments limit", 2.0*PS_SQR(sigma[i])); 281 282 // determine the PSF parameters from the source moment values 283 pmPSFClump psfClump = pmSourcePSFClump (NULL, sources, recipe); 284 psLogMsg ("psphot", 3, "radius %.1f, nStars: %d, nSigma: %5.2f, X, Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]); 285 286 psMetadataAddS32 (analysis, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", 1); 287 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, "PSF.CLUMP.REGION.000"); 288 if (!regionMD) { 289 regionMD = psMetadataAlloc(); 290 psMetadataAddMetadata (analysis, PS_LIST_TAIL, "PSF.CLUMP.REGION.000", PS_META_REPLACE, "psf clump region", regionMD); 291 psFree (regionMD); 292 } 293 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X); 294 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y); 295 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX); 296 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY); 297 298 // psphotVisualPlotMoments (recipe, sources); 299 300 Sout[i] = sqrt(0.5*(psfClump.X + psfClump.Y)) / sigma[i]; 301 301 } 302 302 … … 307 307 float maxS = Sout[0]; 308 308 for (int i = 0; i < 4; i++) { 309 minS = PS_MIN(Sout[i], minS);310 maxS = PS_MAX(Sout[i], maxS);309 minS = PS_MIN(Sout[i], minS); 310 maxS = PS_MAX(Sout[i], maxS); 311 311 } 312 312 if (minS > 0.65) Sigma = sigma[3]; … … 314 314 315 315 for (int i = 0; i < 3; i++) { 316 if ((Sout[i] > 0.65) && (Sout[i+1] > 0.65)) continue;317 if ((Sout[i] < 0.65) && (Sout[i+1] < 0.65)) continue;318 Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]);316 if ((Sout[i] > 0.65) && (Sout[i+1] > 0.65)) continue; 317 if ((Sout[i] < 0.65) && (Sout[i+1] < 0.65)) continue; 318 Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]); 319 319 } 320 320 psAssert (isfinite(Sigma), "did we miss a case?"); 321 321 322 322 // choose a grid scale that is a fixed fraction of the psf sigma^2 323 323 psMetadataAddF32(recipe, PS_LIST_TAIL, "PSF_CLUMP_GRID_SCALE", PS_META_REPLACE, "clump grid", 0.1*PS_SQR(Sigma)); -
trunk/psphot/src/psphotVisual.c
r25755 r25852 28 28 switch (channel) { 29 29 case 1: 30 if (kapa1 == -1) {31 kapa1 = KapaOpenNamedSocket ("kapa", "psphot:images");32 if (kapa1 == -1) {33 fprintf (stderr, "failure to open kapa; visual mode disabled\n");34 pmVisualSetVisual(false);35 }36 }37 return kapa1;30 if (kapa1 == -1) { 31 kapa1 = KapaOpenNamedSocket ("kapa", "psphot:images"); 32 if (kapa1 == -1) { 33 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 34 pmVisualSetVisual(false); 35 } 36 } 37 return kapa1; 38 38 case 2: 39 if (kapa2 == -1) {40 kapa2 = KapaOpenNamedSocket ("kapa", "psphot:plots");41 if (kapa2 == -1) {42 fprintf (stderr, "failure to open kapa; visual mode disabled\n");43 pmVisualSetVisual(false);44 }45 }46 return kapa2;39 if (kapa2 == -1) { 40 kapa2 = KapaOpenNamedSocket ("kapa", "psphot:plots"); 41 if (kapa2 == -1) { 42 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 43 pmVisualSetVisual(false); 44 } 45 } 46 return kapa2; 47 47 case 3: 48 if (kapa3 == -1) {49 kapa3 = KapaOpenNamedSocket ("kapa", "psphot:stamps");50 if (kapa3 == -1) {51 fprintf (stderr, "failure to open kapa; visual mode disabled\n");52 pmVisualSetVisual(false);53 }54 }55 return kapa3;48 if (kapa3 == -1) { 49 kapa3 = KapaOpenNamedSocket ("kapa", "psphot:stamps"); 50 if (kapa3 == -1) { 51 fprintf (stderr, "failure to open kapa; visual mode disabled\n"); 52 pmVisualSetVisual(false); 53 } 54 } 55 return kapa3; 56 56 default: 57 psAbort ("unknown kapa channel");57 psAbort ("unknown kapa channel"); 58 58 } 59 59 psAbort ("unknown kapa channel"); … … 315 315 316 316 // draw the top 317 // XXX need to allow top (and bottom) to have more than one span317 // XXX need to allow top (and bottom) to have more than one span 318 318 span = footprint->spans->data[0]; 319 319 overlay[Noverlay].type = KII_OVERLAY_LINE; … … 448 448 } 449 449 450 bool psphotVisualPlotMoments (psMetadata *recipe, ps Array *sources) {450 bool psphotVisualPlotMoments (psMetadata *recipe, psMetadata *analysis, psArray *sources) { 451 451 452 452 bool status; … … 469 469 float Ymin = 1000.0, Ymax = 0.0; 470 470 { 471 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");471 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 472 472 for (int n = 0; n < nRegions; n++) { 473 473 474 474 char regionName[64]; 475 475 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 476 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);477 478 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");476 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 477 478 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 479 479 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 480 480 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 481 481 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 482 482 483 float X0 = psfX - 4.0*psfdX;484 float X1 = psfX + 4.0*psfdX;485 float Y0 = psfY - 4.0*psfdY;486 float Y1 = psfY + 4.0*psfdY;487 488 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }489 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }490 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }491 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }492 } 493 } 494 Xmin = PS_MAX(Xmin, -0.1); 495 Ymin = PS_MAX(Ymin, -0.1); 483 float X0 = psfX - 4.0*psfdX; 484 float X1 = psfX + 4.0*psfdX; 485 float Y0 = psfY - 4.0*psfdY; 486 float Y1 = psfY + 4.0*psfdY; 487 488 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); } 489 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); } 490 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); } 491 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); } 492 } 493 } 494 Xmin = PS_MAX(Xmin, -0.1); 495 Ymin = PS_MAX(Ymin, -0.1); 496 496 497 497 // storage vectors for data to be plotted … … 653 653 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32); 654 654 655 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");656 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");655 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 656 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, analysis, "PSF_CLUMP_NSIGMA"); 657 657 658 658 graphdata.color = KapaColorByName ("blue"); 659 659 graphdata.style = 0; 660 660 661 graphdata.xmin = Xmin;662 graphdata.ymin = Ymin;663 graphdata.xmax = Xmax;664 graphdata.ymax = Ymax;665 KapaSetLimits (myKapa, &graphdata);661 graphdata.xmin = Xmin; 662 graphdata.ymin = Ymin; 663 graphdata.xmax = Xmax; 664 graphdata.ymax = Ymax; 665 KapaSetLimits (myKapa, &graphdata); 666 666 667 667 for (int n = 0; n < nRegions; n++) { … … 669 669 char regionName[64]; 670 670 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 671 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);671 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 672 672 673 673 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); … … 926 926 if (Xo == 0) { 927 927 // place source alone on this row 928 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);929 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);928 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 929 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 930 930 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 931 931 932 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);932 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 933 933 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 934 934 935 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);935 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 936 936 937 937 Yo += DY; … … 943 943 Xo = 0; 944 944 945 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);946 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);945 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 946 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 947 947 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 948 948 949 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);949 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 950 950 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 951 951 952 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);952 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 953 953 954 954 Xo = DX; … … 957 957 } else { 958 958 // extend this row 959 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);960 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);959 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 960 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 961 961 psphotMosaicSubimage (outpos, source, Xo, Yo, DX, DY, true); 962 962 963 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);963 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 964 964 psphotMosaicSubimage (outsub, source, Xo, Yo, DX, DY, true); 965 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);965 if (!subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 966 966 967 967 Xo += DX; … … 1020 1020 pmSource *source = sources->data[i]; 1021 1021 1022 // only show "real" saturated stars (not defects)1022 // only show "real" saturated stars (not defects) 1023 1023 if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;; 1024 1024 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;; … … 1065 1065 pmSource *source = sources->data[i]; 1066 1066 1067 // only show "real" saturated stars (not defects)1067 // only show "real" saturated stars (not defects) 1068 1068 if (!(source->mode & PM_SOURCE_MODE_SATSTAR)) continue;; 1069 1069 if (source->mode & PM_SOURCE_MODE_DEFECT) continue;; 1070 nSAT ++;1070 nSAT ++; 1071 1071 1072 1072 if (Xo + DX > NX) { … … 1074 1074 if (Xo == 0) { 1075 1075 // place source alone on this row 1076 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);1077 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);1076 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1077 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 1078 1078 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1079 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);1079 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 1080 1080 1081 1081 Yo += DY; … … 1087 1087 Xo = 0; 1088 1088 1089 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);1090 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);1089 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1090 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 1091 1091 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1092 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);1092 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 1093 1093 1094 1094 Xo = DX; … … 1097 1097 } else { 1098 1098 // extend this row 1099 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED);1100 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);1099 bool subtracted = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1100 if (subtracted) pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 1101 1101 psphotMosaicSubimage (outsat, source, Xo, Yo, DX, DY, false); 1102 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);1102 if (subtracted) pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 1103 1103 1104 1104 Xo += DX; … … 1406 1406 1407 1407 // if (source->type != type) continue; 1408 if (mode) {1409 if (keep) {1410 if (!(source->mode & mode)) continue;1411 } else {1412 if (source->mode & mode) continue;1413 }1414 }1408 if (mode) { 1409 if (keep) { 1410 if (!(source->mode & mode)) continue; 1411 } else { 1412 if (source->mode & mode) continue; 1413 } 1414 } 1415 1415 1416 1416 pmMoments *moments = source->moments; … … 1463 1463 } 1464 1464 1465 bool psphotVisualPlotSourceSize (psMetadata *recipe, ps Array *sources) {1465 bool psphotVisualPlotSourceSize (psMetadata *recipe, psMetadata *analysis, psArray *sources) { 1466 1466 1467 1467 bool status; … … 1482 1482 float Ymin = 1000.0, Ymax = 0.0; 1483 1483 { 1484 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");1484 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 1485 1485 for (int n = 0; n < nRegions; n++) { 1486 1486 1487 1487 char regionName[64]; 1488 1488 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 1489 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);1490 1491 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X");1489 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 1490 1491 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); 1492 1492 float psfY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); 1493 1493 float psfdX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); 1494 1494 float psfdY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); 1495 1495 1496 float X0 = psfX - 10.0*psfdX;1497 float X1 = psfX + 10.0*psfdX;1498 float Y0 = psfY - 10.0*psfdY;1499 float Y1 = psfY + 10.0*psfdY;1500 1501 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); }1502 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); }1503 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); }1504 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); }1505 } 1506 } 1507 Xmin = PS_MAX(Xmin, -0.1); 1508 Ymin = PS_MAX(Ymin, -0.1); 1496 float X0 = psfX - 10.0*psfdX; 1497 float X1 = psfX + 10.0*psfdX; 1498 float Y0 = psfY - 10.0*psfdY; 1499 float Y1 = psfY + 10.0*psfdY; 1500 1501 if (isfinite(X0)) { Xmin = PS_MIN(Xmin, X0); } 1502 if (isfinite(X1)) { Xmax = PS_MAX(Xmax, X1); } 1503 if (isfinite(Y0)) { Ymin = PS_MIN(Ymin, Y0); } 1504 if (isfinite(Y1)) { Ymax = PS_MAX(Ymax, Y1); } 1505 } 1506 } 1507 Xmin = PS_MAX(Xmin, -0.1); 1508 Ymin = PS_MAX(Ymin, -0.1); 1509 1509 1510 1510 // storage vectors for data to be plotted … … 1544 1544 if (source->moments == NULL) continue; 1545 1545 1546 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) { 1547 xCR->data.F32[nCR] = source->moments->Mxx;1548 yCR->data.F32[nCR] = source->moments->Myy;1549 mCR->data.F32[nCR] = -2.5*log10(source->moments->Sum);1550 sCR->data.F32[nCR] = source->extNsigma;1551 nCR++;1552 }1553 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 1554 xSAT->data.F32[nSAT] = source->moments->Mxx;1555 ySAT->data.F32[nSAT] = source->moments->Myy;1556 mSAT->data.F32[nSAT] = -2.5*log10(source->moments->Sum);1557 sSAT->data.F32[nSAT] = source->extNsigma;1558 nSAT++;1559 }1560 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 1561 xEXT->data.F32[nEXT] = source->moments->Mxx;1562 yEXT->data.F32[nEXT] = source->moments->Myy;1563 mEXT->data.F32[nEXT] = -2.5*log10(source->moments->Sum);1564 sEXT->data.F32[nEXT] = source->extNsigma;1565 nEXT++;1566 continue;1567 }1568 if (source->mode & PM_SOURCE_MODE_DEFECT) { 1569 xDEF->data.F32[nDEF] = source->moments->Mxx;1570 yDEF->data.F32[nDEF] = source->moments->Myy;1571 mDEF->data.F32[nDEF] = -2.5*log10(source->moments->Sum);1572 sDEF->data.F32[nDEF] = source->extNsigma;1573 nDEF++;1574 continue;1575 }1576 if ((source->mode & PM_SOURCE_MODE_CR_LIMIT) || (source->mode & PM_SOURCE_MODE_SATSTAR)) {1577 continue;1578 }1579 xPSF->data.F32[nPSF] = source->moments->Mxx;1580 yPSF->data.F32[nPSF] = source->moments->Myy;1581 mPSF->data.F32[nPSF] = -2.5*log10(source->moments->Sum);1582 sPSF->data.F32[nPSF] = source->extNsigma;1583 nPSF++;1546 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) { 1547 xCR->data.F32[nCR] = source->moments->Mxx; 1548 yCR->data.F32[nCR] = source->moments->Myy; 1549 mCR->data.F32[nCR] = -2.5*log10(source->moments->Sum); 1550 sCR->data.F32[nCR] = source->extNsigma; 1551 nCR++; 1552 } 1553 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 1554 xSAT->data.F32[nSAT] = source->moments->Mxx; 1555 ySAT->data.F32[nSAT] = source->moments->Myy; 1556 mSAT->data.F32[nSAT] = -2.5*log10(source->moments->Sum); 1557 sSAT->data.F32[nSAT] = source->extNsigma; 1558 nSAT++; 1559 } 1560 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 1561 xEXT->data.F32[nEXT] = source->moments->Mxx; 1562 yEXT->data.F32[nEXT] = source->moments->Myy; 1563 mEXT->data.F32[nEXT] = -2.5*log10(source->moments->Sum); 1564 sEXT->data.F32[nEXT] = source->extNsigma; 1565 nEXT++; 1566 continue; 1567 } 1568 if (source->mode & PM_SOURCE_MODE_DEFECT) { 1569 xDEF->data.F32[nDEF] = source->moments->Mxx; 1570 yDEF->data.F32[nDEF] = source->moments->Myy; 1571 mDEF->data.F32[nDEF] = -2.5*log10(source->moments->Sum); 1572 sDEF->data.F32[nDEF] = source->extNsigma; 1573 nDEF++; 1574 continue; 1575 } 1576 if ((source->mode & PM_SOURCE_MODE_CR_LIMIT) || (source->mode & PM_SOURCE_MODE_SATSTAR)) { 1577 continue; 1578 } 1579 xPSF->data.F32[nPSF] = source->moments->Mxx; 1580 yPSF->data.F32[nPSF] = source->moments->Myy; 1581 mPSF->data.F32[nPSF] = -2.5*log10(source->moments->Sum); 1582 sPSF->data.F32[nPSF] = source->extNsigma; 1583 nPSF++; 1584 1584 } 1585 1585 xSAT->n = nSAT; … … 1861 1861 psVector *yLimit = psVectorAlloc (120, PS_TYPE_F32); 1862 1862 1863 int nRegions = psMetadataLookupS32 (&status, recipe, "PSF.CLUMP.NREGIONS");1864 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, recipe, "PSF_CLUMP_NSIGMA");1863 int nRegions = psMetadataLookupS32 (&status, analysis, "PSF.CLUMP.NREGIONS"); 1864 float PSF_CLUMP_NSIGMA = psMetadataLookupF32 (&status, analysis, "PSF_CLUMP_NSIGMA"); 1865 1865 1866 1866 graphdata.color = KapaColorByName ("blue"); 1867 1867 graphdata.style = 0; 1868 1868 1869 graphdata.xmin = Xmin;1870 graphdata.ymin = Ymin;1871 graphdata.xmax = Xmax;1872 graphdata.ymax = Ymax;1873 KapaSetLimits (myKapa, &graphdata);1869 graphdata.xmin = Xmin; 1870 graphdata.ymin = Ymin; 1871 graphdata.xmax = Xmax; 1872 graphdata.ymax = Ymax; 1873 KapaSetLimits (myKapa, &graphdata); 1874 1874 1875 1875 for (int n = 0; n < nRegions; n++) { … … 1877 1877 char regionName[64]; 1878 1878 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", n); 1879 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName);1879 psMetadata *regionMD = psMetadataLookupPtr (&status, analysis, regionName); 1880 1880 1881 1881 float psfX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); … … 2069 2069 2070 2070 for (int i = 0; i < sources->n; i++) { 2071 pmSource *source = sources->data[i];2072 2073 if (!source) continue;2074 if (!source->extpars) continue;2075 if (!source->extpars->profile) continue;2076 if (!source->extpars->petrosian_80) continue;2077 2078 pmSourceRadialProfile *profile = source->extpars->profile;2079 pmSourceExtendedFlux *petrosian = source->extpars->petrosian_80;2080 2081 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;2082 overlay[Noverlay].x = source->peak->xf;2083 overlay[Noverlay].y = source->peak->yf;2084 overlay[Noverlay].dx = 2.0*petrosian->radius;2085 overlay[Noverlay].dy = 2.0*petrosian->radius*profile->axes.minor/profile->axes.major;2086 overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD;2087 overlay[Noverlay].text = NULL;2088 Noverlay ++;2071 pmSource *source = sources->data[i]; 2072 2073 if (!source) continue; 2074 if (!source->extpars) continue; 2075 if (!source->extpars->profile) continue; 2076 if (!source->extpars->petrosian_80) continue; 2077 2078 pmSourceRadialProfile *profile = source->extpars->profile; 2079 pmSourceExtendedFlux *petrosian = source->extpars->petrosian_80; 2080 2081 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 2082 overlay[Noverlay].x = source->peak->xf; 2083 overlay[Noverlay].y = source->peak->yf; 2084 overlay[Noverlay].dx = 2.0*petrosian->radius; 2085 overlay[Noverlay].dy = 2.0*petrosian->radius*profile->axes.minor/profile->axes.major; 2086 overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD; 2087 overlay[Noverlay].text = NULL; 2088 Noverlay ++; 2089 2089 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 2090 2090 2091 overlay[Noverlay].type = KII_OVERLAY_CIRCLE;2092 overlay[Noverlay].x = source->peak->xf;2093 overlay[Noverlay].y = source->peak->yf;2094 overlay[Noverlay].dx = 4.0*petrosian->radius;2095 overlay[Noverlay].dy = 4.0*petrosian->radius*profile->axes.minor/profile->axes.major;2096 overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD;2097 overlay[Noverlay].text = NULL;2098 Noverlay ++;2091 overlay[Noverlay].type = KII_OVERLAY_CIRCLE; 2092 overlay[Noverlay].x = source->peak->xf; 2093 overlay[Noverlay].y = source->peak->yf; 2094 overlay[Noverlay].dx = 4.0*petrosian->radius; 2095 overlay[Noverlay].dy = 4.0*petrosian->radius*profile->axes.minor/profile->axes.major; 2096 overlay[Noverlay].angle = profile->axes.theta * PS_DEG_RAD; 2097 overlay[Noverlay].text = NULL; 2098 Noverlay ++; 2099 2099 CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 100); 2100 2100 }
Note:
See TracChangeset
for help on using the changeset viewer.
