Changeset 3666 for trunk/stac/src/stac.c
- Timestamp:
- Apr 5, 2005, 11:51:26 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/stac/src/stac.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/stac.c
r3660 r3666 2 2 #include "pslib.h" 3 3 #include "stac.h" 4 #include "stacConfig.h" 4 5 #include <sys/time.h> 5 6 … … 47 48 48 49 // Read input files 49 psArray *inputs = stacReadImages(config );50 psArray *inputs = stacReadImages(config->inputs); 50 51 51 52 // Read maps 52 psArray *maps = stacReadMaps(config );53 psArray *maps = stacReadMaps(config->inputs); 53 54 54 55 psTrace("stac.time", 1, "I/O completed at %f seconds\n", getTime() - startTime); … … 56 57 // Get size, if not input 57 58 if (config->outnx == 0 || config->outny == 0) { 58 stacSize( config, inputs, maps);59 stacSize(&config->outnx, &config->outny, &config->xMapDiff, &config->yMapDiff, inputs, maps); 59 60 } 60 61 61 62 // Invert maps 62 psArray *inverseMaps = stacInvertMaps(maps, config );63 psArray *inverseMaps = stacInvertMaps(maps, config->outnx, config->outny); 63 64 64 65 // Generate errors 65 psArray *errors = stacErrorImages(inputs, config); 66 psArray *errors = stacErrorImages(inputs, config->gain, config->readnoise); 67 #ifdef TESTING 68 // Write error images out to check 69 for (int i = 0; i < inputs->n; i++) { 70 char errName[MAXCHAR]; // Filename of error image 71 sprintf(errName,"%s.err",config->inputs->data[i]); 72 psFits *errorFile = psFitsAlloc(errName); 73 if (!psFitsWriteImage(errorFile, NULL, error, 0, NULL)) { 74 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName); 75 } 76 psTrace("stac", 1, "Error image written to %s\n", errName); 77 psFree(errorFile); 78 } 79 #endif 66 80 67 81 // Transform inputs and errors … … 69 83 psArray *transformedErrors = NULL; 70 84 (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, NULL, NULL, NULL, NULL, 71 config); 72 85 config->outnx, config->outny); 73 86 psTrace("stac.time",1,"Transformation completed at %f seconds\n", getTime() - startTime); 87 88 #ifdef TESTING 89 // Write transformed images out to check 90 for (int i = 0; i < inputs->n; i++) { 91 char shiftName[MAXCHAR]; // Filename of shift image 92 char errName[MAXCHAR]; // Filename of error image 93 sprintf(shiftName,"%s.shift1",config->inputs->data[n],numTransforms); 94 sprintf(errName,"%s.shifterr1",config->inputs->data[n],numTransforms); 95 psTrace("stac.transform.test", 6, 96 "Output files have size: %dx%d\n",outImage->numCols,outImage->numRows); 97 psFits *shiftFile = psFitsAlloc(shiftName); 98 psFits *errFile = psFitsAlloc(errName); 99 if (!psFitsWriteImage(shiftFile, NULL, outImage, 0, NULL)) { 100 psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName); 101 } 102 psTrace("stac", 1, "Shifted image written to %s\n", shiftName); 103 if (!psFitsWriteImage(errFile, NULL, outError, 0, NULL)) { 104 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName); 105 } 106 psTrace("stac", 1, "Shifted error image written to %s\n", errName); 107 psFree(shiftFile); 108 psFree(errFile); 109 } 110 #endif 111 112 74 113 75 114 psVector *scales = NULL; // Relative scales between images 76 115 psVector *offsets = NULL; // Offsets between images 77 (void)stacScales(&scales, &offsets, transformed, config); 116 (void)stacScales(&scales, &offsets, transformed, config->starFile, config->starMapFile, config->xMapDiff, 117 config->yMapDiff, config->aper); 78 118 // Rescale the images 79 119 (void)stacRescale(transformed, transformedErrors, NULL, scales, offsets); 120 // Set the saturation and bad values 121 psVector *saturated = psVectorAlloc(transformed->n, PS_TYPE_F32); // Saturation limits 122 psVector *bad = psVectorAlloc(transformed->n, PS_TYPE_F32); // Bad limits 123 for (int i = 0; i < transformed->n; i++) { 124 saturated->data.F32[i] = (config->saturated - offsets->data.F32[i]) / scales->data.F32[i]; 125 bad->data.F32[i] = (config->bad - offsets->data.F32[i]) / scales->data.F32[i]; 126 } 80 127 81 128 // Combine with rejection 82 129 psArray *rejected = NULL; 83 130 psImage *combined = NULL; 84 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, config->nReject, NULL, config); 131 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, config->nReject, NULL, saturated, 132 bad, config->reject); 85 133 86 134 psTrace("stac.time",1,"First combination completed at %f seconds\n", getTime() - startTime); 87 135 88 #ifdef TESTING 136 137 #ifdef TESTING 138 // Write rejection images out to check 139 for (int i = 0; i < nImages; i++) { 140 char rejName[MAXCHAR]; // Filename of rejection image 141 sprintf(rejName,"%s.shiftrej",config->inputs->data[i]); 142 143 psFits *rejFile = psFitsAlloc(rejName); 144 if (!psFitsWriteImage(rejFile, NULL, (*rejected)->data[i], 0, NULL)) { 145 psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName); 146 } 147 psTrace("stac", 1, "Rejection image written to %s\n", rejName); 148 psFree(rejFile); 149 } 150 151 // Write out pre-combined image 89 152 char preName[MAXCHAR]; // Filename of precombined image 90 153 sprintf(preName,"%s.pre",config->output); … … 116 179 117 180 // Transform rejected pixels to source frame 118 psArray *rejectedSource = stacRejection(inputs, rejected, regions, maps, inverseMaps, config); 181 psArray *rejectedSource = stacRejection(inputs, rejected, regions, maps, inverseMaps, config->frac, 182 config->grad, config->inputs); 119 183 120 184 // Get regions of interest in the output frame … … 134 198 // Redo transformation with the masks and scales/offsets 135 199 (void)stacTransform(&transformed, &transformedErrors, inputs, inverseMaps, errors, rejectedSource, 136 combineRegion, scales, offsets, config );200 combineRegion, scales, offsets, config->outnx, config->outny); 137 201 138 202 // Combine the newly-transformed CR-free images, no rejection 139 203 psFree(rejected); 140 204 rejected = NULL; 141 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, 0, combineRegion, config); 205 (void)stacCombine(&combined, &rejected, transformed, transformedErrors, 0, combineRegion, saturated, 206 bad, config->reject); 142 207 143 208 // Write output image
Note:
See TracChangeset
for help on using the changeset viewer.
