Changeset 27649
- Timestamp:
- Apr 9, 2010, 4:41:16 PM (16 years ago)
- Location:
- branches/eam_branches/stackphot.20100406/psphot/src
- Files:
-
- 21 edited
-
Makefile.am (modified) (1 diff)
-
psphot.h (modified) (1 diff)
-
psphotApResid.c (modified) (1 diff)
-
psphotChoosePSF.c (modified) (1 diff)
-
psphotEfficiency.c (modified) (1 diff)
-
psphotFitSourcesLinearStack.c (modified) (9 diffs)
-
psphotGuessModels.c (modified) (1 diff)
-
psphotImageLoop.c (modified) (1 diff)
-
psphotImageQuality.c (modified) (1 diff)
-
psphotMagnitudes.c (modified) (1 diff)
-
psphotModelBackground.c (modified) (1 diff)
-
psphotReadoutCleanup.c (modified) (2 diffs)
-
psphotRoughClass.c (modified) (1 diff)
-
psphotSkyReplace.c (modified) (1 diff)
-
psphotSourceMatch.c (modified) (1 diff)
-
psphotSourceSize.c (modified) (1 diff)
-
psphotStackChisqImage.c (modified) (6 diffs)
-
psphotStackImageLoop.c (modified) (3 diffs)
-
psphotStackParseCamera.c (modified) (5 diffs)
-
psphotStackReadout.c (modified) (5 diffs)
-
psphotSubtractBackground.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/stackphot.20100406/psphot/src/Makefile.am
r27625 r27649 87 87 # a psphot-variant for stack photometry 88 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 89 psphotStack.c \ 90 psphotStackArguments.c \ 91 psphotStackParseCamera.c \ 92 psphotStackImageLoop.c \ 93 psphotStackReadout.c \ 94 psphotStackChisqImage.c \ 95 psphotFitSourcesLinearStack.c \ 96 psphotSourceMatch.c \ 97 psphotCleanup.c 98 98 99 99 100 -
branches/eam_branches/stackphot.20100406/psphot/src/psphot.h
r27625 r27649 350 350 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration 351 351 const pmFPAview *view, 352 pmReadout * chiReadout,352 pmReadout **chiReadout, 353 353 char *filename, 354 354 int index); 355 355 356 bool psphotStackRemoveChisqFromInputs (pmConfig *config); 357 bool pmFPAfileRemoveSingle(psMetadata *files, const char *name, int num); 358 359 psArray *psphotMatchSources (pmConfig *config, const pmFPAview *view); 360 bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index); 361 bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS); 362 363 bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final); 364 int pmPhotObjSortBySN (const void **a, const void **b); 365 int pmPhotObjSortByX (const void **a, const void **b); 356 366 357 367 #endif -
branches/eam_branches/stackphot.20100406/psphot/src/psphotApResid.c
r26894 r27649 16 16 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 17 17 18 // skip the chisq image (optionally?) 19 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 20 if (!status) chisqNum = -1; 21 18 22 // loop over the available readouts 19 23 for (int i = 0; i < num; i++) { 24 if (i == chisqNum) continue; // skip chisq image 20 25 if (!psphotApResidReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 21 26 psError (PSPHOT_ERR_CONFIG, false, "failed to measure aperture residual for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotChoosePSF.c
r27568 r27649 13 13 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 14 14 15 // skip the chisq image (optionally?) 16 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 17 if (!status) chisqNum = -1; 18 15 19 // loop over the available readouts 16 20 for (int i = 0; i < num; i++) { 21 if (i == chisqNum) continue; // skip chisq image 17 22 if (!psphotChoosePSFReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 18 23 psError (PSPHOT_ERR_CONFIG, false, "failed to choose a psf model for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotEfficiency.c
r27532 r27649 160 160 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 161 161 162 // skip the chisq image (optionally?) 163 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 164 if (!status) chisqNum = -1; 165 162 166 // loop over the available readouts 163 167 for (int i = 0; i < num; i++) { 168 if (i == chisqNum) continue; // skip chisq image 164 169 if (!psphotEfficiencyReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 165 170 psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotFitSourcesLinearStack.c
r27625 r27649 3 3 // XXX define the 'good' / 'bad' flags? 4 4 5 # define COVAR_FACTOR 1.0 6 5 7 bool psphotFitSourcesLinearStack (pmConfig *config, psArray *objects, bool final) { 6 8 7 9 bool status; 8 float x;9 float y;10 10 float f; 11 11 … … 29 29 // analysis is done in spatial order (to speed up overlap search) 30 30 // sort by first element in each source list 31 objects = psArraySort (objects, pmPhotObjSortBy Y);31 objects = psArraySort (objects, pmPhotObjSortByX); 32 32 33 33 // storage array for fitSources … … 66 66 } 67 67 } 68 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), sources->n);68 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), objects->n); 69 69 70 70 if (fitSources->n == 0) { … … 86 86 87 87 // diagonal elements of the sparse matrix (auto-cross-product) 88 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);88 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR); 89 89 psSparseMatrixElement (sparse, i, i, f); 90 90 91 91 // the formal error depends on the weighting scheme 92 92 if (CONSTANT_PHOTOMETRIC_WEIGHTS) { 93 float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor);93 float var = pmSourceModelDotModel (SRCi, SRCi, false, COVAR_FACTOR); 94 94 errors->data.F32[i] = 1.0 / sqrt(var); 95 95 } else { … … 98 98 99 99 // find the image x model value 100 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);100 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR); 101 101 psSparseVectorElement (sparse, i, f); 102 102 … … 109 109 110 110 // skip over disjoint source images, break after last possible overlap 111 if (SRC i->pixels->row0 + SRCi->pixels->numRows < SRCj->pixels->row0) break;112 if (SRC j->pixels->row0 + SRCj->pixels->numRows < SRCi->pixels->row0) continue;113 if (SRC i->pixels->col0 + SRCi->pixels->numCols < SRCj->pixels->col0) continue;114 if (SRC j->pixels->col0 + SRCj->pixels->numCols < SRCi->pixels->col0) continue;111 if (SRCj->pixels->row0 + SRCj->pixels->numRows < SRCi->pixels->row0) continue; // source(i) is above source(j) 112 if (SRCi->pixels->row0 + SRCi->pixels->numRows < SRCj->pixels->row0) continue; // source(i) is below source(j) 113 if (SRCj->pixels->col0 + SRCj->pixels->numCols < SRCi->pixels->col0) continue; // source(i) is right of source(j) 114 if (SRCi->pixels->col0 + SRCi->pixels->numCols < SRCj->pixels->col0) break; // source(i) is left of source(j) [no other source(j) can overlap source(i)] 115 115 116 116 // got an overlap; calculate cross-product and add to output array 117 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor);117 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR); 118 118 psSparseMatrixElement (sparse, j, i, f); 119 119 } … … 157 157 if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) continue; 158 158 pmModel *model = pmSourceGetModel (NULL, source); 159 pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, covarFactor);159 pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, COVAR_FACTOR); 160 160 } 161 161 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "get chisqs: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem); … … 172 172 } 173 173 174 // sort by Y(ascending)175 int pmPhotObjSortBy SN(const void **a, const void **b)174 // sort by X (ascending) 175 int pmPhotObjSortByX (const void **a, const void **b) 176 176 { 177 177 pmPhotObj *objA = *(pmPhotObj **)a; 178 178 pmPhotObj *objB = *(pmPhotObj **)b; 179 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; 180 psF32 fA = objA->x; 181 psF32 fB = objB->x; 194 182 195 183 psF32 diff = fA - fB; … … 198 186 return (0); 199 187 } 200 -
branches/eam_branches/stackphot.20100406/psphot/src/psphotGuessModels.c
r26894 r27649 15 15 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 16 16 17 // skip the chisq image (optionally?) 18 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 19 if (!status) chisqNum = -1; 20 17 21 // loop over the available readouts 18 22 for (int i = 0; i < num; i++) { 23 if (i == chisqNum) continue; // skip chisq image 19 24 if (!psphotGuessModelsReadout (config, view, "PSPHOT.INPUT", i)) { 20 25 psError (PSPHOT_ERR_CONFIG, false, "failed on to guess models for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotImageLoop.c
r25755 r27649 91 91 } 92 92 93 status = true; 94 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL"); 95 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV"); 96 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND"); 97 if (!status) { 98 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files"); 99 psFree (view); 100 return false; 101 } 93 // drop all versions of the internal files 94 status = true; 95 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL"); 96 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV"); 97 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND"); 98 if (!status) { 99 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files"); 100 psFree (view); 101 return false; 102 } 102 103 } 103 104 104 // save output which is saved at the chip level 105 105 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot."); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotImageQuality.c
r26894 r27649 16 16 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 17 17 18 // skip the chisq image (optionally?) 19 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 20 if (!status) chisqNum = -1; 21 18 22 // loop over the available readouts 19 23 for (int i = 0; i < num; i++) { 24 if (i == chisqNum) continue; // skip chisq image 20 25 if (!psphotImageQualityReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 21 26 psError (PSPHOT_ERR_CONFIG, false, "failed on to measure image quality for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotMagnitudes.c
r27532 r27649 12 12 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 13 13 14 // skip the chisq image (optionally?) 15 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 16 if (!status) chisqNum = -1; 17 14 18 // loop over the available readouts 15 19 for (int i = 0; i < num; i++) { 20 if (i == chisqNum) continue; // skip chisq image 16 21 17 22 // find the currently selected readout -
branches/eam_branches/stackphot.20100406/psphot/src/psphotModelBackground.c
r26894 r27649 371 371 372 372 psImageBinning *binning = psphotBackgroundBinning(readout->image, config); // Image binning parameters 373 pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning );374 pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning );373 pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning, index); 374 pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning, index); 375 375 376 376 if (!psphotModelBackgroundReadout(model->image, modelStdev->image, model->analysis, readout, binning, config)) { -
branches/eam_branches/stackphot.20100406/psphot/src/psphotReadoutCleanup.c
r26894 r27649 53 53 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 54 54 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 55 psArray *sources = detections ->allSources;55 psArray *sources = detections ? detections->allSources : NULL; 56 56 // XXX where do we free these, in here (psMetadataRemove?) 57 57 … … 73 73 // Check to see if the image quality was measured 74 74 // XXX not sure we want / need this test 75 if ( !psf) {75 if (0 && !psf) { 76 76 bool mdok; // Status of MD lookup 77 77 int nIQ = psMetadataLookupS32(&mdok, recipe, "IQ_NSTAR"); // Number of stars for IQ measurement -
branches/eam_branches/stackphot.20100406/psphot/src/psphotRoughClass.c
r26894 r27649 19 19 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 20 20 21 // skip the chisq image (optionally?) 22 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 23 if (!status) chisqNum = -1; 24 21 25 // loop over the available readouts 22 26 for (int i = 0; i < num; i++) { 27 if (i == chisqNum) continue; // skip chisq image 23 28 if (!psphotRoughClassReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 24 29 psError (PSPHOT_ERR_CONFIG, false, "failed on rough classification for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotSkyReplace.c
r26894 r27649 8 8 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 9 9 10 // skip the chisq image (optionally?) 11 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 12 if (!status) chisqNum = -1; 13 10 14 // loop over the available readouts 11 15 for (int i = 0; i < num; i++) { 16 if (i == chisqNum) continue; // skip chisq image 12 17 if (!psphotSkyReplaceReadout (config, view, "PSPHOT.INPUT", i)) { 13 18 psError (PSPHOT_ERR_CONFIG, false, "failed to replace sky for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceMatch.c
r27628 r27649 14 14 if (!psphotMatchSourcesReadout (objects, config, view, "PSPHOT.INPUT", i)) { 15 15 psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i); 16 return false; 16 psFree (objects); 17 return NULL; 17 18 } 18 19 } 20 21 // psphotMatchSourcesGenerate (objects, config, view, "PSPHOT.INPUT", i); 22 23 return objects; 24 } 25 26 bool psphotMatchSourcesReadout (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) { 27 28 bool status = false; 29 30 // select the appropriate recipe information 31 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 32 psAssert (recipe, "missing recipe?"); 33 34 int RADIUS = psMetadataLookupF32 (&status, recipe, "PSPHOT.STACK.MATCH.RADIUS"); 35 psAssert (status, "programming error: must define PSPHOT.STACK.MATCH.RADIUS"); 36 37 // find the currently selected readout 38 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 39 psAssert (file, "missing file?"); 40 41 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 42 psAssert (readout, "missing readout?"); 43 44 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 45 psAssert (detections, "missing detections?"); 46 psAssert (detections->newSources, "new sources not defined?"); 47 psAssert (!detections->allSources, "all sources already defined?"); 48 49 // XXX TEST: 50 if (detections->newSources) { 51 psphotMatchSourcesToObjects(objects, detections->newSources, RADIUS); 52 } 53 19 54 return true; 20 55 } 21 56 22 // we need a couple of functions to distinguish coincident sources:23 // XXX these are similar (identical?) to the goals of pmSourceMatch.c24 25 57 # define NEXT1 { i++; continue; } 26 58 # define NEXT2 { j++; continue; } 27 28 bool psphotSourceMerge (psArray *objects, pmConfig *config, const pmFPAview *view, char *filename, int index) { 59 bool psphotMatchSourcesToObjects (psArray *objects, psArray *sources, float RADIUS) { 29 60 30 61 float dx, dy; 31 62 63 float RADIUS2 = RADIUS*RADIUS; 64 32 65 // sort the source list by X 33 pmSourceSortByX (sources1);34 pmSourceSortByX (sources2);66 sources = psArraySort (sources, pmSourceSortByX); 67 objects = psArraySort (objects, pmPhotObjSortByX); 35 68 69 psVector *found = psVectorAlloc(sources->n, PS_TYPE_U8); 70 psVectorInit (found, 0); 71 72 // match sources to existing objects 73 74 psLogMsg ("psphot", PS_LOG_DETAIL, "attempt to match sources (%ld vs %ld)", sources->n, objects->n); 75 36 76 int i, j; 37 for (i = j = 0; (i < sources 1->n) && (j < sources2->n); ) {77 for (i = j = 0; (i < sources->n) && (j < objects->n); ) { 38 78 39 pmSource *src1 = sources1->data[i];40 pm Source *src2 = sources2->data[j];79 pmSource *src = sources->data[i]; 80 pmPhotObj *obj = objects->data[j]; 41 81 42 if (!src 1) NEXT1;43 if (!src 1->peak) NEXT1;44 if (!finite(src 1->peak->xf)) NEXT1;45 if (!finite(src 1->peak->yf)) NEXT1;82 if (!src) NEXT1; 83 if (!src->peak) NEXT1; 84 if (!finite(src->peak->xf)) NEXT1; 85 if (!finite(src->peak->yf)) NEXT1; 46 86 47 if (!src2) NEXT2; 48 if (!src2->peak) NEXT2; 49 if (!finite(src2->peak->xf)) NEXT2; 50 if (!finite(src2->peak->yf)) NEXT2; 87 if (!obj) NEXT2; 88 if (!finite(obj->x)) NEXT2; 89 if (!finite(obj->y)) NEXT2; 51 90 52 dx = src 1->peak->xf - src2->peak->xf;91 dx = src->peak->xf - obj->x; 53 92 if (dx < -1.02*RADIUS) NEXT1; 54 93 if (dx > +1.02*RADIUS) NEXT2; 55 94 56 95 // we are within match range, look for matches: 57 for (int J = j; (dx > -1.02*radius) && (J < sources2->n); J++) { 96 int Jmin = -1; 97 float Rmin = RADIUS2; 98 for (int J = j; (dx > -1.02*RADIUS) && (J < objects->n); J++) { 58 99 59 dx = src1->peak->xf - src2->peak->xf; 60 dy = src1->peak->yf - src2->peak->yf; 100 obj = objects->data[J]; 101 102 dx = src->peak->xf - obj->x; 103 dy = src->peak->yf - obj->y; 61 104 62 dr = dx*dx + dy*dy;105 float dr = dx*dx + dy*dy; 63 106 if (dr > RADIUS2) continue; 64 65 // add to group? 66 } 107 if (dr < Rmin) { 108 Rmin = dr; 109 Jmin = J; 110 } 111 } 112 113 // no match, try next source 114 if (Jmin == -1) { 115 i++; 116 continue; 117 } 118 obj = objects->data[Jmin]; 119 120 // add to object 121 pmPhotObjAddSource (obj, src); 122 found->data.U8[i] = 1; 67 123 i++; 68 124 } 125 126 // add missed sources to new objects 127 128 for (i = 0; i < sources->n; i++) { 129 130 if (found->data.U8[i]) continue; 131 132 pmSource *src = sources->data[i]; 133 134 pmPhotObj *obj = pmPhotObjAlloc(); 135 pmPhotObjAddSource(obj, src); 136 psArrayAdd (objects, 100, obj); 137 } 138 psLogMsg ("psphot", PS_LOG_DETAIL, "matched sources (%ld vs %ld)", sources->n, objects->n); 139 140 return true; 69 141 } -
branches/eam_branches/stackphot.20100406/psphot/src/psphotSourceSize.c
r27532 r27649 44 44 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 45 45 46 // skip the chisq image (optionally?) 47 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 48 if (!status) chisqNum = -1; 49 46 50 // loop over the available readouts 47 51 for (int i = 0; i < num; i++) { 52 if (i == chisqNum) continue; // skip chisq image 48 53 if (!psphotSourceSizeReadout (config, view, "PSPHOT.INPUT", i, recipe, getPSFsize)) { 49 54 psError (PSPHOT_ERR_CONFIG, false, "failed on source size analysis for PSPHOT.INPUT entry %d", i); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackChisqImage.c
r27625 r27649 12 12 psTimerStart ("psphot.chisq.image"); 13 13 14 pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ. OUTPUT", 0);14 pmFPAfile *chisqFile = pmFPAfileSelectSingle(config->files, "PSPHOT.CHISQ.IMAGE", 0); 15 15 psAssert (chisqFile, "missing chisq image FPA?"); 16 16 17 pmCell *chisqCell = pmFPAviewThisCell(view, chisqFile->fpa); 18 19 // create a holder for the image 20 pmReadout *chiReadout = pmFPAviewThisReadout(view, chisqFile->fpa); 21 if (!chiReadout) { 22 chiReadout = pmReadoutAlloc(chisqCell); 23 } else { 24 psMemIncrRefCounter(chiReadout); 25 } 17 pmReadout *chiReadout = NULL; 26 18 27 19 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); … … 30 22 // loop over the available readouts 31 23 for (int i = 0; i < num; i++) { 32 if (!psphotStackChisqImageAddReadout(config, view, chiReadout, "PSPHOT.INPUT", i)) {24 if (!psphotStackChisqImageAddReadout(config, view, &chiReadout, "PSPHOT.INPUT", i)) { 33 25 psError (PSPHOT_ERR_CONFIG, false, "failed to model background for PSPHOT.INPUT entry %d", i); 34 26 return false; … … 51 43 psLogMsg ("psphot", PS_LOG_INFO, "built chisq image: %f sec\n", psTimerMark ("psphot.chisq.image")); 52 44 53 psFree (chiReadout);54 45 return true; 55 46 } … … 57 48 bool psphotStackChisqImageAddReadout(const pmConfig *config, // Configuration 58 49 const pmFPAview *view, 59 pmReadout * chiReadout,50 pmReadout **chiReadout, 60 51 char *filename, 61 52 int index) … … 71 62 72 63 psImage *inImage = inReadout->image; 64 psAssert (inImage, "missing image?"); 65 73 66 psImage *inVariance = inReadout->variance; 67 psAssert (inVariance, "missing variance?"); 68 74 69 psImage *inMask = inReadout->mask; 70 psAssert (inMask, "missing mask?"); 75 71 76 psImage *chiImage = chiReadout->image; 77 psImage *chiVariance = chiReadout->variance; 78 psImage *chiMask = chiReadout->mask; 72 if (*chiReadout == NULL) { 73 *chiReadout = pmFPAGenerateReadout(config, view, "PSPHOT.CHISQ.IMAGE", input->fpa, NULL, 0); 74 } 75 76 psImage *chiImage = (*chiReadout)->image; 77 psAssert (chiImage, "missing chi image"); 78 79 psImage *chiVariance = (*chiReadout)->variance; 80 psAssert (chiVariance, "missing chi variance"); 81 82 psImage *chiMask = (*chiReadout)->mask; 83 psAssert (chiMask, "missing chi mask"); 79 84 80 85 // select the appropriate recipe information … … 105 110 return true; 106 111 } 112 113 bool psphotStackRemoveChisqFromInputs (pmConfig *config) { 114 115 bool status = false; 116 117 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 118 psAssert (status, "programming error: must define PSPHOT.CHISQ.NUM"); 119 120 int inputNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 121 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 122 123 pmFPAfileRemoveSingle (config->files, "PSPHOT.INPUT", chisqNum); 124 125 inputNum --; 126 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "", inputNum); 127 128 return true; 129 } 130 131 bool pmFPAfileRemoveSingle(psMetadata *files, const char *name, int num) 132 { 133 PS_ASSERT_PTR_NON_NULL(files, NULL); 134 PS_ASSERT_INT_NONNEGATIVE(num, NULL); 135 136 psList* mdList = files->list; 137 psHash* mdHash = files->hash; 138 139 // Generate a REGEX to select only items that match 'name' 140 psString regex = NULL; // Regular expression 141 if (name) { 142 if (!psMetadataLookup(files, name)) { 143 // No files match the requested name 144 return false; 145 } 146 psStringAppend(®ex, "^%s$", name); 147 } 148 149 psMetadataIterator *iter = psMetadataIteratorAlloc(files, PS_LIST_HEAD, regex); // Iterator 150 psFree(regex); 151 psMetadataItem *item; // Item from iteration 152 153 bool found = false; 154 int i = 0; // Counter 155 for (i = 0; !found && (item = psMetadataGetAndIncrement(iter)); i++) { 156 if (i == num) found = true; 157 } 158 psFree(iter); 159 if (!found) { 160 return false; 161 } 162 163 char *key = item->name; 164 165 // look up the name via hash to see if we have a multi or not 166 psMetadataItem* hashItem = psHashLookup(mdHash, name); 167 if (hashItem == NULL) { 168 psError(PS_ERR_UNKNOWN, false, _("Failed to remove metadata item, %s, from metadata table."), key); 169 return false; 170 } 171 172 if (hashItem->type == PS_DATA_METADATA_MULTI) { 173 // multiple entries with same key, remove just the specified one 174 psListRemoveData(hashItem->data.list, item); 175 } else { 176 psHashRemove(mdHash, key); 177 } 178 psListRemoveData(mdList, item); 179 180 return true; 181 } -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackImageLoop.c
r27625 r27649 9 9 bool psphotStackImageLoop (pmConfig *config) { 10 10 11 bool status; 12 pmChip *chip; 13 pmCell *cell; 14 pmReadout *readout; 15 16 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT"); 17 if (!status) { 18 psError(PSPHOT_ERR_PROG, false, "Can't find input data!"); 19 return false; 20 } 21 11 22 pmFPAview *view = pmFPAviewAlloc (0); 12 23 … … 14 25 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot."); 15 26 16 // XXX for now, we assume there is only a single chip in the PHU: 17 psphotStackReadout (config, view); 27 // for psphot, we force data to be read at the chip level 28 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 29 psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 30 if (! chip->process || ! chip->file_exists) { continue; } 31 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphotStack."); 32 33 // there is now only a single chip (multiple readouts?). loop over it and process 34 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 35 psLogMsg ("psphot", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 36 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Cell in psphotStack."); 37 38 // process each of the readouts 39 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 40 psLogMsg ("psphot", 6, "Readout %d: %x %x\n", view->readout, cell->file_exists, cell->process); 41 if (! readout->data_exists) { continue; } 42 43 // XXX for now, we assume there is only a single chip in the PHU: 44 if (!psphotStackReadout (config, view)) { 45 psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout); 46 psFree (view); 47 return false; 48 } 49 50 } 51 // drop all versions of the internal files 52 status = true; 53 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL"); 54 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV"); 55 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND"); 56 if (!status) { 57 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files"); 58 psFree (view); 59 return false; 60 } 61 } 62 // save output which is saved at the chip level 63 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot."); 64 } 65 // save output which is saved at the fpa level 66 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed ouput for FPA in psphot."); 18 67 19 68 // fail if we failed to handle an error … … 27 76 the easiest way to implement this is to assume we can pre-load the full set of images up front. 28 77 with 5 filters and 6000^2 (image, mask, var = 10 byte per pixel), we need 1.8GB, which is not too bad. 29 */78 */ 30 79 -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackParseCamera.c
r27625 r27649 15 15 } 16 16 17 psMetadataItem *item = NULL;18 int nInputs = 0;19 while ((item = psMetadataGet(inputs, nInputs)) != NULL) { 17 int nInputs = inputs->list->n; 18 for (int i = 0; i < nInputs; i++) { 19 psMetadataItem *item = psMetadataGet(inputs, i); 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)", nInputs, image);36 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image); 37 37 return false; 38 38 } … … 40 40 psString mask = psMetadataLookupStr(&status, input, "MASK"); // Name of mask 41 41 if (mask && strlen(mask) > 0) { 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)", nInputs, mask);42 if (!defineFile(config, imageFile, "PSPHOT.MASK", mask, PM_FPA_FILE_MASK)) { 43 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask); 44 44 return false; 45 45 } … … 48 48 psString variance = psMetadataLookupStr(&status, input, "VARIANCE"); // Name of variance map 49 49 if (variance && strlen(variance) > 0) { 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)", nInputs, variance);50 if (!defineFile(config, imageFile, "PSPHOT.VARIANCE", variance, PM_FPA_FILE_VARIANCE)) { 51 psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance); 52 52 return false; 53 53 } 54 54 } 55 nInputs ++; 55 // the output sources are carried on the input->fpa structures 56 pmFPAfile *outsources = pmFPAfileDefineOutputFromFile (config, imageFile, "PSPHOT.STACK.OUTPUT"); 57 if (!outsources) { 58 psError(PSPHOT_ERR_CONFIG, false, "Cannot find a rule for PSPHOT.STACK.OUTPUT"); 59 return false; 60 } 61 outsources->save = true; 62 outsources->fileID = i; // this is used to generate output names 56 63 } 57 64 psMetadataRemoveKey(config->arguments, "FILENAMES"); 58 65 psMetadataAddS32 (config->arguments, PS_LIST_TAIL, "PSPHOT.INPUT.NUM", PS_META_REPLACE, "number of inputs", nInputs); 66 67 if (!psphotSetMaskBits (config)) { 68 psError (PS_ERR_UNKNOWN, false, "failed to set mask bit values"); 69 return NULL; 70 } 59 71 60 72 // generate an pmFPAimage for the chisqImage … … 64 76 return false; 65 77 } 66 pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PPIMAGE.CHISQ.MASK"); 78 chisqImage->save = true; 79 80 pmFPAfile *chisqMask = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.MASK"); 67 81 if (!chisqMask) { 68 psError(PS_ERR_IO, false, _("Unable to generate output file from P PIMAGE.CHISQ.MASK"));82 psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.MASK")); 69 83 return NULL; 70 84 } 71 85 if (chisqMask->type != PM_FPA_FILE_MASK) { 72 psError(PS_ERR_IO, true, "P PIMAGE.CHISQ.MASK is not of type MASK");86 psError(PS_ERR_IO, true, "PSPHOT.CHISQ.MASK is not of type MASK"); 73 87 return NULL; 74 88 } 75 pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PPIMAGE.CHISQ.VARIANCE"); 89 chisqMask->save = true; 90 91 pmFPAfile *chisqVariance = pmFPAfileDefineOutput(config, chisqImage->fpa, "PSPHOT.CHISQ.VARIANCE"); 76 92 if (!chisqVariance) { 77 psError(PS_ERR_IO, false, _("Unable to generate output file from P PIMAGE.CHISQ.VARIANCE"));93 psError(PS_ERR_IO, false, _("Unable to generate output file from PSPHOT.CHISQ.VARIANCE")); 78 94 return NULL; 79 95 } 80 96 if (chisqVariance->type != PM_FPA_FILE_VARIANCE) { 81 psError(PS_ERR_IO, true, "P PIMAGE.CHISQ.VARIANCE is not of type VARIANCE");97 psError(PS_ERR_IO, true, "PSPHOT.CHISQ.VARIANCE is not of type VARIANCE"); 82 98 return NULL; 83 99 } 100 chisqVariance->save = true; 84 101 85 102 # if (0) -
branches/eam_branches/stackphot.20100406/psphot/src/psphotStackReadout.c
r27625 r27649 59 59 60 60 // find the detections (by peak and/or footprint) in the image. 61 // This finds the detections on Chisq image as well as the individuals 61 62 if (!psphotFindDetections (config, view, true)) { // pass 1 62 63 // this only happens if we had an error in psphotFindDetections … … 66 67 67 68 // construct sources and measure basic stats (saved on detections->newSources) 69 // only run this on detections from the input images, not chisq image 68 70 if (!psphotSourceStats (config, view, true)) { // pass 1 69 71 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 70 72 return psphotReadoutCleanup (config, view); 71 73 } 72 if (!strcasecmp (breakPt, "PEAKS")) { 73 return psphotReadoutCleanup(config, view); 74 75 // *** generate the objects (which unify the sources from the different images) 76 psArray *objects = psphotMatchSources (config, view); 77 78 // construct sources for the newly-generated sources (from other images) 79 if (!psphotSourceStats (config, view, false)) { // pass 1 80 psError(PSPHOT_ERR_UNKNOWN, false, "failure to generate sources"); 81 return psphotReadoutCleanup (config, view); 74 82 } 75 83 76 84 // 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 }85 // if (!psphotDeblendSatstars (config, view)) { 86 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on satstar deblend analysis"); 87 // return psphotReadoutCleanup (config, view); 88 // } 81 89 82 90 // 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);86 }91 // if (!psphotBasicDeblend (config, view)) { 92 // psError (PSPHOT_ERR_UNKNOWN, false, "failed on deblend analysis"); 93 // return psphotReadoutCleanup (config, view); 94 // } 87 95 88 96 // classify sources based on moments, brightness 97 // only run this on detections from the input images, not chisq image 89 98 if (!psphotRoughClass (config, view)) { 90 99 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classifications"); … … 92 101 } 93 102 // if we were not supplied a PSF model, determine the IQ stats here (detections->newSources) 103 // only run this on detections from the input images, not chisq image 94 104 if (!psphotImageQuality (config, view)) { // pass 1 95 105 psError (PSPHOT_ERR_UNKNOWN, false, "failed to measure image quality"); … … 121 131 psphotMergeSources (config, view); 122 132 123 // *** generate the objects (which unify the sources from the different images)124 // pmArray *objects = psphotMatchSources (config, view);125 126 133 // linear PSF fit to source peaks, subtract the models from the image (in PSF mask) 127 // psphotFitSourcesLinearStack (config, objects, FALSE); 134 psphotFitSourcesLinearStack (config, objects, FALSE); 135 psFree (objects); 128 136 129 137 // identify CRs and extended sources … … 153 161 psphotSourceFreePixels (config, view); 154 162 163 // remove chisq image from config->file:PSPHOT.INPUT (why?) 164 psphotStackRemoveChisqFromInputs(config); 165 155 166 // create the exported-metadata and free local data 156 167 return psphotReadoutCleanup (config, view); -
branches/eam_branches/stackphot.20100406/psphot/src/psphotSubtractBackground.c
r26894 r27649 23 23 pmFPAfile *modelFile = pmFPAfileSelectSingle(config->files, "PSPHOT.BACKMDL", index); // File of interest 24 24 assert (modelFile); 25 pmReadout *model = pmFPAviewThisReadout (view, modelFile->fpa); 25 26 pmReadout *model = NULL; 27 if (modelFile->mode == PM_FPA_MODE_INTERNAL) { 28 model = modelFile->readout; 29 } else { 30 model = pmFPAviewThisReadout (view, modelFile->fpa); 31 } 26 32 assert (model); 27 33
Note:
See TracChangeset
for help on using the changeset viewer.
