- Timestamp:
- Oct 25, 2012, 11:37:10 AM (14 years ago)
- Location:
- trunk/pstamp/src
- Files:
-
- 6 edited
-
ppstampArguments.c (modified) (4 diffs)
-
ppstampMakeStamp.c (modified) (15 diffs)
-
ppstampOptions.c (modified) (1 diff)
-
ppstampOptions.h (modified) (1 diff)
-
ppstampParseCamera.c (modified) (1 diff)
-
pstamp.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/src/ppstampArguments.c
r33504 r34596 25 25 fprintf(stderr, " [-mask mk_image] : mask image\n"); 26 26 fprintf(stderr, " [-variance var_image] : variance image\n"); 27 fprintf(stderr, " [-sources sources] : sources cmf (ignored for chip stage)\n"); 27 28 fprintf(stderr, " [-stage stage] : stage of input image (raw, chip, warp, stack, diff)\n"); 28 29 fprintf(stderr, " [-write_jpeg] : write a JPEG format of the image stamp\n"); 30 fprintf(stderr, " [-write_cmf] : create an output cmf with the sources overlapping the stamp\n"); 31 fprintf(stderr, " [-wholefile] : ignore the region of interest and process the entire input image\n"); 29 32 // fprintf(stderr, " [-no_censor_masked] : do not set masked pixels to NAN\n"); 30 33 fprintf(stderr, "\n"); … … 92 95 options->stage = psStringCopy(argv[argnum]); 93 96 psArgumentRemove(argnum, &argc, argv); 97 } else { 98 // Should we require this? 99 options->stage = psStringCopy("unknown"); 94 100 } 95 101 if ((argnum = psArgumentGet(argc, argv, "-write_jpeg"))) { 96 102 psArgumentRemove(argnum, &argc, argv); 97 103 options->writeJPEG = true; 98 } else { 99 options->writeJPEG = false; 104 } 105 if ((argnum = psArgumentGet(argc, argv, "-write_cmf"))) { 106 psArgumentRemove(argnum, &argc, argv); 107 options->writeCMF = true; 100 108 } 101 109 102 pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist"); 110 // XXX: Note: the various list options have never been tested with ppstamp to my knowledge 111 bool gotAstrom = false; 112 if ((argnum = psArgumentGet(argc, argv, "-astrom"))) { 113 gotAstrom = true; 114 pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist"); 115 } 103 116 pmConfigFileSetsMD(config->arguments, &argc, argv, "MASK", "-mask", "-masklist"); 104 117 pmConfigFileSetsMD(config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist"); 105 118 106 // the input file is a required argument; if not found, we will exit 119 if ((argnum = psArgumentGet(argc, argv, "-sources"))) { 120 pmConfigFileSetsMD(config->arguments, &argc, argv, "SOURCES", "-sources", "-sourceslist"); 121 // supplying a sources file implies that we want to save the output 122 options->writeCMF = true; 123 } else if (options->writeCMF && !gotAstrom) { 124 // if we didn't get a sources file but the user wanted us to write the sources we must 125 // have an astrometry file supplied 126 // XXX: Is this too restrictive? Could the sources be contained in say the input file? 127 psError(PSTAMP_ERR_ARGUMENTS, true, "cannot write cmf file unless input sources are supplied\n"); 128 usage(); 129 } 130 131 // the input image file is a required argument; if not found, we will exit 107 132 bool status = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list"); 108 133 if (!status) { … … 126 151 } 127 152 128 // finally the o utput file153 // finally the only argument left must be output outroot 129 154 if (argc < 2) { 130 155 psError(PSTAMP_ERR_ARGUMENTS, true, "must specify OUTPUT\n"); … … 135 160 } 136 161 137 // Add the output image (which remains on the command-line) to the arguments list138 162 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Name of the output image", argv[1]); 139 140 // psMetadataPrint(stdout, config->arguments,0);141 163 142 164 return config; -
trunk/pstamp/src/ppstampMakeStamp.c
r33504 r34596 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 } -
trunk/pstamp/src/ppstampOptions.c
r33504 r34596 32 32 options->censorMasked = false; 33 33 options->writeJPEG = false; 34 options->writeCMF = false; 34 35 options->nocompress = false; 35 36 options->wholeFile = false; -
trunk/pstamp/src/ppstampOptions.h
r33504 r34596 14 14 bool censorMasked; 15 15 bool writeJPEG; 16 bool writeCMF; 16 17 bool nocompress; 17 18 // -
trunk/pstamp/src/ppstampParseCamera.c
r33504 r34596 120 120 } 121 121 122 // Set up the input and output sources files if needed 123 if (options->writeCMF) { 124 bool status; 125 126 // see if -sources file was supplied. 127 // If so define the file. 128 psPtr sourcesFile = psMetadataLookupStr(&status, config->arguments, "SOURCES"); 129 if (sourcesFile) { 130 pmFPAfile *sources = pmFPAfileBindFromArgs(&status, input, config, "PPSTAMP.INPUT.SOURCES", "SOURCES"); 131 if (!status) { 132 psError(psErrorCodeLast(), false, "Failed to load file definition for PPSTAMP.INPUT.SOURCES"); 133 return false; 134 } 135 if (!sources && !astrom) { 136 psError(psErrorCodeLast(), false, "Failed to define input sources file"); 137 return false; 138 } 139 } else { 140 psLogMsg ("ppstamp", PS_LOG_INFO, "output sources file requested but no input supplied. Will try the supplied astrometry file.\n"); 141 } 142 143 pmFPAfile *outputSources = NULL; 144 outputSources = pmFPAfileDefineSkycell(config, output->fpa, "PPSTAMP.OUTPUT.SOURCES"); 145 if (!outputSources) { 146 psError(psErrorCodeLast(), false, "Failed to define output sources file"); 147 return false; 148 } 149 outputSources->save = true; 150 } 151 122 152 pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSTAMP.CHIP"); 123 153 if (!chipImage) { -
trunk/pstamp/src/pstamp.h
r28291 r34596 26 26 27 27 // values for options mask. 28 #define PSTAMP_SELECT_IMAGE 1 29 #define PSTAMP_SELECT_MASK 2 30 #define PSTAMP_SELECT_WEIGHT 4 31 #define PSTAMP_SELECT_CMF 8 32 #define PSTAMP_SELECT_PSF 16 33 #define PSTAMP_SELECT_BACKMDL 32 34 #define PSTAMP_SELECT_INVERSE 1024 35 #define PSTAMP_SELECT_UNCONV 2048 36 #define PSTAMP_USE_IMFILE_ID 16384 28 #define PSTAMP_SELECT_IMAGE 1 29 #define PSTAMP_SELECT_MASK 2 30 #define PSTAMP_SELECT_WEIGHT 4 31 #define PSTAMP_SELECT_SOURCES 8 32 #define PSTAMP_SELECT_CMF 8 33 #define PSTAMP_SELECT_PSF 16 34 #define PSTAMP_SELECT_BACKMDL 32 35 #define PSTAMP_SELECT_JPEG 64 36 // unused 128 37 // unused 256 38 #define PSTAMP_SELECT_UNCOMPRESSED 512 39 #define PSTAMP_SELECT_INVERSE 1024 40 #define PSTAMP_SELECT_UNCONV 2048 41 #define PSTAMP_RESTORE_BACKGROUND 4096 42 // unused 8192 43 #define PSTAMP_USE_IMFILE_ID 16384 37 44 38 #define PSTAMP_NO_WAIT_FOR_UPDATE 32768 45 #define PSTAMP_NO_WAIT_FOR_UPDATE 32768 46 #define PSTAMP_REQUEST_UNCENSORED 0x10000 47 #define PSTAMP_REQUIRE_UNCENSORED 0x20000 39 48 40 49 #define PSTAMP_CENTER_IN_PIXELS 1
Note:
See TracChangeset
for help on using the changeset viewer.
