Changeset 30101
- Timestamp:
- Dec 17, 2010, 9:57:34 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20101205/psphot/src
- Files:
-
- 1 added
- 12 edited
-
Makefile.am (modified) (1 diff)
-
psphot.h (modified) (3 diffs)
-
psphotExtendedSourceAnalysisByObject.c (modified) (1 diff)
-
psphotExtendedSourceFits.c (modified) (10 diffs)
-
psphotRadialApertures.c (modified) (8 diffs)
-
psphotRadialAperturesByObject.c (modified) (7 diffs)
-
psphotSetThreads.c (modified) (1 diff)
-
psphotStackChisqImage.c (modified) (4 diffs)
-
psphotStackMatchPSFs.c (modified) (1 diff)
-
psphotStackMatchPSFsNext.c (added)
-
psphotStackPSF.c (modified) (2 diffs)
-
psphotStackParseCamera.c (modified) (5 diffs)
-
psphotStackReadout.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/psphot/src/Makefile.am
r29936 r30101 98 98 psphotStackMatchPSFsUtils.c \ 99 99 psphotStackMatchPSFsPrepare.c \ 100 psphotStackMatchPSFsNext.c \ 100 101 psphotStackOptions.c \ 101 102 psphotStackObjects.c \ -
branches/eam_branches/ipp-20101205/psphot/src/psphot.h
r29936 r30101 312 312 313 313 int psphotFileruleCount(const pmConfig *config, const char *filerule); 314 bool psphotFileruleCountSet(const pmConfig *config, const char *filerule, int num); 314 315 315 316 bool psphotAddKnownSources (pmConfig *config, const pmFPAview *view, const char *filerule, psArray *inSources); … … 403 404 bool psphotStackMatchPSFsReadout (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index); 404 405 bool psphotStackMatchPSFsPrepare (pmConfig *config, const pmFPAview *view, psphotStackOptions *options, int index); 406 bool psphotStackMatchPSFsNext (bool *smoothAgain, pmConfig *config, const pmFPAview *view, const char *filerule, int nextSize); 407 bool psphotStackMatchPSFsNextReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe, float currentFWHM, float targetFWHM); 405 408 406 409 // psphotStackMatchPSFsUtils … … 426 429 bool psphotRadialApertures (pmConfig *config, const pmFPAview *view, const char *filerule); 427 430 bool psphotRadialAperturesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 428 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax );431 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax, int entry); 429 432 430 433 bool psphotExtendedSourceAnalysisByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule); 431 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule );434 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule, int nMatchedPSF); 432 435 433 436 bool psphotStackObjectsUnifyPosition (psArray *objects); -
branches/eam_branches/ipp-20101205/psphot/src/psphotExtendedSourceAnalysisByObject.c
r29936 r30101 53 53 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 54 54 psAssert (readout, "missing readout?"); 55 56 psLogMsg("psphot", PS_LOG_INFO, "petrosians for image %d", i); 57 psphotVisualShowImage(readout); 55 58 56 59 readouts->data[i] = psMemIncrRefCounter(readout); -
branches/eam_branches/ipp-20101205/psphot/src/psphotExtendedSourceFits.c
r29936 r30101 18 18 int num = psphotFileruleCount(config, filerule); 19 19 20 // skip the chisq image (optionally?) 21 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 22 if (!status) chisqNum = -1; 23 20 24 // loop over the available readouts 21 25 for (int i = 0; i < num; i++) { 26 if (i == chisqNum) continue; // skip chisq image 22 27 if (!psphotExtendedSourceFitsReadout (config, view, filerule, i, recipe)) { 23 28 psError (PSPHOT_ERR_CONFIG, false, "failed on to fit extended sources for %s entry %d", filerule, i); … … 37 42 int Nplain = 0; 38 43 int NplainPass = 0; 44 int Nfaint = 0; 39 45 40 46 psTimerStart ("psphot.extended"); … … 46 52 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 47 53 psAssert (readout, "missing readout?"); 54 55 psLogMsg("psphot", PS_LOG_INFO, "extended source fits for image %d", index); 56 psphotVisualShowImage(readout); 48 57 49 58 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); … … 167 176 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nplain 168 177 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for NplainPass 178 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfain 169 179 170 180 if (false && !psThreadJobAddPending(job)) { … … 189 199 scalar = job->args->data[11]; 190 200 NplainPass += scalar->data.S32; 201 scalar = job->args->data[12]; 202 Nfaint += scalar->data.S32; 191 203 psFree(job); 192 204 } … … 217 229 scalar = job->args->data[11]; 218 230 NplainPass += scalar->data.S32; 231 scalar = job->args->data[12]; 232 Nfaint += scalar->data.S32; 219 233 } 220 234 psFree(job); … … 227 241 psLogMsg ("psphot", PS_LOG_INFO, " %d convolved models (%d passed)\n", Nconvolve, NconvolvePass); 228 242 psLogMsg ("psphot", PS_LOG_INFO, " %d plain models (%d passed)\n", Nplain, NplainPass); 243 psLogMsg ("psphot", PS_LOG_INFO, " %d too faint to fit\n", Nfaint); 229 244 return true; 230 245 } … … 238 253 int NconvolvePass = 0; 239 254 int Nplain = 0; 255 int Nfaint = 0; 240 256 int NplainPass = 0; 241 257 bool savePics = false; … … 350 366 // limit selection to some SN limit 351 367 assert (source->peak); // how can a source not have a peak? 352 if (source->peak->SN < SNlim) continue; 368 if (source->peak->SN < SNlim) { 369 Nfaint ++; 370 continue; 371 } 353 372 354 373 // check on the model type … … 497 516 scalar->data.S32 = NplainPass; 498 517 518 scalar = job->args->data[12]; 519 scalar->data.S32 = Nfaint; 520 499 521 return true; 500 522 } -
branches/eam_branches/ipp-20101205/psphot/src/psphotRadialApertures.c
r29936 r30101 102 102 if (source->peak->x > AnalysisRegion.x1) continue; 103 103 if (source->peak->y > AnalysisRegion.y1) continue; 104 105 // allocate pmSourceExtendedParameters, if not already defined 106 if (!source->radialAper) { 107 source->radialAper = psArrayAlloc(1); 108 } 104 109 105 110 // replace object in image … … 116 121 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius); 117 122 118 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax )) {123 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, 0)) { 119 124 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 120 125 } else { … … 130 135 } 131 136 132 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax) { 133 134 // allocate pmSourceExtendedParameters, if not already defined 135 if (!source->radial) { 136 source->radial = pmSourceRadialAperturesAlloc (); 137 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *aperRadii, int entry) { 138 139 psAssert(source->radialAper->data[entry] == NULL, "why is this already defined?"); 140 141 pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc (); 142 source->radialAper->data[entry] = radialAper; 143 144 // storage for the derived pixel values 145 psVector *pixRadius2 = psVectorAllocEmpty(100, PS_TYPE_F32); 146 psVector *pixFlux = psVectorAllocEmpty(100, PS_TYPE_F32); 147 psVector *pixVar = psVectorAllocEmpty(100, PS_TYPE_F32); 148 149 // outer-most radius for initial truncation 150 float Rmax = aperRadii->data.F32[aperRadii->n - 1]; 151 float Rmax2 = PS_SQR(Rmax); 152 153 // store the R^2 values for the apertures 154 psVector *aperRadii2 = psVectorAlloc(aperRadii->n, PS_TYPE_F32); 155 for (int i = 0; i < aperRadii->n; i++) { 156 aperRadii2->data.F32[i] = PS_SQR(aperRadii->data.F32[i]); 157 } 158 159 // center of the apertures 160 float xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage 161 float yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage 162 163 // one pass through the pixels to select the valid pixels and calculate R^2 164 for (int iy = 0; iy < source->pixels->numRows; iy++) { 165 166 float yDiff = iy - yCM; 167 if (fabs(yDiff) > Rmax) continue; 168 169 float *vPix = source->pixels->data.F32[iy]; 170 float *vWgt = source->variance->data.F32[iy]; 171 psImageMaskType *vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy]; 172 173 for (int ix = 0; ix < source->pixels->numCols; ix++, vPix++, vWgt++) { 174 175 if (vMsk) { 176 if (*vMsk & maskVal) { 177 vMsk++; 178 continue; 179 } 180 vMsk++; 181 } 182 if (isnan(*vPix)) continue; 183 184 float xDiff = ix - xCM; 185 if (fabs(xDiff) > Rmax) continue; 186 187 // radius is just a function of (xDiff, yDiff) 188 float r2 = PS_SQR(xDiff) + PS_SQR(yDiff); 189 if (r2 > Rmax2) continue; 190 191 psVectorAppend(pixRadius2, r2); 192 psVectorAppend(pixFlux, *vPix); 193 psVectorAppend(pixVar, *vWgt); 194 } 195 } 196 197 psVector *flux = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 198 psVector *fluxErr = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 199 psVector *fill = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 200 201 psVectorInit (flux, 0.0); 202 psVectorInit (fluxErr, 0.0); 203 psVectorInit (fill, 0.0); 204 205 float *rPix2 = pixRadius2->data.F32; 206 for (int i = 0; i < pixRadius2->n; i++, rPix2++) { 207 208 float *aRad2 = aperRadii2->data.F32; 209 for (int j = 0; (*rPix2 < *aRad2) && (j < aperRadii2->n); j++, aRad2++) { 210 flux->data.F32[j] += pixFlux->data.F32[i]; 211 fluxErr->data.F32[j] += pixVar->data.F32[i]; 212 fill->data.F32[j] += 1.0; 213 } 214 } 215 216 for (int i = 0; i < flux->n; i++) { 217 // calculate the total flux for bin 'nOut' 218 float Area = M_PI*aperRadii2->data.F32[i]; 219 fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]); 220 fill->data.F32[i] /= Area; 221 psTrace ("psphot", 5, "radial bins: %3d %5.1f : %8.1f +/- %7.2f : %4.2f %6.1f\n", 222 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], fill->data.F32[i], Area); 137 223 } 138 224 139 psVector *radius = psVectorAllocEmpty(100, PS_TYPE_F32); 225 radialAper->flux = flux; 226 radialAper->fluxErr = fluxErr; 227 radialAper->fill = fill; 228 229 psFree (aperRadii2); 230 psFree (pixRadius2); 231 psFree (pixFlux); 232 psFree (pixVar); 233 234 return true; 235 } 236 237 static int nCalls = 0; 238 static int nPass = 0; 239 static int nPix = 0; 240 241 bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, float skynoise, psImageMaskType maskVal, const psVector *radMax, int entry) { 242 243 psAssert(source->radialAper->data[entry] == NULL, "why is this already defined?"); 244 245 pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc (); 246 source->radialAper->data[entry] = radialAper; 247 248 psVector *pixRadius = psVectorAllocEmpty(100, PS_TYPE_F32); 140 249 psVector *pixFlux = psVectorAllocEmpty(100, PS_TYPE_F32); 141 250 psVector *pixVar = psVectorAllocEmpty(100, PS_TYPE_F32); … … 144 253 for (int ix = 0; ix < source->pixels->numCols; ix++) { 145 254 146 // 0.5 PIX: get radius as a function of pixel coord255 // 0.5 PIX: get pixRadius as a function of pixel coord 147 256 float x = ix + 0.5 - source->peak->xf + source->pixels->col0; 148 257 float y = iy + 0.5 - source->peak->yf + source->pixels->row0; … … 150 259 float r = hypot(x, y); 151 260 152 psVectorAppend( radius, r);261 psVectorAppend(pixRadius, r); 153 262 psVectorAppend(pixFlux, source->pixels->data.F32[iy][ix]); 154 263 psVectorAppend(pixVar, source->variance->data.F32[iy][ix]); 155 } 156 } 157 psphotRadialAperturesSortFlux(radius, pixFlux, pixVar); 264 nPix ++; 265 // if (nPix % 10000 == 0) {fprintf (stderr, "?");} 266 } 267 } 268 psphotRadialAperturesSortFlux(pixRadius, pixFlux, pixVar); 158 269 159 270 psVector *flux = psVectorAllocEmpty(radMax->n, PS_TYPE_F32); // surface brightness of radial bin … … 174 285 175 286 // XXX assume (or enforce) that the bins are contiguous and non-overlapping (Rmax[i] = Rmin[i+1]) 176 for (int i = 0; !done && (i < radius->n); i++) {177 if ( radius->data.F32[i] > Rmax) {287 for (int i = 0; !done && (i < pixRadius->n); i++) { 288 if (pixRadius->data.F32[i] > Rmax) { 178 289 // calculate the total flux for bin 'nOut' 179 290 float Area = M_PI*PS_SQR(Rmax); … … 185 296 nOut, radMax->data.F32[nOut], flux->data.F32[nOut], fluxErr->data.F32[nOut], fill->data.F32[nOut], Area); 186 297 298 nPass ++; 299 // if (nPass % 1000 == 0) {fprintf (stderr, "!");} 300 187 301 nOut ++; 188 302 if (nOut >= radMax->n) break; … … 195 309 flux->n = fluxErr->n = fill->n = nOut; 196 310 197 psFree(source->radial->flux); 198 psFree(source->radial->fluxErr); 199 psFree(source->radial->fill); 200 201 source->radial->flux = flux; 202 source->radial->fluxErr = fluxErr; 203 source->radial->fill = fill; 204 205 psFree (radius); 311 radialAper->flux = flux; 312 radialAper->fluxErr = fluxErr; 313 radialAper->fill = fill; 314 315 psFree (pixRadius); 206 316 psFree (pixFlux); 207 317 psFree (pixVar); 208 318 319 nCalls ++; 320 // if (nCalls % 100 == 0) {fprintf (stderr, "*");} 209 321 return true; 210 322 } -
branches/eam_branches/ipp-20101205/psphot/src/psphotRadialAperturesByObject.c
r29936 r30101 3 3 // aperture-like measurements for extended sources 4 4 // flux in simple, circular apertures 5 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule) { 5 6 // **** it looks like this function will re-point the source pixels at the specified FILERULE 7 // **** I need to distinguish PSF-matched images from raw 8 // **** save (somewhere) the PSF-matched PSF values 9 10 // this function measures the radial aperture fluxes for the set of readouts. this function 11 // may be called multiple times (presumably with different matched PSF sizes). we must have 12 // already added an entry to the readout->analysis identifying the FWHM of this version. 13 14 bool psphotRadialAperturesByObject (pmConfig *config, psArray *objects, const pmFPAview *view, const char *filerule, int nMatchedPSF) { 6 15 7 16 bool status; … … 28 37 psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe"); 29 38 psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define"); 39 float outerRadius = radMax->data.F32[radMax->n - 1]; 30 40 31 41 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 39 49 float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM"); 40 50 51 // how many target PSFs do we want? 52 int nPSFsizes = 0; 53 { 54 psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); 55 if (status) { 56 nPSFsizes = 1; 57 } else { 58 psVector *fwhmValues = psMetadataLookupVector(&status, recipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets 59 psAssert (status, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 60 nPSFsizes = fwhmValues->n; 61 } 62 } 63 41 64 // source analysis is done in S/N order (brightest first) 42 65 objects = psArraySort (objects, pmPhotObjSortBySN); … … 53 76 psAssert (readout, "missing readout?"); 54 77 78 psVector *fwhmValues = psMetadataLookupVector(&status, readout->analysis, "STACK.PSF.FWHM.VALUES"); 79 if (!fwhmValues) { 80 psError (PSPHOT_ERR_CONFIG, true, "convolved or measured FWHM is not defined for this readout"); 81 return false; 82 } 83 if (fwhmValues->n != nMatchedPSF + 1) { 84 psError (PSPHOT_ERR_CONFIG, true, "convolved or measured FWHM sequence is inconsistent this readout"); 85 return false; 86 } 87 psLogMsg ("psphot", PS_LOG_DETAIL, "PSF FWHM of %s : %f pixels\n", file->name, fwhmValues->data.F32[nMatchedPSF]); 88 55 89 readouts->data[i] = psMemIncrRefCounter(readout); 56 90 } 57 91 58 92 // process the objects in order. 59 for (int i = 0; i < objects->n; i++) { 93 // XXX TEST: fix this! 94 for (int i = 0; (i < 50) && (i < objects->n); i++) { 60 95 pmPhotObj *object = objects->data[i]; 61 96 if (!object) continue; … … 77 112 if (source->peak->SN < SN_LIM) continue; 78 113 114 int index = source->imageID; 115 if (index >= readouts->n) continue; // skip the sources generated by the chisq image 116 pmReadout *readout = readouts->data[index]; 117 118 // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index); 119 // psphotVisualShowImage(readout); 120 121 // allocate pmSourceExtendedParameters, if not already defined 122 if (!source->radialAper) { 123 source->radialAper = psArrayAlloc(nPSFsizes); 124 } 125 79 126 // replace object in image 80 127 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { … … 83 130 Nradial ++; 84 131 85 int index = source->imageID;86 pmReadout *readout = readouts->data[index];132 // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index); 133 // psphotVisualShowImage(readout); 87 134 88 135 // force source image to be a bit larger... 89 float radius = source->peak->xf - source->pixels->col0;90 radius = PS_MAX (radius, source->peak->yf - source->pixels->row0);91 radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0);92 radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0);93 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius);136 // float radius = source->peak->xf - source->pixels->col0; 137 // radius = PS_MAX (radius, source->peak->yf - source->pixels->row0); 138 // radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0); 139 // radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0); 140 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, outerRadius + 2); 94 141 95 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax )) {142 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, nMatchedPSF)) { 96 143 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 97 144 } else { … … 101 148 // re-subtract the object, leave local sky 102 149 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 150 151 // psLogMsg("psphot", PS_LOG_INFO, "radial apertures for %d", index); 152 // psphotVisualShowImage(readout); 103 153 } 104 154 } -
branches/eam_branches/ipp-20101205/psphot/src/psphotSetThreads.c
r29004 r30101 35 35 psFree(task); 36 36 37 task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 1 2);37 task = psThreadTaskAlloc("PSPHOT_EXTENDED_FIT", 13); 38 38 task->function = &psphotExtendedSourceFits_Threaded; 39 39 psThreadTaskAdd(task); -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackChisqImage.c
r30028 r30101 6 6 7 7 // XXX supply filename or keep PSPHOT.INPUT fixed? 8 bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *ruleDet, const char *rule Cnv)8 bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view, const char *ruleDet, const char *ruleSrc) 9 9 { 10 10 psTimerStart ("psphot.chisq.image"); … … 27 27 28 28 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.CHISQ.NUM", PS_META_REPLACE, "", num); 29 30 // we need to increment the counter for ruleDet and ruleSrc: 29 31 num++; 30 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", num);31 32 32 33 // save the resulting image in the 'detection' set … … 35 36 return false; 36 37 } 38 psphotFileruleCountSet(config, ruleDet, num); 37 39 38 // save the resulting image in the 'convolved' set 39 // XXX whil am I doing this as well? 40 if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, ruleCnv, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) { 41 psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files"); 42 return false; 40 // also save the resulting image in the 'source' set (analysis set) 41 if (strcmp(ruleDet, ruleSrc)) { 42 if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, ruleSrc, PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) { 43 psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files"); 44 return false; 45 } 46 psphotFileruleCountSet(config, ruleSrc, num); 43 47 } 44 48 … … 120 124 psAssert (status, "programming error: must define PSPHOT.CHISQ.NUM"); 121 125 122 int inputNum = psphotFileruleCount(config, "PSPHOT.INPUT");126 int inputNum = psphotFileruleCount(config, filerule); 123 127 124 128 pmFPAfileRemoveSingle (config->files, filerule, chisqNum); 125 129 126 130 inputNum --; 127 ps MetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", inputNum);131 psphotFileruleCountSet(config, filerule, inputNum); 128 132 129 133 return true; -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackMatchPSFs.c
r30006 r30101 106 106 rescaleData(readoutOut, config, options, index); 107 107 108 // dumpImage(readoutOut, readoutSrc, index, "convolved"); 108 // save the output fwhm values in the readout->analysis. we may have / will have multiple output PSF sizes, 109 // so we save this in a vector. if the vector is not yet defined, create it 110 bool mdok = false; 111 psVector *fwhmValues = psMetadataLookupVector(&mdok, readoutOut->analysis, "STACK.PSF.FWHM.VALUES"); 112 if (!fwhmValues) { 113 fwhmValues = psVectorAllocEmpty(10, PS_TYPE_F32); 114 psMetadataAddVector(readoutOut->analysis, PS_LIST_TAIL, "STACK.PSF.FWHM.VALUES", PS_META_REPLACE, "PSF sizes", fwhmValues); 115 psFree(fwhmValues); // drops the extra copy 116 } 117 psVectorAppend(fwhmValues, options->targetSeeing); 109 118 110 119 return true; -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackPSF.c
r28013 r30101 12 12 bool autoPSF = psMetadataLookupBool (&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.AUTO"); 13 13 14 // Get the recipe values 15 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "PPSTACK"); // ppStack recipe 16 psAssert(recipe, "We've thrown an error on this before."); 17 18 char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF 19 14 20 if (autoPSF) { 15 // Get the recipe values16 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "PPSTACK"); // ppStack recipe17 psAssert(recipe, "We've thrown an error on this before.");18 19 21 int psfInstances = psMetadataLookupS32(NULL, recipe, "PSF.INSTANCES"); // Number of instances for PSF 20 22 float psfRadius = psMetadataLookupF32(NULL, recipe, "PSF.RADIUS"); // Radius for PSF 21 const char *psfModel = psMetadataLookupStr(NULL, recipe, "PSF.MODEL"); // Model for PSF22 23 int psfOrder = psMetadataLookupS32(NULL, recipe, "PSF.ORDER"); // Spatial order for PSF 23 24 … … 49 50 50 51 float targetFWHM = psMetadataLookupF32 (&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); 51 psAssert (isfinite(targetFWHM), "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 52 if (!mdok) { 53 psVector *fwhmValues = psMetadataLookupVector(&mdok, psphotRecipe, "PSPHOT.STACK.TARGET.PSF.FWHM"); // Magnitude offsets 54 psAssert (mdok, "missing psphot recipe value PSPHOT.STACK.TARGET.PSF.FWHM"); 55 targetFWHM = fwhmValues->data.F32[0]; 56 } 52 57 53 58 float Sxx = sqrt(2.0)*targetFWHM / 2.35; 54 59 55 60 // XXX probably should make the model type (and par 7) optional from recipe 56 psf = pmPSFBuildSimple( "PS_MODEL_PS1_V1", Sxx, Sxx, 0.0, 1.0);61 psf = pmPSFBuildSimple(psfModel, Sxx, Sxx, 0.0, 1.0); 57 62 if (!psf) { 58 63 psError(PSPHOT_ERR_PSF, false, "Unable to build dummy PSF."); -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackParseCamera.c
r29548 r30101 15 15 } 16 16 17 int nRaw = 0; 18 int nCnv = 0; 17 19 int nInputs = inputs->list->n; 18 20 for (int i = 0; i < nInputs; i++) { … … 57 59 } 58 60 } 61 nRaw ++; 59 62 } 60 63 … … 88 91 } 89 92 } 93 nCnv ++; 90 94 } 91 95 … … 93 97 psError(PSPHOT_ERR_CONFIG, true, "Component %s (%d) lacks both RAW:IMAGE and CNV:IMAGE of type STR", item->name, i); 94 98 return false; 99 } 100 101 // XXX what if they do not match in length 102 if (nCnv && nRaw) { 103 if (nCnv != nRaw) { 104 psError (PSPHOT_ERR_CONFIG, true, "if both RAW and CNV images are supplied, the number must match"); 105 return false; 106 } 95 107 } 96 108 … … 150 162 } 151 163 psMetadataRemoveKey(config->arguments, "FILENAMES"); 164 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.STACK.INPUT.RAW.NUM", PS_META_REPLACE, "number of inputs", nRaw); 165 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.STACK.INPUT.CNV.NUM", PS_META_REPLACE, "number of inputs", nCnv); 166 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.STACK.OUTPUT.IMAGE.NUM", PS_META_REPLACE, "number of inputs", nInputs); 152 167 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", nInputs); 153 168 -
branches/eam_branches/ipp-20101205/psphot/src/psphotStackReadout.c
r30027 r30101 1 1 # include "psphotInternal.h" 2 2 3 // we have 3 possible real filesets: 3 4 # define STACK_RAW "PSPHOT.STACK.INPUT.RAW" 4 5 # define STACK_CNV "PSPHOT.STACK.INPUT.CNV" 5 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" 6 # define STACK_OUT "PSPHOT.STACK.OUTPUT.IMAGE" /* the psf-matched image */ 7 8 // we have 3 files on which we operate: 9 // DET (detection image) : nominally RAW (optionally CNV?) 10 // SRC (source analysis image) : nominally CNV (optionally RAW) 11 // OUT (psf-matched images) : always OUT 6 12 7 13 bool psphotStackReadout (pmConfig *config, const pmFPAview *view) { … … 21 27 PS_ASSERT_PTR_NON_NULL (breakPt, false); 22 28 23 BST = RAW : CNV; 29 // XXX or do I set OUT to be a pmFPAfile pointing at the input of interest? 30 bool useRaw = psMetadataLookupBool (NULL, recipe, "PSPHOT.STACK.USE.RAW"); 31 char *STACK_SRC = useRaw ? STACK_RAW : STACK_CNV; 32 char *STACK_DET = STACK_RAW; // XXX optionally allow this to be CNV? 24 33 25 34 // we have 3 relevant files: RAW, CNV, OUT 26 35 27 36 // set the photcode for each image 28 if (!psphotAddPhotcode (config, view, STACK_ BST)) {37 if (!psphotAddPhotcode (config, view, STACK_SRC)) { 29 38 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); 30 39 return false; … … 33 42 // Generate the mask and weight images 34 43 // XXX this should be done before we perform the convolutions 35 if (!psphotSetMaskAndVariance (config, view, STACK_ RAW)) {36 return psphotReadoutCleanup (config, view, STACK_ OUT);44 if (!psphotSetMaskAndVariance (config, view, STACK_DET)) { 45 return psphotReadoutCleanup (config, view, STACK_SRC); 37 46 } 38 47 if (!strcasecmp (breakPt, "NOTHING")) { 39 return psphotReadoutCleanup (config, view, STACK_ OUT);48 return psphotReadoutCleanup (config, view, STACK_SRC); 40 49 } 41 50 … … 43 52 // XXX I think this is not defined correctly for an array of images. 44 53 // XXX probably need to subtract the model (same model?) for both RAW and OUT 45 if (!psphotModelBackground (config, view, STACK_ RAW)) {46 return psphotReadoutCleanup (config, view, STACK_ OUT);47 } 48 if (!psphotSubtractBackground (config, view, STACK_ RAW)) {49 return psphotReadoutCleanup (config, view, STACK_ OUT);54 if (!psphotModelBackground (config, view, STACK_DET)) { 55 return psphotReadoutCleanup (config, view, STACK_SRC); 56 } 57 if (!psphotSubtractBackground (config, view, STACK_DET)) { 58 return psphotReadoutCleanup (config, view, STACK_SRC); 50 59 } 51 60 if (!strcasecmp (breakPt, "BACKMDL")) { 52 return psphotReadoutCleanup (config, view, STACK_OUT); 53 } 54 55 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are determined and saved on 56 // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT 57 if (!psphotLoadPSF (config, view, STACK_RAW)) { 58 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 59 return psphotReadoutCleanup (config, view, STACK_OUT); 60 } 61 62 if (!psphotStackChisqImage(config, view, STACK_RAW, STACK_OUT)) { 61 return psphotReadoutCleanup (config, view, STACK_SRC); 62 } 63 64 if (!psphotStackChisqImage(config, view, STACK_DET, STACK_SRC)) { 63 65 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); 64 return psphotReadoutCleanup (config, view, STACK_ OUT);66 return psphotReadoutCleanup (config, view, STACK_SRC); 65 67 } 66 68 if (!strcasecmp (breakPt, "CHISQ")) { 67 return psphotReadoutCleanup (config, view, STACK_ OUT);69 return psphotReadoutCleanup (config, view, STACK_SRC); 68 70 } 69 71 70 72 // find the detections (by peak and/or footprint) in the image. 71 73 // This finds the detections on Chisq image as well as the individuals 72 if (!psphotFindDetections (config, view, STACK_ RAW, true)) { // pass 174 if (!psphotFindDetections (config, view, STACK_DET, true)) { // pass 1 73 75 // this only happens if we had an error in psphotFindDetections 74 76 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 75 return psphotReadoutCleanup (config, view, STACK_OUT); 76 } 77 78 // copy the detections from RAW to OUT 79 if (!psphotCopySources (config, view, STACK_OUT, STACK_RAW)) { 80 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 81 return psphotReadoutCleanup (config, view, STACK_OUT); 77 return psphotReadoutCleanup (config, view, STACK_SRC); 78 } 79 80 // copy the detections from DET to SRC 81 if (strcmp(STACK_SRC, STACK_DET)) { 82 if (!psphotCopySources (config, view, STACK_SRC, STACK_DET)) { 83 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 84 return psphotReadoutCleanup (config, view, STACK_SRC); 85 } 82 86 } 83 87 84 88 // construct sources and measure basic stats (saved on detections->newSources) 85 // only run this on detections from the input images, not chisq image 86 if (!psphotSourceStats (config, view, STACK_OUT, true)) { // pass 1 89 if (!psphotSourceStats (config, view, STACK_SRC, true)) { // pass 1 87 90 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 88 return psphotReadoutCleanup (config, view, STACK_ OUT);91 return psphotReadoutCleanup (config, view, STACK_SRC); 89 92 } 90 93 91 94 // generate the objects (object unify the sources from the different images) 92 psArray *objects = psphotMatchSources (config, view, STACK_OUT); 95 // XXX this could just match the detections for the chisq image, and not bother measuring the 96 // source stats in that case... 97 psArray *objects = psphotMatchSources (config, view, STACK_SRC); 93 98 94 99 // construct sources for the newly-generated sources (from other images) 95 if (!psphotSourceStats (config, view, STACK_ OUT, false)) { // pass 1100 if (!psphotSourceStats (config, view, STACK_SRC, false)) { // pass 1 96 101 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 97 return psphotReadoutCleanup (config, view, STACK_ OUT);102 return psphotReadoutCleanup (config, view, STACK_SRC); 98 103 } 99 104 … … 101 106 // if (!psphotDeblendSatstars (config, view)) { 102 107 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 103 // return psphotReadoutCleanup (config, view, STACK_ OUT);108 // return psphotReadoutCleanup (config, view, STACK_SRC); 104 109 // } 105 110 … … 107 112 // if (!psphotBasicDeblend (config, view)) { 108 113 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 109 // return psphotReadoutCleanup (config, view, STACK_ OUT);114 // return psphotReadoutCleanup (config, view, STACK_SRC); 110 115 // } 111 116 112 117 // classify sources based on moments, brightness 113 118 // only run this on detections from the input images, not chisq image 114 if (!psphotRoughClass (config, view, STACK_ OUT)) {119 if (!psphotRoughClass (config, view, STACK_SRC)) { 115 120 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 116 return psphotReadoutCleanup (config, view, STACK_ OUT);121 return psphotReadoutCleanup (config, view, STACK_SRC); 117 122 } 118 123 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 119 124 // only run this on detections from the input images, not chisq image 120 if (!psphotImageQuality (config, view, STACK_ OUT)) { // pass 1125 if (!psphotImageQuality (config, view, STACK_SRC)) { // pass 1 121 126 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 122 return psphotReadoutCleanup (config, view, STACK_ OUT);127 return psphotReadoutCleanup (config, view, STACK_SRC); 123 128 } 124 129 if (!strcasecmp (breakPt, "MOMENTS")) { 125 return psphotReadoutCleanup (config, view, STACK_ OUT);130 return psphotReadoutCleanup (config, view, STACK_SRC); 126 131 } 127 132 128 133 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 129 134 // this step is skipped 130 if (!psphotChoosePSF (config, view, STACK_ OUT)) { // pass 1135 if (!psphotChoosePSF (config, view, STACK_SRC)) { // pass 1 131 136 psLogMsg ("psphot", 3, "failure to construct a psf model"); 132 return psphotReadoutCleanup (config, view, STACK_ OUT);137 return psphotReadoutCleanup (config, view, STACK_SRC); 133 138 } 134 139 if (!strcasecmp (breakPt, "PSFMODEL")) { 135 return psphotReadoutCleanup (config, view, STACK_ OUT);140 return psphotReadoutCleanup (config, view, STACK_SRC); 136 141 } 137 142 138 143 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 139 psphotGuessModels (config, view, STACK_ OUT);144 psphotGuessModels (config, view, STACK_SRC); 140 145 141 146 // merge the newly selected sources into the existing list 142 147 // NOTE: merge OLD and NEW 143 psphotMergeSources (config, view, STACK_ OUT);148 psphotMergeSources (config, view, STACK_SRC); 144 149 145 150 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) … … 147 152 148 153 // identify CRs and extended sources 149 psphotSourceSize (config, view, STACK_ OUT, TRUE);154 psphotSourceSize (config, view, STACK_SRC, TRUE); 150 155 151 156 // measure aperture photometry corrections 152 if (!psphotApResid (config, view, STACK_ OUT)) {157 if (!psphotApResid (config, view, STACK_SRC)) { 153 158 psFree (objects); 154 159 psLogMsg ("psphot", 3, "failed on psphotApResid"); 155 return psphotReadoutCleanup (config, view, STACK_ OUT);160 return psphotReadoutCleanup (config, view, STACK_SRC); 156 161 } 157 162 158 163 psphotStackObjectsUnifyPosition (objects); 159 164 160 // measure circular, radial apertures (objects sorted by S/N)161 psphotRadialAperturesByObject (config, objects, view, STACK_OUT);162 163 165 // measure elliptical apertures, petrosians (objects sorted by S/N) 164 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_ OUT); // pass 1 (detections->allSources)166 psphotExtendedSourceAnalysisByObject (config, objects, view, STACK_SRC); // pass 1 (detections->allSources) 165 167 166 168 // measure non-linear extended source models (exponential, deVaucouleur, Sersic) (sources sorted by S/N) 167 psphotExtendedSourceFits (config, view, STACK_ OUT); // pass 1 (detections->allSources)169 psphotExtendedSourceFits (config, view, STACK_SRC); // pass 1 (detections->allSources) 168 170 169 171 // calculate source magnitudes 170 psphotMagnitudes(config, view, STACK_OUT); 172 psphotMagnitudes(config, view, STACK_SRC); 173 174 // copy the detections from SRC to OUT (for radial aperture photometry) 175 if (!psphotCopySources (config, view, STACK_OUT, STACK_SRC)) { 176 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 177 return psphotReadoutCleanup (config, view, STACK_SRC); 178 } 179 // XXX need to do something to reassign the source pixels here 180 181 bool smoothAgain = true; 182 for (int nMatchedPSF = 0; smoothAgain; nMatchedPSF++) { 183 // measure circular, radial apertures (objects sorted by S/N) 184 psphotRadialAperturesByObject (config, objects, view, STACK_OUT, nMatchedPSF); 185 psphotStackMatchPSFsNext(&smoothAgain, config, view, STACK_OUT, nMatchedPSF); 186 } 171 187 172 188 if (0 && !psphotEfficiency(config, view, STACK_OUT)) { … … 179 195 180 196 // replace background in residual image 181 psphotSkyReplace (config, view, STACK_ RAW);197 psphotSkyReplace (config, view, STACK_DET); 182 198 183 199 // drop the references to the image pixels held by each source 184 psphotSourceFreePixels (config, view, STACK_OUT); 185 186 // remove chisq image from config->file:PSPHOT.INPUT (why?) 187 psphotStackRemoveChisqFromInputs(config, STACK_RAW); 200 // psphotSourceFreePixels (config, view, STACK_OUT); 201 psphotSourceFreePixels (config, view, STACK_SRC); 202 203 // remove chisq image from config->file:PSPHOT.INPUT 204 psphotStackRemoveChisqFromInputs(config, STACK_DET); 205 if (strcmp(STACK_SRC, STACK_DET)) { 206 psphotStackRemoveChisqFromInputs(config, STACK_SRC); 207 } 188 208 189 209 psFree (objects); 190 210 191 211 // create the exported-metadata and free local data 192 return psphotReadoutCleanup (config, view, STACK_ OUT);212 return psphotReadoutCleanup (config, view, STACK_SRC); 193 213 } 194 214 … … 258 278 ****** 259 279 260 the above is all wrong: first, we s ohould be doing the full280 the above is all wrong: first, we should be doing the full 261 281 morphology analysis (ExtendedAnalysis & ExtendedFits) on the CNV or 262 282 RAW image (as desired optionally), etc.
Note:
See TracChangeset
for help on using the changeset viewer.
