Changeset 23357
- Timestamp:
- Mar 17, 2009, 1:36:01 PM (17 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 3 edited
-
ppStackCamera.c (modified) (2 diffs)
-
ppStackFiles.c (modified) (1 diff)
-
ppStackMatch.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackCamera.c
r21366 r23357 11 11 #include "ppStack.h" 12 12 13 14 #if 0 15 // Define an output convolved image file 16 static pmFPAfile *defineOutputConvolved(const char *name, // FPA file name 17 pmFPA *fpa, // FPA to bind 18 const pmConfig *config, // Configuration 19 pmFPAfileType type // Expected type 20 ) 13 // Define a file 14 static pmFPAfile *defineFile(pmConfig *config, // Configuration 15 pmFPAfile *bind, // File to which to bind 16 const char *name, // Name of file rule 17 const char *filename, // Name of file 18 pmFPAfileType type // Type of file 19 ) 21 20 { 22 pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, name); 23 if (!file) { 24 psError(PS_ERR_UNKNOWN, false, "Unable to define output convolved file %s", name); 21 22 psArray *dummy = psArrayAlloc(1); // Dummy array of filenames for this FPA 23 dummy->data[0] = psStringCopy(filename); 24 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "FILENAMES", PS_META_REPLACE, 25 "Filenames for file rule definition", dummy); 26 psFree(dummy); 27 28 bool found = false; // Found the file? 29 pmFPAfile *file = pmFPAfileDefineFromArgs(&found, config, name, "FILENAMES"); 30 if (!file || !found) { 31 psError(PS_ERR_UNKNOWN, false, "Unable to define file %s from %s", name, filename); 25 32 return NULL; 26 33 } 27 if (file->type != PM_FPA_FILE_IMAGE) {28 psError(PS_ERR_IO, true, " PPSTACK.OUTCONV is not of type %s", pmFPAfileStringFromType(type));34 if (file->type != type) { 35 psError(PS_ERR_IO, true, "%s is not of type %s", name, pmFPAfileStringFromType(type)); 29 36 return NULL; 30 37 } … … 33 40 } 34 41 35 // Define an input convolved image file, using the output as a basis36 static pmFPAfile *defineInputConvolved(const char *inputName, // Input FPA file name37 pmFPAfile *outFile, // Corresponding output FPA file38 pmConfig *config, // Configuration39 pmFPAfileType type // Expected type40 )41 {42 pmFPAview *view = pmFPAviewAlloc(0); // View into sky cells43 view->chip = view->cell = view->readout = 0;44 45 psString imageName = pmFPANameFromRule(outFile->filerule, outFile->fpa, view);46 psArray *imageNames = psArrayAlloc(1);47 imageNames->data[0] = imageName;48 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "INCONV.FILENAMES", PS_META_REPLACE,49 "Filenames of input convolved image files", imageNames);50 psFree(imageNames);51 bool found = false; // Found the file?52 pmFPAfile *imageFile = pmFPAfileDefineFromArgs(&found, config, "PPSTACK.INCONV",53 "INCONV.FILENAMES");54 psMetadataRemoveKey(config->arguments, "INCONV.FILENAMES");55 if (!imageFile || !found) {56 psError(PS_ERR_UNKNOWN, false, "Unable to define %s file", inputName);57 return NULL;58 }59 if (imageFile->type != type) {60 psError(PS_ERR_IO, true, "PPSTACK.INCONV is not of type %s",61 pmFPAfileStringFromType(type));62 return NULL;63 }64 65 return imageFile;66 }67 #endif68 69 42 70 43 71 44 bool ppStackCamera(pmConfig *config) 72 45 { 73 bool haveVariances = false; // Do we have variance maps? 46 int num = 0; // Number of inputs 47 bool haveVariances = false; // Do we have variance maps? 74 48 bool havePSFs = false; // Do we have PSFs? 75 49 76 psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info 77 psMetadataIterator *iter = psMetadataIteratorAlloc(inputs, PS_LIST_HEAD, NULL); // Iterator 78 psMetadataItem *item; // Item from iteration 79 int i = 0; // Counter 80 while ((item = psMetadataGetAndIncrement(iter))) { 81 if (item->type != PS_DATA_METADATA) { 82 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 83 "Component %s of the input metadata is not of type METADATA", item->name); 84 psFree(iter); 85 return false; 86 } 87 88 psMetadata *input = item->data.md; // The input metadata of interest 89 90 psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image 91 if (!image || strlen(image) == 0) { 92 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name); 93 psFree(iter); 94 return false; 95 } 96 97 bool mdok; 98 psString mask = psMetadataLookupStr(&mdok, input, "MASK"); // Name of mask 99 psString variance = psMetadataLookupStr(&mdok, input, "VARIANCE"); // Name of variance map 100 psString psf = psMetadataLookupStr(&mdok, input, "PSF"); // Name of PSF 101 psString sources = psMetadataLookupStr(&mdok, input, "SOURCES"); // Name of sources 102 103 // Add the image file 104 psArray *imageFiles = psArrayAlloc(1); // Array of filenames for this FPA 105 imageFiles->data[0] = psMemIncrRefCounter(image); 106 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "IMAGE.FILENAMES", PS_META_REPLACE, 107 "Filenames of image files", imageFiles); 108 psFree(imageFiles); 109 110 bool found = false; // Found the file? 111 pmFPAfile *imageFile = pmFPAfileDefineFromArgs(&found, config, "PPSTACK.INPUT", "IMAGE.FILENAMES"); 112 if (!imageFile || !found) { 113 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image); 114 return false; 115 } 116 if (imageFile->type != PM_FPA_FILE_IMAGE) { 117 psError(PS_ERR_IO, true, "PPSTACK.INPUT is not of type IMAGE"); 118 return false; 119 } 120 121 // Optionally add the mask file 122 if (mask && strlen(mask) > 0) { 123 psArray *maskFiles = psArrayAlloc(1); // Array of filenames for this FPA 124 maskFiles->data[0] = psMemIncrRefCounter(mask); 125 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "MASK.FILENAMES", PS_META_REPLACE, 126 "Filenames of mask files", maskFiles); 127 psFree(maskFiles); 128 129 bool status; 130 pmFPAfile *maskFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.MASK", 131 "MASK.FILENAMES"); 132 if (!status) { 50 bool status = false; // Status of file definition 51 52 psArray *runImages = pmFPAfileDefineMultipleFromRun(&status, NULL, config, 53 "PPSTACK.INPUT"); // Input images from previous run 54 if (runImages) { 55 // Defining files from the RUN metadata 56 num = runImages->n; 57 58 psArray *runMasks = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 59 "PPSTACK.INPUT.MASK"); // Input masks 60 if (!status) { 61 psError(PS_ERR_UNKNOWN, false, "Unable to define input masks from RUN metadata."); 62 psFree(runImages); 63 return false; 64 } 65 psFree(runMasks); 66 67 psArray *runVars = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 68 "PPSTACK.INPUT.VARIANCE"); // Input variances 69 if (!status) { 70 psError(PS_ERR_UNKNOWN, false, "Unable to define input variances from RUN metadata."); 71 psFree(runImages); 72 return false; 73 } 74 if (runVars) { 75 haveVariances = true; 76 } 77 psFree(runVars); 78 79 psArray *runPSF = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 80 "PPSTACK.INPUT.PSF"); // Input PSFs 81 if (!status) { 82 psError(PS_ERR_UNKNOWN, false, "Unable to define input PSFs from RUN metadata."); 83 psFree(runImages); 84 return false; 85 } 86 if (runPSF) { 87 havePSFs = true; 88 } 89 psFree(runPSF); 90 91 psArray *runSrc = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 92 "PPSTACK.INPUT.SOURCES"); // Input sources 93 if (!status) { 94 psError(PS_ERR_UNKNOWN, false, "Unable to define input sources from RUN metadata."); 95 psFree(runImages); 96 return false; 97 } 98 if (!runSrc) { 99 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define input sources from RUN metadta."); 100 psFree(runImages); 101 return false; 102 } 103 psFree(runSrc); 104 105 psArray *runKernel = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 106 "PPSTACK.CONV.KERNEL"); // Convolution kernels 107 if (!status) { 108 psError(PS_ERR_UNKNOWN, false, "Unable to define convolution kernels from RUN metadata."); 109 psFree(runImages); 110 return false; 111 } 112 if (!runSrc) { 113 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define convolution kernels from RUN metadta."); 114 psFree(runImages); 115 return false; 116 } 117 psFree(runKernel); 118 119 psFree(runImages); 120 } else { 121 // Defining files from the input metadata 122 psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info 123 if (!inputs) { 124 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find inputs."); 125 return false; 126 } 127 psMetadataIterator *iter = psMetadataIteratorAlloc(inputs, PS_LIST_HEAD, NULL); // Iterator 128 psMetadataItem *item; // Item from iteration 129 int i = 0; // Counter 130 while ((item = psMetadataGetAndIncrement(iter))) { 131 if (item->type != PS_DATA_METADATA) { 132 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 133 "Component %s of the input metadata is not of type METADATA", item->name); 134 psFree(iter); 135 return false; 136 } 137 138 psMetadata *input = item->data.md; // The input metadata of interest 139 140 psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image 141 if (!image || strlen(image) == 0) { 142 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name); 143 psFree(iter); 144 return false; 145 } 146 147 bool mdok; 148 psString mask = psMetadataLookupStr(&mdok, input, "MASK"); // Name of mask 149 psString variance = psMetadataLookupStr(&mdok, input, "VARIANCE"); // Name of variance map 150 psString psf = psMetadataLookupStr(&mdok, input, "PSF"); // Name of PSF 151 psString sources = psMetadataLookupStr(&mdok, input, "SOURCES"); // Name of sources 152 153 pmFPAfile *imageFile = defineFile(config, NULL, "PPSTACK.INPUT", 154 image, PM_FPA_FILE_IMAGE); // File for image 155 if (!imageFile) { 156 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image); 157 return false; 158 } 159 160 if (mask && strlen(mask) > 0 && 161 !defineFile(config, imageFile, "PPSTACK.INPUT.MASK", mask, PM_FPA_FILE_MASK)) { 133 162 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask); 134 163 return false; 135 164 } 136 if (maskFile->type != PM_FPA_FILE_MASK) { 137 psError(PS_ERR_IO, true, "PPSTACK.INPUT.MASK is not of type MASK"); 138 return false; 139 } 140 } 141 142 // Optionally add the variance file 143 if (variance && strlen(variance) > 0) { 144 haveVariances = true; 145 psArray *varianceFiles = psArrayAlloc(1); // Array of filenames for this FPA 146 varianceFiles->data[0] = psMemIncrRefCounter(variance); 147 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "VARIANCE.FILENAMES", PS_META_REPLACE, 148 "Filenames of variance files", varianceFiles); 149 psFree(varianceFiles); 150 151 bool status; 152 pmFPAfile *varianceFile = pmFPAfileBindFromArgs(&status, imageFile, config, 153 "PPSTACK.INPUT.VARIANCE", "VARIANCE.FILENAMES"); 154 if (!status) { 155 psError(PS_ERR_UNKNOWN, false, "Unable to define file from variance %d (%s)", i, variance); 156 return false; 157 } 158 if (varianceFile->type != PM_FPA_FILE_VARIANCE) { 159 psError(PS_ERR_IO, true, "PPSTACK.INPUT.VARIANCE is not of type VARIANCE"); 160 return false; 161 } 162 } 163 164 // Add the psf file 165 if (!psf || strlen(psf) == 0) { 166 if (havePSFs) { 167 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF %d", i); 168 return false; 169 } 170 } else { 171 if (!havePSFs && i != 0) { 172 psWarning("PSF not provided for all inputs --- ignoring."); 173 } else { 174 psArray *psfFiles = psArrayAlloc(1); // Array of filenames for this FPA 175 psfFiles->data[0] = psMemIncrRefCounter(psf); 176 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "PSF.FILENAMES", PS_META_REPLACE, 177 "Filenames of PSF files", psfFiles); 178 psFree(psfFiles); 179 180 bool status; 181 pmFPAfile *psfFile = pmFPAfileBindFromArgs(&status, imageFile, config, "PPSTACK.INPUT.PSF", 182 "PSF.FILENAMES"); 183 if (!status) { 184 psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf); 165 166 if (variance && strlen(variance) > 0) { 167 haveVariances = true; 168 if (!defineFile(config, imageFile, "PPSTACK.INPUT.VARIANCE", variance, 169 PM_FPA_FILE_VARIANCE)) { 170 psError(PS_ERR_UNKNOWN, false, 171 "Unable to define file from variance %d (%s)", i, variance); 185 172 return false; 186 173 } 187 if (psfFile->type != PM_FPA_FILE_PSF) { 188 psError(PS_ERR_IO, true, "PPSTACK.INPUT.PSF is not of type PSF"); 189 return false; 174 } 175 176 if (psf && strlen(psf) > 0) { 177 if (i != 0 && !havePSFs) { 178 psWarning("PSF not provided for all inputs --- ignoring."); 179 } else { 180 havePSFs = true; 181 if (!defineFile(config, imageFile, "PPSTACK.INPUT.PSF", psf, PM_FPA_FILE_PSF)) { 182 psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf); 183 return false; 184 } 190 185 } 191 havePSFs = true; 192 } 193 } 194 195 // Add the sources file 196 { 197 psArray *sourcesFiles = psArrayAlloc(1); // Array of filenames for this FPA 198 sourcesFiles->data[0] = psMemIncrRefCounter(sources); 199 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "SOURCES.FILENAMES", PS_META_REPLACE, 200 "Filenames of SOURCES files", sourcesFiles); 201 psFree(sourcesFiles); 202 203 bool status; 204 pmFPAfile *sourcesFile = pmFPAfileBindFromArgs(&status, imageFile, config, 205 "PPSTACK.INPUT.SOURCES", "SOURCES.FILENAMES"); 206 if (!status) { 186 } else if (havePSFs) { 187 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF %d", i); 188 return false; 189 } 190 191 if (!sources || strlen(sources) == 0) { 192 psError(PS_ERR_UNEXPECTED_NULL, true, "SOURCES not provided for file %d", i); 193 return false; 194 } 195 if (!defineFile(config, imageFile, "PPSTACK.INPUT.SOURCES", sources, PM_FPA_FILE_CMF)) { 207 196 psError(PS_ERR_UNKNOWN, false, "Unable to define file from sources %d (%s)", 208 197 i, sources); 209 198 return false; 210 199 } 211 if (sourcesFile->type != PM_FPA_FILE_CMF) { 212 psError(PS_ERR_IO, true, "PPSTACK.INPUT.SOURCES is not of type CMF"); 213 return false; 214 } 215 } 216 217 #if 0 218 // Output convolved files 219 pmFPAfile *outconvImage = defineOutputConvolved("PPSTACK.OUTCONV", imageFile->fpa, config, 220 PM_FPA_FILE_IMAGE); 221 pmFPAfile *outconvMask = defineOutputConvolved("PPSTACK.OUTCONV.MASK", imageFile->fpa, config, 222 PM_FPA_FILE_MASK); 223 pmFPAfile *outconvVariance = defineOutputConvolved("PPSTACK.OUTCONV.VARIANCE", imageFile->fpa, config, 224 PM_FPA_FILE_VARIANCE); 225 if (!outconvImage || !outconvMask || !outconvVariance) { 226 return false; 227 } 228 229 // Input convolved files 230 pmFPAfile *inconvImage = defineInputConvolved("PPSTACK.INCONV", outconvImage, config, 231 PM_FPA_FILE_IMAGE); 232 pmFPAfile *inconvMask = defineInputConvolved("PPSTACK.INCONV.MASK", outconvMask, config, 233 PM_FPA_FILE_MASK); 234 pmFPAfile *inconvVariance = defineInputConvolved("PPSTACK.INCONV.VARIANCE", outconvVariance, config, 235 PM_FPA_FILE_VARIANCE); 236 if (!inconvImage || !inconvMask || !inconvVariance) { 237 return false; 238 } 239 #endif 240 241 i++; 242 } 243 psFree(iter); 244 psMetadataRemoveKey(config->arguments, "IMAGE.FILENAMES"); 245 if (psMetadataLookup(config->arguments, "MASK.FILENAMES")) { 246 psMetadataRemoveKey(config->arguments, "MASK.FILENAMES"); 247 } 248 if (psMetadataLookup(config->arguments, "VARIANCE.FILENAMES")) { 249 psMetadataRemoveKey(config->arguments, "VARIANCE.FILENAMES"); 250 } 251 if (psMetadataLookup(config->arguments, "PSF.FILENAMES")) { 252 psMetadataRemoveKey(config->arguments, "PSF.FILENAMES"); 253 } 254 if (psMetadataLookup(config->arguments, "SOURCES.FILENAMES")) { 255 psMetadataRemoveKey(config->arguments, "SOURCES.FILENAMES"); 256 } 257 258 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", i); 200 201 pmFPAfile *kernel = pmFPAfileDefineOutput(config, imageFile->fpa, "PPSTACK.CONV.KERNEL"); 202 if (!kernel) { 203 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.CONV.KERNEL")); 204 return false; 205 } 206 207 i++; 208 } 209 psFree(iter); 210 psMetadataRemoveKey(config->arguments, "FILENAMES"); 211 num = i; 212 } 213 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", num); 259 214 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "HAVE.PSF", 0, "Have PSFs available?", havePSFs); 260 215 -
trunk/ppStack/src/ppStackFiles.c
r23341 r23357 17 17 18 18 /// Files required for the convolution 19 static char *filesConvolve[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", NULL }; 19 static char *filesConvolve[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.VARIANCE", 20 "PPSTACK.CONV.KERNEL", NULL }; 20 21 21 22 /// Output files for the combination -
trunk/ppStack/src/ppStackMatch.c
r23287 r23357 381 381 382 382 // Do the image matching 383 if (!pmSubtractionMatch(output, NULL, readout, fake, footprint, stride, regionSize, spacing, 384 threshold, stampSources, stampsName, type, size, order, widths, orders, 385 inner, ringsOrder, binning, penalty, optimum, optWidths, optOrder, 386 optThresh, iter, rej, sysError, maskVal, maskBad, maskPoor, poorFrac, 387 badFrac, PM_SUBTRACTION_MODE_1)) { 388 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); 389 psFree(fake); 390 psFree(optWidths); 391 psFree(stampSources); 392 psFree(output); 393 return false; 383 pmSubtractionKernels *kernel = psMetadataLookupPtr(&mdok, readout->analysis, 384 PM_SUBTRACTION_ANALYSIS_KERNEL); // Conv kernel 385 if (kernel) { 386 if (!pmSubtractionMatchPrecalc(output, NULL, readout, fake, output->analysis, 387 stride, sysError, maskVal, maskBad, maskPoor, 388 poorFrac, badFrac)) { 389 psError(PS_ERR_UNKNOWN, false, "Unable to convolve images."); 390 psFree(fake); 391 psFree(optWidths); 392 psFree(stampSources); 393 psFree(output); 394 return false; 395 } 396 } else { 397 if (!pmSubtractionMatch(output, NULL, readout, fake, footprint, stride, regionSize, spacing, 398 threshold, stampSources, stampsName, type, size, order, widths, 399 orders, inner, ringsOrder, binning, penalty, 400 optimum, optWidths, optOrder, optThresh, iter, rej, sysError, 401 maskVal, maskBad, maskPoor, poorFrac, badFrac, 402 PM_SUBTRACTION_MODE_1)) { 403 psError(PS_ERR_UNKNOWN, false, "Unable to match images."); 404 psFree(fake); 405 psFree(optWidths); 406 psFree(stampSources); 407 psFree(output); 408 return false; 409 } 394 410 } 395 411
Note:
See TracChangeset
for help on using the changeset viewer.
