Changeset 27625
- Timestamp:
- Apr 6, 2010, 1:36:51 PM (16 years ago)
- Location:
- branches/eam_branches/stackphot.20100406/psphot/src
- Files:
-
- 1 deleted
- 9 edited
-
Makefile.am (modified) (3 diffs)
-
psphot.h (modified) (1 diff)
-
psphotFitSourcesLinearStack.c (modified) (9 diffs)
-
psphotReadout.c (modified) (1 diff)
-
psphotSourceMerge.c (deleted)
-
psphotStackArguments.c (modified) (4 diffs)
-
psphotStackChisqImage.c (modified) (3 diffs)
-
psphotStackImageLoop.c (modified) (1 diff)
-
psphotStackParseCamera.c (modified) (5 diffs)
-
psphotStackReadout.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/stackphot.20100406/psphot/src/Makefile.am
r26894 r27625 17 17 # Force recompilation of psphotVersion.c, since it gets the version information 18 18 psphotVersion.c: psphotVersionDefinitions.h 19 psphotVersionDefinitions.h: psphotVersionDefinitions.h.in FORCE20 -$(RM) psphotVersionDefinitions.h21 $(SED) -e "s|@PSPHOT_VERSION@|\"$(PSPHOT_VERSION)\"|" -e "s|@PSPHOT_BRANCH@|\"$(PSPHOT_BRANCH)\"|" -e "s|@PSPHOT_SOURCE@|\"$(PSPHOT_SOURCE)\"|" psphotVersionDefinitions.h.in > psphotVersionDefinitions.h22 FORCE: ;19 # psphotVersionDefinitions.h: psphotVersionDefinitions.h.in FORCE 20 # -$(RM) psphotVersionDefinitions.h 21 # $(SED) -e "s|@PSPHOT_VERSION@|\"$(PSPHOT_VERSION)\"|" -e "s|@PSPHOT_BRANCH@|\"$(PSPHOT_BRANCH)\"|" -e "s|@PSPHOT_SOURCE@|\"$(PSPHOT_SOURCE)\"|" psphotVersionDefinitions.h.in > psphotVersionDefinitions.h 22 # FORCE: ; 23 23 24 24 libpsphot_la_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS) 25 25 libpsphot_la_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS) 26 26 27 bin_PROGRAMS = psphot psphotForced psphotMakePSF 27 bin_PROGRAMS = psphot psphotForced psphotMakePSF psphotStack 28 28 # bin_PROGRAMS = psphotPetrosianStudy psphotTest psphotMomentsStudy 29 29 … … 39 39 psphotMakePSF_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS) 40 40 psphotMakePSF_LDADD = libpsphot.la 41 42 psphotStack_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS) 43 psphotStack_LDFLAGS = $(PSPHOT_LIBS) $(PSMODULE_LIBS) $(PSLIB_LIBS) 44 psphotStack_LDADD = libpsphot.la 41 45 42 46 # psphotMomentsStudy_CFLAGS = $(PSPHOT_CFLAGS) $(PSMODULE_CFLAGS) $(PSLIB_CFLAGS) … … 80 84 psphotMosaicChip.c \ 81 85 psphotCleanup.c 86 87 # a psphot-variant for stack photometry 88 psphotStack_SOURCES = \ 89 psphotStack.c \ 90 psphotStackArguments.c \ 91 psphotStackParseCamera.c \ 92 psphotStackImageLoop.c \ 93 psphotStackReadout.c \ 94 psphotStackChisqImage.c \ 95 psphotCleanup.c 96 97 # psphotFitSourceLinearStack.c 98 82 99 83 100 # # psphot analysis of the detectability of specified positions -
branches/eam_branches/stackphot.20100406/psphot/src/psphot.h
r27532 r27625 341 341 bool psphotMakePSFReadout(pmConfig *config, const pmFPAview *view); 342 342 343 /**** psphotStack prototypes ****/ 344 345 pmConfig *psphotStackArguments(int argc, char **argv); 346 bool psphotStackParseCamera (pmConfig *config); 347 bool psphotStackImageLoop (pmConfig *config); 348 bool psphotStackReadout (pmConfig *config, const pmFPAview *view); 349 bool psphotStackChisqImage (pmConfig *config, const pmFPAview *view); 350 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration 351 const pmFPAview *view, 352 pmReadout *chiReadout, 353 char *filename, 354 int index); 355 356 343 357 #endif -
branches/eam_branches/stackphot.20100406/psphot/src/psphotFitSourcesLinearStack.c
r27547 r27625 1 1 # include "psphotInternal.h" 2 3 // for now, let's store the detections on the readout->analysis for each readout 4 bool psphotFitSourcesLinearStack (pmConfig *config, const pmFPAview *view, bool final) 5 { 6 bool status = true; 7 8 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 9 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 10 11 // loop over the available readouts 12 for (int i = 0; i < num; i++) { 13 if (!psphotFitSourcesLinearReadoutStack (config, view, "PSPHOT.INPUT", i, final)) { 14 psError (PSPHOT_ERR_CONFIG, false, "failed to fit sources (linear) for PSPHOT.INPUT entry %d", i); 15 return false; 16 } 17 } 18 return true; 19 } 20 21 bool psphotFitSourcesLinearReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, bool final) { 2 // XXX need array of covar factors for each image 3 // XXX define the 'good' / 'bad' flags? 4 5 bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final) { 22 6 23 7 bool status; … … 25 9 float y; 26 10 float f; 27 // float r;28 11 29 12 // select the appropriate recipe information … … 31 14 assert (recipe); 32 15 33 // find the currently selected readout34 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest35 psAssert (file, "missing file?");36 37 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa);38 psAssert (readout, "missing readout?");39 40 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");41 psAssert (detections, "missing detections?");42 43 psArray *sources = detections->allSources;44 psAssert (sources, "missing sources?");45 46 if (!sources->n) {47 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping linear fit");48 return true;49 }50 51 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");52 psAssert (sources, "missing psf?");53 54 16 psTimerStart ("psphot.linear"); 55 17 … … 65 27 maskVal |= markVal; 66 28 67 // source analysis is done in spatial order 68 sources = psArraySort (sources, pmSourceSortByY); 29 // analysis is done in spatial order (to speed up overlap search) 30 // sort by first element in each source list 31 objects = psArraySort (objects, pmPhotObjSortByY); 69 32 70 33 // storage array for fitSources 71 psArray *fitSources = psArrayAllocEmpty (sources->n); 72 73 // option to limit analysis to a specific region 74 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 75 psRegion AnalysisRegion = psRegionFromString (region); 76 AnalysisRegion = psRegionForImage (readout->image, AnalysisRegion); 77 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 78 79 bool CONSTANT_PHOTOMETRIC_WEIGHTS = 80 psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS"); 81 if (!status) { 82 psAbort("You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS"); 83 } 84 int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER"); 85 if (!status) { 86 SKY_FIT_ORDER = 0; 87 } 88 bool SKY_FIT_LINEAR = psMetadataLookupBool(&status, recipe, "SKY_FIT_LINEAR"); 89 if (!status) { 90 SKY_FIT_LINEAR = false; 91 } 92 93 // XXX test: choose a larger-than expected radius: 94 float covarFactor = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix 95 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "covariance factor: %f\n", covarFactor); 96 97 // XXX do not apply covarFactor for the moment... 98 // covarFactor = 1.0; 34 psArray *fitSources = psArrayAllocEmpty (objects->n); 35 36 bool CONSTANT_PHOTOMETRIC_WEIGHTS = psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS"); 37 psAssert (status, "You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS"); 38 39 // XXX store a local static array of covar factors for each of the images (by image ID) 40 // float covarFactor = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix 41 // psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "covariance factor: %f\n", covarFactor); 99 42 100 43 // select the sources which will be used for the fitting analysis … … 104 47 if (!object->sources) continue; 105 48 106 // check an element of the group to see if we should use it107 if (!object->flags & PM_PHOT_OBJ_BAD) continue;49 // XXX check an element of the group to see if we should use it 50 // if (!object->flags & PM_PHOT_OBJ_BAD) continue; 108 51 109 52 for (int j = 0; j < object->sources->n; j++) { … … 162 105 pmSource *SRCj = fitSources->data[j]; 163 106 164 // XXX I need to know if this source is on the same image as SRCi --165 if ( !sameImge) { continue; }107 // we only need to generate dot terms for source on the same image 108 if (SRCj->imageID != SRCi->imageID) { continue; } 166 109 167 110 // skip over disjoint source images, break after last possible overlap … … 190 133 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "solve matrix: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem); 191 134 192 // XXXX **** philosophical question:193 // we measure bright objects in three passes: 1) linear fit; 2) non-linear fit; 3) linear fit:194 // should retain the chisq and errors from the intermediate non-linear fit?195 // the non-linear fit provides better values for the position errors, and for196 // extended sources, the shape errors197 198 135 // adjust I0 for fitSources and subtract 199 136 for (int i = 0; i < fitSources->n; i++) { … … 208 145 model->params->data.F32[PM_PAR_I0] = norm->data.F32[i]; 209 146 model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i]; 210 // XXX is the value of 'errors' modified by the sky fit?211 147 212 148 // subtract object … … 229 165 psFree (fitSources); 230 166 psFree (norm); 231 psFree (skyfit);232 167 psFree (errors); 233 psFree (border);234 168 235 169 psLogMsg ("psphot.ensemble", PS_LOG_INFO, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot.linear")); 236 237 psphotVisualShowResidualImage (readout);238 psphotVisualPlotChisq (sources);239 // psphotVisualShowFlags (sources);240 241 // We have to place this visualization here because the models are not realized until242 // psphotGuessModels or fitted until psphotFitSourcesLinear.243 psphotVisualShowPSFStars (recipe, psf, sources);244 170 245 171 return true; 246 172 } 247 173 248 // XXX do we need this? 249 // XXX disallow the simultaneous sky fit and remove this code... 250 251 // Calculate the weight terms for the sky fit component of the matrix. This function operates 252 // on the pixels which correspond to all of the sources of interest. These elements fill in 253 // the border matrix components in the sparse matrix equation. 254 static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal) { 255 256 // generate the image-wide weight terms 257 // turn on MARK for all image pixels 258 psRegion fullArray = psRegionSet (0, 0, 0, 0); 259 fullArray = psRegionForImage (readout->mask, fullArray); 260 psImageMaskRegion (readout->mask, fullArray, "OR", markVal); 261 262 // turn off MARK for all object pixels 263 for (int i = 0; i < sources->n; i++) { 264 pmSource *source = sources->data[i]; 265 pmModel *model = pmSourceGetModel (NULL, source); 266 if (model == NULL) continue; 267 float x = model->params->data.F32[PM_PAR_XPOS]; 268 float y = model->params->data.F32[PM_PAR_YPOS]; 269 psImageMaskCircle (source->maskView, x, y, model->fitRadius, "AND", PS_NOT_IMAGE_MASK(markVal)); 270 } 271 272 // accumulate the image statistics from the masked regions 273 psF32 **image = readout->image->data.F32; 274 psF32 **variance = readout->variance->data.F32; 275 psImageMaskType **mask = readout->mask->data.PS_TYPE_IMAGE_MASK_DATA; 276 277 double w, x, y, x2, xy, y2, xc, yc, wt, f, fo, fx, fy; 278 w = x = y = x2 = xy = y2 = fo = fx = fy = 0; 279 280 int col0 = readout->image->col0; 281 int row0 = readout->image->row0; 282 283 for (int j = 0; j < readout->image->numRows; j++) { 284 for (int i = 0; i < readout->image->numCols; i++) { 285 if (mask[j][i]) continue; 286 if (constant_weights) { 287 wt = 1.0; 288 } else { 289 wt = variance[j][i]; 290 } 291 f = image[j][i]; 292 w += 1/wt; 293 fo += f/wt; 294 if (SKY_FIT_ORDER == 0) continue; 295 296 xc = i + col0; 297 yc = j + row0; 298 x += xc/wt; 299 y += yc/wt; 300 x2 += xc*xc/wt; 301 xy += xc*yc/wt; 302 y2 += yc*yc/wt; 303 fx += f*xc/wt; 304 fy += f*yc/wt; 305 } 306 } 307 308 // turn off MARK for all image pixels 309 psImageMaskRegion (readout->mask, fullArray, "AND", PS_NOT_IMAGE_MASK(markVal)); 310 311 // set the Border T elements 312 psSparseBorderElementG (border, 0, fo); 313 psSparseBorderElementT (border, 0, 0, w); 314 if (SKY_FIT_ORDER > 0) { 315 psSparseBorderElementG (border, 0, fx); 316 psSparseBorderElementG (border, 0, fy); 317 psSparseBorderElementT (border, 1, 0, x); 318 psSparseBorderElementT (border, 2, 0, y); 319 psSparseBorderElementT (border, 0, 1, x); 320 psSparseBorderElementT (border, 1, 1, x2); 321 psSparseBorderElementT (border, 2, 1, xy); 322 psSparseBorderElementT (border, 0, 2, y); 323 psSparseBorderElementT (border, 1, 2, xy); 324 psSparseBorderElementT (border, 2, 2, y2); 325 } 326 327 return true; 174 // sort by Y (ascending) 175 int pmPhotObjSortBySN (const void **a, const void **b) 176 { 177 pmPhotObj *objA = *(pmPhotObj **)a; 178 pmPhotObj *objB = *(pmPhotObj **)b; 179 180 psAssert (objA->sources, "missing sources?"); 181 psAssert (objB->sources, "missing sources?"); 182 183 psAssert (objA->sources->n, "missing sources"); 184 psAssert (objB->sources->n, "missing sources"); 185 186 psAssert (objA->sources->data[0], "missing sources"); 187 psAssert (objB->sources->data[0], "missing sources"); 188 189 pmSource *A = objA->sources->data[0]; 190 pmSource *B = objB->sources->data[0]; 191 192 psF32 fA = (A->peak == NULL) ? 0 : A->peak->y; 193 psF32 fB = (B->peak == NULL) ? 0 : B->peak->y; 194 195 psF32 diff = fA - fB; 196 if (diff > FLT_EPSILON) return (+1); 197 if (diff < FLT_EPSILON) return (-1); 198 return (0); 328 199 } 200 -
branches/eam_branches/stackphot.20100406/psphot/src/psphotReadout.c
r27532 r27625 34 34 35 35 // Generate the mask and weight images, including the user-defined analysis region of interest 36 psphotSetMaskAndVariance (config, view); 36 if (!psphotSetMaskAndVariance (config, view)) { 37 return psphotReadoutCleanup(config, view); 38 } 37 39 if (!strcasecmp (breakPt, "NOTHING")) { 38 40 return psphotReadoutCleanup(config, view); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackArguments.c
r26894 r27625 2 2 3 3 static void usage(pmConfig *config, int exitCode); 4 static void writeHelpInfo( pmConfig* config,FILE* ofile);4 static void writeHelpInfo(FILE* ofile); 5 5 6 6 pmConfig *psphotStackArguments(int argc, char **argv) { 7 7 8 8 int N; 9 bool status;10 9 11 10 // print help info 12 if (psArgumentGet(argc, argv, "-help")) writeHelpInfo( argv[0], config,stdout);13 if (psArgumentGet(argc, argv, "-h")) writeHelpInfo( argv[0], config,stdout);11 if (psArgumentGet(argc, argv, "-help")) writeHelpInfo(stdout); 12 if (psArgumentGet(argc, argv, "-h")) writeHelpInfo(stdout); 14 13 15 14 // load config data from default locations … … 29 28 // Number of threads is handled 30 29 PSARGUMENTS_INSTANTIATE_THREADSARG( psphot, config, argc, argv ) 31 32 // photcode : used in output to supplement header data (argument or recipe?)33 if ((N = psArgumentGet (argc, argv, "-photcode"))) {34 if (argc <= N+1) {35 psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);36 exit(PS_EXIT_CONFIG_ERROR);37 }38 psArgumentRemove (N, &argc, argv);39 psMetadataAddStr (options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", argv[N]);40 psArgumentRemove (N, &argc, argv);41 }42 30 43 31 // visual : interactive display mode … … 90 78 } 91 79 92 static void writeHelpInfo( pmConfig* config,FILE* ofile)80 static void writeHelpInfo(FILE* ofile) 93 81 { 94 82 fprintf(ofile, 95 "Usage: psphotStack -input ( input.mdc) outroot\n"83 "Usage: psphotStack -input (INPUTS.mdc) (OUTROOT)\n" 96 84 "\n" 97 "where :\n"98 " FileNameList is a text file containing filenames, one per line\n"99 " MaskFileNameList is a text file of mask filenames, one per line\n"100 " VarFileNameList is a text file of variance filenames, one per line\n"101 " OutFileBaseNameis the 'root name' for output files\n"85 "where INPUTS.mdc contains various METADATAs, each with:\n" 86 "\tIMAGE(STR): Image filename\n" 87 "\tMASK(STR): Mask filename\n" 88 "\tVARIANCE(STR): Variance map filename\n" 89 "OUTROOT is the 'root name' for output files\n" 102 90 "\n" 103 91 "additional options:\n" … … 136 124 " -trace-levels\n" 137 125 " print current trace levels\n"); 138 psFree(config);139 pmConfigDone();140 126 psLibFinalize(); 141 127 exit(PS_EXIT_SUCCESS); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackChisqImage.c
r27547 r27625 12 12 psTimerStart ("psphot.chisq.image"); 13 13 14 pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.OUTPUT", 0); 15 psAssert (chisqFile, "missing chisq image FPA?"); 16 17 pmCell *chisqCell = pmFPAviewThisCell(view, chisqFile->fpa); 18 14 19 // create a holder for the image 15 pmReadout *chiImage = pmReadoutAlloc(); 20 pmReadout *chiReadout = pmFPAviewThisReadout(view, chisqFile->fpa); 21 if (!chiReadout) { 22 chiReadout = pmReadoutAlloc(chisqCell); 23 } else { 24 psMemIncrRefCounter(chiReadout); 25 } 16 26 17 27 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); … … 20 30 // loop over the available readouts 21 31 for (int i = 0; i < num; i++) { 22 if (!psphotStackChisqImageAddReadout(config, view, chi Image, "PSPHOT.INPUT", i)) {32 if (!psphotStackChisqImageAddReadout(config, view, chiReadout, "PSPHOT.INPUT", i)) { 23 33 psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i); 24 34 return false; … … 26 36 } 27 37 38 num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 39 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 40 41 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.CHISQ.NUM", PS_META_REPLACE, "", num); 42 num++; 43 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", num); 44 28 45 // need to save the resulting image somewhere (PSPHOT.INPUT?) 46 if (!psMetadataAddPtr(config->files, PS_LIST_TAIL, "PSPHOT.INPUT", PS_DATA_UNKNOWN | PS_META_DUPLICATE_OK, "", chisqFile)) { 47 psError(PM_ERR_CONFIG, false, "could not add chisqFPA to config files"); 48 return false; 49 } 29 50 30 51 psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image")); 31 52 53 psFree (chiReadout); 32 54 return true; 33 55 } 34 56 35 57 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration 36 pmFPAview *view,58 const pmFPAview *view, 37 59 pmReadout *chiReadout, 38 60 char *filename, -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackImageLoop.c
r27547 r27625 7 7 } 8 8 9 bool psphotImageLoop (pmConfig *config) { 10 11 bool status; 12 pmChip *chip; 13 pmCell *cell; 14 pmReadout *readout; 9 bool psphotStackImageLoop (pmConfig *config) { 15 10 16 11 pmFPAview *view = pmFPAviewAlloc (0); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackParseCamera.c
r26894 r27625 15 15 } 16 16 17 psMetadata *item == NULL;17 psMetadataItem *item = NULL; 18 18 int nInputs = 0; 19 while ((item = psMetadataGet Index(inputs, nInputs)) != NULL) {19 while ((item = psMetadataGet(inputs, nInputs)) != NULL) { 20 20 if (item->type != PS_DATA_METADATA) { 21 21 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Component %s of the input metadata is not of type METADATA", item->name); … … 34 34 pmFPAfile *imageFile = defineFile(config, NULL, "PSPHOT.INPUT", image, PM_FPA_FILE_IMAGE); // File for image 35 35 if (!imageFile) { 36 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image);36 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", nInputs, image); 37 37 return false; 38 38 } … … 41 41 if (mask && strlen(mask) > 0) { 42 42 if (!defineFile(config, imageFile, "PSPHOT.INPUT.MASK", mask, PM_FPA_FILE_MASK)) { 43 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask);43 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", nInputs, mask); 44 44 return false; 45 45 } 46 46 } 47 47 48 psString variance = psMetadataLookupStr(& mdok, input, "VARIANCE"); // Name of variance map48 psString variance = psMetadataLookupStr(&status, input, "VARIANCE"); // Name of variance map 49 49 if (variance && strlen(variance) > 0) { 50 50 if (!defineFile(config, imageFile, "PSPHOT.INPUT.VARIANCE", variance, PM_FPA_FILE_VARIANCE)) { 51 psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance);51 psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", nInputs, variance); 52 52 return false; 53 53 } … … 58 58 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", nInputs); 59 59 60 // generate an pmFPAimage for the chisqImage 61 pmFPAfile *chisqImage = pmFPAfileDefineOutput(config, NULL, "PSPHOT.CHISQ.IMAGE"); 62 if (!chisqImage) { 63 psError(PSPHOT_ERR_CONFIG, false, "Trouble defining PSPHOT.CHISQ.IMAGE"); 64 return false; 65 } 66 pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PPIMAGE.CHISQ.MASK"); 67 if (!chisqMask) { 68 psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.CHISQ.MASK")); 69 return NULL; 70 } 71 if (chisqMask->type != PM_FPA_FILE_MASK) { 72 psError(PS_ERR_IO, true, "PPIMAGE.CHISQ.MASK is not of type MASK"); 73 return NULL; 74 } 75 pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PPIMAGE.CHISQ.VARIANCE"); 76 if (!chisqVariance) { 77 psError(PS_ERR_IO, false, _("Unable to generate output file from PPIMAGE.CHISQ.VARIANCE")); 78 return NULL; 79 } 80 if (chisqVariance->type != PM_FPA_FILE_VARIANCE) { 81 psError(PS_ERR_IO, true, "PPIMAGE.CHISQ.VARIANCE is not of type VARIANCE"); 82 return NULL; 83 } 84 85 # if (0) 60 86 // define the additional input/output files associated with psphot 61 87 // XXX figure out which files are needed by psphotStack … … 64 90 return false; 65 91 } 92 # endif 66 93 67 94 psTrace("psphot", 1, "Done with psphotStackParseCamera...\n"); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackReadout.c
r26894 r27625 13 13 return false; 14 14 } 15 // optional break-point for processing 16 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT"); 17 PS_ASSERT_PTR_NON_NULL (breakPt, false); 15 18 16 // set the photcode for this image (XXX currently goes into recipe, should it go into analysis?)19 // set the photcode for each image 17 20 if (!psphotAddPhotcode (config, view)) { 18 21 psError (PSPHOT_ERR_CONFIG, false, "trouble defining the photcode"); … … 20 23 } 21 24 22 // generate a background model (median, smoothed image)23 if (!psphotSetMaskAndVariance (config, view , recipe)) {24 return psphotReadoutCleanup (config, NULL, recipe, NULL, NULL, NULL);25 // Generate the mask and weight images 26 if (!psphotSetMaskAndVariance (config, view)) { 27 return psphotReadoutCleanup (config, view); 25 28 } 26 29 if (!strcasecmp (breakPt, "NOTHING")) { 27 return psphotReadoutCleanup (config, NULL, recipe, NULL, NULL, NULL);30 return psphotReadoutCleanup (config, view); 28 31 } 29 32 30 // optional break-point for processing31 char *breakPt = psMetadataLookupStr (NULL, recipe, "BREAK_POINT");32 PS_ASSERT_PTR_NON_NULL (breakPt, false);33 34 33 // generate a background model (median, smoothed image) 34 // XXX I think this is not defined correctly for an array of images. 35 35 if (!psphotModelBackground (config, view)) { 36 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);36 return psphotReadoutCleanup (config, view); 37 37 } 38 38 if (!psphotSubtractBackground (config, view)) { 39 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL);39 return psphotReadoutCleanup (config, view); 40 40 } 41 41 if (!strcasecmp (breakPt, "BACKMDL")) { 42 return psphotReadoutCleanup (config, readout, recipe, NULL, NULL, NULL); 42 return psphotReadoutCleanup (config, view); 43 } 44 45 // load the psf model, if suppled. FWHM_X,FWHM_Y,etc are determined and saved on 46 // readout->analysis XXX this function currently only works with a single PSPHOT.INPUT 47 if (!psphotLoadPSF (config, view)) { 48 psError (PSPHOT_ERR_UNKNOWN, false, "error loading psf model"); 49 return psphotReadoutCleanup (config, view); 50 } 51 52 if (!psphotStackChisqImage(config, view)) { 53 psError (PSPHOT_ERR_UNKNOWN, false, "failure to generate chisq image"); 54 return psphotReadoutCleanup (config, view); 55 } 56 if (!strcasecmp (breakPt, "CHISQ")) { 57 return psphotReadoutCleanup (config, view); 43 58 } 44 59 45 60 // find the detections (by peak and/or footprint) in the image. 46 pmDetections *detections = psphotFindDetections (NULL, readout, recipe);47 if (!detections) {48 ps LogMsg ("psphot", 3, "unable to find detections in this image");49 return psphotReadoutCleanup (config, readout, recipe, detections, psf, NULL);61 if (!psphotFindDetections (config, view, true)) { // pass 1 62 // this only happens if we had an error in psphotFindDetections 63 psError (PSPHOT_ERR_UNKNOWN, false, "failure in peak analysis"); 64 return psphotReadoutCleanup (config, view); 50 65 } 51 66 52 // construct sources and measure basic stats 53 psArray *sources = psphotSourceStats (config, readout, detections, true); 54 if (!sources) return false; 67 // construct sources and measure basic stats (saved on detections->newSources) 68 if (!psphotSourceStats (config, view, true)) { // pass 1 69 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 70 return psphotReadoutCleanup (config, view); 71 } 55 72 if (!strcasecmp (breakPt, "PEAKS")) { 56 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);73 return psphotReadoutCleanup(config, view); 57 74 } 58 75 59 // find blended neighbors of very saturated stars 60 // XXX merge this with Basic Deblend? 61 psphotDeblendSatstars (readout, sources, recipe); 76 // find blended neighbors of very saturated stars (detections->newSources) 77 if (!psphotDeblendSatstars (config, view)) { 78 psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 79 return psphotReadoutCleanup (config, view); 80 } 62 81 63 // mark blended peaks PS_SOURCE_BLEND 64 if (!psphotBasicDeblend ( sources, recipe)) {65 ps LogMsg ("psphot", 3, "failed on deblend analysis");66 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);82 // mark blended peaks PS_SOURCE_BLEND (detections->newSources) 83 if (!psphotBasicDeblend (config, view)) { 84 psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 85 return psphotReadoutCleanup (config, view); 67 86 } 68 87 69 88 // classify sources based on moments, brightness 70 if (!psphotRoughClass (readout, sources, recipe, havePSF)) { 71 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 72 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 89 if (!psphotRoughClass (config, view)) { 90 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); 91 return psphotReadoutCleanup (config, view); 92 } 93 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 94 if (!psphotImageQuality (config, view)) { // pass 1 95 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); 96 return psphotReadoutCleanup(config, view); 73 97 } 74 98 if (!strcasecmp (breakPt, "MOMENTS")) { 75 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources);99 return psphotReadoutCleanup (config, view); 76 100 } 77 101 78 if (!havePSF && !psphotImageQuality (recipe, sources)) { 79 psLogMsg("psphot", 3, "failed to measure image quality"); 80 return psphotReadoutCleanup(config, readout, recipe, detections, psf, sources); 102 // use bright stellar objects to measure PSF if we were supplied a PSF for any input file, 103 // this step is skipped 104 if (!psphotChoosePSF (config, view)) { // pass 1 105 psLogMsg ("psphot", 3, "failure to construct a psf model"); 106 return psphotReadoutCleanup (config, view); 107 } 108 if (!strcasecmp (breakPt, "PSFMODEL")) { 109 return psphotReadoutCleanup (config, view); 81 110 } 82 111 83 // if we were not supplied a PSF, choose one here84 if (psf == NULL) {85 // use bright stellar objects to measure PSF86 // XXX if we do not have enough stars to generate the PSF, build one87 // from the SEEING guess and model class88 psf = psphotChoosePSF (readout, sources, recipe);89 if (psf == NULL) {90 psLogMsg ("psphot", 3, "failure to construct a psf model");91 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);92 }93 havePSF = true;94 }95 if (!strcasecmp (breakPt, "PSFMODEL")) {96 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);97 }98 psphotVisualShowPSFModel (readout, psf);99 100 112 // include externally-supplied sources 101 psphotLoadExtSources (config, view, sources); 113 // XXX fix this in the new multi-input context 114 // psphotLoadExtSources (config, view); // pass 1 102 115 103 116 // construct an initial model for each object, set the radius to fitRadius, set circular fit mask 104 psphotGuessModels (config, readout, sources, psf);117 psphotGuessModels (config, view); 105 118 119 // merge the newly selected sources into the existing list 120 // NOTE: merge OLD and NEW 121 psphotMergeSources (config, view); 122 123 // *** generate the objects (which unify the sources from the different images) 124 // pmArray *objects = psphotMatchSources (config, view); 125 106 126 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 107 psphotFitSourcesLinear (readout, sources, recipe, psf, FALSE); 108 109 // We have to place these visualizations here because the models are not realized until 110 // psphotGuessModels or fitted until psphotFitSourcesLinear. 111 psphotVisualShowPSFStars (recipe, psf, sources); 127 // psphotFitSourcesLinearStack (config, objects, FALSE); 112 128 113 129 // identify CRs and extended sources 114 psphotSourceSize (config, readout, sources, recipe, psf, 0); 115 if (!strcasecmp (breakPt, "ENSEMBLE")) { 116 goto finish; 117 } 118 psphotVisualShowSatStars (recipe, psf, sources); 119 120 // non-linear PSF and EXT fit to brighter sources 121 // replace model flux, adjust mask as needed, fit, subtract the models (full stamp) 122 psphotBlendFit (config, readout, sources, psf); 123 124 // replace all sources 125 psphotReplaceAllSources (sources, recipe); 126 127 // linear fit to include all sources (subtract again) 128 psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE); 129 130 // if we only do one pass, skip to extended source analysis 131 if (!strcasecmp (breakPt, "PASS1")) { 132 goto pass1finish; 133 } 134 // NOTE: possibly re-measure background model here with objects subtracted 135 136 // add noise for subtracted objects 137 psphotAddNoise (readout, sources, recipe); 138 139 // find fainter sources (pass 2) 140 detections = psphotFindDetections (detections, readout, recipe); 141 142 // remove noise for subtracted objects (ie, return to normal noise level) 143 psphotSubNoise (readout, sources, recipe); 144 145 // define new sources based on only the new peaks 146 psArray *newSources = psphotSourceStats (config, readout, detections, false); 147 148 // set source type 149 if (!psphotRoughClass (readout, newSources, recipe, havePSF)) { 150 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 151 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources); 152 } 153 154 // create full input models, set the radius to fitRadius, set circular fit mask 155 psphotGuessModels (config, readout, newSources, psf); 156 157 // replace all sources so fit below applies to all at once 158 psphotReplaceAllSources (sources, recipe); 159 160 // merge the newly selected sources into the existing list 161 psphotMergeSources (sources, newSources); 162 psFree (newSources); 163 164 // linear fit to all sources 165 psphotFitSourcesLinear (readout, sources, recipe, psf, TRUE); 166 167 pass1finish: 168 169 // measure source size for the remaining sources 170 psphotSourceSize (config, readout, sources, recipe, psf, 0); 171 172 psphotExtendedSourceAnalysis (readout, sources, recipe); 173 174 psphotExtendedSourceFits (readout, sources, recipe); 175 176 finish: 177 178 // plot positive sources 179 // psphotSourcePlots (readout, sources, recipe); 130 psphotSourceSize (config, view, TRUE); 180 131 181 132 // measure aperture photometry corrections 182 if (!psphotApResid (config, readout, sources, psf)) {133 if (!psphotApResid (config, view)) { 183 134 psLogMsg ("psphot", 3, "failed on psphotApResid"); 184 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);135 return psphotReadoutCleanup (config, view); 185 136 } 186 137 187 138 // calculate source magnitudes 188 psphotMagnitudes(config, readout, view, sources, psf);139 psphotMagnitudes(config, view); 189 140 190 if (!psphotEfficiency(config, readout, view, psf, recipe, sources)) {141 if (!psphotEfficiency(config, view)) { 191 142 psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources"); 192 143 psErrorClear(); … … 200 151 201 152 // drop the references to the image pixels held by each source 202 psphotSourceFreePixels ( sources);153 psphotSourceFreePixels (config, view); 203 154 204 155 // create the exported-metadata and free local data 205 return psphotReadoutCleanup (config, readout, recipe, detections, psf, sources);156 return psphotReadoutCleanup (config, view); 206 157 } 207 158
Note:
See TracChangeset
for help on using the changeset viewer.
