Changeset 36580 for trunk/ppBackground/src/ppBackgroundStackCamera.c
- Timestamp:
- Mar 7, 2014, 6:08:39 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/ppBackground/src/ppBackgroundStackCamera.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppBackground/src/ppBackgroundStackCamera.c
r36579 r36580 31 31 { 32 32 bool status; // Status of file definition 33 33 pmConfig *config = data->config; // Because I'm reusing code. 34 int u,v; 35 // FIX Figure out what stacks we have to deal with. 36 psString stackName = data->stacks->data[0]; 37 fileArguments("IMAGE", stackName, "Input image", data->config); 38 pmFPAfile *stack = pmFPAfileDefineFromArgs(&status, data->config, "PPBACKGROUND.STACK", 39 "IMAGE"); 40 if (!status || !stack) { 41 psError(psErrorCodeLast(), false, "Failed to build file from PPBACKGROUND.STACK"); 42 return false; 43 } 44 45 // Read over the input background models. 34 46 psMetadataIterator *iter = psMetadataIteratorAlloc(data->contents, PS_LIST_HEAD, NULL); // Iterator 35 47 psMetadataItem *item; // Item from iteration 36 int i = 0;48 // int i = 0; 37 49 while ((item = psMetadataGetAndIncrement(iter))) { 38 50 if (item->type != PS_DATA_METADATA) { 39 psError(PPBACKGROUND_ERR_ARGUMENTS, true 51 psError(PPBACKGROUND_ERR_ARGUMENTS, true, 40 52 "Component %s of the input metadata is not of type METADATA", item->name); 41 53 psFree(iter); … … 47 59 psString smfFileName = psMetadataLookupStr(NULL, input, "astrom"); 48 60 49 // FIX Figure out how to calculate the smf name 50 // psString cam_file = pmFPAfileNameFromRule("PSASTRO.OUTPUT"); 51 // pmFPAfile *smfFile = pmFPAfileBindFromArgs(&status, NULL, config); 52 // pmFPAfile *smfFile = pmFPAfileDefineInput(config, 61 // Read the smf file from this item 53 62 fileArguments("astrom",smfFileName,"",config); 54 63 pmFPAfile *smfFile = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM","astrom"); 55 64 56 65 // Read the SMF data 57 58 66 pmFPAview *view = pmFPAviewAlloc(0); // Pointer into FPA hierarchy 59 67 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { … … 95 103 } 96 104 // read WCS data from the corresponding header 97 pmHDU *hdu = pmFPAviewThisHDU (view, astromFile->fpa);105 pmHDU *hdu = pmFPAviewThisHDU (view, smfFile->fpa); 98 106 if (bilevelAstrometry) { 99 107 if (!pmAstromReadBilevelChip (chip, hdu->header)) { … … 108 116 // we use a default FPA pixel scale of 1.0 109 117 psWarning("Reading WCS astrometry for chip %s.", chipName); 110 if (!pmAstromReadWCS( astromFile->fpa, chip, hdu->header, 1.0)) {118 if (!pmAstromReadWCS(smfFile->fpa, chip, hdu->header, 1.0)) { 111 119 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 112 120 psFree(view); … … 116 124 117 125 // FIX Load model data for this chip 118 psString modelFileName = psMetadataLookupStr(NULL, input ->models, chipName);126 psString modelFileName = psMetadataLookupStr(NULL, input, chipName); 119 127 psFits *modelFits = psFitsOpen(modelFileName,"r"); 120 psImage *image = psFitsReadImage(modelFits,NULL,0); 128 int nC, nR; 129 psElemType *type; 130 psRegion region; 131 psFitsImageSize(&nC,&nR,type,modelFits,region); 132 psImage *image = psFitsReadImage(modelFits,region,0); 121 133 psMetadata *header = psFitsReadHeader(NULL,modelFits); 122 134 123 135 // Allocate the data structures for this chip 124 psImage *raim = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);125 psImage *decim = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);126 psImage *model = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);136 psImage *raim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 137 psImage *decim = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 138 psImage *model = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 127 139 128 140 // Read header and construct original positions … … 142 154 psSphere *sky = psSphereAlloc(); // Sky coordinates 143 155 144 for (v = 0; v < image->n rows; v++) {156 for (v = 0; v < image->numRows; v++) { 145 157 pix->y = (v - yoffset) * ybin; 146 for (u = 0; u < image->n cols; u++) {158 for (u = 0; u < image->numCols; u++) { 147 159 pix->x = (u - xoffset) * xbin; 148 160 psPlaneTransformApply(fp, chip->toFPA, pix); 149 161 psPlaneTransformApply(tp, smfFile->fpa->toTPA, fp); 150 psDeproject(sky, tp, astromFile->fpa->toSky); 151 152 // FIX project sky to stack projection cell grid. 153 if (!data->radians) { 154 sky->r *= 180.0 / M_PI; 155 sky->d *= 180.0 / M_PI; 156 } 157 raim->data.F32[v][u] = sky->r; 158 decim->data.F32[v][u] = sky->d; 162 psDeproject(sky, tp, smfFile->fpa->toSky); 163 164 psProject(tp,sky,stack->fpa->toSky); 165 166 raim->data.F32[v][u] = tp->x; 167 decim->data.F32[v][u] = tp->y; 159 168 model->data.F32[v][u] = 0.0; 160 169 161 170 // Check the bounds so we'll know how large of an area to model in the map 162 if ( sky->r < data->ra_min) { data->ra_min = sky->r; }163 else if ( sky->r > data->ra_max) { data->ra_max = sky->r; }164 if ( sky->d < data->dec_min) { data->dec_min = sky->d; }165 else if ( sky->d > data->dec_max) { data->dec_max = sky->d; }171 if (tp->x < data->ra_min) { data->ra_min = tp->x; } 172 else if (tp->x > data->ra_max) { data->ra_max = tp->x; } 173 if (tp->y < data->dec_min) { data->dec_min = tp->y; } 174 else if (tp->y > data->dec_max) { data->dec_max = tp->y; } 166 175 } 167 176 } … … 187 196 // FIX this should try to find the imagefile. 188 197 if (data->fit_OTAS) { // We are fitting OTAs, so allocate a new image 189 psImage *solution = psImageAlloc(image-> cols,image->rows,PS_TYPE_F32);198 psImage *solution = psImageAlloc(image->numCols,image->numRows,PS_TYPE_F32); 190 199 psMetadataAddPtr(data->OTA_solutions,PS_LIST_TAIL, chipName, PS_DATA_UNKNOWN | PS_META_REPLACE, "OTA solution element", solution); 191 200 } … … 194 203 psStringAppend(&solutionFileName, ".%s.fits",chipName); 195 204 psFits *solutionFits = psFitsOpen(solutionFileName,"r"); 196 psImage *solution = psFitsReadImage(solutionFits,NULL,0); 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); 197 207 } 198 208 } … … 215 225 } 216 226 227 // Allocate the modelMap for the region we're covering. 228 229 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 230 psImageBinning *binning = psImageBinningAlloc(); 231 binning->nXruff = 100; // Number of samples 232 binning->nYruff = 100; 233 binning->nXfine = ceil(data->ra_max - data->ra_min) + 1; // This is the range we're looking at 234 binning->nYfine = ceil(data->dec_max - data->dec_min) + 1; 235 236 data->modelMap = psImageMapNoImageAlloc( binning,stats); 237 217 238 return true; 218 239 }
Note:
See TracChangeset
for help on using the changeset viewer.
