Changeset 32023
- Timestamp:
- Aug 3, 2011, 6:29:49 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110710/psphot/src
- Files:
-
- 8 edited
-
psphot.h (modified) (2 diffs)
-
psphotEfficiency.c (modified) (8 diffs)
-
psphotEllipticalContour.c (modified) (3 diffs)
-
psphotExtendedSourceAnalysis.c (modified) (6 diffs)
-
psphotExtendedSourceFits.c (modified) (1 diff)
-
psphotRadialApertures.c (modified) (5 diffs)
-
psphotSetThreads.c (modified) (1 diff)
-
psphotSourceFits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110710/psphot/src/psphot.h
r31990 r32023 117 117 bool psphotExtendedSourceAnalysis (pmConfig *config, const pmFPAview *view, const char *filerule); 118 118 bool psphotExtendedSourceAnalysisReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 119 bool psphotExtendedSourceAnalysis_Threaded (psThreadJob *job); 119 120 120 121 bool psphotExtendedSourceFits (pmConfig *config, const pmFPAview *view, const char *filerule); … … 445 446 bool psphotRadialApertures (pmConfig *config, const pmFPAview *view, const char *filerule); 446 447 bool psphotRadialAperturesReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe); 448 bool psphotRadialApertures_Threaded (psThreadJob *job); 447 449 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *radMax, int entry); 448 450 -
branches/eam_branches/ipp-20110710/psphot/src/psphotEfficiency.c
r31452 r32023 99 99 100 100 /// Generate a fake image and add it in to the existing readout 101 static booleffGenerate(psImage **xSrc, psImage **ySrc, // Positions of sources101 static pmReadout *effGenerate(psImage **xSrc, psImage **ySrc, // Positions of sources 102 102 const pmReadout *ro, // Readout of interest 103 103 const pmPSF *psf, // Point-spread function … … 152 152 psFree(xAll); 153 153 psFree(yAll); 154 return false;154 return NULL; 155 155 } 156 156 psFree(magAll); … … 161 161 162 162 psBinaryOp(ro->image, ro->image, "+", fakeRO->image); 163 psFree(fakeRO); 164 165 return true;163 164 // return the readout so we can subtract it later 165 return fakeRO; 166 166 } 167 167 … … 290 290 291 291 psImage *xFake = NULL, *yFake = NULL; // Coordinates of sources, each bin in a row 292 if (!effGenerate(&xFake, &yFake, readout, psf, magOffsets,293 numSources, magLim, radius, minFlux)) {292 pmReadout *fakeRO = effGenerate(&xFake, &yFake, readout, psf, magOffsets, numSources, magLim, radius, minFlux); 293 if (!fakeRO) { 294 294 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake sources"); 295 295 psFree(xFake); … … 416 416 psFree(significance); 417 417 418 // psphotFitSourcesLinearReadout subtracts the model fits 418 419 if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) { 419 420 psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources."); … … 427 428 psf->ApTrend = NULL; 428 429 430 // measure the magnitudes and fluxes for the sources 429 431 if (!psphotMagnitudesReadout(config, recipe, view, readout, fakeSourcesAll, psf)) { 430 432 psError(PS_ERR_UNKNOWN, false, "Unable to measure magnitudes of fake sources."); … … 433 435 psf->ApTrend = apTrend; // Casting away const! 434 436 return false; 437 } 438 439 // replace the subtracted model fits 440 for (int i = 0; i < fakeSourcesAll->n; i++) { 441 pmSource *source = fakeSourcesAll->data[i]; 442 443 // replace other sources? 444 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 445 446 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 435 447 } 436 448 psFree(fakeSourcesAll); … … 515 527 psFree(fakeSources); 516 528 529 // subtract the faked sources from the original image 530 psBinaryOp(readout->image, readout->image, "-", fakeRO->image); 531 psFree(fakeRO); 532 517 533 pmDetEff *de = pmDetEffAlloc(magLim, numSources, numBins); // Detection efficiency 518 534 de->magOffsets = psVectorCopy(NULL, magOffsets, PS_TYPE_F32); -
branches/eam_branches/ipp-20110710/psphot/src/psphotEllipticalContour.c
r29004 r32023 127 127 psF32 psphotEllipticalContourFunc (psVector *deriv, const psVector *params, const psVector *coord) { 128 128 129 static int pass = 0;130 131 129 psF32 *par = params->data.F32; 132 130 … … 145 143 146 144 // value is X 147 // if (coord->data.F32[1] == 0) { 148 if (pass == 0) { 149 pass = 1; 150 145 if (coord->data.F32[1] < 0.5) { 151 146 float value = par[PAR_RMIN]*cs_alpha*r; 152 147 … … 161 156 162 157 // value is Y 163 // if (coord->data.F32[1] == 1) { 164 if (pass == 1) { 165 pass = 0; 166 158 if (coord->data.F32[1] > 0.5) { 167 159 float value = par[PAR_RMIN]*sn_alpha*r; 168 160 -
branches/eam_branches/ipp-20110710/psphot/src/psphotExtendedSourceAnalysis.c
r31154 r32023 2 2 3 3 // measure the elliptical radial profile and use this to measure the petrosian parameters for the sources 4 // XXX this function needs to be threaded5 4 6 5 // for now, let's store the detections on the readout->analysis for each readout … … 59 58 } 60 59 61 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 62 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 63 assert (maskVal); 60 // determine the number of allowed threads 61 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 62 if (!status) { 63 nThreads = 0; 64 } 64 65 65 66 // get the sky noise from the background analysis; if this is missing, get the user-supplied value … … 70 71 } 71 72 73 // source analysis is done in S/N order (brightest first) 74 sources = psArraySort (sources, pmSourceSortByFlux); 75 76 // option to limit analysis to a specific region 77 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 78 psRegion *AnalysisRegion = psRegionAlloc(0,0,0,0); 79 *AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 80 if (psRegionIsNaN (*AnalysisRegion)) psAbort("analysis region mis-defined"); 81 82 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 83 int Cx = 1, Cy = 1; 84 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 85 86 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 87 88 for (int i = 0; i < cellGroups->n; i++) { 89 90 psArray *cells = cellGroups->data[i]; 91 92 for (int j = 0; j < cells->n; j++) { 93 94 // allocate a job -- if threads are not defined, this just runs the job 95 psThreadJob *job = psThreadJobAlloc ("PSPHOT_EXTENDED_ANALYSIS"); 96 97 psArrayAdd(job->args, 1, readout); 98 psArrayAdd(job->args, 1, cells->data[j]); // sources 99 psArrayAdd(job->args, 1, AnalysisRegion); 100 psArrayAdd(job->args, 1, recipe); 101 102 PS_ARRAY_ADD_SCALAR(job->args, skynoise, PS_TYPE_F32); 103 104 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 105 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npetro 106 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nannuli 107 108 // set this to 0 to run without threading 109 # if (1) 110 if (!psThreadJobAddPending(job)) { 111 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 112 psFree(AnalysisRegion); 113 return false; 114 } 115 # else 116 if (!psphotExtendedSourceAnalysis_Threaded(job)) { 117 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 118 psFree(AnalysisRegion); 119 return false; 120 } 121 psScalar *scalar = NULL; 122 scalar = job->args->data[5]; 123 Next += scalar->data.S32; 124 scalar = job->args->data[6]; 125 Npetro += scalar->data.S32; 126 scalar = job->args->data[7]; 127 Nannuli += scalar->data.S32; 128 psFree(job); 129 # endif 130 } 131 132 // wait for the threads to finish and manage results 133 if (!psThreadPoolWait (false)) { 134 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 135 psFree(AnalysisRegion); 136 return false; 137 } 138 139 // we have only supplied one type of job, so we can assume the types here 140 psThreadJob *job = NULL; 141 while ((job = psThreadJobGetDone()) != NULL) { 142 if (job->args->n < 1) { 143 fprintf (stderr, "error with job\n"); 144 } else { 145 psScalar *scalar = NULL; 146 scalar = job->args->data[5]; 147 Next += scalar->data.S32; 148 scalar = job->args->data[6]; 149 Npetro += scalar->data.S32; 150 scalar = job->args->data[7]; 151 Nannuli += scalar->data.S32; 152 } 153 psFree(job); 154 } 155 } 156 psFree (cellGroups); 157 psFree(AnalysisRegion); 158 159 psLogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next); 160 psLogMsg ("psphot", PS_LOG_INFO, " %d petrosian\n", Npetro); 161 psLogMsg ("psphot", PS_LOG_INFO, " %d annuli\n", Nannuli); 162 163 psphotVisualShowResidualImage (readout, false); 164 165 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 166 if (doPetrosian) { 167 psphotVisualShowPetrosians (sources); 168 } 169 170 return true; 171 } 172 173 bool psphotExtendedSourceAnalysis_Threaded (psThreadJob *job) { 174 175 bool status; 176 177 int Next = 0; 178 int Npetro = 0; 179 int Nannuli = 0; 180 181 // arguments: readout, sources, models, region, psfSize, maskVal, markVal 182 pmReadout *readout = job->args->data[0]; 183 psArray *sources = job->args->data[1]; 184 psRegion *region = job->args->data[2]; 185 psMetadata *recipe = job->args->data[3]; 186 187 float skynoise = PS_SCALAR_VALUE(job->args->data[4],F32); 188 72 189 // S/N limit to perform full non-linear fits 73 190 float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM"); … … 78 195 bool doPetroStars = psMetadataLookupBool (&status, recipe, "PETROSIAN_FOR_STARS"); 79 196 80 // source analysis is done in S/N order (brightest first) 81 sources = psArraySort (sources, pmSourceSortByFlux); 82 83 // option to limit analysis to a specific region 84 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 85 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 86 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 197 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 198 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 199 assert (maskVal); 87 200 88 201 // choose the sources of interest … … 108 221 109 222 // limit selection by analysis region 110 if (source->peak->x < AnalysisRegion.x0) continue;111 if (source->peak->y < AnalysisRegion.y0) continue;112 if (source->peak->x > AnalysisRegion.x1) continue;113 if (source->peak->y > AnalysisRegion.y1) continue;223 if (source->peak->x < region->x0) continue; 224 if (source->peak->y < region->y0) continue; 225 if (source->peak->x > region->x1) continue; 226 if (source->peak->y > region->y1) continue; 114 227 115 228 // replace object in image … … 159 272 } 160 273 161 ps LogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next);162 psLogMsg ("psphot", PS_LOG_INFO, " %d petrosian\n", Npetro); 163 psLogMsg ("psphot", PS_LOG_INFO, " %d annuli\n", Nannuli);164 165 psphotVisualShowResidualImage (readout, false);166 167 if (doPetrosian) {168 psphotVisualShowPetrosians (sources);169 } 170 171 // fprintf (stderr, "xsrc : tried %ld objects\n", sources->n);274 psScalar *scalar = NULL; 275 276 // change the value of a scalar on the array (wrap this and put it in psArray.h) 277 scalar = job->args->data[5]; 278 scalar->data.S32 = Next; 279 280 scalar = job->args->data[6]; 281 scalar->data.S32 = Npetro; 282 283 scalar = job->args->data[7]; 284 scalar->data.S32 = Nannuli; 172 285 173 286 return true; -
branches/eam_branches/ipp-20110710/psphot/src/psphotExtendedSourceFits.c
r31990 r32023 278 278 psMetadata *models = job->args->data[2]; 279 279 psRegion *region = job->args->data[3]; 280 int psfSize = PS_SCALAR_VALUE(job->args->data[4], PS_TYPE_IMAGE_MASK_DATA);280 int psfSize = PS_SCALAR_VALUE(job->args->data[4],S32); 281 281 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[5],PS_TYPE_IMAGE_MASK_DATA); 282 282 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); -
branches/eam_branches/ipp-20110710/psphot/src/psphotRadialApertures.c
r31452 r32023 63 63 } 64 64 65 // determine the number of allowed threads 66 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 67 if (!status) { 68 nThreads = 0; 69 } 70 71 // source analysis is done in S/N order (brightest first) 72 // XXX are we getting the objects out of order? does it matter? 73 sources = psArraySort (sources, pmSourceSortByFlux); 74 75 // option to limit analysis to a specific region 76 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 77 psRegion *AnalysisRegion = psRegionAlloc(0,0,0,0); 78 *AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 79 if (psRegionIsNaN (*AnalysisRegion)) psAbort("analysis region mis-defined"); 80 81 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 82 int Cx = 1, Cy = 1; 83 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 84 85 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 86 87 for (int i = 0; i < cellGroups->n; i++) { 88 89 psArray *cells = cellGroups->data[i]; 90 91 for (int j = 0; j < cells->n; j++) { 92 93 // allocate a job -- if threads are not defined, this just runs the job 94 psThreadJob *job = psThreadJobAlloc ("PSPHOT_RADIAL_APERTURES"); 95 96 psArrayAdd(job->args, 1, readout); 97 psArrayAdd(job->args, 1, cells->data[j]); // sources 98 psArrayAdd(job->args, 1, AnalysisRegion); 99 psArrayAdd(job->args, 1, recipe); 100 101 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nradial 102 103 // set this to 0 to run without threading 104 # if (1) 105 if (!psThreadJobAddPending(job)) { 106 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 107 psFree(AnalysisRegion); 108 return false; 109 } 110 # else 111 if (!psphotRadialApertures_Threaded(job)) { 112 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 113 psFree(AnalysisRegion); 114 return false; 115 } 116 psScalar *scalar = NULL; 117 scalar = job->args->data[4]; 118 Nradial += scalar->data.S32; 119 psFree(job); 120 # endif 121 } 122 123 // wait for the threads to finish and manage results 124 if (!psThreadPoolWait (false)) { 125 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 126 psFree(AnalysisRegion); 127 return false; 128 } 129 130 // we have only supplied one type of job, so we can assume the types here 131 psThreadJob *job = NULL; 132 while ((job = psThreadJobGetDone()) != NULL) { 133 if (job->args->n < 1) { 134 fprintf (stderr, "error with job\n"); 135 } else { 136 psScalar *scalar = NULL; 137 scalar = job->args->data[4]; 138 Nradial += scalar->data.S32; 139 } 140 psFree(job); 141 } 142 } 143 psFree (cellGroups); 144 psFree(AnalysisRegion); 145 146 psLogMsg ("psphot", PS_LOG_INFO, "radial source apertures: %f sec for %d objects\n", psTimerMark ("psphot.radial"), Nradial); 147 return true; 148 } 149 150 bool psphotRadialApertures_Threaded (psThreadJob *job) { 151 152 bool status; 153 int Nradial = 0; 154 155 // arguments: readout, sources, models, region, psfSize, maskVal, markVal 156 pmReadout *readout = job->args->data[0]; 157 psArray *sources = job->args->data[1]; 158 psRegion *region = job->args->data[2]; 159 psMetadata *recipe = job->args->data[3]; 160 65 161 // radMax stores the upper bounds of the annuli 66 162 // XXX keep the same name here as for the petrosian / elliptical apertures? … … 68 164 psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe"); 69 165 psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define"); 70 float outerRadius = radMax->data.F32[radMax->n - 1];71 166 72 167 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 77 172 float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM"); 78 173 79 // source analysis is done in S/N order (brightest first) 80 // XXX are we getting the objects out of order? does it matter? 81 sources = psArraySort (sources, pmSourceSortByFlux); 82 83 // option to limit analysis to a specific region 84 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 85 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 86 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 174 float outerRadius = radMax->data.F32[radMax->n - 1]; 87 175 88 176 // choose the sources of interest … … 104 192 105 193 // limit selection by analysis region 106 if (source->peak->x < AnalysisRegion.x0) continue;107 if (source->peak->y < AnalysisRegion.y0) continue;108 if (source->peak->x > AnalysisRegion.x1) continue;109 if (source->peak->y > AnalysisRegion.y1) continue;194 if (source->peak->x < region->x0) continue; 195 if (source->peak->y < region->y0) continue; 196 if (source->peak->x > region->x1) continue; 197 if (source->peak->y > region->y1) continue; 110 198 111 199 // allocate pmSourceExtendedParameters, if not already defined … … 145 233 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 146 234 } 147 148 psLogMsg ("psphot", PS_LOG_INFO, "radial source apertures: %f sec for %d objects\n", psTimerMark ("psphot.radial"), Nradial); 235 psScalar *scalar = job->args->data[4]; 236 scalar->data.S32 = Nradial; 237 149 238 return true; 150 239 } -
branches/eam_branches/ipp-20110710/psphot/src/psphotSetThreads.c
r31452 r32023 40 40 psFree(task); 41 41 42 task = psThreadTaskAlloc("PSPHOT_EXTENDED_ANALYSIS", 8); 43 task->function = &psphotExtendedSourceAnalysis_Threaded; 44 psThreadTaskAdd(task); 45 psFree(task); 46 47 task = psThreadTaskAlloc("PSPHOT_RADIAL_APERTURES", 5); 48 task->function = &psphotRadialApertures_Threaded; 49 psThreadTaskAdd(task); 50 psFree(task); 51 42 52 return true; 43 53 } -
branches/eam_branches/ipp-20110710/psphot/src/psphotSourceFits.c
r31990 r32023 637 637 638 638 pmSourceFitModel (source, model, &options, maskVal); 639 fprintf (stderr, "index: %f, chisq: %f, nIter: %d, radius: %f, npix: %d\n", indexGuess[i], model->chisqNorm, model->nIter, model->fitRadius, model->nPix);639 // fprintf (stderr, "index: %f, chisq: %f, nIter: %d, radius: %f, npix: %d\n", indexGuess[i], model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 640 640 641 641 chiSquare[i] = model->chisqNorm;
Note:
See TracChangeset
for help on using the changeset viewer.
