Changeset 4901
- Timestamp:
- Aug 29, 2005, 5:44:55 PM (21 years ago)
- Location:
- trunk
- Files:
-
- 19 edited
-
archive/scripts/Makefile (modified) (1 diff)
-
psphot/Makefile (modified) (2 diffs)
-
psphot/src/LocalSky.c (modified) (2 diffs)
-
psphot/src/apply_psf_model.c (modified) (4 diffs)
-
psphot/src/basic_classes.c (modified) (1 diff)
-
psphot/src/choose_psf_model.c (modified) (4 diffs)
-
psphot/src/find_peaks.c (modified) (2 diffs)
-
psphot/src/fit_galaxies.c (modified) (3 diffs)
-
psphot/src/image_stats.c (modified) (2 diffs)
-
psphot/src/load_args.c (modified) (1 diff)
-
psphot/src/output.c (modified) (7 diffs)
-
psphot/src/psPolynomials.c (modified) (7 diffs)
-
psphot/src/psUtils.c (modified) (5 diffs)
-
psphot/src/psphot-utils.c (modified) (1 diff)
-
psphot/src/psphot.c (modified) (1 diff)
-
psphot/src/psphot.h (modified) (5 diffs)
-
psphot/src/pspsf.c (modified) (12 diffs)
-
psphot/src/setup.c (modified) (4 diffs)
-
psphot/src/source_moments.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/Makefile
r4048 r4901 15 15 LIBS = -lpsmodule $(LPSLIB) 16 16 CFLAGS = $(INCS) -std=c99 17 LFLAGS = $(LIBS) -static17 LFLAGS = $(LIBS) 18 18 19 19 PSPHOT = \ -
trunk/psphot/Makefile
r4641 r4901 3 3 @echo "USAGE: make psphot" 4 4 5 CC = gcc -g -Wall 5 CC = gcc -g -Wall -O2 6 6 SRC = src 7 7 BIN = bin … … 36 36 $(SRC)/fit_galaxies.$(ARCH).o \ 37 37 $(SRC)/LocalSky.$(ARCH).o \ 38 $(SRC)/basic_classes.$(ARCH).o 38 $(SRC)/basic_classes.$(ARCH).o \ 39 $(SRC)/psLine.$(ARCH).o \ 40 $(SRC)/output.$(ARCH).o 39 41 40 42 FITSOURCE = \ -
trunk/psphot/src/LocalSky.c
r4642 r4901 18 18 // psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion); 19 19 20 psImage *subImage = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1); 21 psImage *subImageMask = psImageSubset(imdata->mask, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1); 22 psImage *subImageNoise = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1); 23 24 mySource->pixels = subImage; 25 mySource->mask = subImageMask; 26 mySource->noise = subImageNoise; 20 mySource->pixels = psImageSubset(imdata->image, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1); 21 mySource->noise = psImageSubset(imdata->noise, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1); 22 mySource->mask = psImageSubset(imdata->mask, srcRegion->x0, srcRegion->y0, srcRegion->x1, srcRegion->y1); 23 27 24 psFree (srcRegion); 28 29 25 return(mySource); 30 26 } … … 48 44 myStats = psImageStats(myStats, image, mask, 0xff); 49 45 psImageMaskRegion (mask, srcRegion, AND, 0x7f); 50 psFree (srcRegion);51 46 52 47 psF64 tmpF64; 53 48 p_psGetStatValue(myStats, &tmpF64); 49 50 psFree (myStats); 51 psFree (srcRegion); 52 54 53 if (isnan(tmpF64)) return (false); 55 56 54 source->moments = pmMomentsAlloc(); 57 55 source->moments->Sky = (psF32) tmpF64; -
trunk/psphot/src/apply_psf_model.c
r4642 r4901 14 14 int Niter = 0; 15 15 16 psMemoryId id = psMemGetId (); 16 17 psTimerStart ("psphot"); 17 18 … … 33 34 34 35 for (int i = 0; i < sources->n; i++) { 36 35 37 psSource *source = sources->data[i]; 36 38 … … 39 41 if (source->type == PS_SOURCE_SATURATED) continue; 40 42 41 // do I even need to test?42 if (source->modelPSF != NULL) {43 psFree (source->modelPSF);44 }45 46 43 // use the source moments, etc to guess basic model parameters 47 psModel *model = pmSourceModelGuess (source, psf->type);44 psModel *modelFLT = pmSourceModelGuess (source, psf->type); 48 45 49 46 // set PSF parameters for this model 50 model = psModelFromPSF (model, psf);47 psModel *model = psModelFromPSF (modelFLT, psf); 51 48 x = model->params->data.F32[2]; 52 49 y = model->params->data.F32[3]; 50 psFree (modelFLT); 53 51 54 52 // set the fit radius based on the object flux limit and the model … … 72 70 psLogMsg ("psphot", 3, "PSF fit failed for %f, %f (%d iterations)\n", x, y, model->nIter); 73 71 source->type = PS_SOURCE_FAIL_FIT_PSF; // better choice? 72 psFree (model); 74 73 continue; 75 74 } -
trunk/psphot/src/basic_classes.c
r4642 r4901 6 6 7 7 // group into STAR, COSMIC, GALAXY, SATURATED 8 // XXX - this has 1 leak 8 9 psfClump = pmSourcePSFClump (sources, config); 9 10 pmSourceRoughClass (sources, config, psfClump); 11 10 12 return (true); 11 13 } -
trunk/psphot/src/choose_psf_model.c
r4642 r4901 7 7 bool status; 8 8 char *modelName; 9 char key[64] , filename[64];9 char key[64]; 10 10 pmPSF_Test *test = NULL; 11 11 psArray *stars = NULL; … … 31 31 psArray *tests = psArrayAlloc (Ntest); 32 32 for (int i = 0; i < tests->n; i++) { 33 s printf (key, "PSF_MODEL_%d", i);33 snprintf (key, 64, "PSF_MODEL_%d", i); 34 34 modelName = psMetadataLookupPtr (&status, config, key); 35 35 36 tests->data[i] = pmPSF_TestModel (stars, modelName, RADIUS); 36 37 psFree (modelName); … … 55 56 } 56 57 } 58 // keep only the selected test: 57 59 test = tests->data[bestN]; 58 60 modelName = psModelGetType (test->modelType); 59 61 psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, test->ApResid, test->dApResid); 60 psFree (modelName);61 62 63 // XXX I am having trouble tracking down the double frees vs leaks 64 # if (0) 62 65 // we are keeping the modelPSF fits from the PSF test, 63 66 // but we replace these later on (apply_psf_model) … … 70 73 source->modelPSF = NULL; 71 74 } else { 75 // source->modelPSF = psMemCopy(test->modelPSF->data[i]); 72 76 source->modelPSF = test->modelPSF->data[i]; 73 77 } 74 78 } 75 pmPSF *psf = test->psf;79 # endif 76 80 77 // free unused test models: 78 psFree (test); 79 psFree (stars); 80 81 pmPSF *psf = psMemCopy(test->psf); 82 psFree (tests); 81 83 return (psf); 82 84 } -
trunk/psphot/src/find_peaks.c
r4642 r4901 21 21 psTimerStart ("psphot"); 22 22 23 // find the peaks in the smoothed image23 // set peak threshold 24 24 NSIGMA = psMetadataLookupF32 (&status, config, "PEAK_NSIGMA"); 25 25 threshold = NSIGMA*sky->sampleStdev + sky->sampleMean; 26 26 psLogMsg ("psphot", 3, "threshold: %f DN\n", threshold); 27 27 28 // find the peaks in the smoothed image 28 29 psArray *peaks = pmFindImagePeaks (smooth, threshold); 29 30 if (peaks == NULL) psAbort ("find peaks", "no peaks found"); … … 31 32 32 33 // make this optional 33 DumpPeaks (peaks, "peaks.dat");34 // DumpPeaks (peaks, "peaks.dat"); 34 35 35 36 psLogMsg ("psphot", 3, "%d peaks: %f sec\n", peaks->n, psTimerMark ("psphot")); -
trunk/psphot/src/fit_galaxies.c
r4642 r4901 24 24 25 25 psTimerStart ("psphot"); 26 27 float dt = 0; 28 float dT = 0; 29 float dT2 = 0; 30 int dTn = 0; 31 26 32 for (int i = 0; i < sources->n; i++) { 27 33 psSource *source = sources->data[i]; … … 72 78 // fit as FLT, not PSF (skip poor fits) 73 79 psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80); 80 psTimerStart ("galfit"); 74 81 status = pmSourceFitModel_EAM (source, model, false); 82 dt = psTimerMark ("galfit"); 83 dT += dt; 84 dT2 += dt*dt; 85 dTn ++; 75 86 psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f); 76 87 if (!status) { … … 105 116 106 117 } 118 dt = dT / dTn; 119 fprintf (stderr, "dt: %f +/- %f\n", dt, sqrt(dT2/dTn - PS_SQR(dt))); 107 120 psLogMsg ("psphot", 3, "fit galaxies: %f sec for %d galaxies (%d failures, %d total iterations)\n", psTimerMark ("psphot"), Nfit, Nfail, Niter); 108 121 return (true); -
trunk/psphot/src/image_stats.c
r4642 r4901 36 36 stats = psVectorStats (stats, subset, NULL, NULL, 0); // use a mask? 37 37 psFree (subset); 38 psFree (rnd) 38 psFree (rnd); 39 39 } 40 40 … … 52 52 psLogMsg ("psphot", 3, "background: %f +/- %f\n", sky->sampleMean, sky->sampleStdev); 53 53 54 psFree (stats); 54 55 return (sky); 55 56 } -
trunk/psphot/src/load_args.c
r4641 r4901 36 36 37 37 // load config information 38 // XXX - 3 leaks from this 38 39 psMetadata *config = psMetadataParseConfig (NULL, &Nfail, argv[3], FALSE); 39 40 -
trunk/psphot/src/output.c
r4641 r4901 3 3 // output functions: we have several fixed modes (sx, obj, cmp) 4 4 5 static int GetDophotType (psSource *source) { 6 7 switch (source->type) { 8 9 case PS_SOURCE_DEFECT: 10 case PS_SOURCE_SATURATED: 11 return (8); 12 13 case PS_SOURCE_SATSTAR: 14 return (10); 15 16 case PS_SOURCE_PSFSTAR: 17 case PS_SOURCE_GOODSTAR: 18 return (1); 19 20 case PS_SOURCE_POOR_FIT_PSF: 21 return (7); 22 23 case PS_SOURCE_FAIL_FIT_PSF: 24 case PS_SOURCE_FAINTSTAR: 25 return (4); 26 27 case PS_SOURCE_GALAXY: 28 case PS_SOURCE_FAINT_GALAXY: 29 case PS_SOURCE_DROP_GALAXY: 30 case PS_SOURCE_FAIL_FIT_GAL: 31 case PS_SOURCE_POOR_FIT_GAL: 32 return (2); 33 34 case PS_SOURCE_OTHER: 35 default: 36 return (0); 37 } 38 return (0); 39 } 40 5 41 void output (psImageData *imdata, psMetadata *config, psArray *sources) { 6 42 7 char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE"); 8 9 if (outputMode == NULL) { 10 WriteSourcesText (imdata, config, sources); 43 bool status; 44 45 char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE"); 46 47 if (outputMode == NULL) { 48 WriteSourcesText (imdata, config, sources); 49 exit (0); 50 } 51 52 if (!strcasecmp (outputMode, "OBJ")) { 53 WriteSourcesOBJ (imdata, config, sources); 54 exit (0); 55 } 56 57 if (!strcasecmp (outputMode, "SX")) { 58 WriteSourcesSX (imdata, config, sources); 59 exit (0); 60 } 61 62 if (!strcasecmp (outputMode, "CMP")) { 63 WriteSourcesCMP (imdata, config, sources); 64 exit (0); 65 } 66 67 if (!strcasecmp (outputMode, "CMF")) { 68 WriteSourcesCMF (imdata, config, sources); 69 exit (0); 70 } 71 72 psAbort ("psphot", "unknown output mode %s", outputMode); 73 } 74 75 bool WriteSourcesText (psImageData *imdata, psMetadata *config, psArray *sources) { 76 77 bool status; 78 79 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 80 81 DumpImage (imdata->image, filename); 82 83 // get these names from config? 84 DumpModelPSF (sources, "psfsources.dat"); 85 DumpModelFLT (sources, "fltsources.dat"); 86 DumpModelNULL (sources, "nullsources.dat"); 87 DumpMoments (sources, "moments.dat"); 88 11 89 exit (0); 12 }13 14 if (!strcasecmp (outputMode, "OBJ")) {15 WriteSourcesOBJ (imdata, config, sources);16 exit (0);17 }18 19 if (!strcasecmp (outputMode, "SX")) {20 WriteSourcesSX (imdata, config, sources);21 exit (0);22 }23 24 if (!strcasecmp (outputMode, "CMP")) {25 WriteSourcesCMP (imdata, config, sources);26 exit (0);27 }28 29 if (!strcasecmp (outputMode, "CMF")) {30 WriteSourcesCMF (imdata, config, sources);31 exit (0);32 }33 34 psAbort ("psphot", "unknown output mode %s", outputMode);35 }36 37 bool WriteSourceText (psImageData *imdata, psMetadata *config, psArray *sources) {38 39 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT");40 41 DumpImage (imdata->image, filename);42 43 // get these names from config?44 DumpModelPSF (sources, "psfsources.dat");45 DumpModelFLT (sources, "fltsources.dat");46 DumpModelNULL (sources, "nullsources.dat");47 DumpMoments (sources, "moments.dat");48 49 exit (0);50 90 } 51 91 … … 53 93 bool WriteSourcesOBJ (psImageData *imdata, psMetadata *config, psArray *sources) { 54 94 55 # define NCHAR 104 56 57 char line[NCHAR]; 58 59 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 95 int i, type; 96 bool status; 97 psModel *model; 98 psF32 *PAR, *dPAR; 99 float dmag, apMag, fitMag; 100 101 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 102 psLine *line = psLineAlloc (104); // 104 is dophot-defined line length 103 104 FILE *f = fopen (filename, "w"); 105 if (f == NULL) { 106 psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename); 107 return false; 108 } 109 110 // write sources with models first 111 for (i = 0; i < sources->n; i++) { 112 psSource *source = (psSource *) sources->data[i]; 113 model = source->modelPSF; 114 if (model == NULL) continue; 115 PAR = model->params->data.F32; 116 dPAR = model->dparams->data.F32; 117 118 pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask); 119 dmag = dPAR[1] / PAR[1]; 120 121 type = GetDophotType (source); 122 psLineInit (line); 123 psLineAdd (line, "%3d", type); 124 psLineAdd (line, "%8.2f", PAR[2]); 125 psLineAdd (line, "%8.2f", PAR[3]); 126 psLineAdd (line, "%8.3f", fitMag); 127 psLineAdd (line, "%6.3f", dmag); 128 psLineAdd (line, "%9.2f", PAR[0]); 129 psLineAdd (line, "%9.3f", PAR[4]); 130 psLineAdd (line, "%9.3f", PAR[5]); 131 psLineAdd (line, "%7.2f", PAR[6]); 132 psLineAdd (line, "%8.3f", 32.0); 133 psLineAdd (line, "%8.3f", apMag); 134 psLineAdd (line, "%8.2f", apMag - fitMag); 135 fwrite (line->line, 1, line->Nline, f); 136 } 137 fclose (f); 138 return true; 139 140 } 141 142 // elixir/sextractor-style output list with fixed line width 143 bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources) { 144 145 int i, type; 146 bool status; 147 psModel *model; 148 psF32 *PAR, *dPAR; 149 float dmag, apMag, fitMag; 150 151 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 152 psLine *line = psLineAlloc (104); // 104 is dophot-defined line length 60 153 61 154 FILE *f = fopen (filename, "w"); … … 70 163 model = (psModel *) source->modelPSF; 71 164 if (model == NULL) continue; 72 params = model->params;73 d params = model->dparams;165 PAR = model->params->data.F32; 166 dPAR = model->dparams->data.F32; 74 167 75 168 pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask); 76 dmag = dparams[0].data.F32[1] / params[0].data.F32[1]; 77 169 dmag = dPAR[1] / PAR[1]; 170 171 // XXX EAM : fix this to match sextractor output 78 172 type = GetDophotType (source); 79 init_line (line, &Nline); 80 add_to_line (line, &Nline, "%3d", type); 81 add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]); 82 add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]); 83 add_to_line (line, &Nline, "%8.3f", fitMag); 84 add_to_line (line, &Nline, "%6.3f", dmag); 85 add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]); 86 add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]); 87 add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]); 88 add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]); 89 add_to_line (line, &Nline, "%8.3f", 32.0); 90 add_to_line (line, &Nline, "%8.3f", apMag); 91 add_to_line (line, &Nline, "%8.2f", apMag - fitMag); 173 psLineInit (line); 174 psLineAdd (line, "%3d", type); 175 psLineAdd (line, "%8.2f", PAR[2]); 176 psLineAdd (line, "%8.2f", PAR[3]); 177 psLineAdd (line, "%8.3f", fitMag); 178 psLineAdd (line, "%6.3f", dmag); 179 psLineAdd (line, "%9.2f", PAR[0]); 180 psLineAdd (line, "%9.3f", PAR[4]); 181 psLineAdd (line, "%9.3f", PAR[5]); 182 psLineAdd (line, "%7.2f", PAR[6]); 183 psLineAdd (line, "%8.3f", 32.0); 184 psLineAdd (line, "%8.3f", apMag); 185 psLineAdd (line, "%8.2f", apMag - fitMag); 186 fwrite (line->line, 1, line->Nline, f); 92 187 } 93 188 fclose (f); 94 189 return true; 95 96 } 97 98 // elixir/sextractor-style output list with fixed line width 99 bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources) { 100 101 # define NCHAR 104 102 103 char line[NCHAR]; 104 105 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 190 } 191 192 // elixir-style pseudo FITS table (header + ascii list) 193 bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources) { 194 195 int i, type; 196 bool status; 197 psModel *model; 198 psF32 *PAR, *dPAR; 199 float dmag, apMag, fitMag; 200 201 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 202 psLine *line = psLineAlloc (104); // 104 is dophot-defined line length 106 203 107 204 FILE *f = fopen (filename, "w"); … … 110 207 return false; 111 208 } 209 210 // write imdata->header to file 112 211 113 212 // write sources with models first … … 116 215 model = (psModel *) source->modelPSF; 117 216 if (model == NULL) continue; 118 params = model->params;119 d params = model->dparams;217 PAR = model->params->data.F32; 218 dPAR = model->dparams->data.F32; 120 219 121 220 pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask); 122 dmag = d params[0].data.F32[1] / params[0].data.F32[1];221 dmag = dPAR[1] / PAR[1]; 123 222 124 223 // XXX EAM : fix this to match sextractor output 125 224 type = GetDophotType (source); 126 init_line (line, &Nline); 127 add_to_line (line, &Nline, "%3d", type); 128 add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]); 129 add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]); 130 add_to_line (line, &Nline, "%8.3f", fitMag); 131 add_to_line (line, &Nline, "%6.3f", dmag); 132 add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]); 133 add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]); 134 add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]); 135 add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]); 136 add_to_line (line, &Nline, "%8.3f", 32.0); 137 add_to_line (line, &Nline, "%8.3f", apMag); 138 add_to_line (line, &Nline, "%8.2f", apMag - fitMag); 139 } 140 fclose (f); 141 return true; 142 143 } 144 145 // elixir-style pseudo FITS table (header + ascii list) 146 bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources) { 147 148 149 # define NCHAR 104 150 151 char line[NCHAR]; 152 153 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 154 155 FILE *f = fopen (filename, "w"); 156 if (f == NULL) { 157 psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", filename); 158 return false; 159 } 160 161 // write imdata->header to file 162 163 // write sources with models first 164 for (i = 0; i < sources->n; i++) { 165 psSource *source = (psSource *) sources->data[i]; 166 model = (psModel *) source->modelPSF; 167 if (model == NULL) continue; 168 params = model->params; 169 dparams = model->dparams; 170 171 pmSourcePhotometry (&fitMag, &apMag, model, source->pixels, source->mask); 172 dmag = dparams[0].data.F32[1] / params[0].data.F32[1]; 173 174 // XXX EAM : fix this to match sextractor output 175 type = GetDophotType (source); 176 init_line (line, &Nline); 177 add_to_line (line, &Nline, "%3d", type); 178 add_to_line (line, &Nline, "%8.2f", params[0].data.F32[2]); 179 add_to_line (line, &Nline, "%8.2f", params[0].data.F32[3]); 180 add_to_line (line, &Nline, "%8.3f", fitMag); 181 add_to_line (line, &Nline, "%6.3f", dmag); 182 add_to_line (line, &Nline, "%9.2f", params[0].data.F32[0]); 183 add_to_line (line, &Nline, "%9.3f", params[0].data.F32[4]); 184 add_to_line (line, &Nline, "%9.3f", params[0].data.F32[5]); 185 add_to_line (line, &Nline, "%7.2f", params[0].data.F32[6]); 186 add_to_line (line, &Nline, "%8.3f", 32.0); 187 add_to_line (line, &Nline, "%8.3f", apMag); 188 add_to_line (line, &Nline, "%8.2f", apMag - fitMag); 225 psLineInit (line); 226 psLineAdd (line, "%3d", type); 227 psLineAdd (line, "%8.2f", PAR[2]); 228 psLineAdd (line, "%8.2f", PAR[3]); 229 psLineAdd (line, "%8.3f", fitMag); 230 psLineAdd (line, "%6.3f", dmag); 231 psLineAdd (line, "%9.2f", PAR[0]); 232 psLineAdd (line, "%9.3f", PAR[4]); 233 psLineAdd (line, "%9.3f", PAR[5]); 234 psLineAdd (line, "%7.2f", PAR[6]); 235 psLineAdd (line, "%8.3f", 32.0); 236 psLineAdd (line, "%8.3f", apMag); 237 psLineAdd (line, "%8.2f", apMag - fitMag); 238 fwrite (line->line, 1, line->Nline, f); 189 239 } 190 240 fclose (f); … … 195 245 bool WriteSourcesCMF (psImageData *imdata, psMetadata *config, psArray *sources) { 196 246 247 bool status; 248 197 249 char *filename = psMetadataLookupPtr (&status, config, "OUTPUT"); 198 250 … … 200 252 201 253 // write FITS table to file (use autocode tools) 202 } 203 204 // we require a fixed number of chars already allocated 205 init_line (char *line, int *Nline) { 206 *Nline = 0; 207 } 208 209 add_to_line (char *line, int *Nline, char *format, ...) { 210 211 va_list ap; 212 213 va_start (ap, format); 214 Nchar = vsprintf (&line[*Nline], format, ap); 215 *Nline += Nchar; 216 } 217 254 255 return true; 256 } -
trunk/psphot/src/psPolynomials.c
r4375 r4901 42 42 } 43 43 44 static void psPolynomial1DFree (psPolynomial1D *poly) { 45 46 if (poly == NULL) return; 47 psFree (poly->coeff); 48 psFree (poly->coeffErr); 49 psFree (poly->mask); 50 return; 51 } 52 44 53 // XXX EAM : use Nterm = Norder + 1 definition 45 54 // XXX EAM : should we provide both order and nterms in struct? … … 54 63 55 64 newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D)); 56 // p_psMemSetDeallocator(newPoly, (psFreeFcn) polynomial1DFree);57 // XXX EAM : me, being lazy58 59 65 newPoly->type = type; 60 66 newPoly->n = nOrder; … … 67 73 newPoly->mask[i] = 0; 68 74 } 75 p_psMemSetDeallocator(newPoly, (psFreeFcn) psPolynomial1DFree); 69 76 return(newPoly); 70 77 } … … 185 192 myPoly->coeff[k] = coeffs->data.F64[k]; 186 193 } 194 psFree (ALUD); 195 psFree (outPerm); 196 psFree (coeffs); 187 197 } 188 198 … … 262 272 } 263 273 274 static void psPolynomial2DFree(psPolynomial2D *poly) { 275 276 if (poly == NULL) return; 277 for (int i = 0; i < poly->nX + 1; i++) { 278 psFree (poly->coeff[i]); 279 psFree (poly->coeffErr[i]); 280 psFree (poly->mask[i]); 281 } 282 psFree (poly->coeff); 283 psFree (poly->coeffErr); 284 psFree (poly->mask); 285 return; 286 } 287 264 288 // XXX EAM : use Nterm = Norder + 1 definition 265 289 // the user requests a polynomial of order Norder … … 277 301 278 302 newPoly = (psPolynomial2D* ) psAlloc(sizeof(psPolynomial2D)); 279 // p_psMemSetDeallocator(newPoly, (psFreeFcn) polynomial2DFree);280 // XXX EAM : me, being lazy281 282 303 newPoly->type = type; 283 304 newPoly->nX = nXorder; … … 299 320 } 300 321 } 322 p_psMemSetDeallocator(newPoly, (psFreeFcn) psPolynomial2DFree); 301 323 return(newPoly); 302 324 } -
trunk/psphot/src/psUtils.c
r4375 r4901 2 2 3 3 static psHash *timers = NULL; 4 5 bool psTimerClear (char *name) { 6 7 bool status; 8 9 if (name == NULL) return false; 10 11 status = psHashRemove (timers, name); 12 return (status); 13 } 14 15 void psTimerFree () { 16 17 psFree (timers); 18 p_psTimeFinalize(); 19 return; 20 } 4 21 5 22 // start/restart a named timer … … 11 28 12 29 start = psTimeGetTime (PS_TIME_UTC); 13 14 30 psHashAdd (timers, name, start); 15 31 psFree (start); 16 32 return (TRUE); 17 33 } … … 31 47 mark = psTimeGetTime (PS_TIME_UTC); 32 48 delta = psTimeDelta (mark, start); 49 psFree (mark); 50 // psFree (start); -- XXX is psHashLookup not psMemCopying? 51 33 52 return (delta); 34 53 } … … 191 210 } 192 211 *status = true; 212 // psFree (item); 193 213 return (value); 194 214 } … … 198 218 if (item->type == PS_META_F32) { 199 219 value = item->data.F32; 220 // psFree (item); 200 221 return (value); 201 222 } -
trunk/psphot/src/psphot-utils.c
r4630 r4901 439 439 440 440 # endif 441 442 static void psImageDataFree (psImageData *imdata) { 443 444 if (imdata == NULL) return; 445 446 psFree (imdata->image); 447 psFree (imdata->header); 448 psFree (imdata->noise); 449 psFree (imdata->mask); 450 return; 451 } 452 453 psImageData *psImageDataAlloc (psImage *image, psImage *noise, psImage *mask, psMetadata *header) { 454 455 psImageData *imdata = psAlloc(sizeof(psImageData)); 456 imdata->image = image; 457 imdata->header = header; 458 imdata->noise = noise; 459 imdata->mask = mask; 460 461 p_psMemSetDeallocator(imdata, (psFreeFcn) psImageDataFree); 462 return (imdata); 463 } 464 -
trunk/psphot/src/psphot.c
r4641 r4901 14 14 // load input data (image and config) 15 15 // create or load mask and noise images 16 // we have memory leaks here -- may be from psMetadata 16 17 imdata = setup (config); 17 18 -
trunk/psphot/src/psphot.h
r4630 r4901 31 31 } pmPSF_Test; 32 32 33 // structure to carry a dynamic string 34 typedef struct { 35 int NLINE; 36 int Nline; 37 char *line; 38 } psLine; 39 33 40 // used by mask operations 34 41 # define AND true 35 42 # define OR false 36 43 44 # define psMemCopy(A)(psMemIncrRefCounter((A))) 37 45 38 46 // top-level psphot functions … … 71 79 bool DumpImage (psImage *image, char *filename); 72 80 bool DumpPSFTestData (pmPSF_Test *test, char *filename); 81 void output (psImageData *imdata, psMetadata *config, psArray *sources); 82 bool WriteSourcesText (psImageData *imdata, psMetadata *config, psArray *sources); 83 bool WriteSourcesOBJ (psImageData *imdata, psMetadata *config, psArray *sources); 84 bool WriteSourcesSX (psImageData *imdata, psMetadata *config, psArray *sources); 85 bool WriteSourcesCMP (psImageData *imdata, psMetadata *config, psArray *sources); 86 bool WriteSourcesCMF (psImageData *imdata, psMetadata *config, psArray *sources); 87 bool init_line (char *line, int *Nline); 88 bool add_to_line (char *line, int *Nline, char *format, ...); 73 89 74 90 // psphot utilities … … 86 102 psBool psMinimizeLMChi2_EAM(psMinimization *min, psImage *covar, psVector *params, const psVector *paramMask, const psArray *x, const psVector *y, const psVector *yErr, psMinimizeLMChi2Func func); 87 103 psF64 p_psMinLM_dLinear (const psVector *Beta, const psVector *beta, psF64 lambda); 104 psImageData *psImageDataAlloc (psImage *image, psImage *noise, psImage *mask, psMetadata *header); 88 105 89 106 // fitsource utilities … … 110 127 // utilities 111 128 bool psTimerStart (char *name); 129 void psTimerFree (); 130 bool psTimerClear (char *name); 112 131 psF64 psTimerMark (char *name); 113 132 psS32 psLogArguments (int *argc, char **argv); … … 117 136 psF32 pmConfigLookupF32 (bool *status, psMetadata *config, psMetadata *header, char *name); 118 137 psVector *psVectorCreate (double lower, double upper, double delta, psElemType type); 138 139 // psLine functions 140 psLine *psLineAlloc (int Nline); 141 bool psLineInit (psLine *line); 142 bool psLineAdd (psLine *line, char *format, ...); 119 143 120 144 // polynomial functions -
trunk/psphot/src/pspsf.c
r4642 r4901 1 1 # include "psphot.h" 2 3 static void pmPSFFree (pmPSF *psf) { 4 5 if (psf == NULL) return; 6 7 psFree (psf->params); 8 return; 9 } 2 10 3 11 // a PSF always has 4 parameters fewer than the equivalent model … … 16 24 return(NULL); 17 25 } 26 18 27 psf->params = psArrayAlloc (Nparams - 4); 19 28 for (int i = 0; i < psf->params->n; i++) { … … 21 30 psf->params->data[i] = Polynomial2DAlloc(1, 1, PS_POLYNOMIAL_ORD); 22 31 } 23 // set the destructors 32 33 p_psMemSetDeallocator(psf, (psFreeFcn) pmPSFFree); 24 34 return(psf); 35 } 36 37 static void pmPSF_TestFree (pmPSF_Test *test) { 38 39 if (test == NULL) return; 40 41 psFree (test->psf); 42 psFree (test->sources); 43 psFree (test->modelFLT); 44 psFree (test->modelPSF); 45 psFree (test->metric); 46 psFree (test->fitMag); 47 psFree (test->mask); 48 return; 25 49 } 26 50 … … 32 56 test->modelType = psModelSetType (modelName); 33 57 test->psf = pmPSFAlloc (test->modelType); 34 test->sources = sources;58 test->sources = psMemCopy(sources); 35 59 test->modelFLT = psArrayAlloc (sources->n); 36 60 test->modelPSF = psArrayAlloc (sources->n); … … 49 73 test->fitMag->data.F64[i] = 0; 50 74 } 51 // set the destructors 52 75 76 p_psMemSetDeallocator(test, (psFreeFcn) pmPSF_TestFree); 53 77 return (test); 54 78 } … … 74 98 psTimerStart ("fit"); 75 99 for (int i = 0; i < test->sources->n; i++) { 100 76 101 psSource *source = test->sources->data[i]; 77 102 psModel *model = pmSourceModelGuess (source, test->modelType); … … 88 113 if (!status) { 89 114 test->mask->data.U8[i] = 2; 115 psFree (model); 90 116 continue; 91 117 } … … 122 148 if (!status) { 123 149 test->mask->data.U8[i] = 3; 150 psFree (modelPSF); 124 151 goto next_source; 125 152 } … … 154 181 psLogMsg ("psphot.pspsf", 3, "test model %s, ap-fit: %f +/- %f, sky bias: %f\n", 155 182 modelName, test->ApResid, test->dApResid, test->skyBias); 183 156 184 return (test); 157 185 } … … 223 251 float dBin; 224 252 int nKeep, nSkip; 225 226 253 227 254 // the measured (aperture - fit) magnitudes (dA == test->metric) … … 280 307 if (tmp->n < 2) { 281 308 maskB->data.U8[i] = 1; 309 psFree (tmp); 282 310 continue; 283 311 } … … 327 355 test->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS)); 328 356 329 psFree ( maskB);357 psFree (rflux); 330 358 psFree (rfBin); 331 359 psFree (daBin); 360 psFree (maskB); 332 361 psFree (daBinFit); 333 362 psFree (daResid); -
trunk/psphot/src/setup.c
r4642 r4901 29 29 image = psFitsReadImage (NULL, file, region, 0); 30 30 psFree (file); 31 // psFree (input); 32 // XXX - does the current API expect to get a copy or a view? 31 33 32 34 // grab these values from the approrpiate location (image header if necessary) … … 42 44 noise = psFitsReadImage (NULL, file, region, 0); 43 45 psFree (file); 46 // psFree (noiseName); XXX - see psFree (input) 44 47 } else { 45 48 … … 73 76 mask = psFitsReadImage (NULL, file, region, 0); 74 77 psFree (file); 78 // psFree (maskName); XXX - see psFree (input) 75 79 // XXX require / convert mask to psU8? 76 80 } else { … … 96 100 } 97 101 } 102 98 103 psLogMsg ("psphot", 3, "load data: %f sec\n", psTimerMark ("psphot")); 99 104 100 105 // save the image data & return it 101 psImageData *imdata = psAlloc(sizeof(psImageData)); 102 imdata->image = image; 103 imdata->header = header; 104 imdata->noise = noise; 105 imdata->mask = mask; 106 106 psImageData *imdata = psImageDataAlloc(image, noise, mask, header); 107 107 return (imdata); 108 108 } -
trunk/psphot/src/source_moments.c
r4574 r4901 5 5 bool status = false; 6 6 psArray *sources = NULL; 7 8 psMemoryId id = psMemGetId (); 7 9 8 10 psTimerStart ("psphot"); … … 17 19 18 20 for (int i = 0; i < peaks->n; i++) { 21 19 22 // create a new source, add peak 20 23 psSource *source = pmSourceAlloc(); 21 source->peak = (psPeak *)p eaks->data[i];24 source->peak = (psPeak *)psMemCopy(peaks->data[i]); 22 25 23 26 // allocate image, noise, mask arrays for each peak (square of radius OUTER) 27 // XXX - this has 12 leaks (v.5) 24 28 pmSourceDefinePixels (source, imdata, source->peak->x, source->peak->y, OUTER); 25 29 26 30 // this should use ROBUST not SAMPLE median, but it is broken 27 31 status = pmSourceLocalSky_EAM (source, PS_STAT_SAMPLE_MEDIAN, INNER); 28 if (!status) continue; 32 if (!status) { 33 psFree (source); 34 continue; 35 } 29 36 30 37 status = pmSourceMoments (source, RADIUS); 31 if (!status) continue; 38 if (!status) { 39 psFree (source); 40 continue; 41 } 32 42 33 43 psArrayAdd (sources, 100, source); 44 psFree (source); 34 45 } 35 46
Note:
See TracChangeset
for help on using the changeset viewer.
