Changeset 6851
- Timestamp:
- Apr 12, 2006, 8:59:15 PM (20 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 1 added
- 14 edited
-
Makefile.am (modified) (1 diff)
-
psphot.c (modified) (2 diffs)
-
psphot.h (modified) (2 diffs)
-
psphotArguments.c (modified) (2 diffs)
-
psphotBlendFit.c (modified) (1 diff)
-
psphotChoosePSF.c (modified) (2 diffs)
-
psphotEvalPSF.c (modified) (1 diff)
-
psphotFitSet.c (modified) (2 diffs)
-
psphotImageMedian.c (modified) (6 diffs)
-
psphotModelTest.c (modified) (4 diffs)
-
psphotParseCamera.c (modified) (3 diffs)
-
psphotReadout.c (modified) (3 diffs)
-
psphotSkyReplace.c (modified) (1 diff)
-
psphotSourceFits.c (modified) (11 diffs)
-
psphotWeightBias.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/Makefile.am
r6727 r6851 41 41 psphotModelTest.c \ 42 42 psphotFitSet.c \ 43 psphotWeightBias.c \ 43 44 psphotCleanup.c 44 45 -
trunk/psphot/src/psphot.c
r6727 r6851 3 3 // XXX need a better structure for handling optional sequences 4 4 int main (int argc, char **argv) { 5 6 // headtest (argc, argv);7 5 8 6 psTimerStart ("complete"); … … 27 25 exit (0); 28 26 } 29 30 /** I/O test code31 32 psFits *fits = psFitsOpen (argv[1], "r");33 psMetadata *header = psFitsReadHeader (NULL, fits);34 psFitsClose (fits);35 36 psMetadata *new = psMetadataCopy (NULL, header);37 psMetadataConfigWrite (new, "test.cnf");38 39 fits = psFitsOpen ("test.fits", "w");40 psFitsWriteHeaderNotImage (fits, new);41 psFitsClose (fits);42 43 exit (0);44 45 **/ -
trunk/psphot/src/psphot.h
r6753 r6851 54 54 bool psphotDumpMoments (psMetadata *config, psArray *sources); 55 55 psMetadata *psphotDefineHeader (psMetadata *config); 56 bool psphotWeightBias (pmReadout *readout, psArray *sources, psMetadata *config, pmPSF *psf); 56 57 57 58 // PSF / DBL / EXT evaluation functions … … 63 64 bool psphotInitLimitsPSF (psMetadata *config); 64 65 bool psphotInitLimitsEXT (psMetadata *config); 65 bool psphotFitBlend (pmReadout *readout, pmSource *source );66 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources );67 bool psphotFitPSF (pmReadout *readout, pmSource *source );66 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf); 67 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf); 68 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf); 68 69 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source); 69 70 psArray *psphotFitDBL (pmReadout *readout, pmSource *source); 70 71 72 // functions to support simultaneous multi-source fitting 73 bool psphotFitSet (pmSource *oneSrc, pmModel *oneModel, char *fitset, pmSourceFitMode mode); 74 71 75 // XXX these can probably be dropped: 72 73 // functions to support simultaneous multi-source fitting74 bool psphotFitSet (pmSource *oneSrc, pmModel *oneModel, char *fitset, bool PSF);75 76 76 77 # if (0) -
trunk/psphot/src/psphotArguments.c
r6715 r6851 10 10 11 11 int N; 12 bool status; 12 13 13 14 if (*argc == 1) usage (); … … 118 119 } 119 120 120 // we load all input files onto a psArray, to be parsed later 121 psArray *input = psArrayAlloc (16); 122 input->n = 0; 123 124 // load the list of filenames the supplied file (may be a glob: "file*.fits") 125 if ((N = psArgumentGet (*argc, argv, "-file"))) { 126 glob_t globList; 127 psArgumentRemove (N, argc, argv); 128 globList.gl_offs = 0; 129 glob (argv[N], 0, NULL, &globList); 130 for (int i = 0; i < globList.gl_pathc; i++) { 131 char *filename = psStringCopy (globList.gl_pathv[i]); 132 psArrayAdd (input, 16, filename); 133 psFree (filename); 134 } 135 psArgumentRemove (N, argc, argv); 136 } 137 138 // load the list from the supplied text file 139 if ((N = psArgumentGet (*argc, argv, "-list"))) { 140 int nItems; 141 char line[1024]; // XXX limits the list lines to 1024 chars 142 char word[1024]; 143 char *filename; 144 145 psArgumentRemove (N, argc, argv); 146 FILE *f = fopen (argv[N], "r"); 147 if (f == NULL) { 148 psAbort ("psphot", "unable to open specified list file"); 149 } 150 while (fgets (line, 1024, f) != NULL) { 151 nItems = sscanf (line, "%s", word); 152 switch (nItems) { 153 case 0: 154 break; 155 case 1: 156 filename = psStringCopy (word); 157 psArrayAdd (input, 16, filename); 158 psFree (filename); 159 break; 160 default: 161 // rigid format, no comments allowed? 162 psAbort ("psphot", "error parsing input list file"); 163 break; 164 } 165 } 166 psArgumentRemove (N, argc, argv); 167 } 168 if (input->n < 1) usage (); 169 170 // input list gets places as an array on the config->arguements list 171 psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "INPUT", PS_DATA_ARRAY, "", input); 172 psFree (input); 121 // the input file is a required argument; if not found, we will exit 122 status = pmConfigFileSetsMD (config->arguments, argc, argv, "INPUT", "-file", "-list"); 123 if (!status) { usage ();} 173 124 174 125 if (*argc != 2) usage (); -
trunk/psphot/src/psphotBlendFit.c
r6753 r6851 54 54 55 55 // try fitting PSFs, then try extended sources 56 if (psphotFitBlend (readout, source )) continue;57 if (psphotFitBlob (readout, source, sources )) continue;56 if (psphotFitBlend (readout, source, psf)) continue; 57 if (psphotFitBlob (readout, source, sources, psf)) continue; 58 58 59 59 psTrace ("psphot.blend", 5, "failed fits\n"); -
trunk/psphot/src/psphotChoosePSF.c
r6715 r6851 27 27 int NSTARS = psMetadataLookupS32 (&status, config, "PSF_MAX_NSTARS"); 28 28 if (!status) NSTARS = PS_MIN (sources->n, 200); 29 30 // use poissonian errors or local-sky errors 31 bool POISSON_ERRORS = psMetadataLookupBool (&status, config, "POISSON_ERRORS"); 32 if (!status) POISSON_ERRORS = true; 33 pmSourceFitModelInit (15, 0.1, POISSON_ERRORS); 29 34 30 35 stars = psArrayAlloc (sources->n); … … 63 68 psMetadataItem *item = psListGetAndIncrement (iter); 64 69 modelName = item->data.V; 65 models->data[i] = pmPSFtryModel (stars, modelName, RADIUS );70 models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS); 66 71 } 67 72 psFree (iter); -
trunk/psphot/src/psphotEvalPSF.c
r6715 r6851 109 109 dSX = model->dparams->data.F32[4]; 110 110 dSY = model->dparams->data.F32[5]; 111 Chi = model->chisq / model->nDOF;111 Chi = model->chisqNorm / model->nDOF; 112 112 113 113 // swing of sigma_x,y in sigmas -
trunk/psphot/src/psphotFitSet.c
r6715 r6851 1 1 # include "psphot.h" 2 2 3 bool psphotFitSet (pmSource *source, pmModel *oneModel, char *fitset, bool PSF) {3 bool psphotFitSet (pmSource *source, pmModel *oneModel, char *fitset, pmSourceFitMode mode) { 4 4 5 5 double x, y, Io; … … 24 24 } 25 25 26 pmSourceFitSet (source, modelSet, PSF);26 pmSourceFitSet (source, modelSet, mode); 27 27 28 28 // write out positive object -
trunk/psphot/src/psphotImageMedian.c
r6753 r6851 1 1 # include "psphot.h" 2 double psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax);3 void fsort (float *value, int N);4 5 // random number seed to select a fraction of the image pixels6 static psRandom *rnd;7 8 // use no more than MAX_SAMPLE_PIXELS pixels for each median box9 static int MAX_SAMPLE_PIXELS;10 2 11 3 // generate the median in NxN boxes, clipping heavily … … 15 7 bool status; 16 8 psRegion region; 17 psImage *model = NULL;9 int MAX_SAMPLE_PIXELS; 18 10 19 11 psTimerStart ("psphot"); 20 12 13 // select the appropriate recipe information 14 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, "PSPHOT"); 15 16 MAX_SAMPLE_PIXELS = psMetadataLookupF32 (&status, recipe, "IMSTATS_NPIX"); 17 if (!status) MAX_SAMPLE_PIXELS = 1000; 18 psImageClippedStatsInit(MAX_SAMPLE_PIXELS); 19 20 // subtract this amount extra from the sky 21 float SKY_BIAS = psMetadataLookupF32 (&status, recipe, "SKY_BIAS"); 22 if (!status) SKY_BIAS = 0; 23 21 24 // find the currently selected readout 22 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, "PSPHOT"); 23 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT"); 24 pmReadout *readout = pmFPAviewThisReadout (view, input->fpa); 25 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT"); 25 26 26 27 psImage *image = readout->image; 27 28 psImage *mask = readout->mask; 28 29 rnd = psRandomAlloc (PS_RANDOM_TAUS, 0);30 MAX_SAMPLE_PIXELS = psMetadataLookupF32 (&status, recipe, "IMSTATS_NPIX");31 if (!status) MAX_SAMPLE_PIXELS = 1000;32 29 33 30 // dimensions of input & output image … … 49 46 int ny = (Ny % DY) ? (int)(Ny / DY) + 1 : Ny / DY; 50 47 51 // select model pixels, from output background model file, or create 52 model = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32); 48 // select model pixels (from output background model file, or create internal file) 49 pmReadout *model = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKMDL"); 50 if (model == NULL) { 51 // select model pixels, from output background model file, or create 52 model = pmFPAfileCreateInternal (config->files, "PSPHOT.BACKMDL", nx, ny, PS_TYPE_F32); 53 } else { 54 // replace the supplied image data with an image of the desired size 55 psImageRecycle (model->image, nx, ny, PS_TYPE_F32); 56 } 57 psF32 **modelData = model->image->data.F32; 53 58 54 59 // measure clipped median for subimages … … 63 68 psImage *submask = psImageSubset (mask, region); 64 69 65 model->data.F32[iy][ix] = psImageClippedStats (subset, submask, 0xff, 0.25, 0.50); 70 // XXX the value of the upper and lower cuts probably should be studied... 71 modelData[iy][ix] = psImageClippedStats (subset, submask, 0xff, 0.25, 0.75) + SKY_BIAS; 66 72 67 73 psFree (subset); … … 76 82 psLogMsg ("psphot", 3, "build median image: %f sec\n", psTimerMark ("psphot")); 77 83 78 // linear interpolation to full-scale 84 // XXX temporarily until we get the pmFPAfile output finished 85 psphotSaveImage (NULL, model->image, "model.fits"); 79 86 80 87 // select background pixels, from output background file, or create 81 psImage *background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32); 82 83 // XXX this code skips the initial pixels 84 for (int Iy = 0; Iy < ny-1; Iy ++) { 85 for (int Ix = 0; Ix < nx-1; Ix ++) { 86 87 float V00 = model->data.F32[Iy+0][Ix+0]; 88 float V01 = model->data.F32[Iy+0][Ix+1]; 89 float V10 = model->data.F32[Iy+1][Ix+0]; 90 float V11 = model->data.F32[Iy+1][Ix+1]; 91 92 // a single binned pixel quad 93 // (Xs,Ys) : (Xe,Ye) : binned pixel centers in unbinned coords 94 // corresponding to (Ix,Iy), (Ix+1,Iy+1) 95 int Xs = (Ix + 1)*DX - dx; 96 int Ys = (Iy + 1)*DY - dy; 97 int Xe = Xs + DX; 98 int Ye = Ys + DY; 99 100 for (int iy = Ys; (iy < Ye) && (iy < Ny); iy++) { 101 float Vxs = (V10 - V00)*(iy - Ys) / DY + V00; 102 float Vxe = (V11 - V01)*(iy - Ys) / DY + V01; 103 float dV = (Vxe - Vxs) / DX; 104 float V = Vxs; 105 for (int ix = Xs; (ix < Xe) && (ix < Nx); ix++) { 106 background->data.F32[iy][ix] = V; 107 V += dV; 108 } 109 } 110 } 88 pmReadout *background = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKGND"); 89 if (background == NULL) { 90 background = pmFPAfileCreateInternal (config->files, "PSPHOT.BACKGND", Nx, Ny, PS_TYPE_F32); 91 } else { 92 // replace the supplied image data with an image of the desired size 93 // XXX should not have to do this: it should be allocated correctly 94 // psImageRecycle (background->image, Nx, Ny, PS_TYPE_F32); 111 95 } 112 96 113 // side pixels 114 int Xs = DX - dx; 115 int Xe = nx*DX - dx; 116 for (int Iy = 0; Iy < ny - 1; Iy++) { 97 psF32 **backData = background->image->data.F32; 117 98 118 int Ys = (Iy + 1)*DY - dy; 119 int Ye = Ys + DY; 120 121 // leading edge 122 float V0 = model->data.F32[Iy+0][0]; 123 float V1 = model->data.F32[Iy+1][0]; 124 float dV = (V1 - V0) / DY; 125 float V = V0; 126 for (int iy = Ys; (iy < Ye) && (iy < Ny); iy++) { 127 for (int ix = 0; ix < Xs; ix++) { 128 background->data.F32[iy][ix] = V; 129 } 130 V += dV; 131 } 132 133 // trailing edge 134 V0 = model->data.F32[Iy+0][nx-1]; 135 V1 = model->data.F32[Iy+1][nx-1]; 136 dV = (V1 - V0) / DY; 137 V = V0; 138 for (int iy = Ys; (iy < Ye) && (iy < Ny); iy++) { 139 for (int ix = Xe; ix < Nx; ix++) { 140 background->data.F32[iy][ix] = V; 141 } 142 V += dV; 143 } 144 } 145 146 // top and bottom pixels 147 int Ys = DY - dy; 148 int Ye = ny*DY - dy; 149 for (int Ix = 0; Ix < nx - 1; Ix++) { 150 151 int Xs = (Ix + 1)*DX - dx; 152 int Xe = Xs + DX; 153 154 // top edge 155 float V0 = model->data.F32[0][Ix+0]; 156 float V1 = model->data.F32[0][Ix+1]; 157 float dV = (V1 - V0) / DX; 158 for (int iy = 0; iy < Ys; iy++) { 159 float V = V0; 160 for (int ix = Xs; (ix < Xe) && (ix < Nx); ix++) { 161 background->data.F32[iy][ix] = V; 162 V += dV; 163 } 164 } 165 166 // bottom edge 167 V0 = model->data.F32[ny-1][Ix+0]; 168 V1 = model->data.F32[ny-1][Ix+1]; 169 dV = (V1 - V0) / DX; 170 for (int iy = Ye; iy < Ny; iy++) { 171 float V = V0; 172 for (int ix = Xs; (ix < Xe) && (ix < Nx); ix++) { 173 background->data.F32[iy][ix] = V; 174 V += dV; 175 } 176 } 177 } 178 179 // the four corners 180 { 181 float V; 182 // 0,0 183 V = model->data.F32[0][0]; 184 for (int iy = 0; iy < DY - dy; iy++) { 185 for (int ix = 0; ix < DX - dx; ix++) { 186 background->data.F32[iy][ix] = V; 187 } 188 } 189 // Nx,0 190 V = model->data.F32[0][nx-1]; 191 for (int iy = 0; iy < DY - dy; iy++) { 192 for (int ix = nx*DX - dx; ix < Nx; ix++) { 193 background->data.F32[iy][ix] = V; 194 } 195 } 196 // 0,Ny 197 V = model->data.F32[ny-1][0]; 198 for (int iy = ny*DY - dy; iy < Ny; iy++) { 199 for (int ix = 0; ix < DX - dx; ix++) { 200 background->data.F32[iy][ix] = V; 201 } 202 } 203 // Nx,Ny 204 V = model->data.F32[nx-1][ny-1]; 205 for (int iy = ny*DY - dy; iy < Ny; iy++) { 206 for (int ix = nx*DX - dx; ix < Nx; ix++) { 207 background->data.F32[iy][ix] = V; 208 } 209 } 210 } 99 // linear interpolation to full-scale 100 psImageUnbin (background->image, model->image, DX, DY, dx, dy); 211 101 psLogMsg ("psphot", 3, "build resampled image: %f sec\n", psTimerMark ("psphot")); 212 102 213 psphotSaveImage (NULL, background, "back.fits"); 103 // XXX temporarily until we get the pmFPAfile output finished... 104 psphotSaveImage (NULL, background->image, "back.fits"); 214 105 215 106 // back-sub image pixels, from output background file (don't create if not requested) 216 p sImage *backSub = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKSUB", 0, 0, PS_TYPE_F32);107 pmReadout *backSub = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKSUB"); 217 108 218 // subtract the background model 109 // subtract the background model (save in backSub, if requested) 219 110 for (int j = 0; j < image->numRows; j++) { 220 111 for (int i = 0; i < image->numCols; i++) { 221 112 if (!mask->data.U8[j][i]) { 222 image->data.F32[j][i] -= back ground->data.F32[j][i];113 image->data.F32[j][i] -= backData[j][i]; 223 114 if (backSub) { 224 backSub-> data.F32[j][i] = image->data.F32[j][i];115 backSub->image->data.F32[j][i] = image->data.F32[j][i]; 225 116 } 226 117 } … … 229 120 230 121 psLogMsg ("psphot", 3, "subtracted background model: %f sec\n", psTimerMark ("psphot")); 231 ps Free (rnd);122 psImageClippedStatsCleanup(); 232 123 233 // it is safe to free all of these: either they are saved on config->files or are local 234 psFree (model); 235 psFree (background); 236 psFree (backSub); 124 // the pmReadout selected in this function are all view on entries in config->files 237 125 return true; 238 126 } 239 240 double psImageClippedStats (psImage *image, psImage *mask, psU8 maskValue, double fmin, double fmax) {241 242 double value;243 int nx = image->numCols;244 int ny = image->numRows;245 246 if (nx*ny <= 0) return 0.0;247 248 int Nsubset = PS_MIN (MAX_SAMPLE_PIXELS, nx*ny);249 int Npixels = nx*ny;250 251 psVector *values = psVectorAlloc (Nsubset, PS_TYPE_F32);252 253 float min = values->data.F32[0];254 float max = values->data.F32[0];255 256 int n = 0;257 for (int i = 0; i < Nsubset; i++) {258 double frnd = psRandomUniform (rnd);259 int pixel = Npixels * frnd;260 int ix = pixel % nx;261 int iy = pixel / nx;262 263 if (mask->data.U8[iy][ix] & maskValue) continue;264 265 value = image->data.F32[iy][ix];266 min = PS_MIN (value, min);267 max = PS_MIN (value, max);268 values->data.F32[n] = value;269 n++;270 }271 values->n = n;272 273 int imin = fmin * n;274 int imax = fmax * n;275 int npts = imax - imin + 1;276 277 fsort (values->data.F32, n);278 279 value = 0;280 for (int i = imin; (i <= imax) && (i < n); i++) {281 value += values->data.F32[i];282 }283 value = value / npts;284 285 // XXX correct for selection bias??286 287 psFree (values);288 return value;289 }290 291 void fsort (float *value, int N) {292 293 int l,j,ir,i;294 float temp;295 296 if (N < 2) return;297 l = N >> 1;298 ir = N - 1;299 for (;;) {300 if (l > 0) {301 temp = value[--l];302 }303 else {304 temp = value[ir];305 value[ir] = value[0];306 if (--ir == 0) {307 value[0] = temp;308 return;309 }310 }311 i = l;312 j = (l << 1) + 1;313 while (j <= ir) {314 if (j < ir && value[j] < value[j+1]) ++j;315 if (temp < value[j]) {316 value[i]=value[j];317 j += (i=j) + 1;318 }319 else j = ir + 1;320 }321 value[i] = temp;322 }323 }324 -
trunk/psphot/src/psphotModelTest.c
r6727 r6851 10 10 char name[64]; 11 11 pmPSF *psf = NULL; 12 pmSourceFitMode fitMode; 12 13 13 14 psMetadataItem *item = NULL; 15 16 // use poissonian errors or local-sky errors 17 bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, "POISSON_ERRORS"); 18 if (!status) POISSON_ERRORS = true; 19 pmSourceFitModelInit (15, 0.1, POISSON_ERRORS); 14 20 15 21 // run model fitting tests on a single source … … 17 23 18 24 // what fitting mode to use? 19 char * psfModeWord = psMetadataLookupStr (&status, recipe, "TEST_FIT_MODE");25 char *fitModeWord = psMetadataLookupStr (&status, recipe, "TEST_FIT_MODE"); 20 26 if (!status) { 21 psfModeWord = DEFAULT_MODE;27 fitModeWord = DEFAULT_MODE; 22 28 } 23 bool psfMode = !strcasecmp (psfModeWord, "PSF"); 29 fitMode = PM_SOURCE_FIT_EXT; 30 if (!strcasecmp (fitModeWord, "PSF")) fitMode = PM_SOURCE_FIT_PSF; 24 31 25 // in psfMode, psf sets the model type26 if ( psfMode) {32 // in fitMode, psf sets the model type 33 if (fitMode == PM_SOURCE_FIT_PSF) { 27 34 char *psfFile = psMetadataLookupStr (&status, recipe, "PSF_INPUT_FILE"); 28 35 if (!status) psAbort ("psphotModelTest", "PSF_INPUT_FILE not supplied"); … … 128 135 fprintf (stderr, "peak: %f @ (%f, %f)\n", source->moments->Sum*area, (double)source->peak->x, (double)source->peak->y); 129 136 130 if ( psfMode) {137 if (fitMode == PM_SOURCE_FIT_PSF) { 131 138 pmModel *modelPSF = pmModelFromPSF (model, psf); 132 139 psFree (model); … … 155 162 char *fitset = psMetadataLookupStr (&status, recipe, "TEST_FIT_SET"); 156 163 if (status) { 157 status = psphotFitSet (source, model, fitset, psfMode);164 status = psphotFitSet (source, model, fitset, fitMode); 158 165 exit (0); 159 166 } 160 167 161 status = pmSourceFitModel (source, model, psfMode);168 status = pmSourceFitModel (source, model, fitMode); 162 169 163 170 // measure the source mags -
trunk/psphot/src/psphotParseCamera.c
r6727 r6851 4 4 5 5 bool status; 6 psFits *fits = NULL;7 psMetadata *phu = NULL;8 psMetadata *format = NULL;9 6 10 // psphot is supplied with a list of input images (may be only one image) 11 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, "INPUT"); 12 if (!status) psAbort (__func__, "missing INPUT entry"); 13 if (infiles->n < 1) psAbort (__func__, "empty input list"); 14 15 // if no camera has been specified, use the first image as a template for the rest. 16 if (config->camera == NULL) { 17 fits = psFitsOpen (infiles->data[0], "r"); 18 phu = psFitsReadHeader (NULL, fits); 19 format = pmConfigCameraFormatFromHeader (config, phu); 20 psFitsClose (fits); 7 status = false; 8 pmFPAfile *input = pmFPAfileFromArgs (&status, config, "PSPHOT.INPUT", "INPUT"); 9 if (!status) { 10 psAbort (__func__, "missing INPUT entry"); 21 11 } 22 // There's no point in continuing if we can't recognize what we've got23 if (! config->camera) {24 psErrorStackPrint(stderr, "Can't find camera configuration!\n");25 exit(EXIT_FAILURE);26 }27 28 // files29 config->files = psMetadataAlloc ();30 31 // build the template fpa, set up the basic view32 // XXX : 216 leaks in pmFPAConstruct / psFree (input)33 pmFPA *input = pmFPAConstruct (config->camera);34 35 // assign the I/O files (potentially) needed by psphot36 // the output file is just a view to the file on config->files37 pmFPAfile *file = pmFPAfileDefine (config->files, format, input, "PSPHOT.INPUT");38 if (!file) {39 exit(EXIT_FAILURE);40 }41 42 for (int i = 0; i < infiles->n; i++) {43 if (phu == NULL) {44 fits = psFitsOpen (infiles->data[i], "r");45 phu = psFitsReadHeader (NULL, fits);46 pmConfigValidateCameraFormat (format, phu);47 psFitsClose (fits);48 }49 50 // set the view to the corresponding entry for this phu51 pmFPAview *view = pmFPAAddSource (input, phu, format);52 53 // XXX is this the correct psMD to save the filename?54 char *name = pmFPAfileNameFromRule (file->filextra, file, view);55 psMetadataAddStr (file->names, PS_LIST_TAIL, name, 0, "", infiles->data[i]);56 57 psFree (view);58 psFree (name);59 psFree (phu);60 phu = NULL;61 }62 63 pmFPAfileDefine (config->files, format, input, "PSPHOT.OUTPUT");64 pmFPAfileDefine (config->files, format, input, "PSPHOT.RESID");65 66 // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_INPUT");67 // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_OUTPUT");68 69 // build the template fpa, set up the basic view70 // supply the backgnd with a different camera?71 // allow alternate format?72 // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKSUB");73 // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKGND");74 // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.BACKMDL");75 // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.PSF_SAMPLE");76 77 // psphot is supplied with the output name78 // this needs to be better: supply to all output (WRITE) files?79 char *output = psMetadataLookupPtr(&status, config->arguments, "OUTPUT");80 81 file = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");82 if (!status) psAbort (__func__, "missing OUTPUT entry");83 psMetadataAddStr (file->names, PS_LIST_TAIL, "OUTPUT", 0, "", output);84 85 file = psMetadataLookupPtr (&status, config->files, "PSPHOT.RESID");86 if (!status) psAbort (__func__, "missing OUTPUT entry");87 psMetadataAddStr (file->names, PS_LIST_TAIL, "OUTPUT", 0, "", output);88 12 89 13 // recipe override values (command-line options): … … 96 20 } 97 21 psFree (iter); 22 23 // these calls bind the I/O handle to the specified fpa 24 pmFPAfileDefine (config->files, config->camera, input->fpa, "PSPHOT.OUTPUT"); 25 pmFPAfileDefine (config->files, config->camera, input->fpa, "PSPHOT.RESID"); 26 27 // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_INPUT"); 28 // pmFPAfileDefine (config->files, format, input, "PSPHOT.PSF_OUTPUT"); 29 30 // these calls construct a new fpa for the I/O handle 31 int DX = psMetadataLookupS32 (&status, recipe, "BACKGROUND_XBIN"); 32 if (!status) {DX = 64;} 33 int DY = psMetadataLookupS32 (&status, recipe, "BACKGROUND_YBIN"); 34 if (!status) {DY = 64;} 35 pmFPAfileFromFPA (config, input->fpa, DX, DY, "PSPHOT.BACKMDL"); 36 pmFPAfileFromFPA (config, input->fpa, 1, 1, "PSPHOT.BACKGND"); 37 pmFPAfileFromFPA (config, input->fpa, 1, 1, "PSPHOT.BACKSUB"); 38 39 // pmFPAfileConstruct (config->files, format, config->camera, "PSPHOT.PSF_SAMPLE"); 40 41 // psphot is supplied with the output name 42 // this needs to be better: supply to all output (WRITE) files? 43 char *output = psMetadataLookupPtr(&status, config->arguments, "OUTPUT"); 44 pmFPAfileAddFileNames (config->files, "OUTPUT", output, PM_FPA_MODE_WRITE); 98 45 99 46 // set default recipe values here … … 129 76 # endif 130 77 131 psFree (input);132 psFree (format);133 134 78 psTrace(__func__, 1, "Done with psphotParseCamera...\n"); 135 79 return true; -
trunk/psphot/src/psphotReadout.c
r6753 r6851 9 9 bool status; 10 10 11 // select the current recipe 12 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, "PSPHOT"); 13 11 14 // find the currently selected readout 12 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, "PSPHOT"); 13 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT"); 14 pmReadout *readout = pmFPAviewThisReadout (view, input->fpa); 15 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT"); 15 16 16 17 // XXX does this need to invoke I/O? 18 // XXX move this input the psphotImageLoop level? 17 19 pmReadoutSetWeights (readout); 20 psphotSaveImage (NULL, readout->weight, "weight.fits"); 18 21 19 22 // I have a valid mask, now mask in the analysis region of interest … … 49 52 psphotBlendFit (readout, sources, recipe, psf); 50 53 54 // psphotWeightBias (readout, sources, recipe, psf); 55 51 56 // replace fitted sources 52 57 psphotReplaceUnfit (sources); … … 75 80 status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN, "psphot psf", psf); 76 81 82 // remove internal pmFPAfiles, if created 83 pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL"); 84 pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND"); 85 77 86 // free up the local copies of the data 78 87 psFree (psf); -
trunk/psphot/src/psphotSkyReplace.c
r6727 r6851 5 5 bool psphotSkyReplace (pmConfig *config, pmFPAview *view) { 6 6 7 bool status; 7 // find the currently selected readout 8 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT"); 9 if (readout == NULL) psAbort ("psphot", "input not defined"); 8 10 9 // find the currently selected readout 10 // psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, "PSPHOT"); 11 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT"); 12 pmReadout *readout = pmFPAviewThisReadout (view, input->fpa); 11 // select background pixels, from output background file, or create 12 pmReadout *background = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKGND"); 13 if (background == NULL) psAbort ("psphot", "background not defined"); 13 14 14 15 // select the corresponding images 15 psImage *image = readout->image; 16 psImage *mask = readout->mask; 17 18 // select background pixels, from output background file, or create 19 psImage *background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", 0, 0, PS_TYPE_F32); 20 if (background == NULL) { 21 return false; 22 } 16 psF32 **image = readout->image->data.F32; 17 psU8 **mask = readout->mask->data.U8; 18 psF32 **back = background->image->data.F32; 23 19 24 20 // replace the background model 25 for (int j = 0; j < image->numRows; j++) {26 for (int i = 0; i < image->numCols; i++) {27 if (!mask ->data.U8[j][i]) {28 image ->data.F32[j][i] += background->data.F32[j][i];21 for (int j = 0; j < readout->image->numRows; j++) { 22 for (int i = 0; i < readout->image->numCols; i++) { 23 if (!mask[j][i]) { 24 image[j][i] += back[j][i]; 29 25 } 30 26 } 31 27 } 32 33 psFree (background);34 28 return true; 35 29 } -
trunk/psphot/src/psphotSourceFits.c
r6753 r6851 3 3 // given a source with an existing modelPSF, attempt a full PSF fit, subtract if successful 4 4 5 bool psphotFitPSF (pmReadout *readout, pmSource *source ) {5 bool psphotFitPSF (pmReadout *readout, pmSource *source, pmPSF *psf) { 6 6 7 7 float x, y; 8 double chiTrend; 8 9 9 10 // save the PSF model from the Ensemble fit … … 18 19 // fit PSF model (set/unset the pixel mask) 19 20 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "OR", PM_SOURCE_MASK_MARKED); 20 pmSourceFitModel (source, PSF, true);21 pmSourceFitModel (source, PSF, PM_SOURCE_FIT_PSF); 21 22 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", ~PM_SOURCE_MASK_MARKED); 23 24 // correct model chisq for flux trend 25 chiTrend = psPolynomial1DEval (psf->ChiTrend, PSF->params->data.F32[1]); 26 PSF->chisqNorm = PSF->chisq / chiTrend; 27 // PSF->chisqNorm = PSF->chisq; 22 28 23 29 // does the PSF model succeed? … … 60 66 } 61 67 62 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources ) {68 bool psphotFitBlob (pmReadout *readout, pmSource *source, psArray *sources, pmPSF *psf) { 63 69 64 70 bool okEXT, okDBL; 65 71 float chiEXT, chiDBL; 72 double chiTrend; 73 pmModel *ONE = NULL; 66 74 67 75 // skip the source if we don't think it is extended … … 86 94 okDBL = psphotEvalDBL (tmpSrc, DBL->data[0]); 87 95 okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]); 88 pmModel *ONE = DBL->data[0]; 89 chiDBL = ONE->chisq / ONE->nDOF; 96 97 // correct first model chisqs for flux trend 98 ONE = DBL->data[0]; 99 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 100 ONE->chisqNorm = ONE->chisq / chiTrend; 101 // ONE->chisqNorm = ONE->chisq; 102 103 // save chisq for double-star/galaxy comparison 104 chiDBL = ONE->chisqNorm; 105 106 // correct second model chisqs for flux trend 107 ONE = DBL->data[1]; 108 chiTrend = psPolynomial1DEval (psf->ChiTrend, ONE->params->data.F32[1]); 109 ONE->chisqNorm = ONE->chisq / chiTrend; 110 // ONE->chisqNorm = ONE->chisq; 90 111 91 112 psFree (tmpSrc); // XXX should I keep / save the flags set in the eval functions? … … 93 114 if (okEXT && okDBL) { 94 115 psTrace ("psphot.blend", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL); 95 // XXX EAM : a bogus bias: need to examine this better 116 // XXX EAM : a bogus bias: need to examine this better 96 117 if (3*chiEXT > chiDBL) goto keepDBL; 97 118 goto keepEXT; … … 188 209 y = source->moments->y; 189 210 190 // fit EXT (not PSF)model (set/unset the pixel mask)211 // fit PSF model (set/unset the pixel mask) 191 212 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "OR", PM_SOURCE_MASK_MARKED); 192 pmSourceFitSet (source, modelSet, true);213 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF); 193 214 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", ~PM_SOURCE_MASK_MARKED); 194 215 … … 210 231 // fit EXT (not PSF) model (set/unset the pixel mask) 211 232 psImageKeepCircle (source->mask, x, y, EXT->radiusTMP, "OR", PM_SOURCE_MASK_MARKED); 212 pmSourceFitModel (source, EXT, false);233 pmSourceFitModel (source, EXT, PM_SOURCE_FIT_EXT); 213 234 psImageKeepCircle (source->mask, x, y, EXT->radiusTMP, "AND", ~PM_SOURCE_MASK_MARKED); 214 235 … … 216 237 } 217 238 218 bool psphotFitBlend (pmReadout *readout, pmSource *source ) {239 bool psphotFitBlend (pmReadout *readout, pmSource *source, pmPSF *psf) { 219 240 220 241 float x, y, dR; … … 222 243 // if this source is not a possible blend, just fit as PSF 223 244 if ((source->blends == NULL) || (source->mode & PM_SOURCE_MODE_SATSTAR)) { 224 bool status = psphotFitPSF (readout, source );245 bool status = psphotFitPSF (readout, source, psf); 225 246 return status; 226 247 } … … 273 294 // fit PSF model (set/unset the pixel mask) 274 295 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "OR", PM_SOURCE_MASK_MARKED); 275 pmSourceFitSet (source, modelSet, true);296 pmSourceFitSet (source, modelSet, PM_SOURCE_FIT_PSF); 276 297 psImageKeepCircle (source->mask, x, y, PSF->radiusTMP, "AND", ~PM_SOURCE_MASK_MARKED); 298 299 // correct model chisq for flux trend 300 double chiTrend = psPolynomial1DEval (psf->ChiTrend, PSF->params->data.F32[1]); 301 PSF->chisqNorm = PSF->chisq / chiTrend; 302 // PSF->chisqNorm = PSF->chisq; 277 303 278 304 // evaluate the blend objects, subtract if good, free otherwise … … 280 306 pmSource *src = sourceSet->data[i]; 281 307 pmModel *model = modelSet->data[i]; 308 309 // correct model chisq for flux trend 310 chiTrend = psPolynomial1DEval (psf->ChiTrend, model->params->data.F32[1]); 311 model->chisqNorm = model->chisq / chiTrend; 312 // model->chisqNorm = model->chisq; 282 313 283 314 // if we skip this one, free the corresponding blend entry model
Note:
See TracChangeset
for help on using the changeset viewer.
