- Timestamp:
- Nov 29, 2012, 2:15:01 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20120905
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/src/ppstampMakeStamp.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20120905
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20120905/pstamp/src/ppstampMakeStamp.c
r33504 r34735 19 19 static void chipToSky(pmAstromObj *pt, pmFPA *fpa, pmChip *chip); 20 20 static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance); 21 static bool copySources(pmReadout *outputReadout, pmReadout *inputReadout, pmReadout *astromReadout, psRegion extractRegion); 21 22 22 23 // convert the input chip's transforms to the output … … 80 81 } 81 82 82 static bool copyMetadata(pmFPAfile *output, pmFPAfile *input, pmChip *inChip, ppstampOptions *options, pmAstromObj *center )83 static bool copyMetadata(pmFPAfile *output, pmFPAfile *input, pmChip *inChip, ppstampOptions *options, pmAstromObj *center, pmFPAfile *astrom, pmFPAview *inView) 83 84 { 84 85 pmChip *outChip; 85 pmFPAview * view = pmFPAviewAlloc(0);86 pmFPAview *outView = pmFPAviewAlloc(0); 86 87 87 88 // our output file has a single chip 88 view->chip = 0; 89 outChip = pmFPAviewThisChip(view, output->fpa); 90 psFree(view); 91 92 // copy data from the input chip header to the output. 89 outView->chip = 0; 90 outChip = pmFPAviewThisChip(outView, output->fpa); 91 psFree(outView); 92 pmHDU *outHDU = pmHDUGetHighest(output->fpa, outChip, NULL); 93 94 // copy data from the input's chip header to the output. 93 95 // since some of the keywords might be duplicated we may not want to copy both 94 96 95 pmHDU *inHDU = pmHDUFromChip(inChip); 96 pmHDU *outHDU = pmHDUGetHighest(output->fpa, outChip, NULL); 97 pmHDU *inHDU = NULL; 98 if (strcmp(options->stage, "raw") && input != astrom) { 99 // Copy the header from the astrometry file since it contains the psphot and psastro results 100 pmChip *astromChip = pmFPAviewThisChip(inView, astrom->fpa); 101 inHDU = pmHDUFromChip(astromChip); 102 } else { 103 inHDU = pmHDUFromChip(inChip); 104 } 97 105 98 106 if (inHDU->header) { … … 102 110 } 103 111 104 // copy the fpa concepts112 // copy the fpa and chip concepts 105 113 pmConceptsCopyFPA(output->fpa, input->fpa, false, false); 114 // Needed to preserve FPA.ZP 106 115 pmConceptsCopyChip(outChip, inChip, false); 116 117 // copy the cell concepts (needed to get CELL.EXPOSURE which gets used to set EXPTIME) 107 118 pmCell *outCell = outChip->cells->data[0]; // The only output cell 108 119 … … 122 133 } 123 134 124 // If input had WCS convert it for stamp135 // If input had WCS convert it for the new image coordinate system of our stamp 125 136 if (input->fpa->toSky) { 126 137 // copy the input fpa's transforms … … 135 146 } 136 147 } else { 137 psWarning("No WCS present in input\n"); 138 } 139 148 psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "No WCS present in input."); 149 } 150 151 // Save our specific metadata 140 152 psMetadataAddF64(outHDU->header, PS_LIST_TAIL, "RA_DEG", PS_META_REPLACE, "Right Ascension of stamp center", RAD_TO_DEG(center->sky->r)); 141 153 psMetadataAddF64(outHDU->header, PS_LIST_TAIL, "DEC_DEG", PS_META_REPLACE, "Declination of stamp center", RAD_TO_DEG(center->sky->d)); 154 155 // XXX: TODO: save the region of interest boundary and the offset to be applied. 156 // XXX: Gene thinks that there may be a way to handle this in the WCS 157 158 // Now a few sanity checks 159 // Make sure zero point in the fpa concepts matches the observed value in the input header 160 bool status; 161 float zpt_obs = psMetadataLookupF32(&status, outHDU->header, "ZPT_OBS"); 162 if (status) { 163 psMetadataAddF32(output->fpa->concepts, PS_LIST_TAIL, "FPA.ZP", PS_META_REPLACE, "Magnitude zero point", zpt_obs); 164 } 142 165 143 166 ppstampVersionMetadata(outHDU->header, options); … … 324 347 325 348 if (options->censorMasked && !setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) { 326 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");327 status = false;328 break;349 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n"); 350 status = false; 351 break; 329 352 } 330 353 } … … 335 358 status = true; 336 359 360 if (options->writeCMF) { 361 pmReadout *astromReadout = NULL; 362 if (astrom->fpa != input->fpa) { 363 astromReadout = pmFPAviewThisReadout(srcView, astrom->fpa); 364 } 365 if (!copySources(outReadout, astromReadout, astromReadout, extractRegion)) { 366 psError(PS_ERR_UNKNOWN, false, "failed to extract sources from region of interest.\n"); 367 status = false; 368 break; 369 } 370 } 371 337 372 psFree(outReadout); // drop reference 338 373 } … … 341 376 342 377 if (status) { 343 status = copyMetadata(output, input, inChip, options, center); 378 // For raw stage we need to do more work to build a proper header 379 status = copyMetadata(output, input, inChip, options, center, astrom, view); 344 380 } 345 381 return status ? PS_EXIT_SUCCESS : PS_EXIT_UNKNOWN_ERROR; … … 428 464 double dy = 0.5 * options->roip.dDEC / fpa->toSky->Ys; 429 465 430 if (dx > 5000) { 431 fprintf(stderr, "requested width %f too large reducing to 5000\n", dx); 432 dx = 5000; 433 } 434 if (dy > 5000) { 435 fprintf(stderr, "requested height %f too large reducing to 5000\n", dy); 436 dy = 5000; 466 // XXX: why do we limit this? 467 if (dx > 8000) { 468 psWarning( "requested width %f too large reducing to 8000\n", dx); 469 dx = 8000; 470 } 471 if (dy > 8000) { 472 psWarning( "requested height %f too large reducing to 8000\n", dy); 473 dy = 8000; 437 474 } 438 475 … … 480 517 ppstampOverlap returnval = PPSTAMP_OFF; 481 518 482 // fprintf(stderr, "ppstampChipBounds: %s\n", psRegionToString(*chipBounds));483 484 519 // set up the astrometry 485 520 pmHDU *hdu = pmFPAviewThisHDU(view, astrom->fpa); … … 498 533 } 499 534 } else { 500 // we use a default FPA pixel scale of 1.0501 535 if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0) && mustHaveAstrometry) { 502 536 psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA."); … … 537 571 center->chip->yErr = 0; 538 572 onChip = true; 539 chipToSky(center, input->fpa, chip); 573 if (input->fpa->toSky) { 574 chipToSky(center, input->fpa, chip); 575 } 540 576 } 541 577 } … … 550 586 int width = options->roip.dX; 551 587 int height = options->roip.dY; 552 if (width > 7000) {553 fprintf(stderr, "requested width %d too large reducing to 7000\n", width);554 width = 7000;588 if (width > 8000) { 589 psWarning( "requested width %d too large reducing to 8000\n", width); 590 width = 8000; 555 591 } 556 if (height > 7000) {557 fprintf(stderr, "requested height %d too large reducing to 7000\n", height);558 height = 7000;592 if (height > 8000) { 593 psWarning( "requested height %d too large reducing to 8000\n", height); 594 height = 8000; 559 595 } 560 596 … … 675 711 676 712 if (!foundOverlap && (returnval == PS_EXIT_SUCCESS)) { 677 fprintf(stderr,"ROI not found in input\n");713 psWarning( "ROI not found in input\n"); 678 714 returnval = PSTAMP_NO_OVERLAP; 679 715 } … … 739 775 } 740 776 741 // XXX: this shouldn't be a fprintf 742 fprintf(stderr, "Censored %ld masked pixels\n", numCensored); 777 psLogMsg("ppstamp", PS_LOG_DETAIL, "Censored %ld masked pixels\n", numCensored); 743 778 744 779 return true; 745 780 } 781 782 static bool copySources(pmReadout *outReadout, pmReadout *inReadout, pmReadout *astromReadout, psRegion extractRegion) { 783 bool status; 784 785 // first look for detections in the input readout. Those would have come from the -sources file 786 pmDetections *inDetections = psMetadataLookupPtr (&status, inReadout->analysis, "PSPHOT.DETECTIONS"); 787 if (!inDetections) { 788 // No detections on the input readout. Try the astrometry readout if supplied. 789 if (astromReadout) { 790 inDetections = psMetadataLookupPtr (&status, astromReadout->analysis, "PSPHOT.DETECTIONS"); 791 if (!inDetections) { 792 psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "no detections found on input or astrometry readout\n"); 793 return false; 794 } else { 795 psLogMsg("ppstampMakeStamp", PS_LOG_INFO, "using detections from astrom file\n"); 796 } 797 } else { 798 psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "no detections found on input readout\n"); 799 return false; 800 } 801 } 802 if (!inDetections->allSources) { 803 psLogMsg("ppstampMakeStamp", PS_LOG_WARN, "no sources array found on detections structure\n"); 804 return false; 805 } 806 807 // Ok we have sources, allocate a detections structure and copy them to the output readout 808 psArray *inSources = inDetections->allSources; 809 810 pmDetections *outDetections = pmDetectionsAlloc(); 811 psMetadataAddPtr (outReadout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, 812 "psphot detections", outDetections); 813 814 psArray *outSources = outDetections->allSources = psArrayAllocEmpty( 100 ); 815 816 // include sources that are off the stamp by just a little bit 817 #define EXPAND_SIZE 16 818 psRegion sourceRegion = extractRegion; 819 sourceRegion.x0 -= EXPAND_SIZE; 820 sourceRegion.y0 -= EXPAND_SIZE; 821 sourceRegion.x1 += EXPAND_SIZE; 822 sourceRegion.y1 += EXPAND_SIZE; 823 824 for (int i = 0; i < inSources->n; i++ ) { 825 pmSource *src = inSources->data[i]; 826 827 float x = src->peak->xf; 828 float y = src->peak->yf; 829 if (x < sourceRegion.x0 || x > sourceRegion.x1 || 830 y < sourceRegion.y0 || y > sourceRegion.y1) { 831 continue; 832 } 833 psArrayAdd(outSources, 100, src); 834 } 835 836 return true; 837 }
Note:
See TracChangeset
for help on using the changeset viewer.
