IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9857


Ignore:
Timestamp:
Nov 3, 2006, 4:40:46 PM (20 years ago)
Author:
Paul Price
Message:

Adding fringe processing.

Location:
trunk/ppImage/src
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/Makefile.am

    r8348 r9857  
    44        ppImage.h \
    55        ppImageOptions.h \
     6        ppImageDetrendFringe.h \
    67        ppMem.h
    78
     
    1819        ppImageDetrendBias.c \
    1920        ppImageDetrendNonLinear.c \
     21        ppImageDetrendFringe.c \
    2022        ppImageRebinReadout.c \
    2123        ppImageMosaic.c \
     
    3840        ppImageDetrendBias.c \
    3941        ppImageDetrendNonLinear.c \
     42        ppImageDetrendFringe.c \
    4043        ppImageRebinReadout.c \
    4144        ppImageMosaic.c \
  • trunk/ppImage/src/ppImageLoop.c

    r9657 r9857  
    55#include <ppStats.h>
    66#include "ppImage.h"
     7#include "ppImageDetrendFringe.h"
    78
    89bool ppImageLoop (pmConfig *config, ppImageOptions *options) {
     
    4445        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) return false;
    4546
     47        const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip
     48        psArray *fringeRef = NULL;      // Array of array of fringe statistics for reference --- for each cell
     49        psArray *fringeSci = NULL;      // Array of fringe statistics for science --- for each cell
     50        if (options->doFringe) {
     51            fringeRef = psArrayAlloc(chip->cells->n);
     52            fringeSci = psArrayAlloc(chip->cells->n);
     53        }
     54
    4655        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
    4756            psLogMsg ("ppImageLoop", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    4857            if (!cell->process || !cell->file_exists) { continue; }
    4958            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) return false;
     59            const char *cellName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of cell
     60
     61            if (options->doFringe) {
     62                pmFPAfile *fringeFile = psMetadataLookupPtr(&status, config->files, "PPIMAGE.FRINGE");
     63                if (!status || !fringeFile) {
     64                    psErrorStackPrint(stderr, "Can't find fringe data!\n");
     65                    exit(EXIT_FAILURE);
     66                }
     67
     68                psString fringeExt = NULL; // Fringe extension name
     69                psStringAppend(&fringeExt, "FRINGE_%s_%s", chipName, cellName);
     70                fringeRef->data[view->cell] = pmFringesReadFits(NULL, fringeFile->fits, fringeExt);
     71                psFree(fringeExt);
     72            }
    5073
    5174            // process each of the readouts
     
    5780                if (!ppImageDetrendReadout (config, options, view)) return false;
    5881
     82                if (options->doFringe) {
     83                    ppImageDetrendFringeMeasure((pmFringeStats**)(&fringeSci->data[view->cell]),
     84                                                fringeRef->data[view->cell], readout, options);
     85                }
     86            }
     87        }
     88
     89        // Solve the fringe system
     90        pmFringeScale *fringeSoln = NULL; // Solution for the fringes
     91        if (options->doFringe) {
     92            fringeSoln = ppImageDetrendFringeSolve(fringeSci, fringeRef, options);
     93            psFree(fringeSci);
     94            psFree(fringeRef);
     95        }
     96
     97        // Go back over the cells to apply the fringe and do statistics
     98        view->cell = view->readout = -1;
     99        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
     100            if (!cell->process || !cell->file_exists) { continue; }
     101
     102            // Apply the fringe correction
     103            psTrace("ppImage", 3, "Applying fringe correction...\n");
     104            bool mdok;                          // Status of MD lookup
     105            pmFPAfile *fringeFile = psMetadataLookupPtr(&mdok, config->files, "PPIMAGE.FRINGE");
     106            pmCell *fringeCell = pmFPAviewThisCell(view, fringeFile->fpa);
     107            psImage *fringe = ppImageDetrendFringeGenerate(cell, fringeCell, fringeSoln);
     108            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
     109                if (!readout->data_exists) { continue; }
     110
     111                // XXX: Make generic, so subregions may be subtracted as well
     112                psBinaryOp(readout->image, readout->image, "-", fringe);
     113
    59114                if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) return false;
    60115            }
     116            psFree(fringe);
     117
    61118
    62119            // Perform statistics on the detrended cell
     
    67124            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) return false;
    68125        }
     126        psFree(fringeSoln);
    69127
    70128        ppImageMosaicChip (config, view, "PPIMAGE.OUTPUT.CHIP", "PPIMAGE.OUTPUT");
  • trunk/ppImage/src/ppImageOptions.c

    r9539 r9857  
    4949    // Overscan defaults
    5050    options->overscan      = NULL;      // Overscan options
     51
     52    // Fringe defaults
     53    options->fringeRej = NAN;
     54    options->fringeIter = 0;
     55    options->fringeKeep = 1.0;
    5156
    5257    // Non-linearity default options
     
    163168    options->doDark = psMetadataLookupBool(NULL, recipe, "DARK");
    164169    options->doFlat = psMetadataLookupBool(NULL, recipe, "FLAT");
     170    options->doFringe = psMetadataLookupBool(NULL, recipe, "FRINGE");
    165171    options->doShutter = psMetadataLookupBool(NULL, recipe, "SHUTTER");
    166172
     
    200206    }
    201207
     208    // Fringe options
     209    options->fringeRej = psMetadataLookupF32(NULL, recipe, "FRINGE.REJ");
     210    options->fringeIter = psMetadataLookupS32(NULL, recipe, "FRINGE.ITER");
     211    options->fringeKeep = psMetadataLookupF32(NULL, recipe, "FRINGE.KEEP");
     212
    202213    return options;
    203214}
  • trunk/ppImage/src/ppImageOptions.h

    r9342 r9857  
    3838    int xBin2, yBin2;
    3939
     40    float fringeRej;                    // Fringe rejection limit
     41    int fringeIter;                     // Fringe iterations
     42    float fringeKeep;                   // Fringe keep fraction
     43
    4044} ppImageOptions;
    4145
  • trunk/ppImage/src/ppImageParseCamera.c

    r9438 r9857  
    3434        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.BIAS", input->fpa, PM_DETREND_TYPE_BIAS);
    3535        if (!status) {
    36             psError (PS_ERR_IO, false, "can't find a bias image source");
    37             return NULL;
    38         }
     36            psError (PS_ERR_IO, false, "can't find a bias image source");
     37            return NULL;
     38        }
    3939    }
    4040    if (options->doDark) {
     
    4444        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.DARK", input->fpa, PM_DETREND_TYPE_DARK);
    4545        if (!status) {
    46             psError (PS_ERR_IO, false, "can't find a dark image source");
    47             return NULL;
    48         }
     46            psError (PS_ERR_IO, false, "can't find a dark image source");
     47            return NULL;
     48        }
    4949    }
    5050    if (options->doMask) {
     
    5454        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.MASK", input->fpa, PM_DETREND_TYPE_MASK);
    5555        if (!status) {
    56             psError (PS_ERR_IO, false, "can't find a mask image source");
    57             return NULL;
    58         }
     56            psError (PS_ERR_IO, false, "can't find a mask image source");
     57            return NULL;
     58        }
    5959    }
    6060    if (options->doShutter) {
     
    6262        pmFPAfileDefineFromArgs  (&status, config, "PPIMAGE.SHUTTER", "SHUTTER");
    6363        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.SHUTTER");
    64         pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.SHUTTER", input->fpa, PM_DETREND_TYPE_FLAT);
     64        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.SHUTTER", input->fpa, PM_DETREND_TYPE_SHUTTER);
    6565        if (!status) {
    66             psError (PS_ERR_IO, false, "can't find a shutter image source");
    67             return NULL;
    68         }
     66            psError (PS_ERR_IO, false, "can't find a shutter image source");
     67            return NULL;
     68        }
    6969    }
    7070    if (options->doFlat) {
     
    7474        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.FLAT", input->fpa, PM_DETREND_TYPE_FLAT);
    7575        if (!status) {
    76             psError (PS_ERR_IO, false, "can't find a flat image source");
    77             return NULL;
    78         }
     76            psError (PS_ERR_IO, false, "can't find a flat image source");
     77            return NULL;
     78        }
     79    }
     80    if (options->doFringe) {
     81        bool status = false;
     82        pmFPAfileDefineFromArgs  (&status, config, "PPIMAGE.FRINGE", "FRINGE");
     83        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.FRINGE");
     84        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.FRINGE", input->fpa, PM_DETREND_TYPE_FRINGE_IMAGE);
     85        if (!status) {
     86            psError (PS_ERR_IO, false, "can't find a fringe image source");
     87            return NULL;
     88        }
    7989    }
    8090
  • trunk/ppImage/src/ppImageParseDetrend.c

    r9342 r9857  
    5454    }
    5555
     56    if (options->doFringe) {
     57        bool status = false;
     58        pmFPAfileFromArgs (&status, config, "PPIMAGE.FRINGE", "FRINGE");
     59        pmFPAfileFromConf (&status, config, "PPIMAGE.FRINGE", input->fpa);
     60        if (!status) psAbort ("ppImageParseDetrend", "can't find a fringe image source");
     61    }
     62
    5663    // the following files are output targets
    5764    // XXX which of these are required?
Note: See TracChangeset for help on using the changeset viewer.