- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ppStack/src (modified) (1 prop)
-
ppStack/src/ppStackCleanup.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ppStack/src
- Property svn:ignore
-
old new 10 10 stamp-h1 11 11 ppStackVersionDefinitions.h 12 ppStackErrorCodes.c 13 ppStackErrorCodes.h
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ppStack/src/ppStackCleanup.c
r23341 r27840 4 4 5 5 #include <stdio.h> 6 #include <unistd.h>7 6 #include <pslib.h> 8 7 #include <psmodules.h> 8 #include <ppStats.h> 9 9 10 10 #include "ppStack.h" 11 11 #include "ppStackLoop.h" 12 13 #define WCS_TOLERANCE 0.001 // Tolerance for WCS14 12 15 13 … … 22 20 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe 23 21 psAssert(recipe, "We've thrown an error on this before."); 24 25 bool mdok; // Status of MD lookup26 bool tempDelete = psMetadataLookupBool(&mdok, recipe, "TEMP.DELETE"); // Delete temporary files?27 22 28 23 #if 0 … … 37 32 #endif 38 33 39 // Close up40 bool wcsDone = false; // Have we done the WCS?41 for (int i = 0; i < options->num; i++) {42 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {43 continue;44 }45 46 ppStackThread *thread = stack->threads->data[0]; // Representative stack47 pmReadout *inRO = thread->readouts->data[i]; // Template readout48 if (inRO && !wcsDone) {49 // Copy astrometry over50 wcsDone = true;51 pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU52 pmHDU *outHDU = pmHDUFromCell(options->outRO->parent); // Output HDU53 pmChip *outChip = options->outRO->parent->parent; // Output chip54 pmFPA *outFPA = outChip->parent; // Output FPA55 if (!outHDU || !inHDU) {56 psWarning("Unable to find HDU at FPA level to copy astrometry.");57 } else {58 if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {59 psErrorClear();60 psWarning("Unable to read WCS astrometry from input FPA.");61 wcsDone = false;62 } else {63 if (!outHDU->header) {64 outHDU->header = psMetadataAlloc();65 }66 if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {67 psErrorClear();68 psWarning("Unable to write WCS astrometry to output FPA.");69 wcsDone = false;70 }71 }72 }73 }74 75 if (tempDelete) {76 psString imageResolved = pmConfigConvertFilename(options->imageNames->data[i],77 config, false, false);78 psString maskResolved = pmConfigConvertFilename(options->maskNames->data[i],79 config, false, false);80 psString varianceResolved = pmConfigConvertFilename(options->varianceNames->data[i],81 config, false, false);82 if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 ||83 unlink(varianceResolved) == -1) {84 psWarning("Unable to delete temporary files for image %d", i);85 }86 psFree(imageResolved);87 psFree(maskResolved);88 psFree(varianceResolved);89 }90 }91 92 ppStackMemDump("cleanup");93 94 34 // Generate binned JPEGs 95 35 { … … 103 43 pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2"); 104 44 psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask 45 psFree(view); 105 46 106 47 pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts 107 48 if (!pmReadoutRebin(ro1, options->outRO, maskValue, bin1, bin1) || 108 49 !pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) { 109 psError(P S_ERR_UNKNOWN, false, "Unable to bin output.");50 psError(PPSTACK_ERR_DATA, false, "Unable to bin output."); 110 51 psFree(ro1); 111 52 psFree(ro2); … … 116 57 } 117 58 118 // Put version information into the header 119 pmHDU *hdu = pmHDUFromCell(options->outRO->parent); 120 if (!hdu) { 121 psError(PS_ERR_UNKNOWN, false, "Unable to find HDU for output."); 59 // Statistics on output 60 if (options->stats) { 61 psTrace("ppStack", 1, "Gathering statistics on stacked image....\n"); 62 psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad 63 psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels 64 65 pmFPAview *view = pmFPAviewAlloc(0); // View to readout 66 view->chip = view->cell = view->readout = 0; 67 68 ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config); 69 70 psFree(view); 71 } 72 73 if (!ppStackFilesIterateUp(config)) { 74 psError(psErrorCodeLast(), false, "Unable to close files."); 122 75 return false; 123 76 } 124 if (!hdu->header) { 125 hdu->header = psMetadataAlloc(); 77 ppStackFileActivation(config, PPSTACK_FILES_STACK, false); 78 ppStackFileActivation(config, PPSTACK_FILES_PHOT, false); 79 80 // Ensure files are freed 81 { 82 options->outRO->data_exists = false; 83 options->outRO->parent->data_exists = false; 84 options->outRO->parent->parent->data_exists = false; 85 psFree(options->outRO); 86 options->outRO = NULL; 87 88 options->expRO->data_exists = false; 89 options->expRO->parent->data_exists = false; 90 options->expRO->parent->parent->data_exists = false; 91 psFree(options->expRO); 92 options->expRO = NULL; 93 94 pmFPAview *view = pmFPAviewAlloc(0);// Pointer into FPA hierarchy 95 view->chip = view->cell = 0; // pmFPAviewFreeData doesn't want to deal with readouts 96 pmFPAfile *jpeg1 = pmFPAfileSelectSingle(config->files, "PPSTACK.OUTPUT.JPEG1", 0); // JPEG file 97 pmFPAviewFreeData(view, jpeg1); 98 pmFPAfile *jpeg2 = pmFPAfileSelectSingle(config->files, "PPSTACK.OUTPUT.JPEG2", 0); // JPEG file 99 pmFPAviewFreeData(view, jpeg2); 100 pmFPAfile *phot = NULL; // Photometry file 101 if (options->photometry) { 102 phot = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // Photometry file 103 pmFPAviewFreeData(view, phot); 104 } 105 106 view->readout = 0; 107 pmReadout *ro1 = pmFPAviewThisReadout(view, jpeg1->fpa); // JPEG readout 108 ro1->data_exists = ro1->parent->data_exists = ro1->parent->parent->data_exists = false; 109 pmReadout *ro2 = pmFPAviewThisReadout(view, jpeg2->fpa); // JPEG readout 110 ro2->data_exists = ro2->parent->data_exists = ro2->parent->parent->data_exists = false; 111 if (options->photometry) { 112 pmReadout *ro = pmFPAviewThisReadout(view, phot->fpa); // Photometry readout 113 ro->data_exists = ro->parent->data_exists = ro->parent->parent->data_exists = false; 114 } 115 psFree(view); 126 116 } 127 ppStackVersionHeader(hdu->header);128 117 129 118 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
