Changeset 35535
- Timestamp:
- May 8, 2013, 4:41:42 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130419/pswarp/src
- Files:
-
- 1 added
- 15 edited
-
Makefile.am (modified) (1 diff)
-
pswarp.c (modified) (1 diff)
-
pswarp.h (modified) (2 diffs)
-
pswarpArguments.c (modified) (4 diffs)
-
pswarpDefineLayout.c (modified) (6 diffs)
-
pswarpLoadAstrometry.c (modified) (3 diffs)
-
pswarpLoop.c (modified) (9 diffs)
-
pswarpLoopBackground.c (modified) (3 diffs)
-
pswarpMakePSF.c (modified) (4 diffs)
-
pswarpMatchRange.c (modified) (1 diff)
-
pswarpOptions.c (added)
-
pswarpOverlaps.c (modified) (2 diffs)
-
pswarpParseCamera.c (modified) (3 diffs)
-
pswarpTransformReadout.c (modified) (4 diffs)
-
pswarpUpdateMetadata.c (modified) (4 diffs)
-
pswarpUpdateStatistics.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130419/pswarp/src/Makefile.am
r35527 r35535 44 44 pswarpMatchRange.c \ 45 45 pswarpOverlaps.c \ 46 pswarpOptions.c \ 46 47 pswarpParseCamera.c \ 47 48 pswarpPixelsLit.c \ -
branches/eam_branches/ipp-20130419/pswarp/src/pswarp.c
r35512 r35535 39 39 } 40 40 41 # if (1)42 // XXX I'm going to add the new code before removing the old code.43 41 // load the input & output astrometry, find the output overlaps, generate the output pixels 44 42 if (!pswarpDefineLayout(config)) { 45 43 pswarpCleanup(config, statsFile); 46 44 } 47 // load and warp 45 46 // load input pixels & and warp 48 47 if (!pswarpLoop(config, statsFile->md)) { 49 48 pswarpCleanup(config, statsFile); 50 49 } 51 50 52 # else 53 // load the skycell layout information: 54 // read the output astrometry description 55 // generate the output pixels 56 // convert header astrometry to pmFPA astrometry structures 57 if (!pswarpDefine(config)) { 58 pswarpCleanup(config, statsFile); 51 // load input pixels & and warp 52 if (!pswarpLoopBackground(config, statsFile->md)) { 53 pswarpCleanup(config, statsFile); 59 54 } 60 if (!pswarpDefineBackground(config)) {61 pswarpCleanup(config, statsFile);62 }63 // load and warp64 if (!pswarpLoopSkycell(config, statsFile->md)) {65 pswarpCleanup(config, statsFile);66 }67 if (!pswarpLoopBackground(config, statsFile->md)) {68 fprintf(stderr,"Dying!\n");69 pswarpCleanup(config, statsFile);70 }71 # endif72 55 56 // output and free 57 // NOTE: pswarpCleanup calls exit 73 58 psLogMsg("pswarp", PS_LOG_INFO, "complete pswarp run: %f sec\n", psTimerMark("pswarp")); 74 59 pswarpCleanup(config, statsFile); 75 60 } 76 77 // NOTE: pswarpCleanup calls exit78 79 // pswarpDumpOutput (config);80 // exit (0); -
branches/eam_branches/ipp-20130419/pswarp/src/pswarp.h
r35527 r35535 201 201 bool pswarpMakePSF (pmConfig *config, pmFPAfile *output, psMetadata *stats); 202 202 bool pswarpUpdateStatistics (pmFPA *output, psMetadata *stats, pmFPA *input, pmFPA *astrom, pmConfig *config); 203 bool pswarpUpdateMetadata (pmFPA *output, pmFPA * input, pmFPA *astrom, pmConfig *config);203 bool pswarpUpdateMetadata (pmFPA *output, pmFPA *skycell, pmFPA *input, pmFPA *astrom, pmConfig *config, bool fullImage); 204 204 205 205 // XXX functions in pswarpParseCamera … … 216 216 bool pswarpParseSingleInput (pmConfig *config); 217 217 bool pswarpParseMultiInput (pmConfig *config, psMetadata *fileListMD); 218 219 bool pswarpModifyChipAstrom (pmConfig *config, pmFPAview *view, pmChip *chip, pmFPAfile *astrom, bool bilevelAstrometry, double xBin, double yBin); 220 bool pswarpGetInputScales (double *xBin, double *yBin, pmConfig *config, pmFPAview *view, pmChip *chip); -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpArguments.c
r35527 r35535 12 12 13 13 # include "pswarp.h" 14 # include <glob.h>15 16 14 17 15 static void usage (void) { 18 fprintf(stderr, "USAGE: pswarp [- file image(s)] [-list imagelist] [options] (output) (skycell)\n");16 fprintf(stderr, "USAGE: pswarp [-input input.mdc] [-file image(s)] [-list imagelist] [options] (output) (skycell)\n"); 19 17 fprintf(stderr, " options:\n"); 18 fprintf(stderr, " [-input input.mdc] : input image information in a metadata file\n"); 19 fprintf(stderr, " [-file input.fits[,input.fits]] : input image to be warped\n"); 20 20 fprintf(stderr, " [-astrom astrom.cmp] : provide an alternative astrometry calibration\n"); 21 21 fprintf(stderr, " [-mask mask.fits] : provide a corresponding mask image\n"); … … 24 24 exit(PS_EXIT_CONFIG_ERROR); 25 25 } 26 27 26 28 27 pmConfig *pswarpArguments (int argc, char **argv) { … … 55 54 } 56 55 56 // XXX move to the single group below? 57 57 pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM", "-astrom", "-astromlist"); 58 58 59 { 60 int arg; ///< Argument Number 61 if ((arg = psArgumentGet(argc, argv, "-psphot-visual"))) { 62 psArgumentRemove(arg, &argc, argv); 63 pmVisualSetVisual(true); 64 } 59 // turn on psphot visualization 60 if ((N = psArgumentGet(argc, argv, "-psphot-visual"))) { 61 psArgumentRemove(N, &argc, argv); 62 pmVisualSetVisual(true); 65 63 } 66 64 … … 143 141 return config; 144 142 } 145 146 /**147 * Parse the recipe and format into the arguments148 */149 bool pswarpOptions(pmConfig *config)150 {151 // Select the appropriate recipe152 psMetadata *recipe = psMetadataLookupPtr(NULL, config->recipes, PSWARP_RECIPE);153 if (!recipe) {154 psError(PSWARP_ERR_CONFIG, true, "Can't find %s recipe!\n", PSWARP_RECIPE);155 return false;156 }157 158 // Get grid size159 bool status; ///< Status of MD lookup160 int nGridX = psMetadataLookupS32(&status, recipe, "GRID.NX");161 if (!status || nGridX <= 0) {162 nGridX = 128;163 psWarning("GRID.NX is not set in the recipe --- defaulting to %d", nGridX);164 }165 int nGridY = psMetadataLookupS32(&status, recipe, "GRID.NY");166 if (!status) {167 nGridY = 128;168 psWarning("GRID.NY is not set in the recipe --- defaulting to %d", nGridY);169 }170 171 // Get interpolation mode172 const char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); ///< Name of interp mode173 if (!name) {174 name = "BILINEAR";175 psLogMsg("pswarp", 3, "defaulting to %s interpolation", name);176 }177 psImageInterpolateMode interpolationMode = psImageInterpolateModeFromString(name); ///< Mode for interp.178 if (interpolationMode == PS_INTERPOLATE_NONE) {179 interpolationMode = PS_INTERPOLATE_BILINEAR;180 psLogMsg ("pswarp", 3,181 "Unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);182 name = "BILINEAR";183 }184 185 int numKernels = psMetadataLookupS32(&status, recipe, "INTERPOLATION.NUM");186 if (!status) {187 numKernels = 0;188 psWarning("INTERPOLATION.NUM is not set in the recipe --- defaulting to %d", numKernels);189 }190 191 float poorFrac = psMetadataLookupF32(&status, recipe, "POOR.FRAC"); ///< Frac of bad flux for a "poor"192 if (!status) {193 poorFrac = 0.0;194 psWarning("POOR.FRAC is not set in the %s recipe --- defaulting to %f.", PSWARP_RECIPE, poorFrac);195 }196 197 bool PSF = psMetadataLookupBool(&status, recipe, "PSF"); ///< Generate a PSF model?198 if (!status) {199 PSF = true;200 psWarning("PSF is not set in the %s recipe --- defaulting to TRUE.", PSWARP_RECIPE);201 }202 203 bool doBKG = psMetadataLookupBool(&status,recipe, "BACKGROUND.MODEL"); ///< Generate the warped background model?204 if (!status) {205 doBKG = false;206 psWarning("BACKGROUND.MODEL is not set in the %s recipe -- defaulting to FALSE.", PSWARP_RECIPE);207 }208 int bkgXgrid = psMetadataLookupS32(&status,recipe, "BKG.XGRID"); ///< Xsize of background model209 if (!status) {210 bkgXgrid = 10;211 psWarning("BKG.XGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgXgrid);212 }213 int bkgYgrid = psMetadataLookupS32(&status,recipe, "BKG.YGRID"); ///< Xsize of background model214 if (!status) {215 bkgYgrid = 10;216 psWarning("BKG.YGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgYgrid);217 }218 219 220 // Set recipe values in the recipe (since we've possibly altered some)221 psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NX", PS_META_REPLACE, "Iso-astrom grid spacing in x", nGridX);222 psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NY", PS_META_REPLACE, "Iso-astrom grid spacing in y", nGridY);223 psMetadataAddStr(recipe, PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "Interpolation mode", name);224 psMetadataAddS32(recipe, PS_LIST_TAIL, "INTERPOLATION.NUM", PS_META_REPLACE, "Interpolation pre-calculated kernels", numKernels);225 psMetadataAddF32(recipe, PS_LIST_TAIL, "POOR.FRAC", PS_META_REPLACE, "Fraction of bad flux for a pixel to be marked as poor", poorFrac);226 psMetadataAddBool(recipe, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);227 psMetadataAddBool(recipe, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);228 psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);229 psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);230 231 // Set recipe values in the arguments232 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0, "Iso-astrom grid spacing in x", nGridX);233 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NY", 0, "Iso-astrom grid spacing in y", nGridY);234 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.MODE", 0, "Interpolation mode", interpolationMode);235 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.NUM", 0, "Interpolation pre-calculated kernels", numKernels);236 psMetadataAddF32(config->arguments, PS_LIST_TAIL, "POOR.FRAC", 0, "Fraction of bad flux for a pixel to be marked as poor", poorFrac);237 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);238 psMetadataAddBool(config->arguments, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);239 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);240 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);241 242 psTrace("pswarp", 1, "Done with pswarpOptions...\n");243 244 return (config);245 } -
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 } -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpLoadAstrometry.c
r35449 r35535 25 25 astrom->type = PM_FPA_FILE_WCS; 26 26 27 // Read the pmFPA headers 27 // **** read in all of the headers from the astrometry source 28 28 29 pmFPAview *view = pmFPAviewAlloc(0); 29 30 … … 76 77 } 77 78 78 // the section below converts the header astrometry info (in astrom) to the pmFPA79 // astrometrystructures, saving them on the target fpa structure.79 // **** convert the header astrometry info (in astrom) to the pmFPA astrometry 80 // structures, saving them on the target fpa structure. 80 81 81 82 pmFPAviewReset (view); … … 97 98 } 98 99 } 100 psMetadataAddBool (astrom->fpa->analysis, PS_LIST_TAIL, "ASTROMETRY.BILEVEL", PS_META_REPLACE, "bilevel astrometry?", bilevelAstrometry); 101 99 102 // for pswarpLocalFrame, I need transformations and HDUs on a single fpa (so set on astrom as well as target) 100 103 // target->fpa->toTPA = psMemIncrRefCounter (astrom->fpa->toTPA); -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpLoop.c
r35527 r35535 1 1 /** @file pswarpLoop.c 2 2 * 3 * @brief mai lprocessing loop for pswarp3 * @brief main processing loop for pswarp 4 4 * @ingroup pswarp 5 5 * … … 13 13 #include "pswarpFileNames.h" // Lists of file rules used at different stages 14 14 15 // Loop over the inputs, warp them to the output skycell and then write out the output.15 // Loop over the inputs, warp them to the output skycell and then update metadata 16 16 bool pswarpLoop(pmConfig *config, psMetadata *stats) 17 17 { 18 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments,19 "SKYCELL.CAMERA"); // Name of camera for skycell20 pmConfigCamerasCull(config, skyCamera);21 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");22 18 23 19 // load the recipe … … 26 22 if (!recipe) { 27 23 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 28 return false;29 }30 31 // XXX move this to pswarpParseCamera? has to come after input mask header is read32 if (!pswarpSetMaskBits(config)) {33 psError(psErrorCodeLast(), false, "failed to set mask bits");34 24 return false; 35 25 } … … 66 56 } 67 57 68 fprintf (stderr, "loading file %s\n", input->filename); 69 70 // use the external astrometry source if supplied 58 // select the input data sources 71 59 pmFPAfile *astrom = pmFPAfileSelectSingle(config->files, "PSWARP.ASTROM", i); 72 60 if (!astrom) { … … 74 62 } 75 63 76 if (astrom->camera != input->camera) { 77 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 78 return false; 79 } 80 81 // ensure everyone is off except what we need below 82 pswarpFileActivation(config, detectorFiles, false); 64 // ensure everyone is off except what we need below 65 // XXX double-check activation issues in general 66 pswarpFileActivation(config, detectorFiles, true); 83 67 pswarpFileActivation(config, photFiles, false); 84 68 pswarpFileActivation(config, independentFiles, false); 85 69 pswarpFileActivation(config, skycellFiles, false); 86 70 87 // the loops below load the input data 88 pswarpFileActivation(config, detectorFiles, true); 89 90 // need to read in these (but only if CMF, right?) 71 // We re-activate the CMF load so we can transform the sources as well as the pixels. 72 // We only need to read in these if the astrometry source is CMF. 91 73 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 92 93 // pswarpFileActivation(config, independentFiles, true);94 74 95 75 pmFPAviewReset (view); … … 174 154 goto FAIL; 175 155 } 176 if (!pswarpUpdateMetadata (output->fpa, input->fpa, astrom->fpa, config)) {156 if (!pswarpUpdateMetadata (output->fpa, skycell->fpa, input->fpa, astrom->fpa, config, true)) { 177 157 psError(psErrorCodeLast(), false, "problem generating statistics."); 178 158 goto FAIL; … … 184 164 goto FAIL; 185 165 } 186 187 // XXX188 // pswarpDumpOutput (config);189 // exit (0);190 166 191 167 psFree(view); … … 196 172 return false; 197 173 } 198 199 // static int Nout = 0;200 174 201 175 // once the output fpa elements have been built, loop over the fpa and generate stats … … 219 193 while ((readout = pmFPAviewNextReadout(view, output, 1)) != NULL) { 220 194 pswarpTransformReadout (readout, input, config); 221 // char name[64];222 // snprintf (name, 64, "dumpwarp.%02d.fits", Nout);223 // Nout ++;224 //225 // psphotSaveImage (NULL, readout->image, name);226 195 } 227 196 } -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpLoopBackground.c
r35421 r35535 11 11 12 12 #include "pswarp.h" 13 #include <ppStats.h>14 13 #include "pswarpFileNames.h" // Lists of file rules used at different stages 15 14 … … 22 21 bool status; 23 22 bool mdok; // Status of MD lookup 24 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 25 "SKYCELL.CAMERA"); // Name of camera for skycell 23 26 24 if (!psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) return true; 27 25 28 pmConfigCamerasCull(config, skyCamera); 29 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 26 int xGrid = psMetadataLookupS32(&mdok,config->arguments,"BKG.XGRID"); 27 int yGrid = psMetadataLookupS32(&mdok,config->arguments,"BKG.YGRID"); 28 29 // WHAT IS THIS?? should it be disabled at the end? 30 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8); 30 31 31 32 // load the recipe … … 36 37 } 37 38 38 if (!pswarpSetMaskBits(config)) {39 psError(psErrorCodeLast(), false, "failed to set mask bits");40 return NULL;41 }42 43 39 // select the input data sources 44 pmFPAfile * input = psMetadataLookupPtr(NULL, config->files, "PSWARP.BKGMODEL");45 if (! input) {46 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");40 pmFPAfile *output = psMetadataLookupPtr(&status, config->files, "PSWARP.OUTPUT.BKGMODEL"); 41 if (!output) { 42 psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n"); 47 43 return false; 48 44 } 49 45 50 46 // use the external astrometry source if supplied 51 pmFPAfile *astrom = psMetadataLookupPtr(NULL, config->files, "PSWARP.ASTROM"); 52 if (!astrom) { 53 astrom = input; 54 } 55 56 if (astrom->camera != input->camera) { 57 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 58 return false; 59 } 60 61 // select the output readout 47 pmFPAfile *skycell = psMetadataLookupPtr(&status, config->files, "PSWARP.SKYCELL"); 48 if (!skycell) { 49 psError(PSWARP_ERR_DATA, true, "Cannot find output astrometry."); 50 return false; 51 } 52 62 53 pmFPAview *view = pmFPAviewAlloc(0); 63 view->chip = 0; 64 view->cell = 0; 65 view->readout = 0; 66 pmReadout *output = pmFPAfileThisReadout(config->files, view, "PSWARP.OUTPUT.BKGMODEL"); 67 if (!output) { 68 psError(PSWARP_ERR_CONFIG, true, "Can't find output background data!\n"); 69 return false; 70 } 54 55 int nInputs = psMetadataLookupS32(&status, config->arguments, "NUM_INPUTS"); 56 if (!status) { 57 psError(PSWARP_ERR_DATA, true, "number of inputs is not defined (programming error)"); 58 return false; 59 } 60 61 // loop over this section once per input group 62 for (int i = 0; i < nInputs; i++) { 63 64 // select the input data source : we are reading & transforming pixels for the background model 65 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PSWARP.BKGMODEL", i); 66 if (!input) { 67 psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n"); 68 return false; 69 } 70 71 // select the input data sources 72 pmFPAfile *astrom = pmFPAfileSelectSingle(config->files, "PSWARP.ASTROM", i); 73 if (!astrom) { 74 astrom = input; 75 } 76 77 // check input astrometry mode 78 bool bilevelAstrometry = psMetadataLookupBool (NULL, astrom->fpa->analysis, "ASTROMETRY.BILEVEL"); 79 if (bilevelAstrometry) { 80 // top-level elements of the input model astrometry 81 input->fpa->toTPA = psMemIncrRefCounter (astrom->fpa->toTPA); 82 input->fpa->fromTPA = psMemIncrRefCounter (astrom->fpa->fromTPA); 83 input->fpa->toSky = psMemIncrRefCounter (astrom->fpa->toSky); 84 } 85 86 // we only need to load the background models here 87 pswarpFileActivation(config, detectorFiles, false); 88 pswarpFileActivation(config, photFiles, false); 89 pswarpFileActivation(config, independentFiles, false); 90 pswarpFileActivation(config, skycellFiles, false); 91 92 // we are only reading the background models, not writing anything 93 pmFPAfileActivate(config->files, true, "PSWARP.BKGMODEL"); 94 95 pmFPAviewReset (view); 96 97 pmFPAview *view = pmFPAviewAlloc(0); 98 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 99 psError(psErrorCodeLast(), false, "Unable to read files."); 100 goto FAIL; 101 } 102 103 pmChip *chip; 104 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 105 if (!chip->process || !chip->file_exists) { continue; } 106 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 107 psError(psErrorCodeLast(), false, "Unable to read files."); 108 goto FAIL; 109 } 110 111 // adjust output astrometry 112 double xBin = NAN; 113 double yBin = NAN; 114 pswarpGetInputScales (&xBin, &yBin, config, view, chip); 115 double fluxRatio = xBin * yBin / (float) (xGrid * yGrid); 116 117 if (!pswarpModifyChipAstrom (config, view, chip, astrom, bilevelAstrometry, xBin, yBin)) { 118 psError(psErrorCodeLast(), false, "failed to set BKGMODEL astrometry."); 119 goto FAIL; 120 } 121 122 pmCell *cell; 123 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 124 psTrace ("pswarp", 4, "ACell %d: %x %x %d\n", view->cell, cell->file_exists, cell->process,psErrorCodeLast()); 125 if (!cell->process || !cell->file_exists) { continue; } 126 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 127 psError(psErrorCodeLast(), false, "Unable to read files."); 128 goto FAIL; 129 } 130 131 // process each of the readouts 132 pmReadout *readout; 133 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 134 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 135 psError(psErrorCodeLast(), false, "Unable to read files."); 136 goto FAIL; 137 } 138 if (!readout->data_exists) { 139 continue; 140 } 141 142 // re-normalize the BKGMODEL pixels by modified astrometry 143 for (int x = 0; x < readout->image->numCols; x++) { 144 for (int y = 0; y < readout->image->numRows; y++) { 145 readout->image->data.F32[y][x] *= fluxRatio; 146 } 147 } 148 149 // transform the actual BKGMODEL pixels from readout to output 150 // XXX replace the use of this temporary metadata item with an argument? 151 // XXX move the source transform out of pswarpTransformReadout? 152 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", true); 153 pswarpTransformToTarget (output->fpa, readout, config); 154 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false); 155 156 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { // Readout 157 psError(psErrorCodeLast(), false, "Unable to close files."); 158 goto FAIL; 159 } 160 } 161 162 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { // Cell 163 psError(psErrorCodeLast(), false, "Unable to close files."); 164 goto FAIL; 165 } 166 } 167 168 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { // Chip 169 psError(psErrorCodeLast(), false, "Unable to close files."); 170 goto FAIL; 171 } 172 } 173 174 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { // FPA 175 psError(psErrorCodeLast(), false, "Unable to close files."); 176 goto FAIL; 177 } 178 179 if (false && !pswarpUpdateMetadata (output->fpa, skycell->fpa, input->fpa, astrom->fpa, config, false)) { 180 psError(psErrorCodeLast(), false, "problem generating statistics."); 181 goto FAIL; 182 } 183 } 184 71 185 psFree (view); 72 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 73 // the input, which is in a different format. 74 { 75 pswarpFileActivation(config, detectorFiles, false); 76 pswarpFileActivation(config, photFiles, false); 77 pswarpFileActivation(config, independentFiles, false); 78 pswarpFileActivation(config, skycellFiles, true); 79 if (!pswarpIOChecksBefore(config)) { 80 psError(psErrorCodeLast(), false, "Unable to read files."); 81 goto DONE; 82 } 83 pswarpFileActivation(config, skycellFiles, false); 84 } 85 // Read the input astrometry 86 // XXX rather than use the activations here, this should just explicitly loop over the desired filerule 87 { 88 89 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 90 91 pmChip *chip; 92 pmFPAview *view = pmFPAviewAlloc(0); 93 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 94 psError(psErrorCodeLast(), false, "Unable to read files."); 95 goto DONE; 96 } 97 98 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 99 #if 0 100 // This needs to be removed because otherwise it throws an error of duplicate PSPHOT.DETECTIONS. 101 if (!chip->process || !chip->file_exists) { continue; } 102 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 103 psError(psErrorCodeLast(), false, "Unable to read files."); 104 goto DONE; 105 } 106 #endif 107 pmCell *cell; 108 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 109 psTrace ("pswarp", 4, "ACell %d: %x %x %d\n", view->cell, cell->file_exists, cell->process,psErrorCodeLast()); 110 if (!cell->process || !cell->file_exists) { continue; } 111 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) || 112 !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 113 psError(psErrorCodeLast(), false, "Unable to read files."); 114 goto DONE; 115 } 116 } 117 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 118 psError(psErrorCodeLast(), false, "Unable to write files."); 119 goto DONE; 120 } 121 } 122 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 123 psError(psErrorCodeLast(), false, "Unable to write files."); 124 goto DONE; 125 } 126 psFree(view); 127 pswarpFileActivation(config, detectorFiles, true); 128 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 129 } 130 131 // Don't care about the skycell anymore --- we've read it, and that's all we need to do. 132 pmFPAfileActivate(config->files, false, "PSWARP.SKYCELL"); 133 view = pmFPAviewAlloc(0); 134 135 // find the FPA phu 136 bool bilevelAstrometry = false; 137 pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa); 138 139 // pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header); 140 141 if (phu) { 142 char *ctype = psMetadataLookupStr(NULL, phu->header, "CTYPE1"); 143 if (ctype) { 144 bilevelAstrometry = !strcmp (&ctype[4], "-DIS"); 145 } 146 } 147 if (bilevelAstrometry) { 148 if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) { 149 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA."); 150 psFree(view); 151 psFree(stats); 152 goto DONE; 153 } 154 } 155 156 psList *cells = psListAlloc(NULL); // List of cells, for concepts averaging 157 158 // files associated with the science image 159 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 160 psError(psErrorCodeLast(), false, "Unable to read files."); 161 goto DONE; 162 } 163 pmChip *chip; 164 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 165 psTrace ("pswarp", 4, "DChip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 166 if (!chip->process || !chip->file_exists) { continue; } 167 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 168 psError(psErrorCodeLast(), false, "Unable to read files."); 169 goto DONE; 170 } 171 172 // Pull information from the header of the background files so we can use it to set values. 173 pmHDU *hdu = pmFPAviewThisHDU(view,input->fpa); 174 psMetadata *header = hdu->header; 186 return true; 187 188 FAIL: 189 psFree (view); 190 return false; 191 } 192 193 // **** input == (small) BKGMODEL, astrom == (fullsize) ASTROM 194 // use astrometry from input ref astrometry and BINNING info from input model to modify the astrometry 195 // elements of input chip. scale is the area of an input pixel is raw image pixels 196 bool pswarpGetInputScales (double *xBin, double *yBin, pmConfig *config, pmFPAview *view, pmChip *chip) { 197 198 // Pull information from the header of the background files so we can use it to set values. 199 pmHDU *hdu = pmFPAviewThisHDU(view, chip->parent); 200 psMetadata *header = hdu->header; 175 201 176 int IMAXIS1 = psMetadataLookupS32(NULL,header,"IMNAXIS1");177 int IMAXIS2 = psMetadataLookupS32(NULL,header,"IMNAXIS2");178 int NAXIS1 = psMetadataLookupS32(NULL,header,"NAXIS1");179 int NAXIS2 = psMetadataLookupS32(NULL,header,"NAXIS2");180 char *CCDSUM = psMetadataLookupStr(NULL,header,"CCDSUM");181 int CCDSUM1 = atoi(strtok(CCDSUM," "));182 int CCDSUM2 = atoi(strtok(NULL," "));202 int IMAXIS1 = psMetadataLookupS32(NULL,header,"IMNAXIS1"); 203 int IMAXIS2 = psMetadataLookupS32(NULL,header,"IMNAXIS2"); 204 int NAXIS1 = psMetadataLookupS32(NULL,header,"NAXIS1"); 205 int NAXIS2 = psMetadataLookupS32(NULL,header,"NAXIS2"); 206 char *CCDSUM = psMetadataLookupStr(NULL,header,"CCDSUM"); 207 int CCDSUM1 = atoi(strtok(CCDSUM," ")); 208 int CCDSUM2 = atoi(strtok(NULL," ")); 183 209 184 psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_XOFFSET", PS_META_REPLACE, 185 "xoffset for background model data", (NAXIS1 * CCDSUM1 - IMAXIS1) / (2.0 * CCDSUM1)); 186 psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_YOFFSET", PS_META_REPLACE, 187 "yoffset for background model data", (NAXIS2 * CCDSUM2 - IMAXIS2) / (2.0 * CCDSUM2)); 188 psTrace("pswarp",5,"%d %d %d %d %d %d %g %g %d %d", 189 psMetadataLookupS32(NULL,header,"IMNAXIS1"), 190 psMetadataLookupS32(NULL,header,"IMNAXIS2"), 191 psMetadataLookupS32(NULL,header,"NAXIS1"), 192 psMetadataLookupS32(NULL,header,"NAXIS2"), 193 CCDSUM1,CCDSUM2, 194 psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"), 195 psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"), 196 psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"), 197 psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID")); 198 199 200 // read WCS data from the corresponding header 201 hdu = pmFPAviewThisHDU (view, astrom->fpa); 202 203 pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header); 204 205 double cd1f = (1.0 * CCDSUM1);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID")); 206 double cd2f = (1.0 * CCDSUM2);// * (1.0 * psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID")); 207 208 WCS->cdelt1 *= cd1f; 209 WCS->cdelt2 *= cd2f; 210 WCS->crpix1 = WCS->crpix1 / cd1f; 211 WCS->crpix2 = WCS->crpix2 / cd2f; 212 213 // WCS->trans->x->nX/nY 214 for (int q = 0; q <= WCS->trans->x->nX; q++) { 215 for (int r = 0; r <= WCS->trans->x->nY; r++) { 216 WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 217 } 218 } 219 for (int q = 0; q <= WCS->trans->y->nX; q++) { 220 for (int r = 0; r <= WCS->trans->y->nY; r++) { 221 WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 222 } 223 } 224 pmAstromWCStoHeader (hdu->header,WCS); 225 226 if (bilevelAstrometry) { 227 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 228 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 229 psFree(view); 230 psFree(stats); 231 goto DONE; 232 } 233 } else { 234 // we use a default FPA pixel scale of 1.0 235 if (!pmAstromReadWCS (astrom->fpa, chip, hdu->header, 1.0)) { 236 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 237 psFree(view); 238 psFree(stats); 239 goto DONE; 240 } 241 } 242 // Modify structure here. 243 244 245 pmCell *cell; 246 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 247 psTrace ("pswarp", 4, "DCell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 248 if (!cell->process || !cell->file_exists) { continue; } 249 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 250 psError(psErrorCodeLast(), false, "Unable to read files."); 251 goto DONE; 252 } 253 254 psListAdd(cells, PS_LIST_TAIL, cell); 255 256 // process each of the readouts 257 pmReadout *readout; 258 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 259 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 260 psError(psErrorCodeLast(), false, "Unable to read files."); 261 goto DONE; 262 } 263 if (!readout->data_exists) { 264 continue; 265 } 266 267 for (int x = 0; x < readout->image->numCols; x++) { 268 for (int y = 0; y < readout->image->numRows; y++) { 269 readout->image->data.F32[y][x] = readout->image->data.F32[y][x] * (cd1f * cd2f) / 270 (psMetadataLookupS32(&mdok,config->arguments,"BKG.XGRID") * 271 psMetadataLookupS32(&mdok,config->arguments,"BKG.YGRID")); 272 } 273 } 274 275 psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8); 276 277 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", true); 278 pswarpTransformReadout(output, readout, config); 279 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false); 280 281 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 282 psError(psErrorCodeLast(), false, "Unable to write files."); 283 goto DONE; 284 } 285 } 286 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 287 psError(psErrorCodeLast(), false, "Unable to write files."); 288 goto DONE; 289 } 290 } 291 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 292 psError(psErrorCodeLast(), false, "Unable to write files."); 293 goto DONE; 294 } 295 } 296 if (!output->data_exists) { 297 psWarning("No overlap between input and skycell."); 298 psphotFilesActivate(config, false); 299 psFree(cells); 300 psFree(view); 301 goto DONE; 302 } 303 pmCell *outCell = output->parent; ///< Output cell 304 pmChip *outChip = outCell->parent; ///< Output chip 305 pmFPA *outFPA = outChip->parent; ///< Output FP 306 307 /* if (!pswarpPixelsLit(output, stats, config)) { */ 308 /* psError(psErrorCodeLast(), false, "Unable to calculate pixel regions."); */ 309 /* psFree(cells); */ 310 /* psFree(view); */ 311 /* goto DONE; */ 312 /* } */ 313 psRegion *trimsec = psMetadataLookupPtr(NULL, outCell->concepts, "CELL.TRIMSEC"); ///< Trim section 314 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels 315 316 if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) { 317 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output."); 318 psFree(stats); 319 psFree(view); 320 goto DONE; 321 } 322 323 pmHDU *hdu = outFPA->hdu; ///< HDU for the output warped image 324 325 // Copy header from target 326 { 327 pmFPAview *skyView = pmFPAviewAlloc(0); ///< View into skycell 328 skyView->chip = skyView->cell = 0; 329 pmCell *cell = pmFPAfileThisCell(config->files, skyView, "PSWARP.SKYCELL"); // Skycell cell 330 psFree(skyView); 331 pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU 332 if (!skyHDU) { 333 psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU."); 334 psFree(view); 335 goto DONE; 336 } 337 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); 338 } 339 pswarpVersionHeader(hdu->header); 340 341 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) { 342 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 343 psFree(stats); 344 goto DONE; 345 } 346 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 347 psError(psErrorCodeLast(), false, "Unable to write files."); 348 goto DONE; 349 } 350 // Done with the detector side of things 351 pswarpFileActivation(config, detectorFiles, false); 352 pswarpFileActivation(config, independentFiles, false); 353 354 // Add MD5 information for readout 355 const char *chipName = psMetadataLookupStr(NULL, output->parent->parent->concepts, "CHIP.NAME"); 356 const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME"); 357 psString headerName = NULL; ///< Header name for MD5 358 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout); 359 psVector *md5 = psImageMD5(output->image); ///< md5 hash 360 psString md5string = psMD5toString(md5); ///< String 361 psFree(md5); 362 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, 363 "Image MD5", md5string); 364 psFree(md5string); 365 psFree(headerName); 366 psFree(view); 367 DONE: 210 psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_XOFFSET", PS_META_REPLACE, "xoffset for background model data", (NAXIS1 * CCDSUM1 - IMAXIS1) / (2.0 * CCDSUM1)); 211 psMetadataAddF32(config->arguments,PS_LIST_TAIL,"BKG_WARP_YOFFSET", PS_META_REPLACE, "yoffset for background model data", (NAXIS2 * CCDSUM2 - IMAXIS2) / (2.0 * CCDSUM2)); 212 213 psTrace("pswarp",5,"%d %d %d %d %d %d %g %g %d %d", 214 psMetadataLookupS32(NULL,header,"IMNAXIS1"), 215 psMetadataLookupS32(NULL,header,"IMNAXIS2"), 216 psMetadataLookupS32(NULL,header,"NAXIS1"), 217 psMetadataLookupS32(NULL,header,"NAXIS2"), 218 CCDSUM1,CCDSUM2, 219 psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"), 220 psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"), 221 psMetadataLookupS32(NULL,config->arguments,"BKG.XGRID"), 222 psMetadataLookupS32(NULL,config->arguments,"BKG.YGRID")); 223 224 *xBin = CCDSUM1; 225 *yBin = CCDSUM2; 368 226 369 227 return true; 370 228 } 229 230 // **** input == (small) BKGMODEL, astrom == (fullsize) ASTROM 231 // use astrometry from input ref astrometry and BINNING info from input model to modify the astrometry 232 // elements of input chip. scale is the area of an input pixel is raw image pixels 233 bool pswarpModifyChipAstrom (pmConfig *config, pmFPAview *view, pmChip *chip, pmFPAfile *astrom, bool bilevelAstrometry, double xBin, double yBin) { 234 235 // read WCS data from the corresponding header 236 pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa); 237 238 // generate a WCS structure from the ASTROM header keywords 239 pmAstromWCS *WCS = pmAstromWCSfromHeader(hdu->header); 240 241 // re-scale the terms of the WCS to match the BKGMODEL scale 242 double cd1f = xBin; 243 double cd2f = yBin; 244 245 WCS->cdelt1 *= cd1f; 246 WCS->cdelt2 *= cd2f; 247 WCS->crpix1 = WCS->crpix1 / cd1f; 248 WCS->crpix2 = WCS->crpix2 / cd2f; 249 250 // WCS->trans->x->nX/nY 251 // adjust the scale of the WCS coeffs 252 for (int q = 0; q <= WCS->trans->x->nX; q++) { 253 for (int r = 0; r <= WCS->trans->x->nY; r++) { 254 WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 255 } 256 } 257 for (int q = 0; q <= WCS->trans->y->nX; q++) { 258 for (int r = 0; r <= WCS->trans->y->nY; r++) { 259 WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 260 } 261 } 262 263 // this is a bit crude : use a locally temporary header to store the WCS information 264 // which is then applied to the input chip (why not modify the input chip header?) 265 psMetadata *tmpHeader = psMetadataAlloc(); 266 267 // write the modified WCS to the header 268 // XXX this should probably not modify the astrom header 269 pmAstromWCStoHeader (tmpHeader, WCS); 270 271 // use the modified header to update the WCS elements of the BKGMODEL fpa/chip structures 272 if (bilevelAstrometry) { 273 if (!pmAstromReadBilevelChip (chip, tmpHeader)) { 274 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 275 return false; 276 } 277 } else { 278 // we use a default FPA pixel scale of 1.0 279 if (!pmAstromReadWCS (chip->parent, chip, tmpHeader, 1.0)) { 280 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 281 return false; 282 } 283 } 284 285 return true; 286 } -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpMakePSF.c
r35521 r35535 11 11 12 12 #include "pswarp.h" 13 14 #define WCS_NONLIN_TOL 0.001 // Non-linear tolerance for header WCS15 #define TESTING 0 // Testing output?16 13 17 14 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but … … 34 31 } 35 32 36 // XXX What was being read here?? skip this for now 37 if (false && !pswarpIOChecksBefore(config)) { 38 psError(psErrorCodeLast(), false, "Unable to read files."); 39 return false; 40 } 41 33 // XXX move above the loop 34 pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); 35 42 36 // supply the readout and fpa of interest to psphot 43 37 pmFPAfile *photFile = psMetadataLookupPtr(&status, config->files, "PSPHOT.INPUT"); … … 71 65 } 72 66 73 // XXX move above the loop74 pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT);75 76 67 // measure the PSF using these sources 77 68 if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) { … … 96 87 item->data.F32 = psMetadataLookupF32(&status, chip->concepts, "CHIP.SEEING"); 97 88 } 98 99 // XXX test function found below100 // pswarpMakePSF_test ();101 89 102 90 psFree(view); -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpMatchRange.c
r35434 r35535 98 98 99 99 // demo forward and backward transformation 100 # if ( 1)100 # if (0) 101 101 srcPix->x = *minX; 102 102 srcPix->y = *minY; -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpOverlaps.c
r35525 r35535 83 83 } 84 84 } 85 // fprintf (stderr, "bounds %d : %f - %f, %f - %f\n", view->chip, Pmin, Pmax, Qmin, Qmax);86 85 pswarpBoundsAppend (bounds, Pmin, Pmax, Qmin, Qmax); 87 86 } … … 215 214 pmChip *inputChip = inputChips->data[nChip]; 216 215 for (int nCell = 0; nCell < inputChip->cells->n; nCell++) { 217 fprintf (stderr, "input %d, %d : output %d\n", nChip, nCell, j);218 216 psArrayAdd (inputCells, 8, inputChip->cells->data[nCell]); 219 217 } -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpParseCamera.c
r35527 r35535 38 38 } 39 39 40 // once we have read the input mask headers (if any), we can use that to set the mask bits 41 if (!pswarpSetMaskBits(config)) { 42 psError(psErrorCodeLast(), false, "failed to set mask bits"); 43 return false; 44 } 45 40 46 // *** parse the output information (output target, output astrometry [skycell]) 41 47 … … 95 101 // only create an output background if an input background is supplied 96 102 if (foundBackground && psMetadataLookupBool(&status, recipe, "BACKGROUND.MODEL")) { 97 pmFPAfile *outBackground = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT.BKGMODEL"); 98 outBackground->xBin = psMetadataLookupS32(&status, recipe, "BKG.XGRID"); 99 outBackground->yBin = psMetadataLookupS32(&status, recipe, "BKG.YGRID"); 100 101 if (!outBackground) { 102 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.BKGMODEL"); 103 return false; 104 } 105 outBackground->save = true; 103 // pmFPAfile *outBackground = pmFPAfileDefineSkycell(config, NULL, "PSWARP.OUTPUT.BKGMODEL"); 104 pmFPAfile *outBackground = pmFPAfileDefineOutputForFormat(config, NULL, "PSWARP.OUTPUT.BKGMODEL", skycell->cameraName, skycell->formatName); 105 outBackground->xBin = psMetadataLookupS32(&status, recipe, "BKG.XGRID"); 106 outBackground->yBin = psMetadataLookupS32(&status, recipe, "BKG.YGRID"); 107 108 if (!outBackground) { 109 psError(psErrorCodeLast(), false, "Failed to build FPA from PSWARP.OUTPUT.BKGMODEL"); 110 return false; 111 } 112 outBackground->save = true; 106 113 } 107 114 … … 152 159 } 153 160 161 // only keep the necessary (output) camera configs and relevant recipes 162 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, "SKYCELL.CAMERA"); 163 pmConfigCamerasCull(config, skyCamera); 164 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 165 154 166 psTrace("pswarp", 1, "Done with pswarpParseCamera...\n"); 155 167 return true; -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpTransformReadout.c
r35434 r35535 48 48 psAssert(mdok, "MASK.INPUT was not defined"); 49 49 50 bool backgroundWarp = psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING"); 51 50 52 if (!input->covariance) { 51 53 input->covariance = psImageCovarianceNone(); 52 54 } 53 55 54 // XXX unused int nThreads = psMetadataLookupS32(&mdok, config->arguments, "NTHREADS"); // Number of threads55 // XXX unused if (!mdok) {56 // XXX unused nThreads = 0;57 // XXX unused }58 56 float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); ///< Flux fraction for "poor" 59 57 … … 61 59 // output coordinates to input coordinates 62 60 pswarpMapGrid *grid = pswarpMapGridFromImage(input, output, nGridX, nGridY); 63 // if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {64 61 65 62 // XXX optionally modify the grid based on this result and force the maxError < XXX … … 118 115 psAssert (yGridMax < grid->nYpts, "yGridMax too big\n"); 119 116 120 fprintf (stderr, "warp %d,%d - %d,%d\n", xGridMin, yGridMin, xGridMax, yGridMax);117 // fprintf (stderr, "warp %d,%d - %d,%d\n", xGridMin, yGridMin, xGridMax, yGridMax); 121 118 122 119 // create jobs and supply them to the threads … … 134 131 args->goodPixels = 0; 135 132 136 if ( psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) {133 if (backgroundWarp) { 137 134 args->background_warping = true; 138 135 args->offset_x = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_XOFFSET"); 139 136 args->offset_y = psMetadataLookupF32(NULL,config->arguments,"BKG_WARP_YOFFSET"); 140 137 } 141 142 138 143 139 // allocate a job -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpUpdateMetadata.c
r35527 r35535 10 10 11 11 #include "pswarp.h" 12 #define WCS_NONLIN_TOL 0.001 // Non-linear tolerance for header WCS 12 13 13 // once the output fpa elements have been built, loop over the fpa and generate stats 14 // for each readout 15 bool pswarpUpdateMetadata (pmFPA *output, pmFPA *input, pmFPA *astrom, pmConfig *config) { 14 // once the output fpa elements have been built, loop over the fpa and generate metadata 15 bool pswarpUpdateMetadata (pmFPA *output, pmFPA *skycell, pmFPA *input, pmFPA *astrom, pmConfig *config, bool fullImage) { 16 16 17 17 pmFPAview *view = pmFPAviewAlloc(0); 18 18 19 // check output astrometry mode 20 bool bilevelAstrometry = psMetadataLookupBool (NULL, skycell->analysis, "ASTROMETRY.BILEVEL"); 21 19 22 pmChip *chip; 20 23 while ((chip = pmFPAviewNextChip (view, output, 1)) != NULL) { … … 39 42 if (!readout->data_exists) continue; 40 43 41 // Set covariance matrix for output 42 # if (0) 43 psList *covariances = psMetadataLookupPtr(&mdok, output->analysis, PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices 44 psAssert(covariances, "Should be there"); 45 psArray *covars = psListToArray(covariances); // Array of covariance matrices 46 psKernel *covar = psImageCovarianceAverage(covars); 47 psFree(covars); 48 psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES); 44 if (fullImage) { 45 // Set covariance matrix for output 46 bool status = false; 47 psList *covariances = psMetadataLookupPtr(&status, readout->analysis, PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices 48 psAssert(covariances, "Should be there"); 49 psArray *covars = psListToArray(covariances); // Array of covariance matrices 50 psKernel *covar = psImageCovarianceAverage(covars); 51 psFree(covars); 52 psMetadataRemoveKey(readout->analysis, PSWARP_ANALYSIS_COVARIANCES); 49 53 50 // Correct covariance matrix scale for the mean (square root of the) Jacobian51 double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian52 int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX); // Good pixels53 jacobian /= goodPixels;54 output->covariance = psImageCovarianceScale(covar, jacobian);55 psFree(covar);54 // Correct covariance matrix scale for the mean (square root of the) Jacobian 55 double jacobian = psMetadataLookupF64(NULL, readout->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian 56 int goodPixels = psMetadataLookupS32(NULL, readout->analysis, PSWARP_ANALYSIS_GOODPIX); // Good pixels 57 jacobian /= goodPixels; 58 readout->covariance = psImageCovarianceScale(covar, jacobian); 59 psFree(covar); 56 60 57 if (output->variance) { 58 psImageCovarianceTransfer(output->variance, output->covariance); 61 if (readout->variance) { 62 psImageCovarianceTransfer(readout->variance, readout->covariance); 63 } 59 64 } 60 # endif61 65 62 { 63 // Add MD5 information for readout 64 psString headerName = NULL; ///< Header name for MD5 65 psVector *md5 = psImageMD5(readout->image); ///< md5 hash 66 psString md5string = psMD5toString(md5); ///< String 67 68 pmHDU *hdu = pmHDUFromReadout(readout); 69 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout); 70 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, "Image MD5", md5string); 71 psFree(md5); 72 psFree(md5string); 73 psFree(headerName); 74 } 66 // Add MD5 information for readout 67 psString headerName = NULL; ///< Header name for MD5 68 psVector *md5 = psImageMD5(readout->image); ///< md5 hash 69 psString md5string = psMD5toString(md5); ///< String 70 71 pmHDU *hdu = pmHDUFromReadout(readout); 72 psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout); 73 psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE, "Image MD5", md5string); 74 psFree(md5); 75 psFree(md5string); 76 psFree(headerName); 75 77 } 76 78 77 psList *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "INPUT.CELLS"); 78 if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) { 79 psError(psErrorCodeLast(), false, "Unable to average cell concepts."); 80 psFree(view); 81 return false; 79 if (fullImage) { 80 psList *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "INPUT.CELLS"); 81 if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) { 82 psError(psErrorCodeLast(), false, "Unable to average cell concepts."); 83 psFree(view); 84 return false; 85 } 82 86 } 83 87 … … 85 89 psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); ///< Trim section 86 90 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels 91 } 87 92 93 // update astrometry headers 94 pmHDU *hdu = pmHDUFromChip(chip); ///< HDU for source 95 if (!hdu || !hdu->header) { 96 psError(PM_ERR_PROG, false, "Unable to find header for output."); 97 psFree(view); 98 return false; 99 } 100 101 if (bilevelAstrometry) { 102 if (!pmAstromWriteBilevelChip(hdu->header, chip, WCS_NONLIN_TOL)) { 103 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for skycell."); 104 psFree(view); 105 return false; 106 } 107 } else { 108 // we use a default FPA pixel scale of 1.0 109 if (!pmAstromWriteWCS(hdu->header, output, chip, WCS_NONLIN_TOL)) { 110 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for skycell."); 111 psFree(view); 112 return false; 113 } 88 114 } 89 115 } … … 93 119 return false; 94 120 } 95 121 96 122 // Update ZP from the astrometry 97 {123 if (fullImage) { 98 124 psMetadataItem *item = psMetadataLookup(output->concepts, "FPA.ZP"); 99 125 item->data.F32 = psMetadataLookupF32(NULL, astrom->concepts, "FPA.ZP"); 100 126 } 101 127 102 // need to update the chip and fpa level astrometry appropriately, see 103 // code in psastro 104 105 # if (0) 106 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) { 107 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 108 return false; 128 // apply the bilevel astrometry elements to the target 129 if (bilevelAstrometry) { 130 pmHDU *phu = pmFPAviewThisPHU(view, output); ///< Astrometry PHU 131 if (!phu->header) { 132 phu->header = psMetadataAlloc (); 133 } 134 if (!pmAstromWriteBilevelMosaic(phu->header, output, WCS_NONLIN_TOL)) { 135 psError(psErrorCodeLast(), false, "Unable to write bilevel mosaic astrometry for skycell."); 136 psFree(view); 137 return false; 138 } 109 139 } 110 # endif111 140 112 141 return true; -
branches/eam_branches/ipp-20130419/pswarp/src/pswarpUpdateStatistics.c
r35527 r35535 1 /** @file pswarp Loop.c1 /** @file pswarpUpdateStatistics.c 2 2 * 3 * @brief mail processing loop for pswarp3 * @brief generate output statistics 4 4 * @ingroup pswarp 5 5 * 6 6 * @author IfA 7 * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $8 7 * @date $Date: 2009-02-13 21:54:32 $ 9 8 * Copyright 2009 Institute for Astronomy, University of Hawaii
Note:
See TracChangeset
for help on using the changeset viewer.
