- Timestamp:
- Mar 29, 2009, 6:15:31 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
-
branches/cnb_branches/cnb_branch_20090301/ppStack
- Property svn:mergeinfo changed
/trunk/ppStack merged: 23357,23360,23362,23364,23367-23368,23371-23373,23379,23462,23573,23575-23577
- Property svn:mergeinfo changed
-
branches/cnb_branches/cnb_branch_20090301/ppStack/src/ppStackCamera.c
r21366 r23594 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 = bind ? pmFPAfileBindFromArgs(&found, bind, config, name, "FILENAMES") : 30 pmFPAfileDefineFromArgs(&found, config, name, "FILENAMES"); 31 if (!file || !found) { 32 psError(PS_ERR_UNKNOWN, false, "Unable to define file %s from %s", name, filename); 25 33 return NULL; 26 34 } 27 if (file->type != PM_FPA_FILE_IMAGE) {28 psError(PS_ERR_IO, true, " PPSTACK.OUTCONV is not of type %s", pmFPAfileStringFromType(type));35 if (file->type != type) { 36 psError(PS_ERR_IO, true, "%s is not of type %s", name, pmFPAfileStringFromType(type)); 29 37 return NULL; 30 38 } … … 33 41 } 34 42 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 43 70 44 71 45 bool ppStackCamera(pmConfig *config) 72 46 { 73 bool haveVariances = false; // Do we have variance maps? 47 int num = 0; // Number of inputs 48 bool haveVariances = false; // Do we have variance maps? 74 49 bool havePSFs = false; // Do we have PSFs? 75 50 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"); 51 bool status = false; // Status of file definition 52 53 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim 54 if (!recipe) { 55 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSTACK_RECIPE); 56 return false; 57 } 58 bool convolve = psMetadataLookupBool(NULL, recipe, "CONVOLVE"); // Convolve images before stack? 59 60 psArray *runImages = pmFPAfileDefineMultipleFromRun(&status, NULL, config, 61 "PPSTACK.INPUT"); // Input images from previous run 62 if (runImages) { 63 // Defining files from the RUN metadata 64 num = runImages->n; 65 66 psArray *runMasks = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 67 "PPSTACK.INPUT.MASK"); // Input masks 68 if (!status) { 69 psError(PS_ERR_UNKNOWN, false, "Unable to define input masks from RUN metadata."); 70 psFree(runImages); 71 return false; 72 } 73 psFree(runMasks); 74 75 psArray *runVars = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 76 "PPSTACK.INPUT.VARIANCE"); // Input variances 77 if (!status) { 78 psError(PS_ERR_UNKNOWN, false, "Unable to define input variances from RUN metadata."); 79 psFree(runImages); 80 return false; 81 } 82 if (runVars) { 83 haveVariances = true; 84 } 85 psFree(runVars); 86 87 psArray *runPSF = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 88 "PPSTACK.INPUT.PSF"); // Input PSFs 89 if (!status) { 90 psError(PS_ERR_UNKNOWN, false, "Unable to define input PSFs from RUN metadata."); 91 psFree(runImages); 92 return false; 93 } 94 if (runPSF) { 95 havePSFs = true; 96 } 97 psFree(runPSF); 98 99 psArray *runSrc = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 100 "PPSTACK.INPUT.SOURCES"); // Input sources 101 if (!status) { 102 psError(PS_ERR_UNKNOWN, false, "Unable to define input sources from RUN metadata."); 103 psFree(runImages); 104 return false; 105 } 106 if (!runSrc) { 107 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to define input sources from RUN metadata."); 108 psFree(runImages); 109 return false; 110 } 111 psFree(runSrc); 112 113 if (convolve) { 114 psArray *runKernel = pmFPAfileDefineMultipleFromRun(&status, runImages, config, 115 "PPSTACK.CONV.KERNEL"); // Convolution kernels 132 116 if (!status) { 117 psError(PS_ERR_UNKNOWN, false, "Unable to define convolution kernels from RUN metadata."); 118 psFree(runImages); 119 return false; 120 } 121 if (!runKernel) { 122 psError(PS_ERR_UNEXPECTED_NULL, true, 123 "Unable to define convolution kernels from RUN metadata."); 124 psFree(runImages); 125 return false; 126 } 127 psFree(runKernel); 128 } 129 130 psFree(runImages); 131 } else { 132 // Defining files from the input metadata 133 psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info 134 if (!inputs) { 135 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find inputs."); 136 return false; 137 } 138 psMetadataIterator *iter = psMetadataIteratorAlloc(inputs, PS_LIST_HEAD, NULL); // Iterator 139 psMetadataItem *item; // Item from iteration 140 int i = 0; // Counter 141 while ((item = psMetadataGetAndIncrement(iter))) { 142 if (item->type != PS_DATA_METADATA) { 143 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 144 "Component %s of the input metadata is not of type METADATA", item->name); 145 psFree(iter); 146 return false; 147 } 148 149 psMetadata *input = item->data.md; // The input metadata of interest 150 151 psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image 152 if (!image || strlen(image) == 0) { 153 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name); 154 psFree(iter); 155 return false; 156 } 157 158 bool mdok; 159 psString mask = psMetadataLookupStr(&mdok, input, "MASK"); // Name of mask 160 psString variance = psMetadataLookupStr(&mdok, input, "VARIANCE"); // Name of variance map 161 psString psf = psMetadataLookupStr(&mdok, input, "PSF"); // Name of PSF 162 psString sources = psMetadataLookupStr(&mdok, input, "SOURCES"); // Name of sources 163 164 pmFPAfile *imageFile = defineFile(config, NULL, "PPSTACK.INPUT", 165 image, PM_FPA_FILE_IMAGE); // File for image 166 if (!imageFile) { 167 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image); 168 return false; 169 } 170 171 if (mask && strlen(mask) > 0 && 172 !defineFile(config, imageFile, "PPSTACK.INPUT.MASK", mask, PM_FPA_FILE_MASK)) { 133 173 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask); 134 174 return false; 135 175 } 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); 176 177 if (variance && strlen(variance) > 0) { 178 haveVariances = true; 179 if (!defineFile(config, imageFile, "PPSTACK.INPUT.VARIANCE", variance, 180 PM_FPA_FILE_VARIANCE)) { 181 psError(PS_ERR_UNKNOWN, false, 182 "Unable to define file from variance %d (%s)", i, variance); 185 183 return false; 186 184 } 187 if (psfFile->type != PM_FPA_FILE_PSF) { 188 psError(PS_ERR_IO, true, "PPSTACK.INPUT.PSF is not of type PSF"); 185 } 186 187 if (psf && strlen(psf) > 0) { 188 if (i != 0 && !havePSFs) { 189 psWarning("PSF not provided for all inputs --- ignoring."); 190 } else { 191 havePSFs = true; 192 if (!defineFile(config, imageFile, "PPSTACK.INPUT.PSF", psf, PM_FPA_FILE_PSF)) { 193 psError(PS_ERR_UNKNOWN, false, "Unable to define file from psf %d (%s)", i, psf); 194 return false; 195 } 196 } 197 } else if (havePSFs) { 198 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find PSF %d", i); 199 return false; 200 } 201 202 if (!sources || strlen(sources) == 0) { 203 psError(PS_ERR_UNEXPECTED_NULL, true, "SOURCES not provided for file %d", i); 204 return false; 205 } 206 if (!defineFile(config, imageFile, "PPSTACK.INPUT.SOURCES", sources, PM_FPA_FILE_CMF)) { 207 psError(PS_ERR_UNKNOWN, false, "Unable to define file from sources %d (%s)", 208 i, sources); 209 return false; 210 } 211 212 if (convolve) { 213 pmFPAfile *kernel = pmFPAfileDefineOutput(config, imageFile->fpa, "PPSTACK.CONV.KERNEL"); 214 if (!kernel) { 215 psError(PS_ERR_IO, false, _("Unable to generate output file from PPSTACK.CONV.KERNEL")); 189 216 return false; 190 217 } 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) { 207 psError(PS_ERR_UNKNOWN, false, "Unable to define file from sources %d (%s)", 208 i, sources); 209 return false; 210 } 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); 218 kernel->save = true; 219 } 220 221 i++; 222 } 223 psFree(iter); 224 psMetadataRemoveKey(config->arguments, "FILENAMES"); 225 num = i; 226 } 227 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", num); 259 228 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "HAVE.PSF", 0, "Have PSFs available?", havePSFs); 260 229 … … 343 312 } 344 313 jpeg2->save = true; 345 346 347 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim348 if (!recipe) {349 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSTACK_RECIPE);350 return false;351 }352 314 353 315 // For photometry, we operate on the chip-mosaicked image
Note:
See TracChangeset
for help on using the changeset viewer.
