Changeset 36615 for trunk/ppBackground/src/ppBackgroundStackLoop.c
- Timestamp:
- Mar 27, 2014, 4:21:00 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/ppBackground/src/ppBackgroundStackLoop.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppBackground/src/ppBackgroundStackLoop.c
r36582 r36615 20 20 // If we didn't load the OTA solution from an external source, we need to build one. 21 21 if (data->fit_OTAS) { 22 printf("Fitting OTAs!\n"); 22 23 if (!ppBackgroundStackModelFitOTASolution(data)) { 23 24 // Currently can't fail. … … 25 26 return(false); 26 27 } 27 } 28 29 if (data->OTApath) { 30 // This will write the solutions out. 31 psMetadataIterator *iter = psMetadataIteratorAlloc(data->OTA_solutions, PS_LIST_HEAD, NULL); // Iterator 32 psMetadataItem *item; // Item from iteration 33 int i = 0; 34 while ((item = psMetadataGetAndIncrement(iter))) { 35 i++; 36 if (item->type != PS_DATA_IMAGE) { 37 psString chipName = item->name; 38 psImage *image = item->data.V; 39 psMetadata *header = psMetadataAlloc(); 40 psString solutionFileName = psStringCopy(data->OTApath); 41 psStringAppend(&solutionFileName, ".%s.fits",chipName); 42 psString resolved = pmConfigConvertFilename(solutionFileName,config,true,true); 43 psFits *solutionFits = psFitsOpen(resolved,"w"); 44 if (!solutionFits) { 45 psError(2, false, "Unable to open FITS file %s to write model %s.", resolved, chipName); 46 psFitsClose(solutionFits); 47 psFree(resolved); 48 return(false); 49 } 50 if (!psFitsWriteImage(solutionFits, header, image, 0, NULL)) { 51 psError(2, false, "Unable to write FITS image %s.", resolved); 52 psFitsClose(solutionFits); 53 psFree(resolved); 54 return false; 55 } 56 if (!psFitsClose(solutionFits)) { 57 psError(2, false, "Unable to close FITS image %s.", resolved); 58 psFree(resolved); 59 return false; 60 } 61 psFree(resolved); 62 psFree(solutionFileName); 63 } 64 } 65 psFree(item); 66 psFree(iter); 67 } 68 69 } 70 28 71 29 72 // This seems wrong, but I need a blank modelMap object, so we fit the zero-data we've stored in the calib objects 73 printf("Determining blank modelMap!\n"); 30 74 if (!ppBackgroundStackModelFit(data)) { 31 75 psError(psErrorCodeLast(), false, "Error determining the blank modelMap object."); … … 34 78 35 79 // Apply OTA solution 80 printf("Calib apply!\n"); 36 81 if (!ppBackgroundStackCalibApply(data)) { 37 82 psError(psErrorCodeLast(), false, "Error applying the calibration models."); … … 43 88 { 44 89 // Construct the offset information 90 printf("Model fit!\n"); 45 91 if (!ppBackgroundStackDataModelFit(data)) { 46 92 psError(psErrorCodeLast(), false, "Error determining the exposure/OTA scaling."); … … 49 95 50 96 // Apply full correction 97 printf("Calib apply!\n"); 51 98 if (!ppBackgroundStackCalibApply(data)) { 52 99 psError(psErrorCodeLast(), false, "Error applying the calibration models."); … … 55 102 56 103 // Fit the new model 104 printf("Determining model!\n"); 57 105 if (!ppBackgroundStackModelFit(data)) { 58 106 psError(psErrorCodeLast(), false, "Error determining the modelMap object."); … … 66 114 pmFPAfile *stack = data->stack_data->data[i]; 67 115 pmFPAview *view = pmFPAviewAlloc(0); 68 // Define output image 69 pmFPAfile *stack_model = pmFPAfileDefineOutput(config,stack->fpa,"PPBACKGROUND.STACK.MODEL"); 70 116 117 // Define output image. Why is this always so hard to do? 118 pmFPA *tmp_fpa1,*tmp_fpa2; 119 tmp_fpa1 = pmFPAConstruct(config->camera,config->cameraName); 120 tmp_fpa2 = pmFPAConstruct(config->camera,config->cameraName); 121 122 pmFPAfile *stack_model = pmFPAfileDefineOutput(config,tmp_fpa1,"PPBACKGROUND.STACK.MODEL"); 123 71 124 if (!stack_model) { 72 125 psError(psErrorCodeLast(), false, "Unable to generate output model"); … … 74 127 } 75 128 76 pmFPAfile *stack_corr = pmFPAfileDefineOutput(config, stack->fpa,"PPBACKGROUND.STACK.OUTPUT");129 pmFPAfile *stack_corr = pmFPAfileDefineOutput(config,tmp_fpa2,"PPBACKGROUND.STACK.OUTPUT"); 77 130 if (!stack_corr) { 78 131 psError(psErrorCodeLast(), false, "Unable to generate output result"); … … 82 135 stack_corr->save = true; 83 136 137 printf("I'm about to loop over the parts of this stack: %d\n",i); 84 138 // Iterate over the images. 139 pmFPAfileActivate(config->files,true,"PPBACKGROUND.STACK"); 140 pmFPAfileActivate(config->files,true,"PPBACKGROUND.STACK.MODEL"); 141 pmFPAfileActivate(config->files,true,"PPBACKGROUND.STACK.OUTPUT"); 142 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 143 psError(psErrorCodeLast(), false, "load failure for Chip"); 144 return(false); 145 } 146 147 85 148 pmChip *chip; 86 149 while ((chip = pmFPAviewNextChip(view, stack->fpa, 1))) { … … 93 156 return(false); 94 157 } 95 158 printf(" I'm in a chip\n"); 96 159 pmCell *cell; 97 160 … … 109 172 continue; 110 173 } 174 printf(" I'm in a cell\n"); 175 111 176 112 177 // process each of the readouts … … 120 185 continue; 121 186 } 122 123 pmReadout *model = pmFPAfileThisReadout(config->files,view,"PPBACKGROUND.STACK.MODEL"); 124 pmReadout *corr = pmFPAfileThisReadout(config->files,view,"PPBACKGROUND.STACK.OUTPUT"); 125 187 printf(" I'm in a readout\n"); 188 189 // Futz with things to get an acceptable output product. 190 pmCell *model_cell = pmFPAviewThisCell(view,stack_model->fpa); 191 pmCell *corr_cell = pmFPAviewThisCell(view,stack_corr->fpa); 192 193 pmReadout *model = pmReadoutAlloc(model_cell); 194 pmReadout *corr = pmReadoutAlloc(corr_cell); 195 model->data_exists = true; 196 corr->data_exists = true; 197 model->parent->data_exists = true; 198 corr->parent->data_exists = true; 199 model->parent->parent->data_exists = true; 200 corr->parent->parent->data_exists = true; 201 model->image = psImageAlloc(readout->image->numCols,readout->image->numRows,PS_TYPE_F32); 202 corr->image = psImageAlloc(readout->image->numCols,readout->image->numRows,PS_TYPE_F32); 203 204 model_cell->concepts = psMemIncrRefCounter(cell->concepts); 205 model_cell->conceptsRead = cell->conceptsRead; 206 corr_cell->concepts = psMemIncrRefCounter(cell->concepts); 207 corr_cell->conceptsRead = cell->conceptsRead; 208 126 209 psPlane *pix = psPlaneAlloc(); // Pixel coordinates on chip 127 210 psPlane *fp = psPlaneAlloc(); // Focal plane coordinates … … 130 213 int x,y; 131 214 for (y = 0; y < readout->image->numRows; y++) { 215 pix->y = y; 132 216 for (x = 0; x < readout->image->numCols; x++) { 217 pix->x = x; 133 218 // Calculate model for each pixel of output 134 psPlaneTransformApply(fp, chip->toFPA, pix);135 psPlaneTransformApply(tp, stack->fpa->toTPA, fp);219 // psPlaneTransformApply(fp, chip->toFPA, pix); 220 psPlaneTransformApply(tp, stack->fpa->toTPA, pix); 136 221 137 222 model->image->data.F32[y][x] = psImageMapEval(data->modelMap,tp->x,tp->y); 138 223 corr->image->data.F32[y][x] = readout->image->data.F32[y][x] + model->image->data.F32[y][x]; 224 139 225 } 140 226 } … … 143 229 psFree(tp); 144 230 } // Close readout 145 231 printf(" I'm done with that readout\n"); 146 232 // Close output image 147 // Close cells (XXX shouldn't pmFPAfileClose iterate down as needed?)148 view->cell = -1;149 while ((cell = pmFPAviewNextCell(view, stack->fpa, 1)) != NULL) {150 if (!cell->process || !cell->file_exists) {151 continue;152 }153 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {154 psError(psErrorCodeLast(), false, "save failure for Cell");155 return(false);156 }157 }158 233 } // Close Cell 159 234 // Close cells (XXX shouldn't pmFPAfileClose iterate down as needed?) 235 view->cell = -1; 236 while ((cell = pmFPAviewNextCell(view, stack->fpa, 1)) != NULL) { 237 if (!cell->process || !cell->file_exists) { 238 continue; 239 } 240 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 241 psError(psErrorCodeLast(), false, "save failure for Cell"); 242 return(false); 243 } 244 } 245 160 246 // Close chip 161 247 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
Note:
See TracChangeset
for help on using the changeset viewer.
