- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psModules/src/objects/pmSourceIO_CMF_PS1_V2.c
r25754 r27838 45 45 // followed by a zero-size matrix, followed by the table data 46 46 47 bool pmSourcesWrite_CMF_PS1_V2 (psFits *fits, pmReadout *readout, psArray *sources, 48 psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 47 bool pmSourcesWrite_CMF_PS1_V2 (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname) 49 48 { 50 49 PS_ASSERT_PTR_NON_NULL(fits, false); … … 54 53 psArray *table; 55 54 psMetadata *row; 56 int i;57 55 psF32 *PAR, *dPAR; 58 56 psEllipseAxes axes; … … 69 67 float magOffset = NAN; 70 68 float exptime = psMetadataLookupF32 (&status1, fpa->concepts, "FPA.EXPOSURE"); 71 float zeropt = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS"); 72 float zeroptErr = psMetadataLookupF32 (&status2, imageHeader, "ZPT_ERR"); 69 float zeropt = psMetadataLookupF32(&status2, fpa->concepts, "FPA.ZP"); 70 if (!isfinite(zeropt)) { 71 zeropt = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS"); 72 } 73 73 if (status1 && status2 && (exptime > 0.0)) { 74 74 magOffset = zeropt + 2.5*log10(exptime); 75 75 } 76 float zeroptErr = psMetadataLookupF32 (&status2, imageHeader, "ZPT_ERR"); 76 77 77 78 // if the sequence is defined, write these in seq order; otherwise … … 80 81 pmSource *source = (pmSource *) sources->data[0]; 81 82 if (source->seq == -1) { 82 // let's write these out in S/N order83 sources = psArraySort (sources, pmSourceSortBySN);83 // let's write these out in S/N order 84 sources = psArraySort (sources, pmSourceSortBySN); 84 85 } else { 85 sources = psArraySort (sources, pmSourceSortBySeq);86 sources = psArraySort (sources, pmSourceSortBySeq); 86 87 } 87 88 } … … 91 92 // we write out PSF-fits for all sources, regardless of quality. the source flags tell us the state 92 93 // by the time we call this function, all values should be assigned. let's use asserts to be sure in some cases. 93 for (i = 0; i < sources->n; i++) {94 for (int i = 0; i < sources->n; i++) { 94 95 pmSource *source = (pmSource *) sources->data[i]; 95 96 … … 99 100 // generated on Alloc, and would thus be wrong for read in sources. 100 101 if (source->seq == -1) { 101 source->seq = i;102 source->seq = i; 102 103 } 103 104 … … 111 112 yPos = PAR[PM_PAR_YPOS]; 112 113 if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) { 113 xErr = dPAR[PM_PAR_XPOS];114 yErr = dPAR[PM_PAR_YPOS];114 xErr = dPAR[PM_PAR_XPOS]; 115 yErr = dPAR[PM_PAR_YPOS]; 115 116 } else { 116 // in linear-fit mode, there is no error on the centroid117 xErr = source->peak->dx;118 yErr = source->peak->dy;117 // in linear-fit mode, there is no error on the centroid 118 xErr = source->peak->dx; 119 yErr = source->peak->dy; 119 120 } 120 121 if (isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX]) && isfinite(PAR[PM_PAR_SXX])) { … … 209 210 } 210 211 212 // XXX why do we make a copy here to be supplemented with the masks? why not do this in the calling function? 211 213 psMetadata *header = psMetadataCopy(NULL, tableHeader); 212 214 pmSourceMasksHeader(header); 213 215 214 216 if (table->n == 0) { 215 psFitsWriteBlank(fits, header, extname); 217 if (!psFitsWriteBlank(fits, header, extname)) { 218 psError(psErrorCodeLast(), false, "Unable to write blank sources file."); 219 psFree(table); 220 psFree(header); 221 return false; 222 } 216 223 psFree(table); 217 224 psFree(header); … … 221 228 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 222 229 if (!psFitsWriteTable(fits, header, table, extname)) { 223 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);230 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 224 231 psFree(table); 225 232 psFree(header); … … 261 268 for (int i = 0; i < numSources; i++) { 262 269 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 270 if (!row) { 271 psError(psErrorCodeLast(), false, "Unable to read row %d of sources", i); 272 psFree(sources); 273 return NULL; 274 } 263 275 264 276 pmSource *source = pmSourceAlloc (); … … 304 316 source->peak->dx = dPAR[PM_PAR_XPOS]; 305 317 source->peak->dy = dPAR[PM_PAR_YPOS]; 318 source->peak->SN = sqrt(source->peak->flux); // XXX a proxy: various functions sort by peak S/N 306 319 307 320 source->pixWeight = psMetadataLookupF32 (&status, row, "PSF_QF"); … … 330 343 } 331 344 332 // XXX this layout is still the same as PS1_DEV_1 333 bool pmSourcesWrite_CMF_PS1_V2_XSRC (psFits *fits, psArray *sources, char *extname, psMetadata *recipe) 345 bool pmSourcesWrite_CMF_PS1_V2_XSRC (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname, psMetadata *recipe) 334 346 { 335 347 … … 340 352 psF32 xPos, yPos; 341 353 psF32 xErr, yErr; 354 int nRow = -1; 342 355 343 356 // create a header to hold the output data … … 347 360 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "xsrc table extension", extname); 348 361 362 pmChip *chip = readout->parent->parent; 363 pmFPA *fpa = chip->parent; 364 365 // zero point corrections 366 bool status1 = false; 367 bool status2 = false; 368 float magOffset = 0.0; 369 float exptime = psMetadataLookupF32(&status1, fpa->concepts, "FPA.EXPOSURE"); 370 float zeropt = psMetadataLookupF32(&status2, fpa->concepts, "FPA.ZP"); 371 if (!isfinite(zeropt)) { 372 zeropt = psMetadataLookupF32 (&status2, imageHeader, "ZPT_OBS"); 373 } 374 if (status1 && status2 && (exptime > 0.0)) { 375 magOffset = zeropt + 2.5*log10(exptime); 376 } 377 349 378 // let's write these out in S/N order 350 379 sources = psArraySort (sources, pmSourceSortBySN); … … 353 382 354 383 // which extended source analyses should we perform? 355 // bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 384 bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI"); 385 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 356 386 // bool doIsophotal = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ISOPHOTAL"); 357 // bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI");358 387 // bool doKron = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_KRON"); 359 388 360 psVector *radialBinsLower = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER"); 361 psVector *radialBinsUpper = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER"); 362 assert (radialBinsLower->n == radialBinsUpper->n); 389 psVector *radMin = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.LOWER"); 390 psVector *radMax = psMetadataLookupPtr (&status, recipe, "RADIAL.ANNULAR.BINS.UPPER"); 391 psAssert (radMin->n == radMax->n, "inconsistent annular bins"); 392 393 // int nRadialBins = 0; 394 // if (doAnnuli) { 395 // // get the max count of radial bins 396 // for (int i = 0; i < sources->n; i++) { 397 // pmSource *source = sources->data[i]; 398 // if (!source->extpars) continue; 399 // if (!source->extpars->radProfile ) continue; 400 // if (!source->extpars->radProfile->binSB) continue; 401 // nRadialBins = PS_MAX(nRadialBins, source->extpars->radProfile->binSB->n); 402 // } 403 // } 363 404 364 405 // we write out all sources, regardless of quality. the source flags tell us the state … … 396 437 psMetadataAdd (row, PS_LIST_TAIL, "Y_EXT_SIG", PS_DATA_F32, "Sigma in EXT y coordinate", yErr); 397 438 398 # if (0) 439 float AxialRatio = NAN; 440 float AxialTheta = NAN; 441 pmSourceExtendedPars *extpars = source->extpars; 442 if (extpars) { 443 AxialRatio = extpars->axes.minor / extpars->axes.major; 444 AxialTheta = extpars->axes.theta; 445 } 446 psMetadataAdd (row, PS_LIST_TAIL, "F25_ARATIO", PS_DATA_F32, "Axial Ratio of radial profile", AxialRatio); 447 psMetadataAdd (row, PS_LIST_TAIL, "F25_THETA", PS_DATA_F32, "Angle of radial profile ellipse", AxialTheta); 448 399 449 // Petrosian measurements 400 450 // XXX insert header data: petrosian ref radius, flux ratio 451 // XXX check flags to see if Pet was measured 401 452 if (doPetrosian) { 402 pmSourcePetrosianValues *petrosian = source->extpars->petrosian; 403 if (petrosian) { 404 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", petrosian->mag); 405 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR", PS_DATA_F32, "Petrosian Magnitude Error", petrosian->magErr); 406 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius", petrosian->rad); 407 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error", petrosian->radErr); 453 pmSourceExtendedPars *extpars = source->extpars; 454 if (extpars) { 455 // XXX note that this mag is either calibrated or instrumental depending on existence of zero point 456 float mag = (extpars->petrosianFlux > 0.0) ? -2.5*log10(extpars->petrosianFlux) + magOffset : NAN; // XXX zero point 457 float magErr = (extpars->petrosianFlux > 0.0) ? extpars->petrosianFlux / extpars->petrosianFluxErr : NAN; // XXX zero point 458 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", mag); 459 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG_ERR", PS_DATA_F32, "Petrosian Magnitude Error", magErr); 460 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius (pix)", extpars->petrosianRadius); 461 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error (pix)", extpars->petrosianRadiusErr); 462 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_50", PS_DATA_F32, "Petrosian R50 (pix)", extpars->petrosianR50); 463 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_50_ERR", PS_DATA_F32, "Petrosian R50 Error (pix)", extpars->petrosianR50Err); 464 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_90", PS_DATA_F32, "Petrosian R90 (pix)", extpars->petrosianR90); 465 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_90_ERR", PS_DATA_F32, "Petrosian R90 Error (pix)", extpars->petrosianR90Err); 408 466 } else { 409 467 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_MAG", PS_DATA_F32, "Petrosian Magnitude", NAN); … … 411 469 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS", PS_DATA_F32, "Petrosian Radius", NAN); 412 470 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_ERR", PS_DATA_F32, "Petrosian Radius Error", NAN); 471 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_50", PS_DATA_F32, "Petrosian R50 (pix)", NAN); 472 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_50_ERR", PS_DATA_F32, "Petrosian R50 Error (pix)",NAN); 473 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_90", PS_DATA_F32, "Petrosian R90 (pix)", NAN); 474 psMetadataAdd (row, PS_LIST_TAIL, "PETRO_RADIUS_90_ERR", PS_DATA_F32, "Petrosian R90 Error (pix)",NAN); 413 475 } 414 476 } 415 477 478 # if (0) 416 479 // Kron measurements 417 480 if (doKron) { … … 446 509 } 447 510 } 448 449 // Flux Annuli 511 # endif 512 513 // Flux Annuli (if we have extended source measurements, we have these. only optionally save them) 450 514 if (doAnnuli) { 451 pmSourceAnnuli *annuli = source->extpars->annuli; 452 if (annuli) { 453 psVector *fluxVal = annuli->flux; 454 psVector *fluxErr = annuli->fluxErr; 455 psVector *fluxVar = annuli->fluxVar; 456 457 for (int j = 0; j < fluxVal->n; j++) { 458 char name[32]; 459 sprintf (name, "FLUX_VAL_R_%02d", j); 460 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", fluxVal->data.F32[j]); 461 sprintf (name, "FLUX_ERR_R_%02d", j); 462 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", fluxErr->data.F32[j]); 463 sprintf (name, "FLUX_VAR_R_%02d", j); 464 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", fluxVar->data.F32[j]); 465 } 466 } else { 467 for (int j = 0; j < radialBinsLower->n; j++) { 468 char name[32]; 469 sprintf (name, "FLUX_VAL_R_%02d", j); 470 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux value in annulus", NAN); 471 sprintf (name, "FLUX_ERR_R_%02d", j); 472 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux error in annulus", NAN); 473 sprintf (name, "FLUX_VAR_R_%02d", j); 474 psMetadataAdd (row, PS_LIST_TAIL, name, PS_DATA_F32, "flux stdev in annulus", NAN); 475 } 476 } 477 } 478 479 # endif 480 psArrayAdd (table, 100, row); 481 psFree (row); 482 } 483 515 psVector *radSB = psVectorAlloc(radMin->n, PS_TYPE_F32); 516 psVector *radFlux = psVectorAlloc(radMin->n, PS_TYPE_F32); 517 psVector *radFill = psVectorAlloc(radMin->n, PS_TYPE_F32); 518 psVectorInit (radSB, NAN); 519 psVectorInit (radFlux, NAN); 520 psVectorInit (radFill, NAN); 521 if (!source->extpars) goto empty_annuli; 522 if (!source->extpars->radProfile) goto empty_annuli; 523 if (!source->extpars->radProfile->binSB) goto empty_annuli; 524 psAssert (source->extpars->radProfile->binSum, "programming error"); 525 psAssert (source->extpars->radProfile->binFill, "programming error"); 526 psAssert (source->extpars->radProfile->binSB->n <= radFlux->n, "inconsistent vector lengths"); 527 psAssert (source->extpars->radProfile->binSum->n <= radFlux->n, "inconsistent vector lengths"); 528 psAssert (source->extpars->radProfile->binFill->n <= radFlux->n, "inconsistent vector lengths"); 529 530 // copy the data from fluxVal (which is not guaranteed to be the full length) to radFlux 531 for (int j = 0; j < source->extpars->radProfile->binSB->n; j++) { 532 radSB->data.F32[j] = source->extpars->radProfile->binSB->data.F32[j]; 533 radFlux->data.F32[j] = source->extpars->radProfile->binSum->data.F32[j]; 534 radFill->data.F32[j] = source->extpars->radProfile->binFill->data.F32[j]; 535 } 536 537 empty_annuli: 538 psMetadataAdd (row, PS_LIST_TAIL, "PROF_SB", PS_DATA_VECTOR, "mean surface brightness annuli", radSB); 539 psMetadataAdd (row, PS_LIST_TAIL, "PROF_FLUX", PS_DATA_VECTOR, "flux within annuli", radFlux); 540 psMetadataAdd (row, PS_LIST_TAIL, "PROF_FILL", PS_DATA_VECTOR, "fill factor of annuli", radFill); 541 psFree (radSB); 542 psFree (radFlux); 543 psFree (radFill); 544 } 545 if (nRow < 0) { 546 nRow = row->list->n; 547 } else { 548 psAssert (nRow == row->list->n, "inconsistent row lengths"); 549 } 550 psArrayAdd (table, 100, row); 551 psFree (row); 552 } 553 484 554 if (table->n == 0) { 485 psFitsWriteBlank (fits, outhead, extname); 486 psFree (outhead); 487 psFree (table); 488 return true; 489 } 490 555 if (!psFitsWriteBlank (fits, outhead, extname)) { 556 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 557 psFree(outhead); 558 psFree(table); 559 return false; 560 } 561 psFree (outhead); 562 psFree (table); 563 return true; 564 } 565 491 566 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 492 567 if (!psFitsWriteTable (fits, outhead, table, extname)) { 493 psError(PS_ERR_IO, false, "writing ext data %s\n", extname);494 psFree (outhead);495 psFree(table);496 return false;568 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 569 psFree (outhead); 570 psFree(table); 571 return false; 497 572 } 498 573 psFree (outhead); 499 574 psFree (table); 500 575 501 576 return true; 502 577 } 503 578 504 579 // XXX this layout is still the same as PS1_DEV_1 505 bool pmSourcesWrite_CMF_PS1_V2_XFIT (psFits *fits, p sArray *sources, char *extname)580 bool pmSourcesWrite_CMF_PS1_V2_XFIT (psFits *fits, pmReadout *readout, psArray *sources, char *extname) 506 581 { 507 582 … … 609 684 610 685 if (table->n == 0) { 611 psFitsWriteBlank (fits, outhead, extname); 686 if (!psFitsWriteBlank (fits, outhead, extname)) { 687 psError(psErrorCodeLast(), false, "Unable to write empty sources file."); 688 psFree(outhead); 689 psFree(table); 690 return false; 691 } 612 692 psFree (outhead); 613 693 psFree (table); … … 617 697 psTrace ("pmFPAfile", 5, "writing ext data %s\n", extname); 618 698 if (!psFitsWriteTable (fits, outhead, table, extname)) { 619 psError( PS_ERR_IO, false, "writing ext data %s\n", extname);699 psError(psErrorCodeLast(), false, "writing ext data %s\n", extname); 620 700 psFree (outhead); 621 701 psFree(table);
Note:
See TracChangeset
for help on using the changeset viewer.
