- Timestamp:
- Apr 7, 2013, 6:23:04 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130307/pswarp/src/pswarpDefine.c
r35372 r35373 1 1 /** @file pswarpDefine.c 2 2 * 3 * @brief 4 * 3 * @brief generates the output images 5 4 * @ingroup pswarp 6 5 * … … 13 12 # include "pswarp.h" 14 13 15 /**16 * loads the skycell metadata17 */18 14 bool pswarpDefine (pmConfig *config) { 19 15 … … 132 128 } 133 129 134 bool pswarpDefineBackground (pmConfig *config) {135 136 // load the PSWARP recipe137 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);138 if (!recipe) {139 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");140 return false;141 }142 143 // select the input data sources144 pmFPAfile *skycell = psMetadataLookupPtr (NULL, config->files, "PSWARP.SKYCELL");145 if (!skycell) {146 psError(PSWARP_ERR_CONFIG, false, "Can't find skycell data!\n");147 return false;148 }149 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT.BKGMODEL");150 if (!output) {151 psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n");152 return false;153 }154 pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PSWARP.INPUT");155 if (!input) {156 psError(PSWARP_ERR_CONFIG, false, "Can't find input data!\n");157 return false;158 }159 160 // open the full skycell file; no need to defer different depths. only load the header data161 pmFPAview *view = pmFPAviewAlloc (0);162 pmFPAfileOpen (skycell, view, config);163 164 // Read header and create target165 {166 if (!pmFPAReadHeaderSet(skycell->fpa, skycell->fits, config)) {167 psError(psErrorCodeLast(), false, "Unable to read headers for skycell.");168 psFree(view);169 return false;170 }171 view->chip = 0;172 view->cell = 0;173 view->readout = 0;174 pmCell *source = pmFPAfileThisCell(config->files, view, "PSWARP.SKYCELL"); ///< Source cell175 pmHDU *hdu = pmHDUFromCell(source); ///< HDU for source176 if (!hdu || !hdu->header) {177 psError(PM_ERR_PROG, false, "Unable to find header for sky cell.");178 psFree(view);179 return false;180 }181 int numCols = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); ///< Number of columns182 int numRows = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); ///< Number of rows183 if ((numCols == 0) || (numRows == 0)) {184 psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows);185 psFree(view);186 return false;187 }188 189 pmCell *target = pmFPAviewThisCell(view, output->fpa); ///< Target cell190 pmReadout *readout = pmReadoutAlloc(target); ///< Target readout191 readout->image = psImageAlloc(numCols / output->xBin, numRows / output->yBin, PS_TYPE_F32);192 psImageInit(readout->image, NAN);193 psFree(readout); // Drop reference194 195 bool status = false;196 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XBIN");197 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YBIN");198 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XBIN",PS_META_REPLACE,"",output->xBin); */199 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YBIN",PS_META_REPLACE,"",output->yBin); */200 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XSIZE");201 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YSIZE");202 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.XSIZE",PS_META_REPLACE,"",numCols / output->xBin); */203 /* psMetadataAddS32(target->concepts,PS_LIST_TAIL,"CELL.YSIZE",PS_META_REPLACE,"",numRows / output->yBin); */204 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.XPARITY");205 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.YPARITY");206 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.X0");207 psMetadataItemSupplement(&status, target->concepts, source->concepts, "CELL.Y0");208 209 210 }211 212 // XXX this is not a sufficient test213 view->chip = 0;214 view->cell = 0;215 view->readout = -1;216 pmHDU *phu = pmFPAviewThisPHU(view, skycell->fpa); ///< Skycell PHU217 pmHDU *hdu = pmFPAviewThisHDU(view, skycell->fpa); ///< Skycell header218 219 pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header);220 221 double cd1f = 1.0 * output->xBin;222 double cd2f = 1.0 * output->yBin;223 224 WCS->crpix1 = WCS->crpix1 / cd1f;225 WCS->crpix2 = WCS->crpix2 / cd2f;226 227 WCS->cdelt1 *= cd1f;228 WCS->cdelt2 *= cd2f;229 230 WCS->trans->x->coeff[1][0] *= cd1f;231 WCS->trans->x->coeff[0][1] *= cd2f;232 WCS->trans->y->coeff[1][0] *= cd1f;233 WCS->trans->y->coeff[0][1] *= cd2f;234 235 236 pmAstromWCStoHeader (hdu->header,WCS);237 238 bool bilevelAstrometry = false;239 if (phu) {240 char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1");241 if (ctype) {242 bilevelAstrometry = !strcmp(&ctype[4], "-DIS");243 }244 }245 246 // We read from the skycell into the output. i.e., the output receives the desired astrometry.247 pmChip *outputChip = pmFPAviewThisChip(view, output->fpa); ///< Chip in the output248 if (bilevelAstrometry) {249 if (!pmAstromReadBilevelMosaic(output->fpa, phu->header)) {250 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for skycell.");251 psFree(view);252 return false;253 }254 if (!pmAstromReadBilevelChip(outputChip, hdu->header)) {255 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell.");256 psFree(view);257 return false;258 }259 } else {260 // we use a default FPA pixel scale of 1.0261 if (!pmAstromReadWCS(output->fpa, outputChip, hdu->header, 1.0)) {262 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell.");263 psFree(view);264 return false;265 }266 }267 268 269 view->chip = view->cell = view->readout = -1;270 pmFPAAddSourceFromView(output->fpa, view, output->format);271 272 273 psFree (view);274 return true;275 }
Note:
See TracChangeset
for help on using the changeset viewer.
