Changeset 6379
- Timestamp:
- Feb 7, 2006, 8:52:03 PM (20 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 27 edited
-
Makefile.am (modified) (1 diff)
-
pmCellSetMask.c (modified) (1 diff)
-
pmModelFitSet.c (modified) (1 diff)
-
pmSourceFitSet.c (modified) (5 diffs)
-
psModulesUtils.c (modified) (2 diffs)
-
psSparse.c (modified) (1 diff)
-
psphot.c (modified) (1 diff)
-
psphot.h (modified) (4 diffs)
-
psphotApResid.c (modified) (4 diffs)
-
psphotArguments.c (modified) (11 diffs)
-
psphotBasicDeblend.c (modified) (4 diffs)
-
psphotBlendFit.c (modified) (1 diff)
-
psphotChoosePSF.c (modified) (5 diffs)
-
psphotEnsemblePSF.c (modified) (6 diffs)
-
psphotFindPeaks.c (modified) (1 diff)
-
psphotFitGalaxies.c (modified) (1 diff)
-
psphotFullFit.c (modified) (1 diff)
-
psphotGrowthCurve.c (modified) (1 diff)
-
psphotImageLoop.c (modified) (3 diffs)
-
psphotLoadPixels.c (modified) (2 diffs)
-
psphotModelTest.c (modified) (5 diffs)
-
psphotOutput.c (modified) (8 diffs)
-
psphotParseCamera.c (modified) (2 diffs)
-
psphotReadout.c (modified) (3 diffs)
-
psphotRoughClass.c (modified) (1 diff)
-
psphotSourceFits.c (modified) (13 diffs)
-
psphotSourceStats.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/Makefile.am
r6311 r6379 31 31 psphotModelGroupInit.c \ 32 32 psphotGrowthCurve.c \ 33 psphotCleanup.c \ 33 34 psphotEvalPSF.c \ 34 35 psphotEvalFLT.c \ -
trunk/psphot/src/pmCellSetMask.c
r6311 r6379 1 1 # include "psphot.h" 2 2 3 // 2006.02.04 : no leaks 3 4 bool pmCellSetMask (pmCell *cell, psMetadata *recipe) { 4 5 -
trunk/psphot/src/pmModelFitSet.c
r5828 r6379 18 18 19 19 return true; 20 } 21 22 void pmModelFitSetClear (void) { 23 24 psFree (onePar); 25 psFree (oneDeriv); 26 return; 20 27 } 21 28 -
trunk/psphot/src/pmSourceFitSet.c
r5993 r6379 105 105 for (psS32 i = 0; i < source->pixels->numRows; i++) { 106 106 for (psS32 j = 0; j < source->pixels->numCols; j++) { 107 // skip masked points 107 108 if (source->mask->data.U8[i][j]) { 108 109 continue; 109 110 } 111 // skip zero-weight points 112 if (source->weight->data.F32[i][j] == 0) { 113 continue; 114 } 110 115 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 111 116 … … 115 120 x->data[nPix] = (psPtr *) coord; 116 121 y->data.F32[nPix] = source->pixels->data.F32[i][j]; 117 118 122 // psMinimizeLMChi2 takes wt = 1/dY^2 119 if (source->weight->data.F32[i][j] == 0) {120 continue;121 }122 123 yErr->data.F32[nPix] = 1.0 / source->weight->data.F32[i][j]; 123 124 nPix++; … … 131 132 psFree (y); 132 133 psFree (yErr); 134 psFree (params); 135 psFree (dparams); 136 psFree (paramMask); 133 137 return(false); 134 138 } … … 180 184 dparams->data.F32[i] = delta->data.F64[i]; 181 185 } 186 psFree (delta); 182 187 } 183 188 … … 217 222 psFree(covar); 218 223 psFree(paramMask); 224 psFree(params); 225 psFree(dparams); 226 psFree(params_min); 227 psFree(params_max); 228 psFree(beta_lim); 229 230 // free static memory used by pmModelFitSet 231 pmModelFitSetClear (); 219 232 220 233 rc = (onPic && fitStatus); -
trunk/psphot/src/psModulesUtils.c
r6311 r6379 180 180 181 181 if (config == NULL) return; 182 psFree (config->site); 183 psFree (config->camera); 184 psFree (config->recipe); 185 psFree (config->arguments); 186 psFree (config->options); 187 psFree (config->database); 182 188 return; 183 189 } … … 202 208 203 209 if (file == NULL) return; 210 psFree (file->phu); 211 psFree (file->filename); 212 psFree (file->fpa); 213 psFitsClose (file->fits); 204 214 return; 205 215 } -
trunk/psphot/src/psSparse.c
r5654 r6379 70 70 tSj->data.S32[i] = Sj->data.S32[j]; 71 71 } 72 psFree (index); 72 73 psFree (Aij); 73 74 psFree (Si); -
trunk/psphot/src/psphot.c
r6311 r6379 22 22 23 23 psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete")); 24 25 psFree (input); 26 psFree (config); 27 psphotCleanup (); 28 24 29 exit (0); 25 30 } -
trunk/psphot/src/psphot.h
r6311 r6379 13 13 # include "psModulesUtils.h" 14 14 # include "psSparse.h" 15 #include "pmFPAConstruct.h" 15 # include "pmFPAConstruct.h" 16 # include "pmConcepts.h" 16 17 17 18 # define PSPHOT_RECIPE "PSPHOT" … … 27 28 bool psphotReadout (pmReadout *readout, psMetadata *config); 28 29 bool ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum); 30 void psphotCleanup (void); 29 31 30 32 // psphotReadout functions … … 89 91 char *psphotSplitName (psMetadata *header); 90 92 void psphotOutputPrep (ppFile *file, ppConfig *config); 93 void psphotOutputCleanup (void); 91 94 char *psphotNameSubstitute (char *input, char *replace, char *key); 92 95 … … 103 106 psF32 pmModelFitSet (psVector *deriv, const psVector *params, const psVector *x); 104 107 bool pmModelFitSetInit (pmModelType type); 108 void pmModelFitSetClear (void); 105 109 106 110 // functions to support the source fitting process -
trunk/psphot/src/psphotApResid.c
r6056 r6379 1 1 # include "psphot.h" 2 static char DEFAULT_OPTION[] = "SKYBIAS"; 2 3 3 4 // measure the aperture residual statistics … … 69 70 // APTREND options : NONE SKYBIAS XY_LIN XY_QUAD SKY_XY_LIN FULL 70 71 char *ApTrendOption = psMetadataLookupPtr (&status, config, "APTREND"); 71 if (!status) ApTrendOption = psStringCopy ("SKYBIAS");72 if (!status) ApTrendOption = DEFAULT_OPTION; 72 73 73 74 // 3hi/1lo sigma clipping on the rflux vs metric fit … … 190 191 psf->ApTrend = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux); 191 192 } 192 193 # if (1)194 psPolynomial4D *poly = psf->ApTrend;195 for (int nt = 0; nt <= poly->nT; nt++) {196 for (int nz = 0; nz <= poly->nZ; nz++) {197 for (int ny = 0; ny <= poly->nY; ny++) {198 for (int nx = 0; nx <= poly->nX; nx++) {199 if (poly->mask[nx][ny][nz][nt]) continue;200 fprintf (stderr, "%d %d %d %d : %22.15g\n", nx, ny, nz, nt, poly->coeff[nx][ny][nz][nt]);201 }202 }203 }204 }205 # endif206 193 207 194 // construct the fitted values and the residuals … … 256 243 1e6*psf->ApTrend->coeff[0][2][0][0]); 257 244 258 // psFree (stats); 259 // psFree (mask); 260 // psFree (rflux); 261 // psFree (apResid); 262 245 psFree (mask); 246 psFree (xPos); 247 psFree (yPos); 248 psFree (flux); 249 psFree (r2rflux); 250 psFree (apResid); 251 psFree (dMag); 252 253 psFree (fit); 254 psFree (resid); 255 psFree (stats); 256 psFree (residStats); 263 257 return true; 264 258 } -
trunk/psphot/src/psphotArguments.c
r6311 r6379 27 27 if ((N = psArgumentGet (*argc, argv, "-mask"))) { 28 28 psArgumentRemove (N, argc, argv); 29 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MASK_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));29 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MASK_IMAGE", PS_META_REPLACE, "", argv[N]); 30 30 psArgumentRemove (N, argc, argv); 31 31 } … … 34 34 if ((N = psArgumentGet (*argc, argv, "-weight"))) { 35 35 psArgumentRemove (N, argc, argv); 36 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "WEIGHT_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));36 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "WEIGHT_IMAGE", PS_META_REPLACE, "", argv[N]); 37 37 psArgumentRemove (N, argc, argv); 38 38 } … … 41 41 if ((N = psArgumentGet (*argc, argv, "-resid"))) { 42 42 psArgumentRemove (N, argc, argv); 43 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "RESID_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));43 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "RESID_IMAGE", PS_META_REPLACE, "", argv[N]); 44 44 psArgumentRemove (N, argc, argv); 45 45 } … … 48 48 if ((N = psArgumentGet (*argc, argv, "-chip"))) { 49 49 psArgumentRemove (N, argc, argv); 50 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", psStringCopy(argv[N]));50 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", argv[N]); 51 51 psArgumentRemove (N, argc, argv); 52 52 } … … 65 65 if ((N = psArgumentGet (*argc, argv, "-model"))) { 66 66 psArgumentRemove (N, argc, argv); 67 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", psStringCopy (argv[N]));67 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", argv[N]); 68 68 psArgumentRemove (N, argc, argv); 69 69 } … … 72 72 if ((N = psArgumentGet (*argc, argv, "-fitmode"))) { 73 73 psArgumentRemove (N, argc, argv); 74 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", psStringCopy (argv[N]));74 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", argv[N]); 75 75 psArgumentRemove (N, argc, argv); 76 76 } 77 77 if ((N = psArgumentGet (*argc, argv, "-fitset"))) { 78 78 psArgumentRemove (N, argc, argv); 79 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", psStringCopy (argv[N]));79 psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", argv[N]); 80 80 psArgumentRemove (N, argc, argv); 81 81 } … … 88 88 if ((N = psArgumentGet (*argc, argv, "-psf"))) { 89 89 psArgumentRemove (N, argc, argv); 90 psMetadataAddStr (config->options, PS_LIST_TAIL, "PSF_INPUT_FILE", PS_META_REPLACE, "", psStringCopy(argv[N]));90 psMetadataAddStr (config->options, PS_LIST_TAIL, "PSF_INPUT_FILE", PS_META_REPLACE, "", argv[N]); 91 91 psArgumentRemove (N, argc, argv); 92 92 } … … 95 95 if ((N = psArgumentGet (*argc, argv, "-photcode"))) { 96 96 psArgumentRemove (N, argc, argv); 97 psMetadataAddStr (config->options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));97 psMetadataAddStr (config->options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", argv[N]); 98 98 psArgumentRemove (N, argc, argv); 99 99 } … … 102 102 if ((N = psArgumentGet (*argc, argv, "-break"))) { 103 103 psArgumentRemove (N, argc, argv); 104 psMetadataAddStr (config->options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N]));104 psMetadataAddStr (config->options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", argv[N]); 105 105 psArgumentRemove (N, argc, argv); 106 106 } … … 109 109 if ((N = psArgumentGet (*argc, argv, "-fitmode"))) { 110 110 psArgumentRemove (N, argc, argv); 111 psMetadataAddStr (config->options, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N]));111 psMetadataAddStr (config->options, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", argv[N]); 112 112 psArgumentRemove (N, argc, argv); 113 113 } … … 116 116 if ((N = psArgumentGet (*argc, argv, "-region"))) { 117 117 psArgumentRemove (N, argc, argv); 118 psMetadataAddStr (config->options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));118 psMetadataAddStr (config->options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", argv[N]); 119 119 psArgumentRemove (N, argc, argv); 120 120 } -
trunk/psphot/src/psphotBasicDeblend.c
r6319 r6379 1 1 # include "psphot.h" 2 2 3 // 2006.02.02 : no leaks? (creates source->blend entries) 4 // XXX if I free sources, I still have 54 leaks? 3 // 2006.02.07 : no leaks 5 4 bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky) { 6 5 … … 35 34 // this results in an index of increasing SN 36 35 37 // temporary array for overlapping objects we find38 psArray *overlap = psArrayAlloc (100);39 40 36 // examine sources in decreasing SN order 41 37 for (int i = sources->n - 1; i >= 0; i--) { … … 45 41 if (source->mode & PM_SOURCE_BLEND) continue; 46 42 43 // temporary array for overlapping objects we find 44 // XXX psArrayAlloc should set ->n to 0 *and* all objects to NULL 45 // XXX I need a psArrayEmpty function to free the elements without the array 46 // XXX then, I could allocate 'overlap' once outside the loop and only 47 // XXX clear at the end of each loop 48 psArray *overlap = psArrayAlloc (100); 47 49 overlap->n = 0; 48 50 … … 73 75 } 74 76 77 if (overlap->n == 0) { 78 psFree (overlap); 79 continue; 80 } 81 82 // this source has overlapping neighbors, check for actual blends 75 83 // generate source contour (1/4 peak counts) 76 if (overlap->n > 0) { 77 // set the threshold based on user inputs 78 threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky; 79 threshold = PS_MAX (threshold, minThreshold); 84 // set the threshold based on user inputs 85 threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky; 86 threshold = PS_MAX (threshold, minThreshold); 80 87 81 // generate a basic contour (set of x,y coordinates at-or-below flux level) 82 psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold); 83 if (contour == NULL) continue; 88 // generate a basic contour (set of x,y coordinates at-or-below flux level) 89 psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold); 90 if (contour == NULL) { 91 psFree (overlap); 92 continue; 93 } 84 94 85 // the source contour consists of two vectors, xv and yv. the contour is86 // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]). both87 // coordinate pairs have the same yv[] value, with xv[i] corresponding to88 // the left boundary and xv[i+1] corresponding to the right boundary95 // the source contour consists of two vectors, xv and yv. the contour is 96 // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]). both 97 // coordinate pairs have the same yv[] value, with xv[i] corresponding to 98 // the left boundary and xv[i+1] corresponding to the right boundary 89 99 90 psVector *xv = contour->data[0];91 psVector *yv = contour->data[1];92 for (int k = 0; k < overlap->n; k++) {93 testSource = overlap->data[k];94 if (testSource->peak->counts > source->peak->counts) continue;95 for (int j = 0; j < xv->n; j+=2) {96 if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;97 if (xv->data.F32[j+0] > testSource->peak->x) break;98 if (xv->data.F32[j+1] < testSource->peak->x) break;100 psVector *xv = contour->data[0]; 101 psVector *yv = contour->data[1]; 102 for (int k = 0; k < overlap->n; k++) { 103 testSource = overlap->data[k]; 104 if (testSource->peak->counts > source->peak->counts) continue; 105 for (int j = 0; j < xv->n; j+=2) { 106 if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue; 107 if (xv->data.F32[j+0] > testSource->peak->x) break; 108 if (xv->data.F32[j+1] < testSource->peak->x) break; 99 109 100 testSource->mode |= PM_SOURCE_BLEND;110 testSource->mode |= PM_SOURCE_BLEND; 101 111 102 // add this to the list of source->blends 103 if (source->blends == NULL) { 104 source->blends = psArrayAlloc (16); 105 source->blends->n = 0; 106 } 107 psArrayAdd (source->blends, 16, testSource); 112 // add this to the list of source->blends 113 if (source->blends == NULL) { 114 source->blends = psArrayAlloc (16); 115 source->blends->n = 0; 116 } 108 117 109 Nblend ++; 110 j = xv->n; 111 } 112 } 113 psFree (contour); 114 } 118 psArrayAdd (source->blends, 16, testSource); 119 120 Nblend ++; 121 j = xv->n; 122 } 123 } 124 psFree (overlap); 125 psFree (contour); 115 126 } 116 127 psLogMsg ("psphot.deblend", 3, "identified %d blended objects (%f sec)\n", Nblend, psTimerMark ("psphot")); 117 128 118 char *breakPt = psMetadataLookup Ptr (&status, config, "BREAK_POINT");129 char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT"); 119 130 if (!strcasecmp (breakPt, "DEBLEND")) exit (0); 120 131 121 132 psFree (SN); 122 133 psFree (index); 123 psFree (overlap);124 125 134 return true; 126 135 } -
trunk/psphot/src/psphotBlendFit.c
r6056 r6379 30 30 psTrace ("psphot.blend", 5, "trying source at %f, %f\n", source->moments->x, source->moments->y); 31 31 32 // try fitting PSFs, then try extended sources 32 33 if (psphotFitBlend (readout, source)) continue; 33 34 if (psphotFitBlob (readout, source, sources)) continue; -
trunk/psphot/src/psphotChoosePSF.c
r6117 r6379 1 1 # include "psphot.h" 2 2 3 // 2006.02.07 : no leaks! 3 4 // try PSF models and select best option 4 5 pmPSF *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *skystats) { … … 8 9 pmPSFtry *try = NULL; 9 10 psArray *stars = NULL; 10 psMetadataItem *item = NULL;11 11 12 12 psTimerStart ("psphot"); … … 37 37 psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL"); 38 38 if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection"); 39 39 40 if (mdi->type == PS_DATA_STRING) { 40 41 list = psListAlloc(NULL); … … 51 52 psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE); 52 53 for (int i = 0; i < models->n; i++) { 53 54 item = psListGetAndIncrement (iter); 54 // XXX psListGetAndIncrement does not increment ref counter!? 55 // XXX if it did, i should free 'item' below 56 psMetadataItem *item = psListGetAndIncrement (iter); 55 57 modelName = item->data.V; 56 57 58 models->data[i] = pmPSFtryModel (stars, modelName, RADIUS); 58 psFree (modelName); 59 psFree (item); 59 // psFree (item); 60 60 } 61 61 psFree (iter); … … 98 98 psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid); 99 99 100 char *breakPt = psMetadataLookup Ptr (&status, config, "BREAK_POINT");100 char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT"); 101 101 if (!strcasecmp (breakPt, "PSFFIT")) exit (0); 102 102 -
trunk/psphot/src/psphotEnsemblePSF.c
r6056 r6379 1 1 # include "psphot.h" 2 2 3 // 2006.02.07 : no leaks! 4 // fit all reasonable sources with the linear PSF model 3 5 bool psphotEnsemblePSF (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) { 4 6 … … 6 8 float x; 7 9 float y; 10 float f; 8 11 9 12 psTimerStart ("psphot"); … … 28 31 bool UseAnalysisRegion = false; 29 32 psRegion AnalysisRegion = {0, 0, 0, 0}; 30 char *region = psMetadataLookup Ptr (&status, config, "ANALYSIS_REGION");33 char *region = psMetadataLookupStr (&status, config, "ANALYSIS_REGION"); 31 34 if (status) { 32 35 UseAnalysisRegion = true; … … 126 129 index->data.U32[models->n] = i; 127 130 psArrayAdd (models, 100, otSource); 131 psFree (otSource); 128 132 } 129 133 psLogMsg ("psphot.emsemble", 4, "built models: %f (%d objects)\n", psTimerMark ("psphot"), sources->n); 130 134 131 float f;132 133 135 // fill out the sparse matrix 134 136 psSparse *sparse = psSparseAlloc (models->n, 100); … … 173 175 pmSource *Mi = models->data[i]; 174 176 175 Fi->modelPSF = Mi->modelPSF; 177 // need to increment counter so we can free models here and sources above 178 Fi->modelPSF = psMemCopy (Mi->modelPSF); 176 179 177 180 // assign linearly-fitted normalization … … 183 186 Fi->mode |= PM_SOURCE_TEMPSUB; 184 187 } 185 186 // XXX EAM : need to free up many things here 188 psFree (index); 189 psFree (sparse); 190 psFree (models); 191 psFree (norm); 187 192 188 193 psLogMsg ("psphot.emsemble", 3, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot")); -
trunk/psphot/src/psphotFindPeaks.c
r6320 r6379 39 39 40 40 // optional dump of all peak data 41 char *output = psMetadataLookup Ptr (&status, config, "PEAKS_OUTPUT_FILE");41 char *output = psMetadataLookupStr (&status, config, "PEAKS_OUTPUT_FILE"); 42 42 if (status && (output != NULL) && (output[0])) { 43 43 pmPeaksWriteText (peaks, output); 44 psFree (output);45 44 } 46 47 45 psLogMsg ("psphot", 3, "%d peaks: %f sec\n", peaks->n, psTimerMark ("psphot")); 48 46 49 char *breakPt = psMetadataLookup Ptr (&status, config, "BREAK_POINT");47 char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT"); 50 48 if (!strcasecmp (breakPt, "PEAKS")) exit (0); 51 49 -
trunk/psphot/src/psphotFitGalaxies.c
r6056 r6379 14 14 float EXT_MIN_SN = psMetadataLookupF32 (&status, config, "EXT_MIN_SN"); 15 15 float EXT_MOMENTS_RAD = psMetadataLookupF32 (&status, config, "EXT_MOMENTS_RADIUS"); 16 char *modelName = psMetadataLookup Ptr (&status, config, "EXT_MODEL");16 char *modelName = psMetadataLookupStr (&status, config, "EXT_MODEL"); 17 17 pmModelType modelType = pmModelSetType (modelName); 18 18 -
trunk/psphot/src/psphotFullFit.c
r6056 r6379 19 19 20 20 // extended source model descriptions 21 char *modelNameEXT = psMetadataLookup Ptr (&status, config, "EXT_MODEL");21 char *modelNameEXT = psMetadataLookupStr (&status, config, "EXT_MODEL"); 22 22 pmModelType modelTypeEXT = pmModelSetType (modelNameEXT); 23 23 -
trunk/psphot/src/psphotGrowthCurve.c
r6311 r6379 62 62 psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f\n", psf->growth->apLoss); 63 63 64 psFree (view); 65 psFree (image); 66 psFree (mask); 67 psFree (model); 68 psFree (modelRef); 69 64 70 return true; 65 71 } -
trunk/psphot/src/psphotImageLoop.c
r6311 r6379 32 32 if (! chip->process) { continue; } 33 33 34 if (imageLoadDepth == PP_LOAD_CHIP) {34 if (imageLoadDepth == PP_LOAD_CHIP) { 35 35 psTrace(__func__, 1, "Loading pixels for chip %d...\n", i); 36 36 ppImageLoadPixels(file, config->database, i, -1); … … 47 47 ppImageLoadPixels(file, config->database, i, j); 48 48 } 49 49 50 50 // XXX optional mask and weight input image should be loaded here? 51 51 // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION … … 61 61 // run a single-model test if desired 62 62 psphotModelTest (readout, config->arguments, config->recipe); 63 64 63 psphotReadout (readout, config->recipe); 65 64 psphotOutput (readout, config->arguments); -
trunk/psphot/src/psphotLoadPixels.c
r6117 r6379 24 24 } 25 25 } 26 26 27 27 // Read in the input pixels 28 28 if (! pmFPARead(input->fpa, input->fits, input->phu, db)) { … … 30 30 exit(EXIT_FAILURE); 31 31 } 32 32 33 return true; 33 34 } -
trunk/psphot/src/psphotModelTest.c
r6311 r6379 1 1 # include "psphot.h" 2 2 # include "psEllipse.h" 3 static char DEFAULT_MODE[] = "EXT"; 3 4 4 5 bool psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe) { … … 17 18 18 19 // what fitting mode to use? 19 char *psfModeWord = psMetadataLookup Ptr (&status, arguments, "TEST_FIT_MODE");20 char *psfModeWord = psMetadataLookupStr (&status, arguments, "TEST_FIT_MODE"); 20 21 if (!status) { 21 psfModeWord = psStringCopy ("EXT");22 psfModeWord = DEFAULT_MODE; 22 23 } 23 24 bool psfMode = !strcasecmp (psfModeWord, "PSF"); … … 25 26 // in psfMode, psf sets the model type 26 27 if (psfMode) { 27 char *psfFile = psMetadataLookup Ptr (&status, arguments, "PSF_INPUT_FILE");28 char *psfFile = psMetadataLookupStr (&status, arguments, "PSF_INPUT_FILE"); 28 29 if (!status) psAbort ("psphotModelTest", "PSF_INPUT_FILE not supplied"); 29 30 psMetadata *psfData = psMetadataConfigParse (NULL, &Nfail, psfFile, FALSE); … … 32 33 } else { 33 34 // find the model: supplied by user or first in the PSF_MODEL list 34 char *modelName = psMetadataLookup Ptr (&status, arguments, "TEST_FIT_MODEL");35 char *modelName = psMetadataLookupStr (&status, arguments, "TEST_FIT_MODEL"); 35 36 if (modelName == NULL) { 36 37 // get the list pointers for the PSF_MODEL entries … … 153 154 psImageKeepCircle (source->mask, xObj, yObj, RADIUS, "OR", PSPHOT_MASK_MARKED); 154 155 155 char *fitset = psMetadataLookup Ptr (&status, arguments, "TEST_FIT_SET");156 char *fitset = psMetadataLookupStr (&status, arguments, "TEST_FIT_SET"); 156 157 if (status) { 157 158 status = psphotFitSet (source, model, fitset, psfMode); -
trunk/psphot/src/psphotOutput.c
r6311 r6379 12 12 static char *extRoot = NULL; 13 13 14 void psphotOutputCleanup () { 15 16 psFree (outputRoot); 17 psFree (outputName); 18 psFree (outputMode); 19 psFree (outputFormat); 20 psFree (extNumberFormat); 21 psFree (extNameKey); 22 psFree (extRoot); 23 return; 24 } 25 14 26 void psphotOutputPrep (ppFile *file, ppConfig *config) { 15 27 16 28 bool status; 17 29 18 outputRoot = psMetadataLookupPtr (&status, config->arguments, "OUTPUT_ROOT");30 outputRoot = psMetadataLookupStr (&status, config->arguments, "OUTPUT_ROOT"); 19 31 if (!status) psAbort ("psphot", "output file not specified"); 20 32 21 outputName = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_NAME");22 outputMode = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_MODE");23 outputFormat = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_FORMAT");33 outputName = psMetadataLookupStr (&status, config->recipe, "OUTPUT_NAME"); 34 outputMode = psMetadataLookupStr (&status, config->recipe, "OUTPUT_MODE"); 35 outputFormat = psMetadataLookupStr (&status, config->recipe, "OUTPUT_FORMAT"); 24 36 25 37 // rules to construct output names 26 extNumberFormat = psMetadataLookup Ptr (&status, config->recipe, "EXTNUMBER_FORMAT");27 extNameKey = psMetadataLookup Ptr (&status, config->recipe, "EXTNAME");28 extRoot = psMetadataLookup Ptr (&status, config->recipe, "EXTROOT");38 extNumberFormat = psMetadataLookupStr (&status, config->recipe, "EXTNUMBER_FORMAT"); 39 extNameKey = psMetadataLookupStr (&status, config->recipe, "EXTNAME"); 40 extRoot = psMetadataLookupStr (&status, config->recipe, "EXTROOT"); 29 41 30 42 if (extNumberFormat == NULL) { … … 63 75 } 64 76 77 // save so freeing config will not drop these references 78 psMemCopy (outputRoot); 79 psMemCopy (outputName); 80 psMemCopy (outputMode); 81 psMemCopy (outputFormat); 82 psMemCopy (extNumberFormat); 83 psMemCopy (extNameKey); 84 psMemCopy (extRoot); 85 65 86 return; 66 87 } … … 79 100 80 101 // find the extname: 81 char *extNameVal = psMetadataLookup Ptr (&status, header, extNameKey);102 char *extNameVal = psMetadataLookupStr (&status, header, extNameKey); 82 103 83 104 extNameWord = extNameVal; … … 157 178 if (!strcasecmp (outputMode, "SPLIT")) { 158 179 outputFile = psphotSplitName (header); 159 } else { 160 // construct appropriate extname 161 psAbort ("psphotOutput", "programming error"); 162 } 163 164 fprintf (stderr, "output file: %s\n", outputFile); 165 return; 166 167 char *psfFile = psMetadataLookupPtr (&status, arguments, "PSF_OUTPUT_FILE"); 168 char *psfSample = psMetadataLookupPtr (&status, arguments, "PSF_SAMPLE_FILE"); 169 char *residImage = psMetadataLookupPtr (&status, arguments, "RESID_IMAGE"); 180 } 181 182 char *psfFile = psMetadataLookupStr (&status, arguments, "PSF_OUTPUT_FILE"); 183 char *psfSample = psMetadataLookupStr (&status, arguments, "PSF_SAMPLE_FILE"); 184 char *residImage = psMetadataLookupStr (&status, arguments, "RESID_IMAGE"); 170 185 171 186 if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample); … … 183 198 if (outputFormat == NULL) { 184 199 psLogMsg ("output", 3, "no data output format selected"); 200 psFree (outputFile); 185 201 return; 186 202 } 187 203 if (!strcasecmp (outputFormat, "SX")) { 188 204 pmSourcesWriteSX (sources, outputFile); 205 psFree (outputFile); 189 206 return; 190 207 } 191 208 if (!strcasecmp (outputFormat, "OBJ")) { 192 209 pmSourcesWriteOBJ (sources, outputFile); 210 psFree (outputFile); 193 211 return; 194 212 } 195 213 if (!strcasecmp (outputFormat, "CMP")) { 196 214 pmSourcesWriteCMP (sources, outputFile, header); 215 psFree (outputFile); 197 216 return; 198 217 } 199 218 if (!strcasecmp (outputFormat, "CMF")) { 200 219 pmSourcesWriteCMF (sources, outputFile, header); 220 psFree (outputFile); 201 221 return; 202 222 } 203 223 if (!strcasecmp (outputFormat, "TEXT")) { 204 224 pmSourcesWriteText (sources, outputFile); 225 psFree (outputFile); 205 226 return; 206 227 } … … 610 631 } 611 632 fclose (f); 633 psFree (empty); 612 634 return true; 613 635 } … … 746 768 747 769 // optional dump of all rough source data 748 char *output = psMetadataLookup Ptr (&status, config, "MOMENTS_OUTPUT_FILE");770 char *output = psMetadataLookupStr (&status, config, "MOMENTS_OUTPUT_FILE"); 749 771 if (!status) return false; 750 772 if (output == NULL) return false; … … 752 774 753 775 pmMomentsWriteText (sources, output); 754 psFree (output);755 776 return true; 756 777 } -
trunk/psphot/src/psphotParseCamera.c
r6311 r6379 6 6 if (ITEM == NULL) { \ 7 7 psMetadataAdd##TYPE (CONFIG, PS_LIST_TAIL, NAME, 0, COMMENT, VALUE); \ 8 } else { psFree (ITEM); }}8 } } 9 9 10 // 2006.02.07 : no leaks! 10 11 ppFile *psphotParseCamera (ppConfig *config) { 11 12 12 13 ppFile *input = ppFileAlloc (); 13 14 14 input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE")); 15 input->filename = psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE"); 16 psMemCopy (input->filename); // keep for external use 15 17 16 18 // Open the input image … … 53 55 while ((item = psMetadataGetAndIncrement (iter)) != NULL) { 54 56 psMetadataAddItem (config->recipe, item, PS_LIST_TAIL, PS_META_REPLACE); 55 psFree (item);56 57 } 57 58 psFree (iter); -
trunk/psphot/src/psphotReadout.c
r6319 r6379 1 1 # include "psphot.h" 2 2 3 # define MEM_0 psMemId ID = psMemGetId (); 4 # define MEM_1(A) \ 5 psTimerStop ();\ 6 if (A != NULL) { psFree (A); } \ 7 fprintf (stderr, "found %d leaks\n", psMemCheckLeaks (ID, NULL, NULL, false));\ 8 exit (1); 9 3 // XXX 2006.02.07 : no leaks! 10 4 bool psphotReadout (pmReadout *readout, psMetadata *config) { 11 5 … … 41 35 42 36 // use bright stellar objects to measure PSF 43 MEM_0;44 37 psf = psphotChoosePSF (config, sources, sky); 45 MEM_1(psf);46 38 47 39 // XXX change FITMODE to a string … … 80 72 status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SKY.MEAN", PS_DATA_F32, "psphot sky mean", sky->sampleMean); 81 73 status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SKY.SIGMA", PS_DATA_F32, "psphot sky stdev", sky->sampleStdev); 74 75 // free up the local copies of the data 76 psFree (psf); 77 psFree (sky); 78 psFree (model); 79 psFree (peaks); 80 psFree (sources); 81 82 82 return true; 83 83 } -
trunk/psphot/src/psphotRoughClass.c
r6320 r6379 15 15 psphotDumpMoments (config, sources); 16 16 17 char *breakPt = psMetadataLookup Ptr (&status, config, "BREAK_POINT");17 char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT"); 18 18 if (!strcasecmp (breakPt, "CLASS")) exit (0); 19 19 -
trunk/psphot/src/psphotSourceFits.c
r6056 r6379 54 54 55 55 // extended source model descriptions 56 char *modelNameEXT = psMetadataLookup Ptr (&status, config, "EXT_MODEL");56 char *modelNameEXT = psMetadataLookupStr (&status, config, "EXT_MODEL"); 57 57 modelTypeEXT = pmModelSetType (modelNameEXT); 58 58 psphotInitRadiusEXT (config, sky, modelTypeEXT); … … 77 77 psTrace ("psphot.blend", 5, "trying blob...\n"); 78 78 79 // this temporary source is used as a place-holder by the psphotEval functions below 79 80 pmSource *tmpSrc = pmSourceAlloc (); 80 81 … … 89 90 chiDBL = ONE->chisq / ONE->nDOF; 90 91 92 psFree (tmpSrc); // XXX should I keep / save the flags set in the eval functions? 93 91 94 if (okEXT && okDBL) { 92 95 psTrace ("psphot.blend", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL); … … 98 101 if (okEXT && !okDBL) goto keepEXT; 99 102 if (!okEXT && okDBL) goto keepDBL; 103 104 // both models failed; reject them both 105 psFree (EXT); 106 psFree (DBL); 100 107 return false; 101 108 102 109 keepEXT: 103 110 // sub EXT 111 psFree (DBL); 104 112 pmSourceSubModel (source->pixels, source->mask, EXT, false, false); 105 113 psTrace ("psphot.blend", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[2], EXT->params->data.F32[3]); … … 113 121 keepDBL: 114 122 // sub DLB 123 psFree (EXT); 115 124 pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[0], false, false); 116 125 pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[1], false, false); … … 120 129 source->mode |= PM_SOURCE_SUBTRACTED; 121 130 source->mode &= ~PM_SOURCE_TEMPSUB; 122 123 // save new model124 // tmpSrc->modelPSF = (pmModel *) modelSet->data[1];125 // psArrayAdd (sources, 100, tmpSrc);126 131 127 132 return true; … … 205 210 return status; 206 211 } 207 208 212 psTrace ("psphot.blend", 5, "trying blend...\n"); 209 213 … … 225 229 psArrayAdd (sourceSet, 16, source); 226 230 231 // counter to track the blend elements used in the fit 232 psVector *index = psVectorAlloc (source->blends->n + 1, PS_TYPE_S32); 233 index->data.S32[0] = -1; // first element corresponds to the primary source 234 227 235 for (int i = 0; i < source->blends->n; i++) { 228 236 pmSource *blend = source->blends->data[i]; … … 237 245 pmModel *model = blend->modelPSF; 238 246 239 for ( psS32 i = 0; i < model->params->n; i++) {240 model->params->data.F32[ i] = PSF->params->data.F32[i];241 model->dparams->data.F32[ i] = PSF->dparams->data.F32[i];247 for (int j = 0; j < model->params->n; j++) { 248 model->params->data.F32[j] = PSF->params->data.F32[j]; 249 model->dparams->data.F32[j] = PSF->dparams->data.F32[j]; 242 250 } 243 251 … … 247 255 248 256 // add this blend to the list 257 index->data.S32[modelSet->n] = i; 249 258 psArrayAdd (modelSet, 16, model); 250 259 psArrayAdd (sourceSet, 16, blend); … … 261 270 pmModel *model = modelSet->data[i]; 262 271 272 // if we skip this one, free the corresponding blend entry model 263 273 if (!psphotEvalPSF (src, model)) { 264 psFree (model); 265 src->modelPSF = NULL; 274 int n = index->data.S32[i]; 275 pmSource *blend = source->blends->data[n]; 276 psFree (blend->modelPSF); 277 blend->modelPSF = NULL; 266 278 continue; 267 279 } … … 272 284 src->mode &= ~PM_SOURCE_TEMPSUB; 273 285 } 286 psFree (index); 287 psFree (modelSet); 288 psFree (sourceSet); 274 289 275 290 // evaluate the primary object … … 281 296 psTrace ("psphot.blend", 5, "fitted primary as PSF\n"); 282 297 pmSourceSubModel (source->pixels, source->mask, PSF, false, false); 298 psFree (source->modelPSF); 283 299 source->modelPSF = PSF; 284 300 source->mode |= PM_SOURCE_SUBTRACTED; -
trunk/psphot/src/psphotSourceStats.c
r6320 r6379 63 63 psLogMsg ("psphot", 3, "%d moments: %f sec\n", sources->n, psTimerMark ("psphot")); 64 64 65 char *breakPt = psMetadataLookup Ptr (&status, config, "BREAK_POINT");65 char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT"); 66 66 if (!strcasecmp (breakPt, "STATS")) exit (0); 67 67
Note:
See TracChangeset
for help on using the changeset viewer.
