Changeset 36582 for trunk/ppBackground/src/ppBackgroundStackCamera.c
- Timestamp:
- Mar 11, 2014, 3:46:50 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/ppBackground/src/ppBackgroundStackCamera.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
