IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20180


Ignore:
Timestamp:
Oct 15, 2008, 5:51:49 PM (18 years ago)
Author:
eugene
Message:

extensive fixes to make these two programs actually work

Location:
trunk/dvoTools/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/dvoTools/src/dvoApplyCorr.h

    r11862 r20180  
    3232
    3333// 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);
     35bool dvoApplyCorrReadout (pmCell *inCell, pmChip *corrChip);
    3536
    3637// free memory, check for leaks
  • trunk/dvoTools/src/dvoApplyCorrArguments.c

    r13239 r20180  
    3535    // save the following additional recipe values based on command-line options
    3636    // 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);
    3838
    3939    // XXX add options from command-line here
    4040
    4141    // drop the local view on the options (saved on config->arguments)
    42     psFree (options);
     42    // psFree (options);
    4343
    4444    // chip selection is used to limit chips to be processed
  • trunk/dvoTools/src/dvoApplyCorrLoop.c

    r11877 r20180  
    1010    pmChip *chip;
    1111    pmCell *cell;
    12     pmReadout *readout;
    1312
    1413    // psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, RECIPE_NAME);
     
    1716    pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "DVOFLAT.INPUT");
    1817    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");
    2026        exit(EXIT_FAILURE);
    2127    }
     
    4046        }
    4147
     48        pmChip *corrChip = pmFPAviewThisChip(view, corr->fpa);
     49
    4250        // process each cell in the Chip
    4351        while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
     
    5058            }
    5159
    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;
    6965            }
    7066            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
  • trunk/dvoTools/src/dvoApplyCorrParseCamera.c

    r11862 r20180  
    44
    55# include "dvoApplyCorr.h"
     6bool dvoApplyCorrSelectCorrFile (pmConfig *config, pmFPA *input);
    67
    78dvoApplyCorrOptions *dvoApplyCorrParseCamera (pmConfig *config) {
     
    2930        return NULL;
    3031    }
     32    output->save = TRUE;
    3133
    3234    // 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);
    3936    if (!status) {
    4037        psError (PS_ERR_IO, false, "can't find a flat-field correction image source");
     
    5249            if (! pmFPASelectChip(output->fpa, chipNum, false)) {
    5350                psError(PS_ERR_IO, false, "Chip number %d doesn't exist in camera.\n", chipNum);
    54                 return false;
     51                return NULL;
    5552            }
    5653        }
     
    5956    return (options);
    6057}
     58
     59bool 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  
    55#include "dvoApplyCorr.h"
    66
    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)
    109
    11 bool dvoApplyCorrReadout (pmConfig *config, pmFPAview *view, char *inName, char *corrName) {
     10bool dvoApplyCorrReadout (pmCell *inCell, pmChip *corrChip) {
    1211   
     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
    1315    bool status;
    1416
    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;
    1920
    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;
    2423
    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    }
    2834
    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    }
    3045
    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];
    3553        }
    3654    }
    37 
    38     // psFits *fits = psFitsOpen ("tmp.fits", "w");
    39     // psFitsWriteImage (fits, NULL, inData->image, 0, NULL);
    40     // psFitsClose (fits);
    41     // exit (0);
    42 
    4355    return true;
    4456}
  • trunk/dvoTools/src/dvoMakeCorr.h

    r11804 r20180  
    3232
    3333// convert low-res image to hi-res image
    34 bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, char *inName, char *refName);
     34bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, psImage *inImage, pmChip *inChip, char *refName);
    3535
    3636// free memory, check for leaks
  • trunk/dvoTools/src/dvoMakeCorrArguments.c

    r13239 r20180  
    3535    // save the following additional recipe values based on command-line options
    3636    // 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);
    3838
    3939    // XXX add options from command-line here
    40 
    41     // drop the local view on the options (saved on config->arguments)
    42     psFree (options);
    4340
    4441    // the input file is a required argument; if not found, we will exit
  • trunk/dvoTools/src/dvoMakeCorrLoop.c

    r11804 r20180  
    55#include "dvoMakeCorr.h"
    66
     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
    710bool dvoMakeCorrLoop (pmConfig *config, dvoMakeCorrOptions *options) {
    811
     
    1013    pmChip *chip;
    1114    pmCell *cell;
    12     pmReadout *readout;
     15    psRegion fullImage = {0, 0, 0, 0};
    1316
    1417    // 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    }
    1525
    1626    pmFPAfile *input = psMetadataLookupPtr(&status, config->files, "DVOCORR.INPUT");
     
    2939    }
    3040
     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
    3149    // process each chip in the FPA
    32     while ((chip = pmFPAviewNextChip(view, input->fpa, 1)) != NULL) {
     50    while ((chip = pmFPAviewNextChip(view, refhead->fpa, 1)) != NULL) {
    3351        psLogMsg ("dvoMakeCorrLoop", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    3452        if (!chip->process || !chip->file_exists) continue;
     
    3957        }
    4058
     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
    4166        // process each cell in the Chip
    42         while ((cell = pmFPAviewNextCell(view, input->fpa, 1)) != NULL) {
     67        while ((cell = pmFPAviewNextCell(view, refhead->fpa, 1)) != NULL) {
    4368            psLogMsg ("dvoMakeCorrLoop", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    4469            if (!cell->process || !cell->file_exists) continue;
     
    4974            }
    5075
    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");
    5978
    60                 // XXX put the function here which unbins the input image
    61                 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             }
    6979            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    7080                psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d, cell %d in dvoMakeCorr\n", view->chip, view->cell);
     
    7383            }
    7484        }
     85        psFree (inImage);
     86
    7587        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    7688            psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in dvoMakeCorr\n", view->chip);
     
    8597    }
    8698
     99    pmFPAfileClose (input, view);
    87100    psFree (view);
    88101
  • trunk/dvoTools/src/dvoMakeCorrParseCamera.c

    r11804 r20180  
    77dvoMakeCorrOptions *dvoMakeCorrParseCamera (pmConfig *config) {
    88
     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
    916    // the input image defines the camera, and all recipes and options the follow
    1017    pmFPAfile *input = pmFPAfileDefineFromArgs (NULL, config, "DVOCORR.INPUT", "INPUT");
    1118    if (!input) {
    1219        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 follow
    17     pmFPAfile *refhead = pmFPAfileDefineFromArgs (NULL, config, "DVOCORR.REFHEAD", "REFHEAD");
    18     if (!refhead) {
    19         psError(PS_ERR_IO, false, "Failed to build FPA from DVOCORR.REFHEAD");
    2020        return NULL;
    2121    }
     
    2929    // the following files are output targets
    3030    // 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");
    3232    if (!output) {
    3333        psError(PS_ERR_IO, false, _("Unable to generate output file from DVOCORR.OUTPUT"));
     
    3535        return NULL;
    3636    }
     37    output->save = TRUE;
    3738
    3839    // Chip selection: turn on only the chips specified (pass status to suppress missing-key log msg)
  • trunk/dvoTools/src/dvoMakeCorrUnbin.c

    r12925 r20180  
    55#include "dvoMakeCorr.h"
    66
    7 bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, char *inName, char *refName) {
     7bool dvoMakeCorrUnbin (pmConfig *config, pmFPAview *view, char *outName, psImage *inImage, pmChip *inChip, char *refName) {
    88   
    99    bool status;
    1010
    11     pmFPAfile *inFile = psMetadataLookupPtr (&status, config->files, inName);
    1211    pmFPAfile *refFile = psMetadataLookupPtr (&status, config->files, refName);
    1312    pmFPAfile *outFile = psMetadataLookupPtr (&status, config->files, outName);
    14     assert (inFile);
    1513    assert (refFile);
    1614    assert (outFile);
     
    1917    assert (refCell);
    2018
    21     pmReadout *inData = pmFPAviewThisReadout (view, inFile->fpa);
    22     assert (inData);
     19    pmChip *refChip = pmFPAviewThisChip (view, refFile->fpa);
     20    assert (refChip);
    2321
    2422    // determine the output array size based on the reference TRIMSEC values
     
    2826    // I have the fine and ruff image sizes, determine the binning factor
    2927    psImageBinning *binning = psImageBinningAlloc();
    30     binning->nXruff = inData->image->numCols;
    31     binning->nYruff = inData->image->numRows;
     28    binning->nXruff = inImage->numCols;
     29    binning->nYruff = inImage->numRows;
    3230    binning->nXfine = trimsec->x1 - trimsec->x0;
    3331    binning->nYfine = trimsec->y1 - trimsec->y0;
    3432    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;
    3639
    3740    // construct the supporing pmFPA/pmChip/pmCell structures
    38     pmReadout *outData = pmFPAviewThisReadout (view, outFile->fpa);
     41    pmReadout *outData = pmFPAviewThisReadout (myView, outFile->fpa);
    3942    if (outData == NULL) {
    40         pmChip *inChip = pmFPAviewThisChip (view, inFile->fpa);
    41         pmChip *outChip = pmFPAviewThisChip (view, outFile->fpa);
     43        pmChip *outChip = pmFPAviewThisChip (myView, outFile->fpa);
     44        pmCell *outCell = pmFPAviewThisCell (myView, outFile->fpa);
    4245
    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);
    4549        assert (outData != NULL);
     50
     51        // outData = pmFPAviewThisReadout (myView, outFile->fpa);
     52        // assert (outData != NULL);
    4653    }
    4754
    4855    // 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);
    5057
    5158    // linear interpolation to full fine scale
    52     if (!psImageUnbin (outData->image, inData->image, binning)) {
     59    if (!psImageUnbin (outData->image, inImage, binning)) {
    5360        psError (PS_ERR_UNKNOWN, true, "failed to unbin image");
    5461        psFree (binning);
Note: See TracChangeset for help on using the changeset viewer.