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