Changeset 6887
- Timestamp:
- Apr 18, 2006, 12:20:45 PM (20 years ago)
- Location:
- trunk/stac
- Files:
-
- 17 edited
-
configure.ac (modified) (1 diff)
-
src/combine.c (modified) (2 diffs)
-
src/combineConfig.c (modified) (5 diffs)
-
src/shift.c (modified) (2 diffs)
-
src/shiftSize.c (modified) (6 diffs)
-
src/stac.c (modified) (9 diffs)
-
src/stac.h (modified) (12 diffs)
-
src/stacCombine.c (modified) (3 diffs)
-
src/stacConfig.c (modified) (7 diffs)
-
src/stacErrorImages.c (modified) (2 diffs)
-
src/stacInvertMaps.c (modified) (4 diffs)
-
src/stacRead.c (modified) (3 diffs)
-
src/stacRejection.c (modified) (5 diffs)
-
src/stacScales.c (modified) (6 diffs)
-
src/stacSize.c (modified) (2 diffs)
-
src/stacTransform.c (modified) (2 diffs)
-
src/sum.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/stac/configure.ac
r6453 r6887 26 26 27 27 stac_CFLAGS="-Wall -Werror -std=c99 -DPS_NO_TRACE" 28 #stac_CFLAGS="-Wall -Werror -std=c99" 28 29 AC_SUBST([stac_CFLAGS]) 29 30 -
trunk/stac/src/combine.c
r6771 r6887 25 25 // Make fake errors 26 26 psArray *errors = psArrayAlloc(images->n); 27 errors->n = images->n; 27 28 for (int i = 0; i < images->n; i++) { 28 29 psImage *image = images->data[i]; … … 44 45 psVector *saturated = psVectorAlloc(images->n, PS_TYPE_F32); // Saturation limits 45 46 psVector *bad = psVectorAlloc(images->n, PS_TYPE_F32); // Bad limits 47 saturated->n = images->n; 48 bad->n = images->n; 46 49 for (int i = 0; i < images->n; i++) { 47 50 saturated->data.F32[i] = (config->saturated - offsets->data.F32[i]) / scales->data.F32[i]; -
trunk/stac/src/combineConfig.c
r3680 r6887 11 11 { 12 12 fprintf (stderr, "shift: shift an image, given the transformation\n" 13 "Usage: %s [-h] [-v] [-g GAIN] [-r READNOISE] [-s SAT] [-b BAD] [-p FILE MAP] [-a APER] [-k SIGMAREJ] [-n NREJECT] OUT IN1 IN2...\n"14 "where\n"15 "\t-h Help (this info)\n"16 "\t-v Increase verbosity level\n"17 "\t-g GAIN Gain in e/ADU (1.0)\n"18 "\t-r READNOISE Read noise in e (0.0)\n"19 "\t-s SAT Saturation point (65535)\n"20 "\t-b BAD Bad level (0)\n"21 "\t-p FILE MAP Specify file containing star coordinates, with map\n"22 "\t-a APER Aperture radius for photometry (3.0)\n"23 "\t-k SIGMAREJ k-sigma rejection threshold (3.0)\n"24 "\t-n NREJECT Number of rejection iterations (1)\n"25 "\tOUT Output image\n"26 "\tIN1 IN2... Input images (identical size)\n",27 programName28 );13 "Usage: %s [-h] [-v] [-g GAIN] [-r READNOISE] [-s SAT] [-b BAD] [-p FILE MAP] [-a APER] [-k SIGMAREJ] [-n NREJECT] OUT IN1 IN2...\n" 14 "where\n" 15 "\t-h Help (this info)\n" 16 "\t-v Increase verbosity level\n" 17 "\t-g GAIN Gain in e/ADU (1.0)\n" 18 "\t-r READNOISE Read noise in e (0.0)\n" 19 "\t-s SAT Saturation point (65535)\n" 20 "\t-b BAD Bad level (0)\n" 21 "\t-p FILE MAP Specify file containing star coordinates, with map\n" 22 "\t-a APER Aperture radius for photometry (3.0)\n" 23 "\t-k SIGMAREJ k-sigma rejection threshold (3.0)\n" 24 "\t-n NREJECT Number of rejection iterations (1)\n" 25 "\tOUT Output image\n" 26 "\tIN1 IN2... Input images (identical size)\n", 27 programName 28 ); 29 29 } 30 30 … … 35 35 36 36 // Parameters with default values 37 config->verbose = 0; // Verbosity level38 config->gain = 1.0; // Gain (e/ADU)39 config->readnoise = 0.0; // Read noise (e)40 config->reject = 4.0; // Rejection threshold (sigma)41 config->nReject = 1; // Number of rejection iterations42 config->saturated = 65535.0; // Saturation level43 config->bad = 0.0; // Bad level44 config->outName = NULL; // Output name45 config->inNames = NULL; // Input names;46 config->starFile = NULL; // Filename of file containing stars47 config->starMap = NULL; // Map for stars48 config->aper = 3.0; // Aperture for photometry37 config->verbose = 0; // Verbosity level 38 config->gain = 1.0; // Gain (e/ADU) 39 config->readnoise = 0.0; // Read noise (e) 40 config->reject = 4.0; // Rejection threshold (sigma) 41 config->nReject = 1; // Number of rejection iterations 42 config->saturated = 65535.0; // Saturation level 43 config->bad = 0.0; // Bad level 44 config->outName = NULL; // Output name 45 config->inNames = NULL; // Input names; 46 config->starFile = NULL; // Filename of file containing stars 47 config->starMap = NULL; // Map for stars 48 config->aper = 3.0; // Aperture for photometry 49 49 50 50 return config; … … 62 62 combineConfig *config = combineConfigAlloc(); // Configuration 63 63 64 const char *programName = argv[0]; // Program name64 const char *programName = argv[0]; // Program name 65 65 66 66 /* Variables for getopt */ … … 72 72 while ((opt = getopt(argc, argv, "hvg:r:s:b:p:a:k:n:")) != -1) { 73 73 switch (opt) { 74 case 'h':75 help(programName);76 exit(EXIT_SUCCESS);77 case 'v':74 case 'h': 75 help(programName); 76 exit(EXIT_SUCCESS); 77 case 'v': 78 78 config->verbose++; 79 79 break; 80 case 'r':80 case 'r': 81 81 if (sscanf(optarg, "%f", &config->readnoise) != 1) { 82 printf("Unable to read readnoise.\n"); 83 help(programName); 84 exit(EXIT_FAILURE); 85 } 86 break; 87 case 'g': 88 if (sscanf(optarg, "%f", &config->gain) != 1) { 89 printf("Unable to read gain.\n"); 90 help(programName); 91 exit(EXIT_FAILURE); 92 } 93 break; 94 case 's': 95 if (sscanf(optarg, "%f", &config->saturated) != 1) { 96 printf("Unable to read saturation limit.\n"); 97 help(programName); 98 exit(EXIT_FAILURE); 99 } 100 break; 101 case 'b': 102 if (sscanf(optarg, "%f", &config->bad) != 1) { 103 printf("Unable to read bad limit.\n"); 104 help(programName); 105 exit(EXIT_FAILURE); 106 } 107 break; 108 case 'p': 109 if (argc < optind+1) { 110 printf("Unable to read photometric files.\n"); 111 help(programName); 112 exit(EXIT_FAILURE); 113 } 114 config->starFile = argv[optind-1]; 115 config->starMap = argv[optind++]; 116 // Note: incrementing optind, so I can read more than one parameter. 117 break; 118 case 'a': 119 if (sscanf(optarg, "%f", &config->aper) != 1) { 120 printf("Unable to read aperture.\n"); 82 printf("Unable to read readnoise.\n"); 121 83 help(programName); 122 84 exit(EXIT_FAILURE); 123 85 } 124 break;125 case 'k':126 if (sscanf(optarg, "%f", &config-> reject) != 1) {127 printf("Unable to read rejection limit.\n");86 break; 87 case 'g': 88 if (sscanf(optarg, "%f", &config->gain) != 1) { 89 printf("Unable to read gain.\n"); 128 90 help(programName); 129 91 exit(EXIT_FAILURE); 130 92 } 131 break;132 case 'n':133 if (sscanf(optarg, "% d", &config->nReject) != 1) {134 printf("Unable to read number of rejection iterations.\n");135 help(programName);93 break; 94 case 's': 95 if (sscanf(optarg, "%f", &config->saturated) != 1) { 96 printf("Unable to read saturation limit.\n"); 97 help(programName); 136 98 exit(EXIT_FAILURE); 137 99 } 138 break; 139 default: 140 printf("Bad option: %c\n", opt); 141 help(programName); 142 exit(EXIT_FAILURE); 143 } 100 break; 101 case 'b': 102 if (sscanf(optarg, "%f", &config->bad) != 1) { 103 printf("Unable to read bad limit.\n"); 104 help(programName); 105 exit(EXIT_FAILURE); 106 } 107 break; 108 case 'p': 109 if (argc < optind+1) { 110 printf("Unable to read photometric files.\n"); 111 help(programName); 112 exit(EXIT_FAILURE); 113 } 114 config->starFile = argv[optind-1]; 115 config->starMap = argv[optind++]; 116 // Note: incrementing optind, so I can read more than one parameter. 117 break; 118 case 'a': 119 if (sscanf(optarg, "%f", &config->aper) != 1) { 120 printf("Unable to read aperture.\n"); 121 help(programName); 122 exit(EXIT_FAILURE); 123 } 124 break; 125 case 'k': 126 if (sscanf(optarg, "%f", &config->reject) != 1) { 127 printf("Unable to read rejection limit.\n"); 128 help(programName); 129 exit(EXIT_FAILURE); 130 } 131 break; 132 case 'n': 133 if (sscanf(optarg, "%d", &config->nReject) != 1) { 134 printf("Unable to read number of rejection iterations.\n"); 135 help(programName); 136 exit(EXIT_FAILURE); 137 } 138 break; 139 default: 140 printf("Bad option: %c\n", opt); 141 help(programName); 142 exit(EXIT_FAILURE); 143 } 144 144 } 145 145 … … 151 151 exit(EXIT_FAILURE); 152 152 } 153 config->outName = argv[0]; // Output filename153 config->outName = argv[0]; // Output filename 154 154 config->inNames = psArrayAlloc(argc-1); // Input filenames 155 config->inNames->n = argc-1; 155 156 for (int i = 1; i < argc; i++) { 156 config->inNames->data[i-1] = psAlloc(strlen(argv[i]));157 strncpy(config->inNames->data[i-1], argv[i], strlen(argv[i]));157 config->inNames->data[i-1] = psAlloc(strlen(argv[i])); 158 strncpy(config->inNames->data[i-1], argv[i], strlen(argv[i])); 158 159 } 159 160 -
trunk/stac/src/shift.c
r6771 r6887 126 126 psArray *maps = psArrayAlloc(1); // An array of one 127 127 psArray *masks = psArrayAlloc(1); // An array of one 128 images->n = maps->n = masks->n = 1; 128 129 images->data[0] = image; 129 130 maps->data[0] = map; … … 132 133 // Get size 133 134 if (outnx == 0 || outny == 0) { 134 stacSize(&outnx, &outny, NULL, NULL, images, maps); 135 psVector *xSize = psVectorAlloc(1, PS_TYPE_S32); // A vector of one 136 psVector *ySize = psVectorAlloc(1, PS_TYPE_S32); // A vector of one 137 xSize->n = 1; 138 ySize->n = 1; 139 xSize->data.S32[0] = image->numCols; 140 ySize->data.S32[0] = image->numRows; 141 stacSize(&outnx, &outny, NULL, NULL, xSize, ySize, maps); 142 psFree(xSize); 143 psFree(ySize); 135 144 } 136 145 -
trunk/stac/src/shiftSize.c
r5743 r6887 17 17 { 18 18 fprintf (stderr, "shiftSize: Calculate size for output combined image\n" 19 "Usage: %s [-h] [-v] IN1 IN2...\n"20 "where\n"21 "\t-h Help (this info)\n"22 "\t-v Increase verbosity level\n"23 "\tIN1, IN2... Input images, which have associated .map files.\n",24 name25 );19 "Usage: %s [-h] [-v] IN1 IN2...\n" 20 "where\n" 21 "\t-h Help (this info)\n" 22 "\t-v Increase verbosity level\n" 23 "\tIN1, IN2... Input images, which have associated .map files.\n", 24 name 25 ); 26 26 } 27 27 … … 41 41 42 42 43 int verbose = 0; // Verbosity level43 int verbose = 0; // Verbosity level 44 44 45 45 // Parse command line 46 const char *programName = argv[0]; // Program name46 const char *programName = argv[0]; // Program name 47 47 /* Variables for getopt */ 48 48 int opt; /* Option, from getopt */ … … 53 53 while ((opt = getopt(argc, argv, "hv")) != -1) { 54 54 switch (opt) { 55 case 'h':56 help(programName);57 exit(EXIT_SUCCESS);58 case 'v':55 case 'h': 56 help(programName); 57 exit(EXIT_SUCCESS); 58 case 'v': 59 59 verbose++; 60 60 break; 61 default:62 help(programName);63 }61 default: 62 help(programName); 63 } 64 64 } 65 65 … … 73 73 74 74 psArray *inputs = psArrayAlloc(argc); // Input filenames 75 inputs->n = argc; 75 76 for (int i = 0; i < argc; i++) { 76 inputs->data[i] = psAlloc(strlen(argv[i])); 77 strncpy(inputs->data[i], argv[i], strlen(argv[i])); 77 inputs->data[i] = psAlloc(strlen(argv[i])); 78 strncpy(inputs->data[i], argv[i], strlen(argv[i])); 79 psTrace("stac.size", 8, "Input file: %s\n", inputs->data[i]); 78 80 } 79 81 80 82 // Read input files 81 psArray *images = stacReadImages(NULL, inputs); 83 psVector *xSize = psVectorAlloc(inputs->n, PS_TYPE_S32); 84 psVector *ySize = psVectorAlloc(inputs->n, PS_TYPE_S32); 85 xSize->n = inputs->n; 86 ySize->n = inputs->n; 87 for (int i = 0; i < inputs->n; i++) { 88 const char *filename = inputs->data[i]; // Name of FITS file 89 psFits *file = psFitsOpen(filename, "r"); // FITS file handle 90 psMetadata *header = psFitsReadHeader(NULL, file); // FITS header 91 psFitsClose(file); 92 bool mdok = true; // Status of MD lookup 93 xSize->data.S32[i] = psMetadataLookupS32(&mdok, header, "NAXIS1"); 94 if (!mdok) { 95 psError(PS_ERR_IO, true, "Unable to find NAXIS1 in %s\n", filename); 96 exit(EXIT_FAILURE); 97 } 98 ySize->data.S32[i] = psMetadataLookupS32(&mdok, header, "NAXIS2"); 99 if (!mdok) { 100 psError(PS_ERR_IO, true, "Unable to find NAXIS2 in %s\n", filename); 101 exit(EXIT_FAILURE); 102 } 103 psFree(header); 104 } 82 105 83 106 // Read maps … … 85 108 86 109 // Get size 87 int outnx, outny; // Size of combined image 88 float xMapDiff, yMapDiff; // Difference to apply to maps 89 stacSize(&outnx, &outny, &xMapDiff, &yMapDiff, images, maps); 110 int outnx, outny; // Size of combined image 111 float xMapDiff, yMapDiff; // Difference to apply to maps 112 stacSize(&outnx, &outny, &xMapDiff, &yMapDiff, xSize, ySize, maps); 113 psFree(xSize); 114 psFree(ySize); 90 115 91 116 printf("%d %d\n", outnx, outny); … … 95 120 96 121 psFree(inputs); 97 psFree(images);98 122 psFree(maps); 99 123 -
trunk/stac/src/stac.c
r6771 r6887 45 45 // Generate masks 46 46 psArray *masks = psArrayAlloc(inputs->n); 47 masks->n = inputs->n; 47 48 for (int i = 0; i < inputs->n; i++) { 48 49 psImage *image = inputs->data[i]; // Image for which to get mask … … 67 68 // Get size, if not input 68 69 if (config->outnx == 0 || config->outny == 0) { 69 stacSize(&config->outnx, &config->outny, &config->xMapDiff, &config->yMapDiff, inputs, maps); 70 psVector *xSize = psVectorAlloc(inputs->n, PS_TYPE_S32); // Sizes of images in x 71 psVector *ySize = psVectorAlloc(inputs->n, PS_TYPE_S32); // Sizes of images in y 72 xSize->n = inputs->n; 73 ySize->n = inputs->n; 74 for (int i = 0; i < inputs->n; i++) { 75 psImage *image = inputs->data[i]; // The i-th image 76 xSize->data.S32[i] = image->numCols; 77 ySize->data.S32[i] = image->numRows; 78 } 79 stacSize(&config->outnx, &config->outny, &config->xMapDiff, &config->yMapDiff, xSize, ySize, maps); 80 psFree(xSize); 81 psFree(ySize); 70 82 } 71 83 … … 96 108 for (int i = 0; i < inputs->n; i++) { 97 109 char errName[MAXCHAR]; // Filename of error image 98 sprintf(errName,"%s.err", config->inputs->data[i]);110 sprintf(errName,"%s.err", (char*)config->inputs->data[i]); 99 111 psFits *errorFile = psFitsOpen(errName, "w"); 100 if (!psFitsWriteImage(errorFile, NULL, errors->data[i], 0 )) {112 if (!psFitsWriteImage(errorFile, NULL, errors->data[i], 0, NULL)) { 101 113 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName); 102 114 } … … 118 130 char shiftName[MAXCHAR]; // Filename of shift image 119 131 char errName[MAXCHAR]; // Filename of error image 120 sprintf(shiftName,"%s.shift1", config->inputs->data[i]);121 sprintf(errName,"%s.shifterr1", config->inputs->data[i]);132 sprintf(shiftName,"%s.shift1", (char*)config->inputs->data[i]); 133 sprintf(errName,"%s.shifterr1",(char*)config->inputs->data[i]); 122 134 psFits *shiftFile = psFitsOpen(shiftName, "w"); 123 135 psFits *errFile = psFitsOpen(errName, "w"); 124 136 psImage *trans = transformed->data[i]; // Transformed image 125 137 psImage *transErr = transformedErrors->data[i]; // Transformed error image 126 if (!psFitsWriteImage(shiftFile, NULL, trans, 0 )) {138 if (!psFitsWriteImage(shiftFile, NULL, trans, 0, NULL)) { 127 139 psErrorStackPrint(stderr, "Unable to write image: %s\n", shiftName); 128 140 } 129 141 psTrace("stac", 1, "Shifted image written to %s\n", shiftName); 130 if (!psFitsWriteImage(errFile, NULL, transErr, 0 )) {142 if (!psFitsWriteImage(errFile, NULL, transErr, 0, NULL)) { 131 143 psErrorStackPrint(stderr, "Unable to write image: %s\n", errName); 132 144 } … … 146 158 psVector *saturated = psVectorAlloc(transformed->n, PS_TYPE_F32); // Saturation limits 147 159 psVector *bad = psVectorAlloc(transformed->n, PS_TYPE_F32); // Bad limits 160 saturated->n = transformed->n; 161 bad->n = transformed->n; 148 162 for (int i = 0; i < transformed->n; i++) { 149 163 saturated->data.F32[i] = (config->saturated - offsets->data.F32[i]) / scales->data.F32[i]; … … 182 196 for (int i = 0; i < rejected->n; i++) { 183 197 char rejName[MAXCHAR]; // Filename of rejection image 184 sprintf(rejName, "%s.shiftrej", config->inputs->data[i]);198 sprintf(rejName, "%s.shiftrej", (char*)config->inputs->data[i]); 185 199 186 200 psFits *rejFile = psFitsOpen(rejName, "w"); 187 if (!psFitsWriteImage(rejFile, NULL, rejected->data[i], 0 )) {201 if (!psFitsWriteImage(rejFile, NULL, rejected->data[i], 0, NULL)) { 188 202 psErrorStackPrint(stderr, "Unable to write image: %s\n", rejName); 189 203 } … … 196 210 sprintf(preName, "%s.pre", config->output); 197 211 psFits *preFile = psFitsOpen(preName, "w"); 198 if (!psFitsWriteImage(preFile, NULL, combined, 0 )) {212 if (!psFitsWriteImage(preFile, NULL, combined, 0, NULL)) { 199 213 psErrorStackPrint(stderr, "Unable to write image: %s\n", preName); 200 214 } … … 205 219 // Get regions of interest in the source frame 206 220 psArray *regions = psArrayAlloc(inputs->n); // Array of images denoting regions of interest 221 regions->n = inputs->n; 207 222 for (int i = 0; i < inputs->n; i++) { 208 223 regions->data[i] = stacAreaOfInterest(rejected->data[i], inverseMaps->data[i], … … 211 226 #ifdef TESTING 212 227 char regionName[MAXCHAR]; // Filename of region image 213 sprintf(regionName,"%s.region", config->inputs->data[i]);228 sprintf(regionName,"%s.region",(char*)config->inputs->data[i]); 214 229 psFits *regionFile = psFitsOpen(regionName, "w"); 215 if (!psFitsWriteImage(regionFile, NULL, regions->data[i], 0 )) {230 if (!psFitsWriteImage(regionFile, NULL, regions->data[i], 0, NULL)) { 216 231 psErrorStackPrint(stderr, "Unable to write image: %s\n", regionName); 217 232 } -
trunk/stac/src/stac.h
r5743 r6887 19 19 // Read the input files and return an array of images 20 20 psArray *stacReadImages(psArray **headers, // The image headers, to be returned 21 psArray *filenames // The file names of the images21 psArray *filenames // The file names of the images 22 22 ); 23 23 … … 38 38 // Calculate the error images 39 39 psArray *stacErrorImages(psArray *inputs, // Array of input images 40 float gain,// Gain, in e/ADU41 float rn// Read noise, in e40 float gain, // Gain, in e/ADU 41 float rn // Read noise, in e 42 42 ); 43 43 … … 47 47 48 48 // Transform input images, return success 49 bool stacTransform(psArray **outputs, // Transformed images for output50 psArray **outErrors, // Transformed error images for output51 const psArray *images, // Array of images to be transformed52 const psArray *maps, // Array of polynomials that do the transformation53 const psArray *errors, // Array of error images to be transformed54 const psArray *masks, // Masks of input images55 const psImage *region, // Region of interest for transformation56 const psVector *scales, // Relative scales57 const psVector *offsets, // Relative offsets58 int outnx, int outny// Size of output images49 bool stacTransform(psArray **outputs, // Transformed images for output 50 psArray **outErrors, // Transformed error images for output 51 const psArray *images, // Array of images to be transformed 52 const psArray *maps, // Array of polynomials that do the transformation 53 const psArray *errors, // Array of error images to be transformed 54 const psArray *masks, // Masks of input images 55 const psImage *region, // Region of interest for transformation 56 const psVector *scales, // Relative scales 57 const psVector *offsets, // Relative offsets 58 int outnx, int outny // Size of output images 59 59 ); 60 60 … … 68 68 // Print out the problem 69 69 void stacMemoryProblem(const psMemBlock* ptr, ///< the pointer to the problematic memory block. 70 const char *file, ///< the file in which the problem originated71 psS32 lineno///< the line number in which the problem originated70 const char *file, ///< the file in which the problem originated 71 psS32 lineno ///< the line number in which the problem originated 72 72 ); 73 73 … … 81 81 82 82 // Get the mean for a bunch of values 83 float stacCombineMean(psVector *values, // Values for which to take the mean84 psVector *errors,// Errors in the values85 psVector *masks// Masks for the values, 0 = don't use, 1 = use83 float stacCombineMean(psVector *values, // Values for which to take the mean 84 psVector *errors, // Errors in the values 85 psVector *masks // Masks for the values, 0 = don't use, 1 = use 86 86 ); 87 87 88 88 // Get the median for a bunch of values 89 89 float stacCombineMedian(psVector *values, // Values for which to take the median 90 psVector *errors, // Errors in the values91 psVector *masks// Masks for the values, 0 = don't use, 1 = use90 psVector *errors, // Errors in the values 91 psVector *masks // Masks for the values, 0 = don't use, 1 = use 92 92 ); 93 93 94 94 // Combine the transformed images 95 bool stacCombine(psImage **combined, // The combined image for output96 psArray **rejected,// Array of rejection masks97 psArray *images,// Array of transformed images98 psArray *errors,// Array of transformed error images99 int nReject,// Number of rejection iterations100 psImage *region,// Region to combine101 psVector *saturated,// Saturation limits for each image102 psVector *bad,// Bad pixel limits for each image103 float reject// Rejection (k-sigma)95 bool stacCombine(psImage **combined, // The combined image for output 96 psArray **rejected, // Array of rejection masks 97 psArray *images, // Array of transformed images 98 psArray *errors, // Array of transformed error images 99 int nReject, // Number of rejection iterations 100 psImage *region, // Region to combine 101 psVector *saturated, // Saturation limits for each image 102 psVector *bad, // Bad pixel limits for each image 103 float reject // Rejection (k-sigma) 104 104 ); 105 105 … … 110 110 // Invert an array of maps 111 111 psArray *stacInvertMaps(const psArray *maps, // Array of maps to invert 112 int outnx, int outny // Size of output image112 int outnx, int outny // Size of output image 113 113 ); 114 114 … … 118 118 119 119 // Return the relative gradient for a given pixel 120 float stacGradient(psImage *image, // Input for which to measure the gradient121 int x, int y// Coordinates at which to measure the gradient120 float stacGradient(psImage *image, // Input for which to measure the gradient 121 int x, int y // Coordinates at which to measure the gradient 122 122 ); 123 123 124 124 // Transform the rejection masks back to the source frame 125 psArray *stacRejection(psArray *inputs, // Input images126 psArray *rejected, // Rejected images127 psArray *regions, // Regions of interest128 psArray *maps,// Maps from input to transformed image129 psArray *inverseMaps, // Maps from transformed to input image130 float frac,// Fraction of pixel rejected before looking more carefully131 float grad,// Gradient limit for rejection132 psArray *names// Names of original images (only for writing out when TESTING)125 psArray *stacRejection(psArray *inputs, // Input images 126 psArray *rejected, // Rejected images 127 psArray *regions, // Regions of interest 128 psArray *maps, // Maps from input to transformed image 129 psArray *inverseMaps, // Maps from transformed to input image 130 float frac, // Fraction of pixel rejected before looking more carefully 131 float grad, // Gradient limit for rejection 132 psArray *names // Names of original images (only for writing out when TESTING) 133 133 ); 134 134 … … 139 139 // Returns the change in x' and y' for a change in x and y of 1 140 140 bool stacPlaneTransformDeriv(psPlane *out, // Output derivative, assumed already allocated 141 psPlaneTransform *transform, // The transform for which to obtain the derivative142 psPlane *in // The position at which to obtain the derivative141 psPlaneTransform *transform, // The transform for which to obtain the derivative 142 psPlane *in // The position at which to obtain the derivative 143 143 ); 144 144 … … 146 146 // Basically, uses derivatives of the transformation to work out what pixels in the source might be of interest 147 147 psImage *stacAreaOfInterest(psImage *mask, // Mask that is to be used to determine the area of interest 148 psPlaneTransform *map, // Map from the mask to the area of interest149 int nxOut, int nyOut // Size of the area of interest148 psPlaneTransform *map, // Map from the mask to the area of interest 149 int nxOut, int nyOut // Size of the area of interest 150 150 ); 151 151 … … 155 155 156 156 // Calculate the size of the output image 157 bool stacSize(int *outnx, int *outny, // Size of output image (returned) 158 float *xMapDiff, float *yMapDiff, // Difference applied to maps 159 const psArray *images, // Input images 160 psArray *maps // Transformation maps 157 bool stacSize(int *outnx, int *outny, // Size of output image (returned) 158 float *xMapDiff, float *yMapDiff, // Difference applied to maps 159 const psVector *xSizes, // Sizes of images in x 160 const psVector *ySizes, // Sizes of images in y 161 psArray *maps // Transformation maps 161 162 ); 162 163 … … 167 168 // Calculate the background in an image 168 169 float stacBackground(const psImage *image, // Image for which to get the background 169 int sample// Sample in increments of this value170 int sample // Sample in increments of this value 170 171 ); 171 172 172 173 173 174 // Calculate the relative scales and offsets between the images 174 bool stacScales(psVector **scalesPtr, // Scales to return175 psVector **offsetsPtr,// Offsets to return176 const psArray *images,// Images on which to measure the scales and offsets177 const char *starFile,// File containing coordinates to photometer178 const char *starMapFile, // Map for coodinates to the common output frame179 float xMapDiff, float yMapDiff, // Difference from the map to apply (due to size difference)180 float aper// Aperture to use for photometry (radius)175 bool stacScales(psVector **scalesPtr, // Scales to return 176 psVector **offsetsPtr, // Offsets to return 177 const psArray *images, // Images on which to measure the scales and offsets 178 const char *starFile, // File containing coordinates to photometer 179 const char *starMapFile, // Map for coodinates to the common output frame 180 float xMapDiff, float yMapDiff, // Difference from the map to apply (due to size difference) 181 float aper // Aperture to use for photometry (radius) 181 182 ); 182 183 183 184 // Rescale images 184 bool stacRescale(psArray *images, // Images to rescale185 psArray *errImages,// Variance images to rescale186 const psImage *mask,// Mask indicating which pixels to scale187 const psVector *scales,// Scales for images188 const psVector *offsets // Offsets for images185 bool stacRescale(psArray *images, // Images to rescale 186 psArray *errImages, // Variance images to rescale 187 const psImage *mask, // Mask indicating which pixels to scale 188 const psVector *scales,// Scales for images 189 const psVector *offsets // Offsets for images 189 190 ); 190 191 … … 196 197 197 198 // Write map out 198 bool stacWriteMap(const char *mapName, // Filename to write to199 psPlaneTransform *map// Map to write199 bool stacWriteMap(const char *mapName, // Filename to write to 200 psPlaneTransform *map // Map to write 200 201 ); 201 202 202 203 // Write multiple maps 203 204 bool stacWriteMaps(const psArray *names, // Filenames of the input images (will add ".map") 204 const psArray *maps// Maps to write205 const psArray *maps // Maps to write 205 206 ); 206 207 -
trunk/stac/src/stacCombine.c
r5745 r6887 103 103 psVector *deltas = psVectorAlloc(nImages, PS_TYPE_F32); // Will hold the errors in the statistics step 104 104 psVector *mask = psVectorAlloc(nImages, PS_TYPE_U8); // Will hold the mask in the statistics step 105 pixels->n = nImages; 106 deltas->n = nImages; 107 mask->n = nImages; 105 108 106 109 // Set up rejection masks … … 109 112 // Allocate the rejection masks, if required 110 113 *rejected = psArrayAlloc(nImages); 114 (*rejected)->n = nImages; 111 115 } else { 112 116 assert((*rejected)->n != nImages); … … 202 206 char chiName[MAXCHAR]; // Filename of chi^2 image 203 207 sprintf(chiName,"chi2_%d.fits",iteration); 204 psFits *chiFile = psFits Alloc(chiName);205 if (!psFitsWriteImage(chiFile, NULL, chi2 , 0 )) {208 psFits *chiFile = psFitsOpen(chiName, "w"); 209 if (!psFitsWriteImage(chiFile, NULL, chi2 , 0, NULL)) { 206 210 psErrorStackPrint(stderr, "Unable to write image: %s\n", chiName); 207 211 } 208 212 psTrace("stac.combine", 1, "Chi^2 image written to %s\n", chiName); 209 psF ree(chiFile);213 psFitsClose(chiFile); 210 214 psFree(chi2); 211 215 #endif -
trunk/stac/src/stacConfig.c
r5743 r6887 24 24 config->outnx = 0; 25 25 config->outny = 0; 26 config->saturated = 65535.0; // Saturation level27 config->bad = 0.0; // Bad level26 config->saturated = 65535.0; // Saturation level 27 config->bad = 0.0; // Bad level 28 28 config->reject = 2.5; 29 29 config->frac = 0.45; … … 39 39 // Free the vectors, if necessary 40 40 if (config->inputs) { 41 psFree(config->inputs);41 psFree(config->inputs); 42 42 } 43 43 // Free everything … … 46 46 47 47 48 stacConfig *stacParseConfig(int argc, // Number of command-line arguments49 char **argv // Command-line arguments48 stacConfig *stacParseConfig(int argc, // Number of command-line arguments 49 char **argv // Command-line arguments 50 50 ) 51 51 { 52 52 stacConfig *config = stacConfigAlloc(); // Configuration values 53 const char *programName = argv[0]; // Program name53 const char *programName = argv[0]; // Program name 54 54 55 55 /* Variables for getopt */ … … 61 61 while ((opt = getopt(argc, argv, "hvSg:r:o:s:b:k:n:f:G:p:a:")) != -1) { 62 62 switch (opt) { 63 case 'h':64 help(programName);65 exit(EXIT_SUCCESS);66 case 'v':63 case 'h': 64 help(programName); 65 exit(EXIT_SUCCESS); 66 case 'v': 67 67 config->verbose++; 68 68 break; 69 case 'g':70 if (sscanf(optarg, "%f", &config->gain) != 1) {71 help(programName);72 exit(EXIT_FAILURE);73 }74 break;75 case 'r':76 if (sscanf(optarg, "%f", &config->readnoise) != 1) {77 help(programName);78 exit(EXIT_FAILURE);79 }80 break;81 case 'o':69 case 'g': 70 if (sscanf(optarg, "%f", &config->gain) != 1) { 71 help(programName); 72 exit(EXIT_FAILURE); 73 } 74 break; 75 case 'r': 76 if (sscanf(optarg, "%f", &config->readnoise) != 1) { 77 help(programName); 78 exit(EXIT_FAILURE); 79 } 80 break; 81 case 'o': 82 82 if ((sscanf(argv[optind-1], "%d", &config->outnx) != 1) || 83 83 (sscanf(argv[optind++], "%d", &config->outny) != 1)) { … … 86 86 exit(EXIT_FAILURE); 87 87 } 88 break;89 case 's':90 if (sscanf(optarg, "%f", &config->saturated) != 1) {91 help(programName);92 exit(EXIT_FAILURE);93 }94 break;95 case 'b':96 if (sscanf(optarg, "%f", &config->bad) != 1) {97 help(programName);98 exit(EXIT_FAILURE);99 }100 break;101 case 'p':102 if (argc < optind+1) {103 help(programName);104 exit(EXIT_FAILURE);105 }106 config->starFile = argv[optind-1];107 config->starMapFile = argv[optind++];108 // Note: incrementing optind, so I can read more than one parameter.109 break;110 case 'a':111 if (sscanf(optarg, "%f", &config->aper) != 1) {112 help(programName);113 exit(EXIT_FAILURE);114 }115 break;116 case 'k':117 if (sscanf(optarg, "%f", &config->reject) != 1) {118 help(programName);119 exit(EXIT_FAILURE);120 }121 break;122 case 'n':123 if (sscanf(optarg, "%d", &config->nReject) != 1) {124 help(programName);125 exit(EXIT_FAILURE);126 }127 break;128 case 'f':129 if (sscanf(optarg, "%f", &config->frac) != 1) {130 help(programName);131 exit(EXIT_FAILURE);132 }133 break;134 case 'G':135 if (sscanf(optarg, "%f", &config->grad) != 1) {136 help(programName);137 exit(EXIT_FAILURE);138 }139 break;140 case 'S':141 config->saveShifts = true;142 break;143 default:144 help(programName);145 }88 break; 89 case 's': 90 if (sscanf(optarg, "%f", &config->saturated) != 1) { 91 help(programName); 92 exit(EXIT_FAILURE); 93 } 94 break; 95 case 'b': 96 if (sscanf(optarg, "%f", &config->bad) != 1) { 97 help(programName); 98 exit(EXIT_FAILURE); 99 } 100 break; 101 case 'p': 102 if (argc < optind+1) { 103 help(programName); 104 exit(EXIT_FAILURE); 105 } 106 config->starFile = argv[optind-1]; 107 config->starMapFile = argv[optind++]; 108 // Note: incrementing optind, so I can read more than one parameter. 109 break; 110 case 'a': 111 if (sscanf(optarg, "%f", &config->aper) != 1) { 112 help(programName); 113 exit(EXIT_FAILURE); 114 } 115 break; 116 case 'k': 117 if (sscanf(optarg, "%f", &config->reject) != 1) { 118 help(programName); 119 exit(EXIT_FAILURE); 120 } 121 break; 122 case 'n': 123 if (sscanf(optarg, "%d", &config->nReject) != 1) { 124 help(programName); 125 exit(EXIT_FAILURE); 126 } 127 break; 128 case 'f': 129 if (sscanf(optarg, "%f", &config->frac) != 1) { 130 help(programName); 131 exit(EXIT_FAILURE); 132 } 133 break; 134 case 'G': 135 if (sscanf(optarg, "%f", &config->grad) != 1) { 136 help(programName); 137 exit(EXIT_FAILURE); 138 } 139 break; 140 case 'S': 141 config->saveShifts = true; 142 break; 143 default: 144 help(programName); 145 } 146 146 } 147 147 … … 154 154 } 155 155 156 config->output = argv[0]; // Output file156 config->output = argv[0]; // Output file 157 157 // Get the input files 158 config->inputs = psArrayAlloc(argc-1); 158 config->inputs = psArrayAlloc(argc - 1); 159 config->inputs->n = argc - 1; 159 160 for (int i = 1; i < argc; i++) { 160 config->inputs->data[i-1] = psAlloc(strlen(argv[i]));161 strncpy(config->inputs->data[i-1], argv[i], strlen(argv[i]));161 config->inputs->data[i-1] = psAlloc(strlen(argv[i])); 162 strncpy(config->inputs->data[i-1], argv[i], strlen(argv[i])); 162 163 } 163 164 … … 167 168 psTrace("stac.config", 9, "%d inputs:\n",config->inputs->n); 168 169 for (int i = 0; i < config->inputs->n; i++) { 169 psTrace("stac.config", 9, "\t%s\n", config->inputs->data[i]);170 psTrace("stac.config", 9, "\t%s\n", config->inputs->data[i]); 170 171 } 171 172 psTrace("stac.config", 9, "Output file is %s\n",config->output); -
trunk/stac/src/stacErrorImages.c
r3666 r6887 4 4 5 5 psArray *stacErrorImages(psArray *inputs, // Array of input images 6 float gain,// Gain, in e/ADU7 float rn// Read noise, in e6 float gain, // Gain, in e/ADU 7 float rn // Read noise, in e 8 8 ) 9 9 { 10 float invGain = 1.0/gain; // Inverse square root of gain11 rn /= gain; // Read noise in ADU10 float invGain = 1.0/gain; // Inverse square root of gain 11 rn /= gain; // Read noise in ADU 12 12 psArray *errors = psArrayAlloc(inputs->n); 13 errors->n = inputs->n; 13 14 14 15 psTrace("stac.errors", 1, "Calculating error images....\n"); … … 16 17 // Iterate over the input images 17 18 for (int i = 0; i < inputs->n; i++) { 18 psTrace("stac.errors",5,"Working on image #%d\n",i);19 psTrace("stac.errors",5,"Working on image #%d\n",i); 19 20 20 psImage *image = inputs->data[i]; // Pull out the image of interest21 int numRows = image->numRows;// Number of rows22 int numCols = image->numCols; // Number of columns 23 psImage *error = psImageAlloc(numCols, numRows, PS_TYPE_F32); // The error image21 psImage *image = inputs->data[i]; // Pull out the image of interest 22 int numRows = image->numRows; // Number of rows 23 int numCols = image->numCols; // Number of columns 24 psImage *error = psImageAlloc(numCols, numRows, PS_TYPE_F32); // The error image 24 25 25 // Iterate over the pixels26 for (int r = 0; r < numRows; r++) {27 for (int c = 0; c < numCols; c++) {28 // We actually calculate the variance29 error->data.F32[r][c] = image->data.F32[r][c]*invGain + rn*rn;30 }31 }26 // Iterate over the pixels 27 for (int r = 0; r < numRows; r++) { 28 for (int c = 0; c < numCols; c++) { 29 // We actually calculate the variance 30 error->data.F32[r][c] = image->data.F32[r][c]*invGain + rn*rn; 31 } 32 } 32 33 33 // Put image onto the array34 errors->data[i] = error;34 // Put image onto the array 35 errors->data[i] = error; 35 36 } 36 37 -
trunk/stac/src/stacInvertMaps.c
r6450 r6887 14 14 int nMaps = maps->n; // Number of maps 15 15 psArray *inverted = psArrayAlloc(nMaps); // Array of inverted maps for output 16 inverted->n = nMaps; 16 17 17 18 psTrace("stac.invertMaps", 1, "Inverting maps....\n"); … … 45 46 psVector *xOut = psVectorAlloc(NUM_GRID * NUM_GRID, PS_TYPE_F32); 46 47 psVector *yOut = psVectorAlloc(NUM_GRID * NUM_GRID, PS_TYPE_F32); 48 xIn->n = NUM_GRID * NUM_GRID; 49 yIn->n = NUM_GRID * NUM_GRID; 50 xOut->n = NUM_GRID * NUM_GRID; 51 yOut->n = NUM_GRID * NUM_GRID; 47 52 48 53 // Create grid of points … … 66 71 psVector *xVector = psVectorAlloc(nCoeff, PS_TYPE_F64); // Vector for solution in x 67 72 psVector *yVector = psVectorAlloc(nCoeff, PS_TYPE_F64); // Vector for solution in y 73 xVector->n = nCoeff; 74 yVector->n = nCoeff; 68 75 for (int i = 0; i < nCoeff; i++) { 69 76 for (int j = 0; j < nCoeff; j++) { … … 104 111 // Solution via LU Decomposition 105 112 psVector *permutation = psVectorAlloc(nCoeff, PS_TYPE_F64); // Permutation vector for LU Decomposition 113 permutation->n = nCoeff; 106 114 psImage *luMatrix = psMatrixLUD(NULL, &permutation, matrix); // LU decomposed matrix 107 115 psVector *xSolution = psMatrixLUSolve(NULL, luMatrix, xVector, permutation); // Solution in x -
trunk/stac/src/stacRead.c
r6771 r6887 13 13 int nFiles = filenames->n; // The number of input files 14 14 psArray *images = psArrayAlloc(nFiles); // The input files, to be returned 15 images->n = nFiles; 15 16 assert(!headers || ! *headers || (*headers)->n == nFiles); 16 17 if (headers && ! *headers) { 17 18 *headers = psArrayAlloc(nFiles); 19 (*headers)->n = nFiles; 18 20 } 19 21 … … 71 73 psArray *coords = psArrayAlloc(BUFFER); // The array of coordinates to be returned 72 74 float x, y; // Coordinates to read 73 int num = 0; // Number of coordinates read74 75 while (fscanf(file, "%f %f\n", &x, &y) == 2) { 75 76 psPlane *coord = psPlaneAlloc();// A coordinate 76 77 coord->x = x; 77 78 coord->y = y; 78 coords->data[num] = coord; 79 num++; 80 if (num % BUFFER) { 81 coords = psArrayRealloc(coords, num + BUFFER); 82 } 83 } 84 coords->n = num; 79 coords->data[coords->n] = coord; 80 coords->n++; 81 if (coords->n % BUFFER == 0) { 82 coords = psArrayRealloc(coords, coords->n + BUFFER); 83 } 84 } 85 85 86 86 psTrace("stac.read.coords", 5, "%d coordinates read.\n", num); … … 184 184 int nFiles = filenames->n; // The number of input files 185 185 psArray *maps = psArrayAlloc(nFiles); // The maps, to be returned 186 maps->n = nFiles; 186 187 char mapfile[MAXCHAR]; // Filename of map 187 188 -
trunk/stac/src/stacRejection.c
r5743 r6887 8 8 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 9 9 10 float stacGradient(psImage *image, // Input for which to measure the gradient11 int x, int y// Coordinates at which to measure the gradient10 float stacGradient(psImage *image, // Input for which to measure the gradient 11 int x, int y // Coordinates at which to measure the gradient 12 12 ) 13 13 { … … 22 22 int yMax = MIN(y + 1, image->numRows - 1); 23 23 for (int j = yMin; j <= yMax; j++) { 24 for (int i = xMin; i <= xMax; i++) {25 if ((i != x) && (j != y)) {26 pixels->data.F32[num] = image->data.F32[j][i];27 mask->data.U8[num] = 0;28 num++;29 }30 }24 for (int i = xMin; i <= xMax; i++) { 25 if ((i != x) && (j != y)) { 26 pixels->data.F32[num] = image->data.F32[j][i]; 27 mask->data.U8[num] = 0; 28 num++; 29 } 30 } 31 31 } 32 32 pixels->n = num; … … 43 43 } 44 44 45 psArray *stacRejection(psArray *inputs, // Input images46 psArray *rejected, // Rejected images47 psArray *regions, // Regions of interest48 psArray *maps,// Maps from input to transformed image49 psArray *inverseMaps, // Maps from transformed to input image50 float frac,// Fraction of pixel rejected before looking more carefully51 float grad,// Gradient limit for rejection52 psArray *names// Names of original images (only for writing out when TESTING)45 psArray *stacRejection(psArray *inputs, // Input images 46 psArray *rejected, // Rejected images 47 psArray *regions, // Regions of interest 48 psArray *maps, // Maps from input to transformed image 49 psArray *inverseMaps, // Maps from transformed to input image 50 float frac, // Fraction of pixel rejected before looking more carefully 51 float grad, // Gradient limit for rejection 52 psArray *names // Names of original images (only for writing out when TESTING) 53 53 ) 54 54 { 55 int nImages = inputs->n; // Number of input images55 int nImages = inputs->n; // Number of input images 56 56 57 57 // Check inputs … … 63 63 64 64 for (int i = 0; i < nImages; i++) { 65 psImage *input = inputs->data[i];66 psImage *region = regions->data[i];67 assert(input->numRows == region->numRows && input->numCols == region->numCols);65 psImage *input = inputs->data[i]; 66 psImage *region = regions->data[i]; 67 assert(input->numRows == region->numRows && input->numCols == region->numCols); 68 68 } 69 69 … … 77 77 psVector *grads = psVectorAlloc(nImages, PS_TYPE_F32); // Gradient for each image 78 78 psVector *gradsMask = psVectorAlloc(nImages, PS_TYPE_U8); // Mask for gradient vector 79 grads->n = nImages; 80 gradsMask->n = nImages; 79 81 80 82 // Transform rejection masks back to source 81 83 psArray *inputRej = psArrayAlloc(nImages); 84 inputRej->n = nImages; 82 85 for (int i = 0; i < nImages; i++) { 83 // Size of input image84 int nxInput = ((psImage*)(inputs->data[i]))->numCols;85 int nyInput = ((psImage*)(inputs->data[i]))->numRows;86 psImage *mask = psImageAlloc(nxInput, nyInput, PS_TYPE_U8); // The pixel mask for the input87 #ifdef TESTING 88 psImage *rejmap = psImageAlloc(nxInput, nyInput, PS_TYPE_F32); // The rejections in the source frame89 psImage *gradient = psImageAlloc(nxInput, nyInput, PS_TYPE_F32);// The gradient image90 #endif 91 psImage *reject = rejected->data[i]; // Pull out the mask in the output frame92 psPlaneTransform *map = maps->data[i]; // The map from input to output93 psImage *region = regions->data[i]; // The region of interest for this image94 95 psTrace("stac.rejection", 3, "Transforming rejection mask %d....\n", i);96 int nBad = 0;// Number of bad pixels86 // Size of input image 87 int nxInput = ((psImage*)(inputs->data[i]))->numCols; 88 int nyInput = ((psImage*)(inputs->data[i]))->numRows; 89 psImage *mask = psImageAlloc(nxInput, nyInput, PS_TYPE_U8); // The pixel mask for the input 90 #ifdef TESTING 91 psImage *rejmap = psImageAlloc(nxInput, nyInput, PS_TYPE_F32); // The rejections in the source frame 92 psImage *gradient = psImageAlloc(nxInput, nyInput, PS_TYPE_F32); // The gradient image 93 #endif 94 psImage *reject = rejected->data[i]; // Pull out the mask in the output frame 95 psPlaneTransform *map = maps->data[i]; // The map from input to output 96 psImage *region = regions->data[i]; // The region of interest for this image 97 98 psTrace("stac.rejection", 3, "Transforming rejection mask %d....\n", i); 99 int nBad = 0; // Number of bad pixels 97 100 98 101 #ifdef CRFLUX 99 // Set up CR output100 FILE *crs = NULL;// File for outputting details of rejected pixels101 char crfile[MAXCHAR];// Filename102 sprintf(crfile,"%s.cr",names->data[i]);103 if ((crs = fopen(crfile, "w")) == NULL) {104 fprintf(stderr, "Unable to open file for detailed output, %s\n");105 return NULL;106 }107 #endif 108 109 // Transform the mask110 // Optimisation option is to only transform the pixels that have been rejected in the output,111 // calculate derivatives of the map, and use that as a buffer around the transformed position112 // in the input image.113 psStats *median = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);114 for (int y = 0; y < nyInput; y++) {115 for (int x = 0; x < nxInput; x++) {116 117 // Only transform pixels of interest118 if (region->data.U8[y][x]) {119 120 inCoords->x = (double)x + 0.5;121 inCoords->y = (double)y + 0.5;122 (void)psPlaneTransformApply(outCoords, map, inCoords);123 float maskVal = (float)psImagePixelInterpolate(reject, outCoords->x, outCoords->y,124 NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR);125 #ifdef TESTING 126 rejmap->data.F32[y][x] = maskVal;127 #endif 128 129 if (maskVal > frac) {130 // Calculate mean gradient on other images131 float meanGrads = 0.0;132 int numGrads = 0;133 for (int j = 0; j < nImages; j++) {134 if (i != j) {135 // Get coordinates for that image136 (void)psPlaneTransformApply(inCoords, inverseMaps->data[j], outCoords);137 int xPix = (int)(inCoords->x + 0.5);138 int yPix = (int)(inCoords->y + 0.5);139 if ((xPix >= 0) && (xPix <= ((psImage*)(inputs->data[j]))->numCols - 1) &&140 (yPix >= 0) && (yPix <= ((psImage*)(inputs->data[j]))->numRows - 1)) {141 // Calculate the gradient142 grads->data.F32[j] = stacGradient(inputs->data[j], xPix, yPix);143 gradsMask->data.U8[j] = 0;144 numGrads++;145 } else {146 gradsMask->data.U8[j] = 1; // Mask this one147 }148 } else {149 gradsMask->data.U8[j] = 1; // Mask this one150 }151 }152 if (numGrads > 0) {153 (void)psVectorStats(median, grads, NULL, gradsMask, (psU8)1);154 meanGrads = median->sampleMedian;155 } else {156 meanGrads = 0.0;157 }158 159 #ifdef TESTING 160 //gradient->data.F32[y][x] = stacGradient(inputs->data[i], x, y) / meanGrads;161 gradient->data.F32[y][x] = meanGrads;162 #endif 163 164 //if (stacGradient(inputs->data[i], x, y) < grad * meanGrads) {165 if (meanGrads > grad) {166 mask->data.U8[y][x] = 1;167 nBad++;102 // Set up CR output 103 FILE *crs = NULL; // File for outputting details of rejected pixels 104 char crfile[MAXCHAR]; // Filename 105 sprintf(crfile,"%s.cr",names->data[i]); 106 if ((crs = fopen(crfile, "w")) == NULL) { 107 fprintf(stderr, "Unable to open file for detailed output, %s\n"); 108 return NULL; 109 } 110 #endif 111 112 // Transform the mask 113 // Optimisation option is to only transform the pixels that have been rejected in the output, 114 // calculate derivatives of the map, and use that as a buffer around the transformed position 115 // in the input image. 116 psStats *median = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 117 for (int y = 0; y < nyInput; y++) { 118 for (int x = 0; x < nxInput; x++) { 119 120 // Only transform pixels of interest 121 if (region->data.U8[y][x]) { 122 123 inCoords->x = (double)x + 0.5; 124 inCoords->y = (double)y + 0.5; 125 (void)psPlaneTransformApply(outCoords, map, inCoords); 126 float maskVal = (float)psImagePixelInterpolate(reject, outCoords->x, outCoords->y, 127 NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR); 128 #ifdef TESTING 129 rejmap->data.F32[y][x] = maskVal; 130 #endif 131 132 if (maskVal > frac) { 133 // Calculate mean gradient on other images 134 float meanGrads = 0.0; 135 int numGrads = 0; 136 for (int j = 0; j < nImages; j++) { 137 if (i != j) { 138 // Get coordinates for that image 139 (void)psPlaneTransformApply(inCoords, inverseMaps->data[j], outCoords); 140 int xPix = (int)(inCoords->x + 0.5); 141 int yPix = (int)(inCoords->y + 0.5); 142 if ((xPix >= 0) && (xPix <= ((psImage*)(inputs->data[j]))->numCols - 1) && 143 (yPix >= 0) && (yPix <= ((psImage*)(inputs->data[j]))->numRows - 1)) { 144 // Calculate the gradient 145 grads->data.F32[j] = stacGradient(inputs->data[j], xPix, yPix); 146 gradsMask->data.U8[j] = 0; 147 numGrads++; 148 } else { 149 gradsMask->data.U8[j] = 1; // Mask this one 150 } 151 } else { 152 gradsMask->data.U8[j] = 1; // Mask this one 153 } 154 } 155 if (numGrads > 0) { 156 (void)psVectorStats(median, grads, NULL, gradsMask, (psU8)1); 157 meanGrads = median->sampleMedian; 158 } else { 159 meanGrads = 0.0; 160 } 161 162 #ifdef TESTING 163 //gradient->data.F32[y][x] = stacGradient(inputs->data[i], x, y) / meanGrads; 164 gradient->data.F32[y][x] = meanGrads; 165 #endif 166 167 //if (stacGradient(inputs->data[i], x, y) < grad * meanGrads) { 168 if (meanGrads > grad) { 169 mask->data.U8[y][x] = 1; 170 nBad++; 168 171 169 172 #ifdef CRFLUX 170 fprintf(crs, "%d %d --> %f %f %f\n", x, y,171 ((psImage*)(inputs->data[i]))->data.F32[y][x], maskVal,172 stacGradient(inputs->data[i], x, y));173 #endif 174 175 } else {176 mask->data.U8[y][x] = 0;177 } // Gradient threshold178 } else {179 mask->data.U8[y][x] = 0;180 } // Rejection threshold181 182 } else {183 mask->data.U8[y][x] = 0;184 } // Only touching pixels of interest185 186 }187 } // Iterating over pixels188 psFree(median);173 fprintf(crs, "%d %d --> %f %f %f\n", x, y, 174 ((psImage*)(inputs->data[i]))->data.F32[y][x], maskVal, 175 stacGradient(inputs->data[i], x, y)); 176 #endif 177 178 } else { 179 mask->data.U8[y][x] = 0; 180 } // Gradient threshold 181 } else { 182 mask->data.U8[y][x] = 0; 183 } // Rejection threshold 184 185 } else { 186 mask->data.U8[y][x] = 0; 187 } // Only touching pixels of interest 188 189 } 190 } // Iterating over pixels 191 psFree(median); 189 192 190 193 #ifdef CRFLUX 191 // Close file used for detailed output192 fclose(crs);193 #endif 194 195 psTrace("stac.rejection", 1, "%d pixels masked in image %d\n", nBad, i);196 // Clip the image, and convert to suitable mask format197 198 #ifdef TESTING 199 // Write error image out to check200 char maskName[MAXCHAR];// Filename of mask image201 char rejmapName[MAXCHAR];// Filename of rejection image202 char gradName[MAXCHAR];// Filename of gradient image203 sprintf(maskName, "%s.mask",names->data[i]);204 sprintf(rejmapName, "%s.rejmap",names->data[i]);205 sprintf(gradName, "%s.grad",names->data[i]);206 207 psFits *maskFile = psFitsAlloc(maskName);208 psFits *rejmapFile = psFitsAlloc(rejmapName);209 psFits *gradFile = psFitsAlloc(gradName);210 if (!psFitsWriteImage(maskFile, NULL, mask, 0)) {211 psErrorStackPrint(stderr, "Unable to write image: %s\n", maskName);212 }213 psTrace("stac", 1, "Mask image written to %s\n", maskName);214 if (!psFitsWriteImage(rejmapFile, NULL, rejmap, 0)) {215 psErrorStackPrint(stderr, "Unable to write image: %s\n", rejmapName);216 }217 psTrace("stac", 1, "Rejection map written to %s\n", rejmapName);218 if (!psFitsWriteImage(gradFile, NULL, gradient, 0)) {219 psErrorStackPrint(stderr, "Unable to write image: %s\n", gradName);220 }221 psTrace("stac", 1, "Gradient image written to %s\n", gradName);222 psFree(maskFile);223 psFree(rejmapFile);224 psFree(gradFile);225 psFree(rejmap);226 psFree(gradient);227 #endif 228 229 // Stuff into the array230 inputRej->data[i] = mask;194 // Close file used for detailed output 195 fclose(crs); 196 #endif 197 198 psTrace("stac.rejection", 1, "%d pixels masked in image %d\n", nBad, i); 199 // Clip the image, and convert to suitable mask format 200 201 #ifdef TESTING 202 // Write error image out to check 203 char maskName[MAXCHAR]; // Filename of mask image 204 char rejmapName[MAXCHAR]; // Filename of rejection image 205 char gradName[MAXCHAR]; // Filename of gradient image 206 sprintf(maskName, "%s.mask", (char*)names->data[i]); 207 sprintf(rejmapName, "%s.rejmap", (char*)names->data[i]); 208 sprintf(gradName, "%s.grad", (char*)names->data[i]); 209 210 psFits *maskFile = psFitsOpen(maskName, "w"); 211 psFits *rejmapFile = psFitsOpen(rejmapName, "w"); 212 psFits *gradFile = psFitsOpen(gradName, "w"); 213 if (!psFitsWriteImage(maskFile, NULL, mask, 0, NULL)) { 214 psErrorStackPrint(stderr, "Unable to write image: %s\n", maskName); 215 } 216 psTrace("stac", 1, "Mask image written to %s\n", maskName); 217 if (!psFitsWriteImage(rejmapFile, NULL, rejmap, 0, NULL)) { 218 psErrorStackPrint(stderr, "Unable to write image: %s\n", rejmapName); 219 } 220 psTrace("stac", 1, "Rejection map written to %s\n", rejmapName); 221 if (!psFitsWriteImage(gradFile, NULL, gradient, 0, NULL)) { 222 psErrorStackPrint(stderr, "Unable to write image: %s\n", gradName); 223 } 224 psTrace("stac", 1, "Gradient image written to %s\n", gradName); 225 psFitsClose(maskFile); 226 psFitsClose(rejmapFile); 227 psFitsClose(gradFile); 228 psFree(rejmap); 229 psFree(gradient); 230 #endif 231 232 // Stuff into the array 233 inputRej->data[i] = mask; 231 234 232 235 } -
trunk/stac/src/stacScales.c
r5745 r6887 19 19 psVector *values = psVectorAlloc(numSamples + 1, PS_TYPE_F32); // Vector containing sub-sample 20 20 psVector *mask = psVectorAlloc(numSamples + 1, PS_TYPE_U8); // Mask for sample 21 values->n = numSamples + 1; 22 mask->n = numSamples + 1; 21 23 22 24 int offset = 0; // Offset from start of the row … … 84 86 } else { 85 87 scales = psVectorAlloc(images->n, PS_TYPE_F32); 88 scales->n = images->n; 86 89 *scalesPtr = scales; 87 90 } … … 93 96 } else { 94 97 offsets = psVectorAlloc(images->n, PS_TYPE_F32); 98 offsets->n = images->n; 95 99 *offsetsPtr = offsets; 96 100 } … … 122 126 // Transform the stellar positions to match the transformed reference frame 123 127 psArray *starCoordsTransformed = psArrayAlloc(starCoords->n); // Transformed positions 128 starCoordsTransformed->n = starCoords->n; 124 129 // Fix up difference between map and output frame 125 130 starMap->x->coeff[0][0] -= xMapDiff; … … 132 137 psArray *stars = psArrayAlloc(images->n); // Array of stellar photometry vectors 133 138 psArray *masks = psArrayAlloc(images->n); // Array of masks for stars 139 stars->n = images->n; 140 masks->n = images->n; 134 141 135 142 // Set scales relative to the first image … … 144 151 psVector *photometry = psVectorAlloc(starCoords->n, PS_TYPE_F32); // Photometry of the stars 145 152 psVector *mask = psVectorAlloc(starCoords->n, PS_TYPE_U8); // Mask for the photometry 153 photometry->n = starCoords->n; 154 mask->n = starCoords->n; 146 155 for (int j = 0; j < starCoordsTransformed->n; j++) { 147 156 psPlane *coords = starCoordsTransformed->data[j]; // The coordinates of the star -
trunk/stac/src/stacSize.c
r3683 r6887 4 4 #include "stac.h" 5 5 6 bool stacSize(int *outnx, int *outny, // Size of output image (returned) 7 float *xMapDiff, float *yMapDiff, // Difference applied to maps 8 const psArray *images, // Input images 9 psArray *maps // Transformation maps 6 bool stacSize(int *outnx, int *outny, // Size of output image (returned) 7 float *xMapDiff, float *yMapDiff, // Difference applied to maps 8 const psVector *xSizes, // Sizes of images in x 9 const psVector *ySizes, // Sizes of images in y 10 psArray *maps // Transformation maps 10 11 ) 11 12 { 12 int nImages = images->n; // Number of input images 13 int nImages = xSizes->n; // Number of input images 14 assert(ySizes->n == nImages); 15 assert(xSizes->type.type == PS_TYPE_S32); 16 assert(ySizes->type.type == PS_TYPE_S32); 13 17 assert(maps->n == nImages); 14 assert(outnx && outny); // Must be able to write to these18 assert(outnx && outny); // Must be able to write to these 15 19 16 20 psPlane *inCoord = psAlloc(sizeof(psPlane)); // Input coordinates … … 24 28 25 29 for (int i = 0; i < nImages; i++) { 26 psImage *image = images->data[i]; // The image 27 psPlaneTransform *map = maps->data[i]; // The map 30 int xSize = xSizes->data.S32[i];// Size of image in x 31 int ySize = ySizes->data.S32[i];// Size of image in y 32 psPlaneTransform *map = maps->data[i]; // The map 28 33 29 psTrace("stac.size", 4, "Image %d:\n", i);34 psTrace("stac.size", 4, "Image %d:\n", i); 30 35 31 // Lower left corner32 inCoord->x = 0.0;33 inCoord->y = 0.0;34 (void)psPlaneTransformApply(outCoord, map, inCoord);35 if (outCoord->x < xMin) {36 xMin = outCoord->x;37 } else if (outCoord->x > xMax) {38 xMax = outCoord->x;39 }40 if (outCoord->y < yMin) {41 yMin = outCoord->y;42 } else if (outCoord->y > yMax) {43 yMax = outCoord->y;44 }45 psTrace("stac.size", 4, "Lower left: %f %f\n", outCoord->x, outCoord->y);36 // Lower left corner 37 inCoord->x = 0.0; 38 inCoord->y = 0.0; 39 (void)psPlaneTransformApply(outCoord, map, inCoord); 40 if (outCoord->x < xMin) { 41 xMin = outCoord->x; 42 } else if (outCoord->x > xMax) { 43 xMax = outCoord->x; 44 } 45 if (outCoord->y < yMin) { 46 yMin = outCoord->y; 47 } else if (outCoord->y > yMax) { 48 yMax = outCoord->y; 49 } 50 psTrace("stac.size", 4, "Lower left: %f %f\n", outCoord->x, outCoord->y); 46 51 47 // Lower right corner48 inCoord->x = image->numCols;49 (void)psPlaneTransformApply(outCoord, map, inCoord);50 if (outCoord->x < xMin) {51 xMin = outCoord->x;52 } else if (outCoord->x > xMax) {53 xMax = outCoord->x;54 }55 if (outCoord->y < yMin) {56 yMin = outCoord->y;57 } else if (outCoord->y > yMax) {58 yMax = outCoord->y;59 }60 psTrace("stac.size", 4, "Lower right: %f %f\n", outCoord->x, outCoord->y);52 // Lower right corner 53 inCoord->x = xSize; 54 (void)psPlaneTransformApply(outCoord, map, inCoord); 55 if (outCoord->x < xMin) { 56 xMin = outCoord->x; 57 } else if (outCoord->x > xMax) { 58 xMax = outCoord->x; 59 } 60 if (outCoord->y < yMin) { 61 yMin = outCoord->y; 62 } else if (outCoord->y > yMax) { 63 yMax = outCoord->y; 64 } 65 psTrace("stac.size", 4, "Lower right: %f %f\n", outCoord->x, outCoord->y); 61 66 62 // Upper right corner63 inCoord->x = 0.0;64 inCoord->y = image->numRows;65 (void)psPlaneTransformApply(outCoord, map, inCoord);66 if (outCoord->x < xMin) {67 xMin = outCoord->x;68 } else if (outCoord->x > xMax) {69 xMax = outCoord->x;70 }71 if (outCoord->y < yMin) {72 yMin = outCoord->y;73 } else if (outCoord->y > yMax) {74 yMax = outCoord->y;75 }76 psTrace("stac.size", 4, "Upper right: %f %f\n", outCoord->x, outCoord->y);67 // Upper right corner 68 inCoord->x = 0.0; 69 inCoord->y = ySize; 70 (void)psPlaneTransformApply(outCoord, map, inCoord); 71 if (outCoord->x < xMin) { 72 xMin = outCoord->x; 73 } else if (outCoord->x > xMax) { 74 xMax = outCoord->x; 75 } 76 if (outCoord->y < yMin) { 77 yMin = outCoord->y; 78 } else if (outCoord->y > yMax) { 79 yMax = outCoord->y; 80 } 81 psTrace("stac.size", 4, "Upper right: %f %f\n", outCoord->x, outCoord->y); 77 82 78 // Upper left corner79 inCoord->x = image->numCols;80 (void)psPlaneTransformApply(outCoord, map, inCoord);81 if (outCoord->x < xMin) {82 xMin = outCoord->x;83 } else if (outCoord->x > xMax) {84 xMax = outCoord->x;85 }86 if (outCoord->y < yMin) {87 yMin = outCoord->y;88 } else if (outCoord->y > yMax) {89 yMax = outCoord->y;90 }91 psTrace("stac.size", 4, "Upper left: %f %f\n", outCoord->x, outCoord->y);83 // Upper left corner 84 inCoord->x = xSize; 85 (void)psPlaneTransformApply(outCoord, map, inCoord); 86 if (outCoord->x < xMin) { 87 xMin = outCoord->x; 88 } else if (outCoord->x > xMax) { 89 xMax = outCoord->x; 90 } 91 if (outCoord->y < yMin) { 92 yMin = outCoord->y; 93 } else if (outCoord->y > yMax) { 94 yMax = outCoord->y; 95 } 96 psTrace("stac.size", 4, "Upper left: %f %f\n", outCoord->x, outCoord->y); 92 97 } 93 98 94 99 // Tweak the maps to account for the offset 95 100 if (xMapDiff != NULL) { 96 *xMapDiff = floorf(xMin);101 *xMapDiff = floorf(xMin); 97 102 } 98 103 if (yMapDiff != NULL) { 99 *yMapDiff = floorf(yMin);104 *yMapDiff = floorf(yMin); 100 105 } 101 106 for (int i = 0; i < nImages; i++) { 102 psPlaneTransform *map = maps->data[i]; // The map of interest103 map->x->coeff[0][0] -= floorf(xMin);104 map->y->coeff[0][0] -= floorf(yMin);107 psPlaneTransform *map = maps->data[i]; // The map of interest 108 map->x->coeff[0][0] -= floorf(xMin); 109 map->y->coeff[0][0] -= floorf(yMin); 105 110 } 106 111 -
trunk/stac/src/stacTransform.c
r5745 r6887 127 127 if (*outputs == NULL) { 128 128 *outputs = psArrayAlloc(nImages); 129 (*outputs)->n = nImages; 129 130 psTrace("stac.transform", 5, "Allocating space for transformed images, %dx%d\n", outnx, outny); 130 131 for (int i = 0; i < nImages; i++) { … … 138 139 if (errors && (*outErrors == NULL)) { 139 140 *outErrors = psArrayAlloc(errors->n); 141 (*outErrors)->n = errors->n; 140 142 psTrace("stac.transform", 5, "Allocating space for transformed error images, %dx%d\n", outnx, outny); 141 143 for (int i = 0; i < nImages; i++) { -
trunk/stac/src/sum.c
r6771 r6887 10 10 const char *outputName = argv[1]; // Output file name 11 11 psArray *inputNames = psArrayAlloc(argc-2); 12 inputNames->n = argc - 2; 12 13 for (int i = 2; i < argc; i++) { 13 14 inputNames->data[i-2] = psStringCopy(argv[i]);
Note:
See TracChangeset
for help on using the changeset viewer.
