Changeset 20180
- Timestamp:
- Oct 15, 2008, 5:51:49 PM (18 years ago)
- Location:
- trunk/dvoTools/src
- Files:
-
- 10 edited
-
dvoApplyCorr.h (modified) (1 diff)
-
dvoApplyCorrArguments.c (modified) (1 diff)
-
dvoApplyCorrLoop.c (modified) (4 diffs)
-
dvoApplyCorrParseCamera.c (modified) (4 diffs)
-
dvoApplyCorrReadout.c (modified) (1 diff)
-
dvoMakeCorr.h (modified) (1 diff)
-
dvoMakeCorrArguments.c (modified) (1 diff)
-
dvoMakeCorrLoop.c (modified) (7 diffs)
-
dvoMakeCorrParseCamera.c (modified) (3 diffs)
-
dvoMakeCorrUnbin.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dvoTools/src/dvoApplyCorr.h
r11862 r20180 32 32 33 33 // apply the correction factor pixel-by-pixel 34 bool dvoApplyCorrReadout (pmConfig *config, pmFPAview *view, char *inName, char *corrName); 34 // XXX : old value bool dvoApplyCorrReadout (pmConfig *config, pmFPAview *view, char *inName, char *corrName); 35 bool dvoApplyCorrReadout (pmCell *inCell, pmChip *corrChip); 35 36 36 37 // free memory, check for leaks -
trunk/dvoTools/src/dvoApplyCorrArguments.c
r13239 r20180 35 35 // save the following additional recipe values based on command-line options 36 36 // these options override the DVOCORR recipe values loaded from recipe files 37 psMetadata *options = pmConfigRecipeOptions (config, RECIPE_NAME);37 // psMetadata *options = pmConfigRecipeOptions (config, RECIPE_NAME); 38 38 39 39 // XXX add options from command-line here 40 40 41 41 // drop the local view on the options (saved on config->arguments) 42 psFree (options);42 // psFree (options); 43 43 44 44 // chip selection is used to limit chips to be processed -
trunk/dvoTools/src/dvoApplyCorrLoop.c
r11877 r20180 10 10 pmChip *chip; 11 11 pmCell *cell; 12 pmReadout *readout;13 12 14 13 // psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, RECIPE_NAME); … … 17 16 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "DVOFLAT.INPUT"); 18 17 if (!status) { 19 psErrorStackPrint(stderr, "Can't find input data!\n"); 18 psErrorStackPrint(stderr, "Can't find input flat-field image\n"); 19 exit(EXIT_FAILURE); 20 } 21 22 // select the input image 23 pmFPAfile *corr = psMetadataLookupPtr(&status, config->files, "DVOFLAT.CORR"); 24 if (!status) { 25 psErrorStackPrint(stderr, "Can't find correction image\n"); 20 26 exit(EXIT_FAILURE); 21 27 } … … 40 46 } 41 47 48 pmChip *corrChip = pmFPAviewThisChip(view, corr->fpa); 49 42 50 // process each cell in the Chip 43 51 while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) { … … 50 58 } 51 59 52 // process each of the readouts 53 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 54 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 55 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d, cell %d, readout %d in dvoApplyCorr\n", view->chip, view->cell, view->readout); 56 psFree (view); 57 return false; 58 } 59 if (!readout->data_exists) continue; 60 61 // XXX put the function here which multiplies the input image and the correction image 62 dvoApplyCorrReadout (config, view, "DVOFLAT.INPUT", "DVOFLAT.CORR"); 63 64 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 65 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d, cell %d, readout %d in dvoApplyCorr\n", view->chip, view->cell, view->readout); 66 psFree (view); 67 return false; 68 } 60 // multiply the input image and the correction image 61 if (!dvoApplyCorrReadout (cell, corrChip)) { 62 psError(PS_ERR_UNKNOWN, false, "failed to apply correction to chip %d, cell %d dvoApplyCorr\n", view->chip, view->cell); 63 psFree (view); 64 return false; 69 65 } 70 66 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { -
trunk/dvoTools/src/dvoApplyCorrParseCamera.c
r11862 r20180 4 4 5 5 # include "dvoApplyCorr.h" 6 bool dvoApplyCorrSelectCorrFile (pmConfig *config, pmFPA *input); 6 7 7 8 dvoApplyCorrOptions *dvoApplyCorrParseCamera (pmConfig *config) { … … 29 30 return NULL; 30 31 } 32 output->save = TRUE; 31 33 32 34 // find the flat-field correction image (from command-line, config file, or detrend db) 33 status = false; 34 pmFPAfileDefineFromArgs (&status, config, "DVOFLAT.CORR", "CORR"); 35 psErrorClear(); 36 pmFPAfileDefineFromConf (&status, config, "DVOFLAT.CORR"); 37 psErrorClear(); 38 pmFPAfileDefineFromDetDB (&status, config, "DVOFLAT.CORR", input->fpa, PM_DETREND_TYPE_FLAT_CORRECTION); 35 status = dvoApplyCorrSelectCorrFile (config, input->fpa); 39 36 if (!status) { 40 37 psError (PS_ERR_IO, false, "can't find a flat-field correction image source"); … … 52 49 if (! pmFPASelectChip(output->fpa, chipNum, false)) { 53 50 psError(PS_ERR_IO, false, "Chip number %d doesn't exist in camera.\n", chipNum); 54 return false;51 return NULL; 55 52 } 56 53 } … … 59 56 return (options); 60 57 } 58 59 bool dvoApplyCorrSelectCorrFile (pmConfig *config, pmFPA *input) { 60 61 bool status; 62 pmFPAfile *file = NULL; 63 64 file = pmFPAfileDefineFromArgs (&status, config, "DVOFLAT.CORR", "CORR"); 65 if (!status) { 66 psError (PS_ERR_UNKNOWN, false, "failed to load file definition"); 67 return false; 68 } 69 if (file) { 70 if (file->type != PM_FPA_FILE_IMAGE) { 71 psError(PS_ERR_IO, true, "DVOFLAT.CORR is not of type IMAGE"); 72 return false; 73 } 74 return true; 75 } 76 77 file = pmFPAfileDefineFromConf (&status, config, "DVOFLAT.CORR"); 78 if (!status) { 79 psError (PS_ERR_UNKNOWN, false, "failed to load file definition"); 80 return false; 81 } 82 if (file) { 83 if (file->type != PM_FPA_FILE_IMAGE) { 84 psError(PS_ERR_IO, true, "DVOFLAT.CORR is not of type IMAGE"); 85 return false; 86 } 87 return true; 88 } 89 90 file = pmFPAfileDefineFromDetDB (&status, config, "DVOFLAT.CORR", input, PM_DETREND_TYPE_FLAT_CORRECTION); 91 if (!status) { 92 psError (PS_ERR_UNKNOWN, false, "failed to load file definition"); 93 return false; 94 } 95 if (file) { 96 if (file->type != PM_FPA_FILE_IMAGE) { 97 psError(PS_ERR_IO, true, "DVOFLAT.CORR is not of type IMAGE"); 98 return false; 99 } 100 return true; 101 } 102 return false; 103 } -
trunk/dvoTools/src/dvoApplyCorrReadout.c
r11862 r20180 5 5 #include "dvoApplyCorr.h" 6 6 7 // this function is operating on each readout, assuming there is a correspondence between 8 // readouts in the input (raw) flat-field image and the correction frame. this is not really 9 // true 7 // this function is operating on each cell (well, readout) of the flat to be corrected. The 8 // input chip is supplied, but may be in a different format (eg, chip-mosaic vs single cell) 10 9 11 bool dvoApplyCorrReadout (pmC onfig *config, pmFPAview *view, char *inName, char *corrName) {10 bool dvoApplyCorrReadout (pmCell *inCell, pmChip *corrChip) { 12 11 12 // XXX for now, let's just assume the input is per-cell, and the correction is per-chip 13 // Also, let's assume they are both binned 1x1 14 13 15 bool status; 14 16 15 pmFPAfile *inFile = psMetadataLookupPtr (&status, config->files, inName); 16 pmFPAfile *corrFile = psMetadataLookupPtr (&status, config->files, corrName); 17 assert (inFile); 18 assert (corrFile); 17 pmCell *corrCell = corrChip->cells->data[0]; 18 pmReadout *corrRO = corrCell->readouts->data[0]; 19 psImage *corrImage = corrRO->image; 19 20 20 pmReadout *inData = pmFPAviewThisReadout (view, inFile->fpa); 21 pmReadout *corrData = pmFPAviewThisReadout (view, corrFile->fpa); 22 assert (inData); 23 assert (corrData); 21 pmReadout *inRO = inCell->readouts->data[0]; 22 psImage *inImage = inRO->image; 24 23 25 // dimensions of input image: 26 assert (inData->image->numCols == corrData->image->numCols); 27 assert (inData->image->numRows == corrData->image->numRows); 24 int x0 = psMetadataLookupS32(&status, inCell->concepts, "CELL.X0"); // Position of (0,0) on chip 25 if (!status) { 26 psError(PS_ERR_UNKNOWN, true, "CELL.X0 hasn't been set for cell.\n"); 27 return false; 28 } 29 int y0 = psMetadataLookupS32(&status, inCell->concepts, "CELL.Y0"); // Position of (0,0) on chip 30 if (!status) { 31 psError(PS_ERR_UNKNOWN, true, "CELL.Y0 hasn't been set for cell.\n"); 32 return false; 33 } 28 34 29 // NOTE : the output pmFPA points at the same pixels as the input pmFPA 35 int xParity = psMetadataLookupS32(&status, inCell->concepts, "CELL.XPARITY"); // Parity in x 36 if (!status) { 37 psError(PS_ERR_UNKNOWN, true, "CELL.XPARITY hasn't been set for cell.\n"); 38 return false; 39 } 40 int yParity = psMetadataLookupS32(&status, inCell->concepts, "CELL.YPARITY"); // Parity in y 41 if (!status) { 42 psError(PS_ERR_UNKNOWN, true, "CELL.YPARITY hasn't been set for cell.\n"); 43 return false; 44 } 30 45 31 // the corr image is a multiplicative factor 32 for (int j = 0; j < inData->image->numRows; j++) { 33 for (int i = 0; i < inData->image->numCols; i++) { 34 inData->image->data.F32[j][i] *= corrData->image->data.F32[j][i]; 46 // The corr image is a multiplicative factor. Need to convert the input flat pixel 47 // coordinates to the correction cell/pixel coords. 48 for (int j = 0; j < inImage->numRows; j++) { 49 int jC = (yParity < 0) ? y0 + j*yParity : y0 + j*yParity + 1; 50 for (int i = 0; i < inImage->numCols; i++) { 51 int iC = (xParity < 0) ? x0 + i*xParity : x0 + i*xParity + 1; 52 inImage->data.F32[j][i] *= corrImage->data.F32[jC][iC]; 35 53 } 36 54 } 37 38 // psFits *fits = psFitsOpen ("tmp.fits", "w");39 // psFitsWriteImage (fits, NULL, inData->image, 0, NULL);40 // psFitsClose (fits);41 // exit (0);42 43 55 return true; 44 56 } -
trunk/dvoTools/src/dvoMakeCorr.h
r11804 r20180 32 32 33 33 // convert low-res image to hi-res image 34 bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, char *inName, char *refName);34 bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, psImage *inImage, pmChip *inChip, char *refName); 35 35 36 36 // free memory, check for leaks -
trunk/dvoTools/src/dvoMakeCorrArguments.c
r13239 r20180 35 35 // save the following additional recipe values based on command-line options 36 36 // these options override the DVOCORR recipe values loaded from recipe files 37 psMetadata *options = pmConfigRecipeOptions (config, RECIPE_NAME);37 // psMetadata *options = pmConfigRecipeOptions (config, RECIPE_NAME); 38 38 39 39 // XXX add options from command-line here 40 41 // drop the local view on the options (saved on config->arguments)42 psFree (options);43 40 44 41 // the input file is a required argument; if not found, we will exit -
trunk/dvoTools/src/dvoMakeCorrLoop.c
r11804 r20180 5 5 #include "dvoMakeCorr.h" 6 6 7 // XXX currently, the input image (the grid map generated by relphot) does not supply enough 8 // header information so the camera and format can be identified. 9 7 10 bool dvoMakeCorrLoop (pmConfig *config, dvoMakeCorrOptions *options) { 8 11 … … 10 13 pmChip *chip; 11 14 pmCell *cell; 12 p mReadout *readout;15 psRegion fullImage = {0, 0, 0, 0}; 13 16 14 17 // psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, RECIPE_NAME); 18 19 // use the reference image to identify the desired extension from DVOCORR.INPUT 20 pmFPAfile *refhead = psMetadataLookupPtr(&status, config->files, "DVOCORR.REFHEAD"); 21 if (!status) { 22 psErrorStackPrint(stderr, "Can't find reference image\n"); 23 exit(EXIT_FAILURE); 24 } 15 25 16 26 pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "DVOCORR.INPUT"); … … 29 39 } 30 40 41 // XXX for now, do not use the I/O system to read this file; do it manually 42 if (!pmFPAfileOpen (input, view, config)) { 43 psError(PS_ERR_UNKNOWN, false, "failed to open grid file\n"); 44 psFree (view); 45 return false; 46 } 47 input->state = PM_FPA_STATE_INACTIVE; 48 31 49 // process each chip in the FPA 32 while ((chip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) {50 while ((chip = pmFPAviewNextChip(view, refhead->fpa, 1)) != NULL) { 33 51 psLogMsg ("dvoMakeCorrLoop", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 34 52 if (!chip->process || !chip->file_exists) continue; … … 39 57 } 40 58 59 // load the input data for this extension 60 pmChip *inChip = pmFPAviewThisChip (view, input->fpa); 61 char *inName = psMetadataLookupStr (&status, inChip->concepts, "CHIP.NAME"); 62 psFitsMoveExtName (input->fits, inName); 63 psImage *inImage = psFitsReadImage (input->fits, fullImage, 0); 64 assert (inImage); 65 41 66 // process each cell in the Chip 42 while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {67 while ((cell = pmFPAviewNextCell(view, refhead->fpa, 1)) != NULL) { 43 68 psLogMsg ("dvoMakeCorrLoop", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 44 69 if (!cell->process || !cell->file_exists) continue; … … 49 74 } 50 75 51 // process each of the readouts 52 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 53 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 54 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d, cell %d, readout %d in dvoMakeCorr\n", view->chip, view->cell, view->readout); 55 psFree (view); 56 return false; 57 } 58 if (!readout->data_exists) continue; 76 // XXX put the function here which unbins the input image 77 dvoMakeCorrUnbin (config, view, "DVOCORR.OUTPUT", inImage, inChip, "DVOCORR.REFHEAD"); 59 78 60 // XXX put the function here which unbins the input image61 dvoMakeCorrUnbin (config, view, "DVOCORR.OUTPUT", "DVOCORR.INPUT", "DVOCORR.REFHEAD");62 63 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {64 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d, cell %d, readout %d in dvoMakeCorr\n", view->chip, view->cell, view->readout);65 psFree (view);66 return false;67 }68 }69 79 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 70 80 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d, cell %d in dvoMakeCorr\n", view->chip, view->cell); … … 73 83 } 74 84 } 85 psFree (inImage); 86 75 87 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 76 88 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in dvoMakeCorr\n", view->chip); … … 85 97 } 86 98 99 pmFPAfileClose (input, view); 87 100 psFree (view); 88 101 -
trunk/dvoTools/src/dvoMakeCorrParseCamera.c
r11804 r20180 7 7 dvoMakeCorrOptions *dvoMakeCorrParseCamera (pmConfig *config) { 8 8 9 // the REFERENCE image defines the camera, and all recipes and options the follow 10 pmFPAfile *refhead = pmFPAfileDefineFromArgs (NULL, config, "DVOCORR.REFHEAD", "REFHEAD"); 11 if (!refhead) { 12 psError(PS_ERR_IO, false, "Failed to build FPA from DVOCORR.REFHEAD"); 13 return NULL; 14 } 15 9 16 // the input image defines the camera, and all recipes and options the follow 10 17 pmFPAfile *input = pmFPAfileDefineFromArgs (NULL, config, "DVOCORR.INPUT", "INPUT"); 11 18 if (!input) { 12 19 psError(PS_ERR_IO, false, "Failed to build FPA from DVOCORR.INPUT"); 13 return NULL;14 }15 16 // the input image defines the camera, and all recipes and options the follow17 pmFPAfile *refhead = pmFPAfileDefineFromArgs (NULL, config, "DVOCORR.REFHEAD", "REFHEAD");18 if (!refhead) {19 psError(PS_ERR_IO, false, "Failed to build FPA from DVOCORR.REFHEAD");20 20 return NULL; 21 21 } … … 29 29 // the following files are output targets 30 30 // XXX get the binning from where? 31 pmFPAfile *output = pmFPAfileDefineFromFPA(config, input->fpa, 1, 1, "DVOCORR.OUTPUT");31 pmFPAfile *output = pmFPAfileDefineFromFPA(config, refhead->fpa, 1, 1, "DVOCORR.OUTPUT"); 32 32 if (!output) { 33 33 psError(PS_ERR_IO, false, _("Unable to generate output file from DVOCORR.OUTPUT")); … … 35 35 return NULL; 36 36 } 37 output->save = TRUE; 37 38 38 39 // Chip selection: turn on only the chips specified (pass status to suppress missing-key log msg) -
trunk/dvoTools/src/dvoMakeCorrUnbin.c
r12925 r20180 5 5 #include "dvoMakeCorr.h" 6 6 7 bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, char *inName, char *refName) {7 bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, psImage *inImage, pmChip *inChip, char *refName) { 8 8 9 9 bool status; 10 10 11 pmFPAfile *inFile = psMetadataLookupPtr (&status, config->files, inName);12 11 pmFPAfile *refFile = psMetadataLookupPtr (&status, config->files, refName); 13 12 pmFPAfile *outFile = psMetadataLookupPtr (&status, config->files, outName); 14 assert (inFile);15 13 assert (refFile); 16 14 assert (outFile); … … 19 17 assert (refCell); 20 18 21 pm Readout *inData = pmFPAviewThisReadout (view, inFile->fpa);22 assert ( inData);19 pmChip *refChip = pmFPAviewThisChip (view, refFile->fpa); 20 assert (refChip); 23 21 24 22 // determine the output array size based on the reference TRIMSEC values … … 28 26 // I have the fine and ruff image sizes, determine the binning factor 29 27 psImageBinning *binning = psImageBinningAlloc(); 30 binning->nXruff = in Data->image->numCols;31 binning->nYruff = in Data->image->numRows;28 binning->nXruff = inImage->numCols; 29 binning->nYruff = inImage->numRows; 32 30 binning->nXfine = trimsec->x1 - trimsec->x0; 33 31 binning->nYfine = trimsec->y1 - trimsec->y0; 34 32 psImageBinningSetScale (binning, PS_IMAGE_BINNING_CENTER); 35 psImageBinningSetSkip(binning, inData->image); 33 psImageBinningSetSkip(binning, inImage); 34 35 // generate a local view of the 0th readout 36 pmFPAview *myView = pmFPAviewAlloc (0); 37 *myView = *view; 38 myView->readout = 0; 36 39 37 40 // construct the supporing pmFPA/pmChip/pmCell structures 38 pmReadout *outData = pmFPAviewThisReadout ( view, outFile->fpa);41 pmReadout *outData = pmFPAviewThisReadout (myView, outFile->fpa); 39 42 if (outData == NULL) { 40 pmChip * inChip = pmFPAviewThisChip (view, inFile->fpa);41 pmC hip *outChip = pmFPAviewThisChip (view, outFile->fpa);43 pmChip *outChip = pmFPAviewThisChip (myView, outFile->fpa); 44 pmCell *outCell = pmFPAviewThisCell (myView, outFile->fpa); 42 45 43 pmChipCopyStructure (outChip, inChip, binning->nXbin, binning->nYbin); 44 outData = pmFPAviewThisReadout (view, outFile->fpa); 46 pmChipCopyStructure (outChip, refChip, 1, 1); 47 48 outData = pmReadoutAlloc (outCell); 45 49 assert (outData != NULL); 50 51 // outData = pmFPAviewThisReadout (myView, outFile->fpa); 52 // assert (outData != NULL); 46 53 } 47 54 48 55 // generate the output (fine-scale) image array 49 psImageRecycle (outData->image, binning->nXfine, binning->nYfine, PS_TYPE_F32);56 outData->image = psImageRecycle (outData->image, binning->nXfine, binning->nYfine, PS_TYPE_F32); 50 57 51 58 // linear interpolation to full fine scale 52 if (!psImageUnbin (outData->image, in Data->image, binning)) {59 if (!psImageUnbin (outData->image, inImage, binning)) { 53 60 psError (PS_ERR_UNKNOWN, true, "failed to unbin image"); 54 61 psFree (binning);
Note:
See TracChangeset
for help on using the changeset viewer.
