Changeset 36582
- Timestamp:
- Mar 11, 2014, 3:46:50 PM (12 years ago)
- Location:
- trunk/ppBackground/src
- Files:
-
- 6 edited
-
ppBackground.c (modified) (1 diff)
-
ppBackgroundStack.c (modified) (1 diff)
-
ppBackgroundStack.h (modified) (1 diff)
-
ppBackgroundStackCamera.c (modified) (10 diffs)
-
ppBackgroundStackData.c (modified) (2 diffs)
-
ppBackgroundStackLoop.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppBackground/src/ppBackground.c
r28280 r36582 18 18 ppBackgroundErrorRegister(); 19 19 20 printf("Initializing data\n"); 20 21 ppBackgroundData *data = ppBackgroundDataInit(&argc, argv); 21 22 if (!data) { 22 23 goto DIE; 23 24 } 24 25 printf("Reading Arguments\n"); 25 26 if (!ppBackgroundArguments(data, argc, argv)) { 26 27 goto DIE; 27 28 } 28 29 printf("Setting up Camera\n"); 29 30 if (!ppBackgroundCamera(data)) { 30 31 goto DIE; 31 32 } 32 33 34 printf("Looping over data!\n"); 33 35 if (!ppBackgroundLoop(data)) { 34 36 goto DIE; -
trunk/ppBackground/src/ppBackgroundStack.c
r36580 r36582 18 18 ppBackgroundErrorRegister(); 19 19 20 printf("Data init\n"); 20 21 ppBackgroundStackData *data = ppBackgroundStackDataInit(&argc, argv); 21 22 if (!data) { 22 23 goto DIE; 23 24 } 24 25 printf("Read arguments\n"); 25 26 if (!ppBackgroundStackArguments(data, argc, argv)) { 26 27 goto DIE; 27 28 } 28 29 30 printf("Setup camera\n"); 29 31 if (!ppBackgroundStackCamera(data)) { 30 32 goto DIE; 31 33 } 32 34 35 printf("Do Loop\n"); 33 36 if (!ppBackgroundStackLoop(data)) { 34 37 goto DIE; -
trunk/ppBackground/src/ppBackgroundStack.h
r36580 r36582 23 23 psF32 dec_min; 24 24 psF32 dec_max; 25 25 26 psArray *stack_data; 26 27 psArray *stacks; // List of stacks to be corrected. 27 28 psString outRoot; // Output root name -
trunk/ppBackground/src/ppBackgroundStackCamera.c
r36580 r36582 36 36 psString stackName = data->stacks->data[0]; 37 37 fileArguments("IMAGE", stackName, "Input image", data->config); 38 pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.STACK", 39 "IMAGE"); 38 psFree(stackName); 39 pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config, 40 "PPBACKGROUND.STACK", "IMAGE"); 40 41 if (!status || !stack) { 41 42 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.STACK"); … … 43 44 } 44 45 46 if (!pmAstromReadBilevelMosaic(stack->fpa,stack->fpa->hdu->header)) { 47 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input stack."); 48 return false; 49 } 50 psArrayAdd(data->stack_data,data->stack_data->n,psMemIncrRefCounter(stack)); 51 45 52 // Read over the input background models. 46 53 psMetadataIterator *iter = psMetadataIteratorAlloc(data->contents, PS_LIST_HEAD, NULL); // Iterator 47 54 psMetadataItem *item; // Item from iteration 48 //int i = 0;55 int i = 0; 49 56 while ((item = psMetadataGetAndIncrement(iter))) { 57 i++; 50 58 if (item->type != PS_DATA_METADATA) { 51 59 psError(PPBACKGROUND_ERR_ARGUMENTS, true, … … 58 66 59 67 psString smfFileName = psMetadataLookupStr(NULL, input, "astrom"); 60 68 psMetadata *modelContent = psMetadataLookupMetadata(NULL, input, "models"); 61 69 // Read the smf file from this item 62 70 fileArguments("astrom",smfFileName,"",config); … … 68 76 return NULL; 69 77 } 70 78 printf("CZW: Item %d\n",i); 71 79 // find the FPA phu 72 80 bool bilevelAstrometry = false; … … 91 99 } 92 100 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip 93 /* if (data->chipName && strcmp(chipName, data->chipName) != 0) { */94 /* continue; */95 /* } */96 101 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 97 102 psError(psErrorCodeLast(), false, "Error loading data from files."); 98 103 return false; 99 104 } 100 101 105 if (chip->cells->n != 1) { 102 106 psWarning("More than one cell present for chip %d", view->chip); 103 107 } 108 104 109 // read WCS data from the corresponding header 105 110 pmHDU *hdu = pmFPAviewThisHDU (view, smfFile->fpa); … … 124 129 125 130 // FIX Load model data for this chip 126 psString modelFileName = psMetadataLookupStr(NULL, input, chipName); 131 psString modelFileName = pmConfigConvertFilename(psMetadataLookupStr(NULL, modelContent, chipName), 132 config, PM_FPA_MODE_READ, false); 127 133 psFits *modelFits = psFitsOpen(modelFileName,"r"); 128 int nC, nR; 129 psElemType *type; 130 psRegion region; 131 psFitsImageSize(&nC,&nR,type,modelFits,region); 132 psImage *image = psFitsReadImage(modelFits,region,0); 134 psImage *image = psFitsReadImage(modelFits,psRegionSet(0,0,0,0),0); 133 135 psMetadata *header = psFitsReadHeader(NULL,modelFits); 134 136 135 137 // Allocate the data structures for this chip 136 138 psImage *raim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); … … 177 179 178 180 // Attach vectors to teh structure of the chip 179 psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg image", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space X vector", image); 180 psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg ra", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space X vector", raim); 181 psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg dec", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space X vector", decim); 182 psMetadataAddPtr(chip->analysis,PS_LIST_TAIL,"bkg calibrated data", PS_DATA_UNKNOWN | PS_META_REPLACE, "ota space corrected data", model); 181 psMetadataAddImage(chip->analysis,PS_LIST_TAIL, 182 "bkg image", 0, 183 "ota space X vector", image); 184 psMetadataAddImage(chip->analysis,PS_LIST_TAIL, 185 "bkg ra", 0, 186 "ota space ra vector", raim); 187 psMetadataAddImage(chip->analysis,PS_LIST_TAIL, 188 "bkg dec", 0, 189 "ota space dec vector", decim); 190 psMetadataAddImage(chip->analysis,PS_LIST_TAIL, 191 "bkg calibrated data", 0, 192 "ota space corrected data", model); 183 193 184 194 // Define default background model parameters, using the assumption: 185 195 // observed = camera + offset + scale * astrophysical 186 psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg offset", PS_META_REPLACE, "background offset for this exposure/ota pair", 0.0); 187 psMetadataAddF32(chip->analysis,PS_LIST_TAIL,"bkg scale", PS_META_REPLACE, "background scale parameter for this exposure/ota pair", 1.0); 196 psMetadataAddF32(chip->analysis,PS_LIST_TAIL, 197 "bkg offset", PS_META_REPLACE, 198 "background offset for this exposure/ota pair", 0.0); 199 psMetadataAddF32(chip->analysis,PS_LIST_TAIL, 200 "bkg scale", PS_META_REPLACE, 201 "background scale parameter for this exposure/ota pair", 1.0); 188 202 // FIX Free model data for this chip 203 psFree(modelFileName); 204 psFree(modelFits); 189 205 psFree(header); 190 psFree(modelFits); 191 psFree(modelFileName); 192 206 psFree(pix); 207 psFree(fp); 208 psFree(tp); 209 psFree(sky); 210 psFree(image); 211 psFree(raim); 212 psFree(decim); 213 psFree(model); 193 214 194 215 // Check to see if we've loaded or allocated an OTA solution container for this chip … … 197 218 if (data->fit_OTAS) { // We are fitting OTAs, so allocate a new image 198 219 psImage *solution = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 199 psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution); 220 psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, 221 chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, 222 "OTA solution element", solution); 200 223 } 201 224 else { // We are not fitting OTAs, so read the one that should be saved on OTApath. … … 203 226 psStringAppend(&solutionFileName, ".%s.fits",chipName); 204 227 psFits *solutionFits = psFitsOpen(solutionFileName,"r"); 205 psImage *solution = psFitsReadImage(solutionFits,region,0); 206 psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution); 228 psImage *solution = psFitsReadImage(solutionFits,psRegionSet(0,0,0,0),0); 229 psMetadataAddImage(data->OTA_solutions,PS_LIST_TAIL, 230 chipName, 0, 231 "OTA solution element", solution); 232 psFree(solutionFits); 233 psFree(solutionFileName); 234 psFree(solution); 207 235 } 208 236 } … … 210 238 // FIX Hopefully this isn't going to destroy everything. 211 239 // Chip 212 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 213 psError(psErrorCodeLast(), false, "Error saving data to files."); 214 return false; 215 } 240 /* if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { */ 241 /* psError(psErrorCodeLast(), false, "Error saving data to files."); */ 242 /* return false; */ 243 /* } */ 216 244 } 217 245 // FPA 218 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 219 psError(psErrorCodeLast(), false, "Error saving data to files."); 220 return false; 221 } 246 /* if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { */ 247 /* psError(psErrorCodeLast(), false, "Error saving data to files."); */ 248 /* return false; */ 249 /* } */ 222 250 223 251 // Add this smf to the smf array. 224 252 psArrayAdd(data->smfs,data->smfs->n,psMemIncrRefCounter(smfFile)); 253 psFree(smfFile); 225 254 } 226 255 -
trunk/ppBackground/src/ppBackgroundStackData.c
r36580 r36582 21 21 psFree(data->modelMap); 22 22 23 24 psFree(data->stack_data); 23 25 psFree(data->stacks); 24 26 psFree(data->outRoot); … … 45 47 data->dec_min = 1e9; 46 48 data->dec_max = -1e9; 47 49 50 data->stack_data = psArrayAlloc(0); 48 51 data->stacks = psArrayAlloc(0); 49 52 data->outRoot = NULL; -
trunk/ppBackground/src/ppBackgroundStackLoop.c
r36580 r36582 13 13 ) 14 14 { 15 //pmConfig *config = data->config; // Configuration data15 pmConfig *config = data->config; // Configuration data 16 16 int i; 17 17 // … … 63 63 // Loop over the input images, and apply the models to construct the restored versions. 64 64 65 for (i = 0; i < data->stacks->n; i++) { 65 for (i = 0; i < data->stack_data->n; i++) { 66 pmFPAfile *stack = data->stack_data->data[i]; 67 pmFPAview *view = pmFPAviewAlloc(0); 66 68 // Define output image 67 // Calculate model for each pixel of output 68 // Close output image 69 pmFPAfile *stack_model = pmFPAfileDefineOutput(config,stack->fpa,"PPBACKGROUND.STACK.MODEL"); 70 71 if (!stack_model) { 72 psError(psErrorCodeLast(), false, "Unable to generate output model"); 73 return (false); 74 } 75 76 pmFPAfile *stack_corr = pmFPAfileDefineOutput(config,stack->fpa,"PPBACKGROUND.STACK.OUTPUT"); 77 if (!stack_corr) { 78 psError(psErrorCodeLast(), false, "Unable to generate output result"); 79 return (false); 80 } 81 stack_model->save = true; 82 stack_corr->save = true; 83 84 // Iterate over the images. 85 pmChip *chip; 86 while ((chip = pmFPAviewNextChip(view, stack->fpa, 1))) { 87 if (!chip->process || !chip->file_exists) { 88 continue; 89 } 90 91 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 92 psError(psErrorCodeLast(), false, "load failure for Chip"); 93 return(false); 94 } 95 96 pmCell *cell; 97 98 while ((cell = pmFPAviewNextCell(view, stack->fpa, 1)) != NULL) { 99 psLogMsg ("ppImageLoop", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 100 if (!cell->process || !cell->file_exists) { 101 continue; 102 } 103 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 104 psError(psErrorCodeLast(), false, "load failure for Cell"); 105 return(false); 106 } 107 if (cell->readouts->n > 1) { 108 psWarning ("Skipping Video Cell for ppImageDetrendReadout"); 109 continue; 110 } 111 112 // process each of the readouts 113 pmReadout *readout; // Readout from cell 114 while ((readout = pmFPAviewNextReadout (view, stack->fpa, 1)) != NULL) { 115 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 116 psError(psErrorCodeLast(), false, "load failure for Readout"); 117 return(false); 118 } 119 if (!readout->data_exists) { 120 continue; 121 } 122 123 pmReadout *model = pmFPAfileThisReadout(config->files,view,"PPBACKGROUND.STACK.MODEL"); 124 pmReadout *corr = pmFPAfileThisReadout(config->files,view,"PPBACKGROUND.STACK.OUTPUT"); 125 126 psPlane *pix = psPlaneAlloc(); // Pixel coordinates on chip 127 psPlane *fp = psPlaneAlloc(); // Focal plane coordinates 128 psPlane *tp = psPlaneAlloc(); // Tangent plane coordinates 129 130 int x,y; 131 for (y = 0; y < readout->image->numRows; y++) { 132 for (x = 0; x < readout->image->numCols; x++) { 133 // Calculate model for each pixel of output 134 psPlaneTransformApply(fp, chip->toFPA, pix); 135 psPlaneTransformApply(tp, stack->fpa->toTPA, fp); 136 137 model->image->data.F32[y][x] = psImageMapEval(data->modelMap,tp->x,tp->y); 138 corr->image->data.F32[y][x] = readout->image->data.F32[y][x] + model->image->data.F32[y][x]; 139 } 140 } 141 psFree(pix); 142 psFree(fp); 143 psFree(tp); 144 } // Close readout 145 146 // 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 } // Close Cell 159 160 // Close chip 161 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 162 psError(psErrorCodeLast(), false, "save failure for Chip"); 163 return(false); 164 } 165 } // Close chip. 166 // Output and Close FPA 167 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 168 psError(psErrorCodeLast(), false, "save failure for FPA"); 169 return(false); 170 } 171 psFree(view); 69 172 } 70 173 174 71 175 return(true); 72 176 }
Note:
See TracChangeset
for help on using the changeset viewer.
