Changeset 5084
- Timestamp:
- Sep 20, 2005, 6:48:16 PM (21 years ago)
- Location:
- trunk/psphot
- Files:
-
- 7 edited
-
Makefile (modified) (1 diff)
-
src/pmPSFtry.c (modified) (4 diffs)
-
src/pmPSFtry.h (modified) (1 diff)
-
src/psPolynomials.c (modified) (4 diffs)
-
src/psphot.h (modified) (2 diffs)
-
src/psphotArguments.c (modified) (3 diffs)
-
src/psphotOutput.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/Makefile
r5058 r5084 15 15 # LIBS = -lpsmodule $(LPSLIB) 16 16 LIBS = $(LPSLIB) 17 CFLAGS = $(INCS) -std=c99 -Wall -Werror -g 17 # CFLAGS = $(INCS) -std=c99 -Wall -Werror -g 18 CFLAGS = $(INCS) -std=c99 -g 18 19 LFLAGS = $(LIBS) 19 20 -
trunk/psphot/src/pmPSFtry.c
r5068 r5084 161 161 162 162 // XXX this function wants aperture radius for pmSourcePhotometry 163 pmPSFtryMetric (try, RADIUS);163 pmPSFtryMetric_Alt (try, RADIUS); 164 164 psLogMsg ("psphot.pspsf", 3, "try model %s, ap-fit: %f +/- %f, sky bias: %f\n", 165 165 modelName, try->psf->ApResid, try->psf->dApResid, try->psf->skyBias); … … 167 167 return (try); 168 168 } 169 170 169 171 170 bool pmPSFtryMetric (pmPSFtry *try, float RADIUS) { … … 195 194 } 196 195 fclose (f); 196 197 // XXX EAM : try 3hi/1lo sigma clipping on the rflux v dap fit 197 198 198 199 // find min and max of (1/flux): … … 297 298 return true; 298 299 } 300 301 bool pmPSFtryMetric_Alt (pmPSFtry *try, float RADIUS) { 302 303 // the measured (aperture - fit) magnitudes (dA == try->metric) 304 // depend on both the true ap-fit (dAo) and the bias in the sky measurement: 305 // dA = dAo + dsky/flux 306 // where flux is the flux of the star 307 // we fit this trend to find the infinite flux aperture correction (dAo), 308 // the nominal sky bias (dsky), and the error on dAo 309 // the values of dA are contaminated by stars with close neighbors in the aperture 310 // we use an outlier rejection to avoid this bias 311 312 // rflux = ten(0.4*fitMag); 313 psVector *rflux = psVectorAlloc (try->sources->n, PS_TYPE_F64); 314 for (int i = 0; i < try->sources->n; i++) { 315 if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue; 316 rflux->data.F64[i] = pow(10.0, 0.4*try->fitMag->data.F64[i]); 317 } 318 319 // XXX EAM : try 3hi/1lo sigma clipping on the rflux vs metric fit 320 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 321 322 // XXX EAM 323 stats->min = 1.0; 324 stats->max = 3.0; 325 stats->clipIter = 3; 326 327 // linear fit to rfBin, daBin 328 psPolynomial1D *poly = Polynomial1DAlloc_EAM (PS_POLYNOMIAL_ORD, 1); 329 330 // XXX EAM : this is the intended API (cycle 7? cycle 8?) 331 poly = VectorClipFitPolynomial1D_EAM (poly, stats, try->mask, PSFTRY_MASK_ALL, try->metric, NULL, rflux); 332 333 fprintf (stderr, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev); 334 335 // these stats should come back from the fit above... 336 // psVector *daFit = Polynomial1DEvalVector_EAM (poly, rflux); 337 // psVector *daResid = (psVector *) psBinaryOp (NULL, (void *) try->metric, "-", (void *) daFit); 338 339 // stats = psStatsAlloc (PS_STAT_CLIPPED_STDEV); 340 // stats->clipIter = 3; 341 // stats->clipSigma = 3; 342 343 // stats = psVectorStats (stats, daResid, NULL, maskB, 1); 344 345 try->psf->ApResid = poly->coeff[0]; 346 try->psf->dApResid = stats->sampleStdev; 347 try->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS)); 348 349 FILE *f; 350 f = fopen ("apresid.dat", "w"); 351 if (f == NULL) psAbort ("pmPSFtry", "can't open output file"); 352 353 for (int i = 0; i < try->sources->n; i++) { 354 fprintf (f, "%3d %8.4f %12.5e %8.4f %3d\n", i, try->fitMag->data.F64[i], rflux->data.F64[i], try->metric->data.F64[i], try->mask->data.U8[i]); 355 } 356 fclose (f); 357 358 psFree (rflux); 359 psFree (poly); 360 psFree (stats); 361 362 // psFree (daFit); 363 // psFree (daResid); 364 365 return true; 366 } -
trunk/psphot/src/pmPSFtry.h
r5058 r5084 27 27 pmPSFtry *pmPSFtryModel (psArray *sources, char *modelName, float radius); 28 28 bool pmPSFtryMetric (pmPSFtry *try, float RADIUS); 29 bool pmPSFtryMetric_Alt (pmPSFtry *try, float RADIUS); 29 30 30 31 # endif -
trunk/psphot/src/psPolynomials.c
r5068 r5084 507 507 psVector *zFit = NULL; 508 508 psVector *zResid = psVectorAlloc (x->n, PS_TYPE_F64); 509 510 // XXX EAM : use SAMPLE_MEAN and SAMPLE_STDEV for stats: 509 float minClipSigma = stats->min; 510 float maxClipSigma = stats->max; 511 float minClipValue; 512 float maxClipValue; 513 514 // XXX EAM : use SAMPLE_MEDIAN and SAMPLE_STDEV for stats: 511 515 stats->options |= (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 512 516 513 for (int N = 0; N < 3; N++) {517 for (int N = 0; N < stats->clipIter; N++) { 514 518 int Nkeep = 0; 515 519 … … 519 523 520 524 stats = psVectorStats (stats, zResid, NULL, mask, maskValue); 521 psTrace (".psphot.RobustFit", 4, "residual stats for robust fit: %g +/- %g\n", 525 minClipValue = -1*fabs(minClipSigma)*stats->sampleStdev; 526 maxClipValue = +1*fabs(maxClipSigma)*stats->sampleStdev; 527 528 psTrace (".psphot.VectorClipFit", 4, "residual stats for robust fit: %g +/- %g\n", 522 529 stats->sampleMedian, stats->sampleStdev); 523 530 … … 527 534 for (int i = 0; i < zResid->n; i++) { 528 535 if (mask->data.U8[i]) continue; 529 if (fabs(zResid->data.F64[i] - stats->sampleMedian) > 2*stats->sampleStdev) { 536 if (zResid->data.F64[i] - stats->sampleMedian > maxClipValue) { 537 mask->data.U8[i] |= 0x01; 538 continue; 539 } 540 if (zResid->data.F64[i] - stats->sampleMedian < minClipValue) { 530 541 mask->data.U8[i] |= 0x01; 531 542 continue; … … 534 545 } 535 546 536 psTrace (".psphot. RobustFit", 4, "keeping %d of %d pts for fit\n",547 psTrace (".psphot.VectorClipFit", 4, "keeping %d of %d pts for fit\n", 537 548 Nkeep, x->n); 538 549 -
trunk/psphot/src/psphot.h
r5068 r5084 39 39 // output functions 40 40 bool pmSourcesWriteText (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 41 bool pmSourcesWriteOBJ (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *sky);42 bool pmSourcesWriteCMP (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *sky);43 bool pmSourcesWriteCMF (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *sky);44 bool pmSourcesWriteSX (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky);45 int pmSourcesDophotType (pmSource *source); 41 bool pmSourcesWriteOBJ (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 42 bool pmSourcesWriteCMP (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 43 bool pmSourcesWriteCMF (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 44 bool pmSourcesWriteSX (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky); 45 46 46 bool pmPeaksWriteText (psArray *sources, char *filename); 47 47 bool pmMomentsWriteText (psArray *sources, char *filename); … … 49 49 bool pmModelWriteFLTs (psArray *sources, char *filename); 50 50 bool pmModelWriteNULLs (psArray *sources, char *filename); 51 52 int pmSourcesDophotType (pmSource *source); -
trunk/psphot/src/psphotArguments.c
r5049 r5084 38 38 } 39 39 40 // optional output residual image - add to config 41 char *photcode = NULL; 42 if ((N = psArgumentGet (*argc, argv, "-photcode"))) { 43 psArgumentRemove (N, argc, argv); 44 photcode = psStringCopy (argv[N]); 45 psArgumentRemove (N, argc, argv); 46 } 47 40 48 if (*argc != 4) usage (); 41 49 … … 60 68 psMetadataAdd (config, PS_LIST_HEAD, "RESID_IMAGE", mode, "", resid); 61 69 } 70 if (photcode != NULL) { 71 psMetadataAdd (config, PS_LIST_HEAD, "PHOTCODE", mode, "", photcode); 72 } 62 73 return (config); 63 74 } … … 70 81 fprintf (stderr, " -weight (filename)\n"); 71 82 fprintf (stderr, " -resid (filename)\n"); 83 fprintf (stderr, " -photcode (photcode)\n"); 72 84 exit (2); 73 85 } -
trunk/psphot/src/psphotOutput.c
r5073 r5084 26 26 27 27 if (!strcasecmp (outputMode, "OBJ")) { 28 pmSourcesWriteOBJ (imdata, outputFile, sources, psf, sky);28 pmSourcesWriteOBJ (imdata, config, outputFile, sources, psf, sky); 29 29 return; 30 30 } … … 36 36 37 37 if (!strcasecmp (outputMode, "CMP")) { 38 pmSourcesWriteCMP (imdata, outputFile, sources, psf, sky);38 pmSourcesWriteCMP (imdata, config, outputFile, sources, psf, sky); 39 39 return; 40 40 } 41 41 42 42 if (!strcasecmp (outputMode, "CMF")) { 43 pmSourcesWriteCMF (imdata, outputFile, sources, psf, sky);43 pmSourcesWriteCMF (imdata, config, outputFile, sources, psf, sky); 44 44 return; 45 45 } … … 68 68 69 69 // dophot-style output list with fixed line width 70 bool pmSourcesWriteOBJ (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {70 bool pmSourcesWriteOBJ (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) { 71 71 72 72 int i, type, status; … … 74 74 psF32 *PAR, *dPAR; 75 75 float sky, dmag, apMag, fitMag; 76 float x, y, rflux; 77 bool result; 76 78 77 79 psLine *line = psLineAlloc (104); // 104 is dophot-defined line length … … 82 84 return false; 83 85 } 86 87 float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS"); 84 88 85 89 // write sources with models first … … 296 300 297 301 // elixir-style pseudo FITS table (header + ascii list) 298 bool pmSourcesWriteCMP (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {302 bool pmSourcesWriteCMP (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) { 299 303 300 304 int i, type, status; 301 305 pmModel *model; 306 psMetadataItem *mdi; 302 307 psF32 *PAR, *dPAR; 303 float sky, dmag, apMag, fitMag, lsky, Theta; 308 float sky, dmag, apMag, fitMag, lsky; 309 float x, y, rflux; 310 bool result; 304 311 305 312 // create file, write-out header 306 313 unlink (filename); 307 314 psFits *fits = psFitsAlloc (filename); 315 316 // set NAXIS to 0 : CFITSIO requires isolated header to have NAXIS = 0 317 mdi = psMetadataLookup (imdata->header, "NAXIS"); 318 mdi->data.S32 = 0; 319 mdi->type = PS_META_S32; 320 321 // psMetadataAdd (imdata->header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0); 308 322 psFitsWriteHeader (imdata->header, fits); 309 323 psFree (fits); … … 317 331 fseek (f, 0, SEEK_END); 318 332 319 psLine *line = psLineAlloc (66); // 66 is imclean-defined line length 333 psLine *line = psLineAlloc (67); // 66 is imclean-defined line length 334 335 float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS"); 336 337 // XXX EAM : need to add these concepts to the header (from psf and config) 338 // fits_modify (header, "ZERO_PT", "%lf", 1, ZERO_POINT); 339 // fits_modify (header, "FWHM_X", "%lf", 1, FWHMx); 340 // fits_modify (header, "FWHM_Y", "%lf", 1, FWHMy); 341 // fits_modify (header, "ANGLE", "%lf", 1, angle); 342 // fits_modify (header, "FSATUR", "%lf", 1, saturate); // can use 0.0 343 // fits_modify (header, "FLIMIT", "%lf", 1, complete); // can use 0.0 344 // fits_modify (header, "NSTARS", "%d", 1, N); 320 345 321 346 // write sources with models first … … 404 429 psLineAdd (line, "%6.2f ", PAR[4]); // should be 'FHWM x' 405 430 psLineAdd (line, "%6.2f ", PAR[5]); // should be 'FHWM y' 406 psLineAdd (line, "%5.1f\n", Theta); // should be theta431 psLineAdd (line, "%5.1f\n", 0); // should be theta 407 432 fwrite (line->line, 1, line->Nline, f); 408 433 } … … 414 439 // this format consists of a header derived from the image header 415 440 // followed by a zero-size matrix, followed by the table data 416 bool pmSourcesWriteCMF (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {441 bool pmSourcesWriteCMF (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) { 417 442 418 443 psArray *table; 444 psMetadataItem *mdi; 419 445 psMetadata *row; 420 446 psMetadata *theader; 447 int i, type, status; 448 pmModel *model; 449 psF32 *PAR, *dPAR; 450 float sky, dmag, apMag, fitMag; 451 float x, y, rflux, lsky; 452 bool result; 421 453 422 454 // set NAXIS to 0 423 psMetadataAdd (header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0); 455 fprintf (stderr, "setting naxis\n"); 456 mdi = psMetadataLookup (imdata->header, "NAXIS"); 457 mdi->data.S32 = 0; 458 mdi->type = PS_META_S32; 459 460 // psMetadataAdd (imdata->header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0); 424 461 425 462 table = psArrayAlloc (sources->n); 426 463 sources->n = 0; 464 465 float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS"); 427 466 428 467 for (i = 0; i < sources->n; i++) { … … 499 538 lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]); 500 539 501 table = psMetdataAlloc ();502 psMetadataAdd ( table, PS_LIST_HEAD, "X_PIX", PS_META_F32, "", PAR[2]);503 psMetadataAdd ( table, PS_LIST_HEAD, "Y_PIX", PS_META_F32, "", PAR[3]);504 psMetadataAdd ( table, PS_LIST_HEAD, "MAG_RAW", PS_META_F32, "", fitMag + 25.0);505 psMetadataAdd ( table, PS_LIST_HEAD, "MAG_ERR", PS_META_F32, "", (int)(1000*dmag));506 psMetadataAdd ( table, PS_LIST_HEAD, "MAG_GAL", PS_META_F32, "", type);507 psMetadataAdd ( table, PS_LIST_HEAD, "MAG_AP", PS_META_F32, "", lsky);508 psMetadataAdd ( table, PS_LIST_HEAD, "LOG_SKY", PS_META_F32, "", 32.0); // should be 'Mgal'509 psMetadataAdd ( table, PS_LIST_HEAD, "FWHM_X", PS_META_F32, "", apMag + 25.0); // 25.0 should come from config510 psMetadataAdd ( table, PS_LIST_HEAD, "FWHM_Y", PS_META_F32, "", PAR[4]); // should be 'FHWM x'511 psMetadataAdd ( table, PS_LIST_HEAD, "THETA", PS_META_F32, "", PAR[5]); // should be 'FHWM y'512 psMetadataAdd ( table, PS_LIST_HEAD, "DOPHOT", PS_META_S8, "", Theta); // should be theta540 row = psMetadataAlloc (); 541 psMetadataAdd (row, PS_LIST_HEAD, "X_PIX", PS_META_F32, "", PAR[2]); 542 psMetadataAdd (row, PS_LIST_HEAD, "Y_PIX", PS_META_F32, "", PAR[3]); 543 psMetadataAdd (row, PS_LIST_HEAD, "MAG_RAW", PS_META_F32, "", fitMag + 25.0); 544 psMetadataAdd (row, PS_LIST_HEAD, "MAG_ERR", PS_META_F32, "", (int)(1000*dmag)); 545 psMetadataAdd (row, PS_LIST_HEAD, "MAG_GAL", PS_META_F32, "", type); 546 psMetadataAdd (row, PS_LIST_HEAD, "MAG_AP", PS_META_F32, "", lsky); 547 psMetadataAdd (row, PS_LIST_HEAD, "LOG_SKY", PS_META_F32, "", 32.0); // should be 'Mgal' 548 psMetadataAdd (row, PS_LIST_HEAD, "FWHM_X", PS_META_F32, "", apMag + 25.0); // 25.0 should come from config 549 psMetadataAdd (row, PS_LIST_HEAD, "FWHM_Y", PS_META_F32, "", PAR[4]); // should be 'FHWM x' 550 psMetadataAdd (row, PS_LIST_HEAD, "THETA", PS_META_F32, "", PAR[5]); // should be 'FHWM y' 551 psMetadataAdd (row, PS_LIST_HEAD, "DOPHOT", PS_TYPE_S8, "", 0); // should be theta 513 552 // psMetadataAdd (header, PS_LIST_HEAD, "DUMMY", PS_META_STR, "", NULL); 514 553 … … 517 556 } 518 557 519 image = psImageAlloc (0, 0, PS_TYPE_F32); 520 theader = psFitsHeaderFromTable (NULL, table, "SMPFILE"); 558 // psAbort ("psphotOutput", "FITS table output not finished"); 559 560 psImage *image = psImageAlloc (1, 1, PS_TYPE_F32); 561 // XXX missing: theader = psFitsHeaderFromTable (NULL, table, "SMPFILE"); 562 563 theader = psMetadataAlloc (); 564 psMetadataAdd (theader, PS_LIST_HEAD, "EXTNAME", PS_META_STR, "extension name", "SMPFILE"); 521 565 522 566 unlink (filename); 523 567 psFits *fits = psFitsAlloc (filename); 524 psFitsWriteImage (fits, header, image, 0, NULL);568 psFitsWriteImage (fits, imdata->header, image, 0); 525 569 psFitsWriteTable (fits, theader, table); 526 570 psFree (fits);
Note:
See TracChangeset
for help on using the changeset viewer.
