Changeset 2661
- Timestamp:
- Dec 7, 2004, 3:38:05 PM (22 years ago)
- Location:
- trunk/stac/src
- Files:
-
- 6 edited
-
Makefile (modified) (4 diffs)
-
stac.h (modified) (2 diffs)
-
stacCombine.c (modified) (6 diffs)
-
stacConfig.c (modified) (5 diffs)
-
stacRejection.c (modified) (3 diffs)
-
stacTransform.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/src/Makefile
r2500 r2661 1 1 SHELL = /bin/sh 2 2 CC = gcc 3 CFLAGS = -O2 -g -std=c99 -I/home/mithrandir/price/psLib3/psLib/include # -DTESTING4 PSLIB = -L/home/mithrandir/price/psLib3/psLib/lib/ -lpslib -lgsl -lgslcblas -lfftw3f -lsla -lcfitsio -lm5 LDFLAGS = $(PSLIB)3 CFLAGS += -O2 -g -std=c99 -I/home/mithrandir/price/psLib3/psLib/include -DTESTING -DCRFLUX 4 PSLIB += -L/home/mithrandir/price/psLib3/psLib/lib/ -lpslib -lgsl -lgslcblas -lfftw3f -lsla -lcfitsio -lm 5 LDFLAGS += $(PSLIB) 6 6 7 7 OBJECTS = stac.o stacConfig.o stacRead.o stacErrorImages.o stacTransform.o stacCheckMemory.o \ … … 18 18 $(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LDFLAGS) $(OPTFLAGS) 19 19 20 calcGrad: calcGrad.o 21 $(CC) $(CFLAGS) -o $@ calcGrad.o $(LDFLAGS) $(OPTFLAGS) 22 20 23 clean: 21 24 -$(RM) *.o gmon.* profile.txt … … 27 30 -$(RM) testout.fits 28 31 -$(RM) testout.fits.pre 32 -$(RM) chi2_*.fits 29 33 -$(RM) test_[0-3].fits.err 30 34 -$(RM) test_[0-3].fits.mask 31 -$(RM) test_[0-3].fits.shift. ?35 -$(RM) test_[0-3].fits.shift.* 32 36 -$(RM) test_[0-3].fits.shiftrej 33 37 -$(RM) test_[0-3].fits.shifterr.* 34 38 -$(RM) leaks.dat 35 ./stac -v testout.fits test_0.fits test_1.fits test_2.fits test_3.fits39 ./stac -v -k 2.5 -f 0.3 -G 0.6 testout.fits test_0.fits test_1.fits test_2.fits test_3.fits 36 40 37 41 # Run profiling. … … 49 53 optimise: clean 50 54 -$(RM) $(TARGET) 51 export OPTFLAGS=-fprofile- arcs; $(MAKE) test55 export OPTFLAGS=-fprofile-generate ; $(MAKE) test 52 56 -$(RM) $(TARGET) 53 57 $(MAKE) clean 54 export OPTFLAGS=-fbranch- probabilities; $(MAKE) $(TARGET)58 export OPTFLAGS=-fbranch-use ; $(MAKE) $(TARGET) 55 59 -$(RM) *.da 56 60 -
trunk/stac/src/stac.h
r2500 r2661 27 27 float frac; // Fraction of input pixel that must be masked before the pixel is 28 28 // considered bad 29 float grad; // Multiplier of the gradient 29 30 } stacConfig; 30 31 … … 129 130 // stacRejection.c 130 131 132 // Return the relative gradient for a given pixel 133 float stacGradient(psImage *image, // Input for which to measure the gradient 134 int x, int y // Coordinates at which to measure the gradient 135 ); 136 131 137 // Transform the rejection masks back to the source frame 132 138 psArray *stacRejection(psArray *inputs, // Input images -
trunk/stac/src/stacCombine.c
r2500 r2661 16 16 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 17 17 (void)psVectorStats(stats, values, masks, 1); 18 float mean = stats->sampleMean; 18 19 psFree(stats); 19 return stats->sampleMean;20 return mean; 20 21 #else 21 22 // Instead, do it ourselves … … 45 46 { 46 47 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 47 (void)psVectorStats(stats, values, masks, 1); 48 (void)psVectorStats(stats, values, masks, 0); 49 float median = stats->sampleMedian; 48 50 psFree(stats); 49 return stats->sampleMedian;51 return median; 50 52 } 51 53 … … 113 115 } 114 116 } 115 117 118 #ifdef TESTING 119 // chi^2 image 120 psImage *chi2 = psImageAlloc(numCols, numRows, PS_TYPE_F32); 121 static int iteration = 0; // Number of times function has been called 122 #endif 116 123 117 124 for (int y = 0; y < numRows; y++) { … … 131 138 } 132 139 133 float average = stacCombineMean(pixels, deltas, mask); // Combined value 140 float average = stacCombineMedian(pixels, deltas, mask); // Combined value 141 142 #ifdef TESTING 143 // Calculate chi^2 144 chi2->data.F32[y][x] = 0.0; 145 int numGoodPix = 0; 146 for (int i = 0; i < nImages; i++) { 147 if (mask->data.U8[i]) { 148 chi2->data.F32[y][x] += SQUARE((pixels->data.F32[i] - average) / deltas->data.F32[i]); 149 numGoodPix++; 150 } 151 } 152 chi2->data.F32[y][x] /= (float)numGoodPix; 153 #endif 134 154 135 155 // Rejection iterations 136 156 for (int rejNum = 0; rejNum < nReject; rejNum++) { 137 157 float max = 0.0; 138 int maxIndex = 0;158 int maxIndex = -1; 139 159 for (int i = 0; i < nImages; i++) { 140 if (mask->data.U8[i] && ( ABS(pixels->data.F32[i] - average) / deltas->data.F32[i] > max)) {141 max = ABS(pixels->data.F32[i] - average) / deltas->data.F32[i];160 if (mask->data.U8[i] && ((pixels->data.F32[i] - average) / deltas->data.F32[i] > max)) { 161 max = (pixels->data.F32[i] - average) / deltas->data.F32[i]; 142 162 maxIndex = i; 143 163 } … … 152 172 } // Rejection iterations 153 173 154 combined->data.F32[y][x] = average;174 combined->data.F32[y][x] = stacCombineMean(pixels, deltas, mask); 155 175 } 156 176 } // Iterating over output pixels … … 160 180 if (nReject > 0) { 161 181 for (int i = 0; i < nImages; i++) { 162 char rejfile[MAXCHAR]; // Filename of rejection image182 char rejfile[MAXCHAR]; // Filename of rejection image 163 183 sprintf(rejfile,"%s.shiftrej",config->inputs->data[i]); 164 184 psImageWriteSection((psImage*)((*rejected)->data[i]),0,0,0,NULL,0,rejfile); 165 185 } 166 186 } 187 // Write chi^2 image 188 iteration++; 189 char chifile[MAXCHAR]; // Filename of chi^2 image 190 sprintf(chifile,"chi2_%d.fits",iteration); 191 psImageWriteSection(chi2,0,0,0,NULL,0,chifile); 192 psFree(chi2); 167 193 #endif 168 194 -
trunk/stac/src/stacConfig.c
r2500 r2661 9 9 { 10 10 fprintf (stderr, "STAC: Simultaneous Telescope Array Combination\n" 11 "Usage: %s [-h] [-v] [-g GAIN] [-r RN] [-o NX NY] [-s SAT] [-b BAD] [-k REJ] [-k FRAC] OUT IN1 IN2...\n"11 "Usage: %s [-h] [-v] [-g GAIN] [-r RN] [-o NX NY] [-s SAT] [-b BAD] [-k REJ] [-k FRAC] [-G GRAD] OUT IN1 IN2...\n" 12 12 "where\n" 13 13 "\t-h Help (this info)\n" … … 19 19 "\t-b BAD Bad level (0)\n" 20 20 "\t-k REJ Rejection level (k-sigma; 3.5)\n" 21 "\t-f FRAC Fraction of pixel to be marked before considered bad (0.8)\n" 21 "\t-f FRAC Fraction of pixel to be marked before considered bad (0.5)\n" 22 "\t-d GRAD Gradient threshold for pixel to be marked (0.0)\n" 22 23 "\tOUT Output image\n" 23 24 "\tIN1, IN2... Input images, which have associated .map files.\n", … … 37 38 config->inputs = NULL; 38 39 config->output = NULL; 39 config->outnx = 512;40 config->outny = 512;40 config->outnx = 1024; 41 config->outny = 1024; 41 42 config->saturated = 65536.0; 42 43 config->bad = 0.0; 43 config->reject = 2.75;44 config->reject = 3.5; 44 45 config->frac = 0.5; 46 config->grad = 0.4; 45 47 46 48 return config; … … 72 74 73 75 /* Parse command-line arguments using getopt */ 74 while ((opt = getopt(argc, argv, "hvg:r:o:s:b:k:f: ")) != -1) {76 while ((opt = getopt(argc, argv, "hvg:r:o:s:b:k:f:G:")) != -1) { 75 77 switch (opt) { 76 78 case 'h': … … 121 123 } 122 124 break; 125 case 'G': 126 if (sscanf(optarg, "%f", &config->grad) != 1) { 127 help(programName); 128 } 129 break; 123 130 default: 124 131 help(programName); -
trunk/stac/src/stacRejection.c
r2500 r2661 2 2 #include "pslib.h" 3 3 #include "stac.h" 4 5 6 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 7 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 8 9 float stacGradient(psImage *image, // Input for which to measure the gradient 10 int x, int y // Coordinates at which to measure the gradient 11 ) 12 { 13 float sum = 0.0; // The sum of surrounding pixels 14 int num = 0; 15 psVector *pixels = psVectorAlloc(9, PS_TYPE_F32); // Array of pixels 16 psVector *mask = psVectorAlloc(9, PS_TYPE_U8); // Corresponding mask 17 18 // Get limits 19 int xMin = MAX(x - 1, 0); 20 int xMax = MIN(x + 1, image->numCols - 1); 21 int yMin = MAX(y - 1, 0); 22 int yMax = MIN(y + 1, image->numRows - 1); 23 for (int j = yMin; j <= yMax; j++) { 24 for (int i = xMin; i <= xMax; i++) { 25 sum += image->data.F32[j][i]; 26 pixels->data.F32[num] = image->data.F32[j][i]; 27 mask->data.U8[num] = 1; 28 num++; 29 } 30 } 31 #if 0 32 sum -= image->data.F32[y][x]; 33 sum /= (float)(num-1); 34 // sum -= image->data.F32[y][x]; 35 return sum / image->data.F32[y][x]; 36 #endif 37 38 // Fill out the array 39 for (int i = num; i < 9; i++) { 40 pixels->data.F32[i] = 0; 41 mask->data.U8[i] = 0; 42 } 43 psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 44 (void)psVectorStats(stats, pixels, mask, 0); 45 float median = stats->sampleMedian; 46 psFree(stats); 47 psFree(pixels); 48 psFree(mask); 49 return median / image->data.F32[y][x]; 50 } 51 52 #if 0 53 float stacGradient(psImage *image, // Input for which to measure the gradient 54 int x, int y // Coordinates at which to measure the gradient 55 ) 56 { 57 float sum = 0.0; // The sum of surrounding pixels 58 float maxDiff = 0.0; 59 int num = 0; 60 // Get limits 61 int xMin = MAX(x - 1, 0); 62 int xMax = MIN(x + 1, image->numCols - 1); 63 int yMin = MAX(y - 1, 0); 64 int yMax = MIN(y + 1, image->numRows - 1); 65 for (int j = yMin; j <= yMax; j++) { 66 for (int i = xMin; i <= xMax; i++) { 67 if (image->data.F32[j][i] - image->data.F32[y][x] < maxDiff) { 68 maxDiff = image->data.F32[j][i] - image->data.F32[y][x]; 69 } 70 sum += image->data.F32[j][i]; 71 num++; 72 } 73 } 74 sum -= image->data.F32[y][x]; 75 sum /= (float)(num-1); 76 sum -= image->data.F32[y][x]; 77 // return sum / image->data.F32[y][x]; 78 return maxDiff / image->data.F32[y][x]; 79 } 80 #endif 4 81 5 82 … … 55 132 int nxInput = ((psImage*)(inputs->data[i]))->numCols; 56 133 int nyInput = ((psImage*)(inputs->data[i]))->numRows; 57 psImage *mask = psImageAlloc(nxInput, nyInput, PS_TYPE_F32); // The mask in the source frame 134 psImage *mask = psImageAlloc(nxInput, nyInput, PS_TYPE_U8); // The pixel mask for the input 135 #ifdef TESTING 136 psImage *rejmap = psImageAlloc(nxInput, nyInput, PS_TYPE_F32); // The rejections in the source frame 137 psImage *grad = psImageAlloc(nxInput, nyInput, PS_TYPE_F32); // The gradient image 138 #endif 58 139 psImage *reject = rejected->data[i]; // Pull out the mask in the output frame 59 140 psPlaneTransform *map = maps->data[i]; // The map from input to output 60 141 61 142 psTrace("stac.rejection", 3, "Transforming rejection mask %d....\n", i); 143 int nBad = 0; // Number of bad pixels 144 145 #ifdef CRFLUX 146 // Set up CR output 147 FILE *crs = NULL; // File for outputting details of rejected pixels 148 char crfile[MAXCHAR]; // Filename 149 sprintf(crfile,"%s.cr",config->inputs->data[i]); 150 if ((crs = fopen(crfile, "w")) == NULL) { 151 psError("stac.rejection","Unable to open file for detailed output, %s\n"); 152 return NULL; 153 } 154 #endif 62 155 63 156 // Transform the mask … … 67 160 for (int y = 0; y < nyInput; y++) { 68 161 for (int x = 0; x < nxInput; x++) { 69 inCoords->x = (double)x + 0.5;70 inCoords->y = (double)y + 0.5;162 inCoords->x = (double)x; 163 inCoords->y = (double)y; 71 164 (void)psPlaneTransformApply(outCoords, map, inCoords); 72 mask->data.F32[y][x] =psImagePixelInterpolate(reject, outCoords->x, outCoords->y,165 float maskVal = (float)psImagePixelInterpolate(reject, outCoords->x, outCoords->y, 73 166 NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 167 #ifdef TESTING 168 rejmap->data.F32[y][x] = maskVal; 169 grad->data.F32[y][x] = stacGradient(inputs->data[i], x, y); 170 #endif 171 // Check threshold, then check gradient 172 if ((maskVal > config->frac) && (stacGradient(inputs->data[i], x, y) < config->grad)) { 173 mask->data.U8[y][x] = 1; 174 nBad++; 175 #ifdef CRFLUX 176 fprintf(crs, "%d %d --> %f %f %f\n", x, y, ((psImage*)(inputs->data[i]))->data.F32[y][x], 177 maskVal, stacGradient(inputs->data[i], x, y)); 178 #endif 179 } else { 180 mask->data.U8[y][x] = 0; 181 } 74 182 75 183 } 76 } 184 } // Iterating over pixels 185 186 #ifdef CRFLUX 187 // Close file used for detailed output 188 fclose(crs); 189 #endif 190 191 psTrace("stac.rejection", 1, "%d pixels masked in image %d.\n", nBad, i); 192 // Clip the image, and convert to suitable mask format 77 193 78 194 #ifdef TESTING 79 195 // Write error image out to check 80 char maskfile[MAXCHAR]; // Filename of mask image 196 char maskfile[MAXCHAR]; // Filename of mask image 197 char rejmapfile[MAXCHAR]; // Filename of rejection image 198 char gradfile[MAXCHAR]; // Filename of gradient image 81 199 sprintf(maskfile,"%s.mask",config->inputs->data[i]); 200 sprintf(rejmapfile,"%s.rejmap",config->inputs->data[i]); 201 sprintf(gradfile,"%s.grad",config->inputs->data[i]); 82 202 psImageWriteSection(mask,0,0,0,NULL,0,maskfile); 83 #endif 84 85 // Clip the image, and convert to suitable mask format 86 (void)psImageClip(mask, config->frac, 0.0, config->frac, 1.0); 87 psImage *maskU8 = psImageCopy(NULL, mask, PS_TYPE_U8); 88 psFree(mask); 89 203 psImageWriteSection(rejmap,0,0,0,NULL,0,rejmapfile); 204 psImageWriteSection(grad,0,0,0,NULL,0,gradfile); 205 psFree(rejmap); 206 psFree(grad); 207 #endif 208 90 209 // Stuff into the array 91 inputRej->data[i] = maskU8; 92 93 } 210 inputRej->data[i] = mask; 211 212 } 213 94 214 95 215 psFree(inCoords); -
trunk/stac/src/stacTransform.c
r2500 r2661 20 20 unsigned int maskVal, 21 21 psF64 unexposedValue) 22 { 22 { 23 23 double floorX = floor((psF64)(x) - 0.5); 24 24 double floorY = floor((psF64)(y) - 0.5); … … 206 206 (void)psPlaneTransformApply(detector, map, sky); 207 207 208 outImage->data.F32[y][x] = (psF32)psImagePixelInterpolate(image, detector->x , detector->y,209 mask, 1, 0.0,208 outImage->data.F32[y][x] = (psF32)psImagePixelInterpolate(image, detector->x + 0.5, 209 detector->y + 0.5, mask, 1, 0.0, 210 210 PS_INTERPOLATE_BILINEAR); 211 outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error, detector->x, 212 detector->y, mask, 1, 213 0.0); 211 outError->data.F32[y][x] = (psF32)p_psImageErrorInterpolateBILINEAR_F32(error, 212 detector->x + 0.5, 213 detector->y + 0.5, 214 mask, 1, 0.0); 214 215 outError->data.F32[y][x] = sqrtf(outError->data.F32[y][x]); 215 216 }
Note:
See TracChangeset
for help on using the changeset viewer.
