Changeset 5837
- Timestamp:
- Dec 23, 2005, 1:58:45 PM (21 years ago)
- Location:
- trunk/psphot
- Files:
-
- 8 edited
-
Makefile (modified) (1 diff)
-
src/psphotApResid.c (modified) (3 diffs)
-
src/psphotArguments.c (modified) (1 diff)
-
src/psphotEnsemblePSF.c (modified) (2 diffs)
-
src/psphotMagnitudes.c (modified) (4 diffs)
-
src/psphotModelTest.c (modified) (1 diff)
-
src/psphotOutput.c (modified) (19 diffs)
-
src/psphotTest.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/Makefile
r5828 r5837 97 97 $(MODELTEST): $(SRC)/psphot.h 98 98 99 test .install: psphotTest.install99 test-install: psphotTest.install 100 100 test: $(BIN)/psphotTest.$(ARCH) 101 101 $(BIN)/psphotTest.$(ARCH) : $(TEST) -
trunk/psphot/src/psphotApResid.c
r5828 r5837 5 5 int Npsf; 6 6 bool status; 7 float x, y;8 float fitMag, obsMag;7 pmModel *model; 8 pmSource *source; 9 9 10 10 // XXX EAM : check that PSF_FIT_RADIUS < SKY_OUTER_RADIUS … … 26 26 // select the NNN brightest, non-saturated sources, or just select PSFSTARs? 27 27 for (int i = 0; (i < sources->n) && (Npsf < 300); i++) { 28 pmSource *source = sources->data[i]; 29 pmModel *model = source->modelPSF; 28 source = sources->data[i]; 30 29 31 if (model == NULL) continue;32 30 if (source->type != PM_SOURCE_STAR) continue; 33 31 if (source->mode & PM_SOURCE_SATSTAR) continue; … … 36 34 if (source->mode & PM_SOURCE_POOR) continue; 37 35 38 // set shape for this model based on PSF 39 x = model->params->data.F32[2]; 40 y = model->params->data.F32[3]; 41 42 pmSourceAddModel (source->pixels, source->mask, model, false, false); 43 44 psImageKeepCircle (source->mask, x, y, RADIUS, "OR", PSPHOT_MASK_MARKED); 45 status = pmSourcePhotometry (&fitMag, &obsMag, model, source->pixels, source->mask); 46 psImageKeepCircle (source->mask, x, y, RADIUS, "AND", ~PSPHOT_MASK_MARKED); 47 48 pmSourceSubModel (source->pixels, source->mask, model, false, false); 49 if (!status) continue; 36 // get magnitudes, uncorrected for (x, y, rflux) 37 model = pmSourceMagnitudes (source, NULL, RADIUS); 38 if (model == NULL) continue; 50 39 51 40 mask->data.U8[Npsf] = 0; 52 xPos->data.F64[Npsf] = x;53 yPos->data.F64[Npsf] = y;54 rflux->data.F64[Npsf] = pow(10.0, 0.4* fitMag);55 apResid->data.F64[Npsf] = obsMag -fitMag;41 xPos->data.F64[Npsf] = model->params->data.F32[2]; 42 yPos->data.F64[Npsf] = model->params->data.F32[3]; 43 rflux->data.F64[Npsf] = pow(10.0, 0.4*source->fitMag); 44 apResid->data.F64[Npsf] = source->apMag - source->fitMag; 56 45 57 46 psVectorExtend (mask, 100, 1); -
trunk/psphot/src/psphotArguments.c
r5828 r5837 61 61 62 62 bool ModelTest = false; 63 float ModelTest_X, ModelTest_Y; 63 float ModelTest_X = 0; 64 float ModelTest_Y = 0; 64 65 char *model = NULL; 65 66 char *fitset = NULL; -
trunk/psphot/src/psphotEnsemblePSF.c
r5828 r5837 74 74 75 75 bool UseAnalysisRegion = false; 76 psRegion AnalysisRegion ;76 psRegion AnalysisRegion = {0, 0, 0, 0}; 77 77 char *region = psMetadataLookupPtr (&status, config, "ANALYSIS_REGION"); 78 78 if (status) { … … 236 236 // XXX EAM : need to free up many things here 237 237 238 psLogMsg ("psphot.emsemble", 3, "measure ensemble of PSFs: %f \n", psTimerMark ("psphot"));238 psLogMsg ("psphot.emsemble", 3, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot")); 239 239 return true; 240 240 } -
trunk/psphot/src/psphotMagnitudes.c
r5828 r5837 1 1 # include "psphot.h" 2 2 3 // XXX EAM : the apMag should only be calculated for the brighter sources 3 // XXX EAM : the apMag should only be calculated for the brighter sources? 4 4 // XXX EAM : SN limit set by user? 5 5 // XXX EAM : masked region should be (optionally) elliptical … … 7 7 8 8 int status; 9 bool isPSF; 9 10 float x, y; 10 11 float rflux; 12 float radius; 11 13 pmModel *model; 12 14 13 // use the correct model (PSF vs FLT) 14 if (psf != NULL) { 15 model = source->modelPSF; 16 } else { 17 model = source->modelFLT; 15 switch (source->type) { 16 case PM_SOURCE_STAR: 17 model = source->modelPSF; 18 if (model == NULL) return NULL; 19 radius = apRadius; 20 isPSF = true; 21 break; 22 23 case PM_SOURCE_GALAXY: 24 model = source->modelFLT; 25 if (model == NULL) return NULL; 26 radius = model->radius; 27 isPSF = false; 28 break; 29 30 default: 31 return NULL; 18 32 } 19 if (model == NULL) return NULL;20 33 21 x = source->peak->x; 22 y = source->peak->y; 23 24 // we have already (psphotApplyPSF) defined pixels at least OUTER_RADIUS from source 25 // we need to mask pixels to measure the aperture magnitude 26 // set aperture mask circle of PSF_FIT_RADIUS 27 psImageKeepCircle (source->mask, x, y, apRadius, "OR", PSPHOT_MASK_MARKED); 34 x = model->params->data.F32[2]; 35 y = model->params->data.F32[3]; 28 36 29 37 // replace source flux 30 38 pmSourceAddModel (source->pixels, source->mask, model, false, false); 39 40 // set aperture mask circle of PSF_FIT_RADIUS 41 psImageKeepCircle (source->mask, x, y, radius, "OR", PSPHOT_MASK_MARKED); 31 42 32 43 // measure object photometry … … 34 45 35 46 // for PSFs, correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS 36 if ( psf != NULL) {47 if (isPSF && (psf != NULL)) { 37 48 rflux = pow (10.0, 0.4*source->fitMag); 38 49 source->apMag -= rflux * psf->skyBias * (M_PI * PS_SQR(apRadius)); … … 44 55 45 56 // unmask aperture 46 psImageKeepCircle (source->mask, x, y, apRadius, "AND", ~PSPHOT_MASK_MARKED); 57 psImageKeepCircle (source->mask, x, y, radius, "AND", ~PSPHOT_MASK_MARKED); 58 59 if (!status) return NULL; 47 60 return model; 48 }49 50 pmModel *pmSourceSelectModel (pmSource *source) {51 52 pmModel *model;53 54 switch (source->type) {55 56 // use PSF model with stars57 case PM_SOURCE_STAR:58 model = source->modelPSF;59 break;60 61 // use FLT model with galaxies62 case PM_SOURCE_GALAXY:63 model = source->modelFLT;64 break;65 66 // skip defects and poorly fitted stars or galaxies67 default:68 model = NULL;69 }70 return (model);71 61 } 72 62 -
trunk/psphot/src/psphotModelTest.c
r5828 r5837 8 8 float obsMag, fitMag, value; 9 9 char name[64]; 10 pmPSF *psf ;10 pmPSF *psf = NULL; 11 11 12 12 psMetadataItem *item = NULL; -
trunk/psphot/src/psphotOutput.c
r5828 r5837 24 24 return; 25 25 } 26 if (!strcasecmp (outputMode, "OBJ")) { 27 pmSourcesWriteOBJ (imdata, config, outputFile, sources, psf, sky); 28 return; 29 } 30 if (!strcasecmp (outputMode, "SX")) { 31 pmSourcesWriteSX (imdata, config, outputFile, sources, psf, sky); 32 return; 33 } 34 if (!strcasecmp (outputMode, "CMP")) { 35 pmSourcesWriteCMP (imdata, config, outputFile, sources, psf, sky); 36 return; 37 } 38 if (!strcasecmp (outputMode, "CMF")) { 39 pmSourcesWriteCMF (imdata, config, outputFile, sources, psf, sky); 40 return; 41 } 26 42 if (!strcasecmp (outputMode, "TEXT")) { 27 43 pmSourcesWriteText (imdata, config, outputFile, sources, psf, sky); … … 29 45 } 30 46 31 if (!strcasecmp (outputMode, "OBJ")) {32 pmSourcesWriteOBJ (imdata, config, outputFile, sources, psf, sky);33 return;34 }35 36 if (!strcasecmp (outputMode, "SX")) {37 pmSourcesWriteSX (imdata, config, outputFile, sources, psf, sky);38 return;39 }40 41 if (!strcasecmp (outputMode, "CMP")) {42 pmSourcesWriteCMP (imdata, config, outputFile, sources, psf, sky);43 return;44 }45 46 if (!strcasecmp (outputMode, "CMF")) {47 pmSourcesWriteCMF (imdata, config, outputFile, sources, psf, sky);48 return;49 }50 51 47 psAbort ("psphot", "unknown output mode %s", outputMode); 52 }53 54 bool pmSourcesWriteText (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky) {55 56 char *name = (char *) psAlloc (strlen(filename) + 10);57 58 sprintf (name, "%s.psf.dat", filename);59 pmModelWritePSFs (sources, config, name, psf);60 61 sprintf (name, "%s.flt.dat", filename);62 pmModelWriteFLTs (sources, name);63 64 sprintf (name, "%s.nul.dat", filename);65 pmModelWriteNULLs (sources, name);66 67 sprintf (name, "%s.mnt.dat", filename);68 pmMomentsWriteText (sources, name);69 70 psFree (name);71 return true;72 48 } 73 49 … … 115 91 psLineAdd (line, "%9.3f", PAR[5]); 116 92 psLineAdd (line, "%7.2f", PAR[6]); 117 psLineAdd (line, "%8.3f", 32.0);93 psLineAdd (line, "%8.3f", 99.999); 118 94 psLineAdd (line, "%8.3f", source->apMag); 119 95 psLineAdd (line, "%8.2f\n", apResid); … … 166 142 psLineAdd (line, "%9.2f", 0.0); // should be FWHMy 167 143 psLineAdd (line, "%6.1f", 0.0); // should be Theta 168 psLineAdd (line, "%9.4f", 32.0); // should be MAG_ISO144 psLineAdd (line, "%9.4f", 99.999); // should be MAG_ISO 169 145 psLineAdd (line, "%9.4f", source->apMag); 170 146 psLineAdd (line, "%4d\n", 0); // should be flags … … 182 158 psMetadataItem *mdi; 183 159 psF32 *PAR, *dPAR; 184 float dmag, apResid,lsky;160 float dmag, lsky; 185 161 bool status; 186 162 … … 188 164 float RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS"); 189 165 float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT"); 166 if (!status) ZERO_POINT = 25.0; 190 167 char *PHOTCODE = psMetadataLookupPtr (&status, config, "PHOTCODE"); 191 168 … … 237 214 dmag = dPAR[1] / PAR[1]; 238 215 type = pmSourceDophotType (source); 239 apResid = source->apMag - source->fitMag;240 216 lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]); 241 217 … … 243 219 psLineAdd (line, "%6.1f ", PAR[2]); 244 220 psLineAdd (line, "%6.1f ", PAR[3]); 245 psLineAdd (line, "%6.3f ", PS_MIN ( 32.0, source->fitMag + ZERO_POINT));246 psLineAdd (line, "%03d ", (int)(1000*dmag));221 psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->fitMag + ZERO_POINT)); 222 psLineAdd (line, "%03d ", PS_MIN (999, (int)(1000*dmag))); 247 223 psLineAdd (line, "%2d ", type); 248 224 psLineAdd (line, "%3.1f ", lsky); 249 psLineAdd (line, "%6.3f ", 32.0); // should be 'Mgal250 psLineAdd (line, "%6.3f ", PS_MIN ( 32.0, source->apMag + ZERO_POINT));225 psLineAdd (line, "%6.3f ", 99.999); // should be 'Mgal 226 psLineAdd (line, "%6.3f ", PS_MIN (99.999, source->apMag + ZERO_POINT)); 251 227 psLineAdd (line, "%6.2f ", PAR[4]); // should be 'FHWM x' 252 228 psLineAdd (line, "%6.2f ", PAR[5]); // should be 'FHWM y' … … 297 273 298 274 table = psArrayAlloc (sources->n); 299 sources->n = 0;275 table->n = 0; 300 276 301 277 for (i = 0; i < sources->n; i++) { … … 313 289 314 290 row = psMetadataAlloc (); 315 psMetadataAdd (row, PS_LIST_ HEAD, "X_PIX", PS_DATA_F32, "", PAR[2]);316 psMetadataAdd (row, PS_LIST_ HEAD, "Y_PIX", PS_DATA_F32, "", PAR[3]);317 psMetadataAdd (row, PS_LIST_ HEAD, "MAG_RAW", PS_DATA_F32, "", source->fitMag + ZERO_POINT);318 psMetadataAdd (row, PS_LIST_ HEAD, "MAG_ERR", PS_DATA_F32, "", (int)(1000*dmag));319 psMetadataAdd (row, PS_LIST_ HEAD, "MAG_GAL", PS_DATA_F32, "", type);320 psMetadataAdd (row, PS_LIST_ HEAD, "MAG_AP", PS_DATA_F32, "", lsky);321 psMetadataAdd (row, PS_LIST_ HEAD, "LOG_SKY", PS_DATA_F32, "", 32.0); // should be 'Mgal'322 psMetadataAdd (row, PS_LIST_ HEAD, "FWHM_X", PS_DATA_F32, "", source->apMag + ZERO_POINT);323 psMetadataAdd (row, PS_LIST_ HEAD, "FWHM_Y", PS_DATA_F32, "", PAR[4]); // should be 'FHWM x'324 psMetadataAdd (row, PS_LIST_ HEAD, "THETA", PS_DATA_F32, "", PAR[5]); // should be 'FHWM y'325 psMetadataAdd (row, PS_LIST_ HEAD, "DOPHOT", PS_TYPE_S8,"", 0); // should be theta291 psMetadataAdd (row, PS_LIST_TAIL, "X_PIX", PS_DATA_F32, "", PAR[2]); 292 psMetadataAdd (row, PS_LIST_TAIL, "Y_PIX", PS_DATA_F32, "", PAR[3]); 293 psMetadataAdd (row, PS_LIST_TAIL, "MAG_RAW", PS_DATA_F32, "", source->fitMag + ZERO_POINT); 294 psMetadataAdd (row, PS_LIST_TAIL, "MAG_ERR", PS_DATA_F32, "", (int)(1000*dmag)); 295 psMetadataAdd (row, PS_LIST_TAIL, "MAG_GAL", PS_DATA_F32, "", type); 296 psMetadataAdd (row, PS_LIST_TAIL, "MAG_AP", PS_DATA_F32, "", lsky); 297 psMetadataAdd (row, PS_LIST_TAIL, "LOG_SKY", PS_DATA_F32, "", 32.0); // should be 'Mgal' 298 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_X", PS_DATA_F32, "", source->apMag + ZERO_POINT); 299 psMetadataAdd (row, PS_LIST_TAIL, "FWHM_Y", PS_DATA_F32, "", PAR[4]); // should be 'FHWM x' 300 psMetadataAdd (row, PS_LIST_TAIL, "THETA", PS_DATA_F32, "", PAR[5]); // should be 'FHWM y' 301 psMetadataAdd (row, PS_LIST_TAIL, "DOPHOT", PS_TYPE_S32, "", 0); // should be theta 326 302 // psMetadataAdd (header, PS_LIST_HEAD, "DUMMY", PS_DATA_STRING, "", NULL); 327 303 … … 339 315 psMetadataAdd (theader, PS_LIST_HEAD, "EXTNAME", PS_DATA_STRING, "extension name", "SMPFILE"); 340 316 317 psImage *image; 318 319 image = psImageAlloc (512, 512, PS_DATA_F32); 320 for (int j = 0; j < 512; j++) { 321 for (int i = 0; i < 512; i++) { 322 image->data.F32[j][i] = i; 323 } 324 } 325 341 326 psFits *fits = psFitsOpen (filename, "w"); 342 psFitsWriteHeader (imdata->header, fits); 343 psFitsWriteTable (fits, theader, table); 327 // psFitsWriteHeader (imdata->header, fits); 328 // psFitsWriteTable (fits, theader, table); 329 330 psFitsWriteImage (fits, NULL, image, 0); 331 psFitsWriteTable (fits, NULL, table); 344 332 psFitsClose (fits); 345 333 … … 349 337 /***** Text Output Methods *****/ 350 338 351 // write the peaks to an output file 352 bool pmPeaksWriteText (psArray *peaks, char *filename) { 353 354 int i; 355 FILE *f; 356 357 f = fopen (filename, "w"); 358 if (f == NULL) { 359 psLogMsg ("pmPeaksWriteText", 3, "can't open output file for peaks%s\n", filename); 360 return false; 361 } 362 363 for (i = 0; i < peaks->n; i++) { 364 pmPeak *peak = peaks->data[i]; 365 if (peak == NULL) continue; 366 fprintf (f, "%5d %5d %7.1f\n", 367 peak->x, peak->y, peak->counts); 368 } 369 fclose (f); 339 bool pmSourcesWriteText (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky) { 340 341 char *name = (char *) psAlloc (strlen(filename) + 10); 342 343 sprintf (name, "%s.psf.dat", filename); 344 pmModelWritePSFs (sources, config, name, psf); 345 346 sprintf (name, "%s.flt.dat", filename); 347 pmModelWriteFLTs (sources, name); 348 349 sprintf (name, "%s.nul.dat", filename); 350 pmModelWriteNULLs (sources, name); 351 352 sprintf (name, "%s.mnt.dat", filename); 353 pmMomentsWriteText (sources, name); 354 355 psFree (name); 370 356 return true; 371 357 } … … 381 367 bool status; 382 368 369 float RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS"); 370 383 371 f = fopen (filename, "w"); 384 372 if (f == NULL) { … … 387 375 } 388 376 389 float RADIUS = psMetadataLookupF32 (&status, config, "PSF_FIT_RADIUS");390 391 377 // write sources with models first 392 378 for (i = 0; i < sources->n; i++) { … … 394 380 395 381 if (source->type != PM_SOURCE_STAR) continue; 396 // if (source->mode & PM_SOURCE_FAIL) continue;397 // if (source->mode & PM_SOURCE_POOR) continue;398 399 382 model = pmSourceMagnitudes (source, psf, RADIUS); 400 383 if (model == NULL) continue; … … 407 390 dMag = dPAR[1] / PAR[1]; 408 391 409 fprintf (f, "%7.1f %7.1f % 5.1f %8.4f %7.4f %7.4f ",392 fprintf (f, "%7.1f %7.1f %7.1f %8.4f %7.4f %7.4f ", 410 393 PAR[2], PAR[3], PAR[0], source->fitMag, dMag, dPos); 411 394 … … 449 432 450 433 if (source->type != PM_SOURCE_GALAXY) continue; 451 452 if (source->modelFLT == NULL) continue; 453 model = pmSourceMagnitudes (source, NULL, source->modelFLT->radius); 434 model = pmSourceMagnitudes (source, NULL, 0.0); 435 if (model == NULL) continue; 454 436 455 437 PAR = model->params->data.F32; … … 458 440 // dPos is shape error 459 441 // XXX these are hardwired for SGAUSS 460 dPos = 0; 461 dPos += PS_SQR(dPAR[4] / PAR[4]); 462 dPos += PS_SQR(dPAR[5] / PAR[5]); 463 // dPos += PS_SQR(dPAR[7] / PAR[7]); 464 dPos = sqrt (dPos); 442 dPos = hypot ((dPAR[4] / PAR[4]), (dPAR[5] / PAR[5])); 465 443 dMag = dPAR[1] / PAR[1]; 466 444 467 fprintf (f, "%7.1f %7.1f %7.1f % 7.3f %7.4f %7.4f ",445 fprintf (f, "%7.1f %7.1f %7.1f %8.4f %7.4f %7.4f ", 468 446 PAR[2], PAR[3], PAR[0], source->fitMag, dMag, dPos); 469 447 … … 560 538 } 561 539 540 // write the peaks to an output file 541 bool pmPeaksWriteText (psArray *peaks, char *filename) { 542 543 int i; 544 FILE *f; 545 546 f = fopen (filename, "w"); 547 if (f == NULL) { 548 psLogMsg ("pmPeaksWriteText", 3, "can't open output file for peaks%s\n", filename); 549 return false; 550 } 551 552 for (i = 0; i < peaks->n; i++) { 553 pmPeak *peak = peaks->data[i]; 554 if (peak == NULL) continue; 555 fprintf (f, "%5d %5d %7.1f\n", 556 peak->x, peak->y, peak->counts); 557 } 558 fclose (f); 559 return true; 560 } 561 562 562 // translations between psphot object types and dophot object types 563 563 int pmSourceDophotType (pmSource *source) { -
trunk/psphot/src/psphotTest.c
r5672 r5837 3 3 int main (int argc, char **argv) { 4 4 5 bool status; 5 char line[80]; 6 psImage *image; 6 7 7 psMetadata *config = psphotTestArguments (&argc, argv); 8 eamReadout *imdata = psphotSetup (config); 9 10 int x = psMetadataLookupF32 (&status, config, "TEST_FIT_X"); 11 int y = psMetadataLookupF32 (&status, config, "TEST_FIT_Y"); 12 float fraction = psMetadataLookupF32 (&status, config, "TEST_FRACTION"); 13 float threshold = psMetadataLookupF32 (&status, config, "TEST_THRESHOLD"); 14 15 if (threshold == -1) { 16 threshold = fraction * imdata->image->data.F32[y][x]; 8 image = psImageAlloc (512, 512, PS_DATA_F32); 9 for (int j = 0; j < 512; j++) { 10 for (int i = 0; i < 512; i++) { 11 image->data.F32[j][i] = i; 12 } 17 13 } 18 14 19 psArray *contour = pmSourceContour_EAM (imdata->image, x, y, threshold); 20 if (contour == NULL) { 21 fprintf (stderr, "error: invalid contour\n"); 22 exit (1); 15 psMetadata *row = NULL; 16 17 psArray *table = psArrayAlloc (100); 18 table->n = 0; 19 20 for (int i = 0; i < 100; i++) { 21 row = psMetadataAlloc (); 22 sprintf (line, "line %03d", i); 23 psMetadataAdd (row, PS_LIST_HEAD, "FLOAT_DATA", PS_DATA_F32, "", 0.2*i); 24 psMetadataAdd (row, PS_LIST_HEAD, "INT_DATA", PS_DATA_S32, "", i); 25 psMetadataAdd (row, PS_LIST_HEAD, "CHAR_DATA", PS_DATA_STRING, "", line); 26 psArrayAdd (table, 100, row); 27 // psFree (row); 23 28 } 24 29 25 psVector *xV = contour->data[0]; 26 psVector *yV = contour->data[1]; 30 psFits *fits = psFitsOpen ("test.fits", "w"); 31 psFitsWriteImage (fits, NULL, image, 0); 32 psFitsWriteTable (fits, NULL, table); 33 psFitsClose (fits); 27 34 28 for (int i = 0; i < xV->n; i++) {29 fprintf (stdout, "%d %f %f\n", i, xV->data.F32[i], yV->data.F32[i]);30 }31 32 // psSparseMatrixTest ();33 35 exit (0); 34 36 }
Note:
See TracChangeset
for help on using the changeset viewer.
