- Timestamp:
- May 8, 2013, 4:41:42 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130419/pswarp/src/pswarpDefineLayout.c
r35527 r35535 11 11 # include "pswarp.h" 12 12 13 bool pswarpGenerateOutputCell (pmChip *chip, pmCell *cell, pmCell *refcell, float xBin, float yBin); 14 13 15 // load the astrometry header info and generate the tranformations 14 16 bool pswarpDefineLayout (pmConfig *config) { … … 31 33 return false; 32 34 } 35 36 // if a background model is supplied and the output is requested, then 37 // this will exist. if not, skip related features 38 pmFPAfile *bkgModel = psMetadataLookupPtr(&status, config->files, "PSWARP.OUTPUT.BKGMODEL"); 33 39 34 40 // chips are not processed unless we have determined they overlap the inputs … … 54 60 astrom = input; 55 61 } 62 if (astrom->camera != input->camera) { 63 // XXX this may cause an error for output / skycell 64 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 65 return false; 66 } 56 67 if (!pswarpLoadAstrometry (input, astrom, config)) { 57 68 psError(PSWARP_ERR_CONFIG, false, "problem loading input astrometry\n"); … … 81 92 pmFPAview *view = pmFPAviewAlloc(0); 82 93 94 // check input astrometry mode 95 bool bilevelAstrometry = psMetadataLookupBool (NULL, skycell->fpa->analysis, "ASTROMETRY.BILEVEL"); 96 83 97 // generate the output hdu and contents bits 84 98 pmFPAAddSourceFromFormat(output->fpa, output->format); 99 100 // XXX this is a bit muddled : we are setting up the astrometry elements for the output 101 // background model here instead of in pswarpLoadAstrometry, where it would be more natural 102 // the only explanation I have is that 1) I need to have the binning factors for the input image, but 103 // 2) at this point I don't yet have the input background models loaded and 3) the source 104 // for the binning factor of the input and output background models is different 105 // (header->CCDSUMi for input, recipe / pmFPAfile.xbin.ybin for the other) 106 107 // if we have an output background model, generate hdu, etc and supply astrometry 108 if (bkgModel) { 109 pmFPAAddSourceFromFormat(bkgModel->fpa, bkgModel->format); 110 111 if (bilevelAstrometry) { 112 // top-level elements of the bkgModel astrometry 113 bkgModel->fpa->toTPA = psMemIncrRefCounter (skycell->fpa->toTPA); 114 bkgModel->fpa->fromTPA = psMemIncrRefCounter (skycell->fpa->fromTPA); 115 bkgModel->fpa->toSky = psMemIncrRefCounter (skycell->fpa->toSky); 116 } 117 } 85 118 86 119 pmChip *chip; … … 95 128 pmCell *refcell = pmFPAviewThisCell(view, skycell->fpa); ///< Target cell 96 129 97 // we've got the output astrom header 98 pmHDU *hdu = pmHDUFromCell(refcell); ///< HDU for source 99 if (!hdu || !hdu->header) { 100 psError(PM_ERR_PROG, false, "Unable to find header for sky cell."); 130 if (!pswarpGenerateOutputCell (chip, cell, refcell, output->xBin, output->yBin)){ 131 psError(PSWARP_ERR_DATA, false, "failed to generate output cell"); 101 132 psFree(view); 102 133 return false; 103 134 } 104 int numCols = psMetadataLookupS32(&status, hdu->header, "NAXIS1"); ///< Number of columns 105 int numRows = psMetadataLookupS32(&status, hdu->header, "NAXIS2"); ///< Number of rows 106 if ((numCols == 0) || (numRows == 0)) { 107 psError(PSWARP_ERR_DATA, false, "skycell has invalid dimensions %d x %d", numCols, numRows); 108 psFree(view); 109 return false; 135 136 if (bkgModel) { 137 pmChip *bkgChip = pmFPAviewThisChip(view, bkgModel->fpa); ///< Target cell 138 pmCell *bkgCell = pmFPAviewThisCell(view, bkgModel->fpa); ///< Target cell 139 if (!pswarpGenerateOutputCell (bkgChip, bkgCell, refcell, bkgModel->xBin, bkgModel->yBin)) { 140 psError(PSWARP_ERR_DATA, false, "failed to generate output cell"); 141 psFree(view); 142 return false; 143 } 144 if (!pswarpModifyChipAstrom (config, view, bkgChip, skycell, bilevelAstrometry, bkgModel->xBin, bkgModel->yBin)) { 145 psError(PSWARP_ERR_DATA, false, "problem with output astrometry"); 146 psFree(view); 147 return false; 148 } 110 149 } 111 112 // generate the pixels for output->fpa113 pmReadout *readout = pmReadoutAlloc(cell); ///< output readout114 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);115 116 psImageInit(readout->image, NAN);117 psFree(readout); // Drop reference118 119 // copy the image concepts from the skycell120 bool status = false;121 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.XBIN");122 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.YBIN");123 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.XSIZE");124 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.YSIZE");125 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.XPARITY");126 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.YPARITY");127 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.X0");128 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.Y0");129 130 chip->data_exists = true;131 chip->file_exists = true;132 cell->data_exists = true;133 cell->file_exists = true;134 135 // copy the basic headers across from astrom ref to output136 pmHDU *outHDU = pmHDUFromCell (cell); ///< HDU for the output warped image137 outHDU->header = psMetadataCopy(outHDU->header, hdu->header);138 pswarpVersionHeader(outHDU->header);139 150 } 140 151 } … … 143 154 } 144 155 145 // Lists of file rules used at different stages 146 # include "pswarpFileNames.h" 147 148 static int Nout = 0; 149 150 // XX function for tests 151 bool pswarpDumpOutput (pmConfig *config) { 152 153 pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT"); 154 if (!output) { 155 psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n"); 156 return false; 157 } 158 159 pswarpFileActivation(config, detectorFiles, false); 160 pswarpFileActivation(config, photFiles, false); 161 pswarpFileActivation(config, independentFiles, false); 162 pswarpFileActivation(config, skycellFiles, false); 163 pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT"); 164 165 pmFPAview *view = pmFPAviewAlloc(0); 166 167 pmChip *chip; 168 while ((chip = pmFPAviewNextChip (view, output->fpa, 1)) != NULL) { 169 psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 170 if (!chip->process || !chip->file_exists) { continue; } 171 172 pmCell *cell; 173 while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) { 174 psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 175 if (!cell->process || !cell->file_exists) { continue; } 176 177 // process each of the readouts 178 pmReadout *readout; 179 while ((readout = pmFPAviewNextReadout(view, output->fpa, 1)) != NULL) { 180 if (!readout->data_exists) { 181 continue; 182 } 183 184 char name[64]; 185 snprintf (name, 64, "dumpwarp.%02d.fits", Nout); 186 Nout ++; 156 bool pswarpGenerateOutputCell (pmChip *chip, pmCell *cell, pmCell *refcell, float xBin, float yBin) { 157 158 bool status = false; 159 160 // we've got the output astrom header 161 pmHDU *hdu = pmHDUFromCell(refcell); ///< HDU for source 162 if (!hdu || !hdu->header) { 163 psError(PM_ERR_PROG, false, "Unable to find header for sky cell."); 164 return false; 165 } 166 int numCols = psMetadataLookupS32(&status, hdu->header, "NAXIS1") / xBin; ///< Number of output columns 167 int numRows = psMetadataLookupS32(&status, hdu->header, "NAXIS2") / yBin; ///< Number of output rows 168 if ((numCols == 0) || (numRows == 0)) { 169 psError(PSWARP_ERR_DATA, false, "output cell has invalid dimensions %d x %d", numCols, numRows); 170 return false; 171 } 187 172 188 psphotSaveImage (NULL, readout->image, name); 189 } 190 } 191 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 192 psError(psErrorCodeLast(), false, "Unable to write files."); 193 goto DONE; 194 } 195 } 196 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 197 psError(psErrorCodeLast(), false, "Unable to write files."); 198 goto DONE; 199 } 200 psFree(view); 201 202 DONE: 203 204 pswarpFileActivation(config, detectorFiles, true); 205 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 173 // generate the pixels for output->fpa 174 pmReadout *readout = pmReadoutAlloc(cell); ///< output readout 175 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 176 177 psImageInit(readout->image, NAN); 178 psFree(readout); // Drop reference 179 180 // copy the image concepts from the skycell 181 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.XBIN"); 182 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.YBIN"); 183 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.XSIZE"); 184 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.YSIZE"); 185 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.XPARITY"); 186 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.YPARITY"); 187 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.X0"); 188 psMetadataItemSupplement(&status, cell->concepts, refcell->concepts, "CELL.Y0"); 189 190 chip->data_exists = true; 191 chip->file_exists = true; 192 chip->process = true; 193 194 cell->data_exists = true; 195 cell->file_exists = true; 196 cell->process = true; 197 198 // copy the basic headers across from astrom ref to output 199 pmHDU *outHDU = pmHDUFromCell (cell); ///< HDU for the output warped image 200 outHDU->header = psMetadataCopy(outHDU->header, hdu->header); 201 pswarpVersionHeader(outHDU->header); 206 202 return true; 207 } 208 203 }
Note:
See TracChangeset
for help on using the changeset viewer.
