IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6064


Ignore:
Timestamp:
Jan 19, 2006, 4:58:42 PM (20 years ago)
Author:
Paul Price
Message:

Working, I think

Location:
trunk/ppImage/src
Files:
1 added
7 edited

Legend:

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

    r5976 r6064  
    1717        ppImageParseCamera.c \
    1818        ppImageParseDetrend.c \
    19         ppImageWeights.c
     19        ppImageWeights.c \
     20        ppImageOutput.c \
     21        ppImagePhot.c
    2022#       ppDetrendFlat.c
    2123#       ppImageOutput.c
  • trunk/ppImage/src/ppImage.c

    r5976 r6064  
    2727    ppImageLoop(&data, &options, &config);
    2828
    29     // output options
    30     // ppImageOutput(&data, &options, &config);
     29    // Output image
     30    ppImageOutput(&data, &config);
     31
     32    // Do photometry
     33    ppImagePhot(&data, &options, &config);
    3134
    3235    exit(EXIT_SUCCESS);
  • trunk/ppImage/src/ppImage.h

    r5976 r6064  
    99#include "psAdditionals.h"
    1010
    11 #include "pmAstrometry.h"
     11#include "pmFPA.h"
     12#include "pmFPAConstruct.h"
     13#include "pmFPARead.h"
     14#include "pmFPAWrite.h"
    1215#include "pmReadout.h"
    1316#include "pmConfig.h"
    14 #include "pmFPAConstruct.h"
    15 #include "pmFPARead.h"
    16 #include "pmFPAConceptsGet.h"
    17 #include "pmFPAWrite.h"
    1817
    1918#include "pmFlatField.h"
     
    2322#include "pmChipMosaic.h"
    2423//#include "pmFPAMorph.h"
     24#include "pmSubtractBias.h"
    2525
    2626#define RECIPE "PHASE2"                 // Name of the recipe to use
     
    5353    bool doSource;                      // Source identification and photometry
    5454    bool doAstrom;                      // Astrometry
    55 
    5655    bool doOverscan;                    // Overscan subtraction
    57     int overscanBins;                   // Number of pixels per bin for overscan
    58     psStats *overscanStats;             // Statistics for overscan
    59     void *overscanFit;                  // Overscan fit (polynomial or spline)
    60     pmFit overscanFitType;              // Fit type for overscan
    61     pmOverscanAxis overscanMode;        // Axis for overscan
    62 
     56    pmOverscanOptions *overscan;        // Overscan options
    6357    bool doNonLin;                      // Non-linearity correction
    6458    psDataType nonLinearType;
    6559    psMetadataItem *nonLinearData;
    6660    void *nonLinearSource;
    67 
    6861    ppImageLoadDepth imageLoadDepth;    // How much of the FPA to load at once
    6962} ppOptions;
     
    142135bool ppDetrendNonLinearLookup(pmReadout *input, psMetadataItem *dataItem);
    143136bool ppDetrendNonLinearPolynomial(pmReadout *input, psMetadataItem *dataItem);
    144 bool ppDetrendBias(pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options);
     137bool ppDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppOptions *options);
     138#if 0
    145139pmReadout* ppDetrendPedestal(pmReadout *pedestal, pmCell *input, pmReadout *bias, pmReadout *dark, float darkTime, ppOptions *options);
     140#endif
    146141pmReadout* ppDetrendSelectFirst(pmCell *cell, char *name, bool doThis);
    147142
     
    150145#endif
    151146
     147bool ppImageOutput(ppData *data, ppConfig *config);
     148bool ppImagePhot(ppData *data, ppOptions *options, ppConfig *config);
    152149
    153150#endif // Pau.
  • trunk/ppImage/src/ppImageDetrendBias.c

    r5858 r6064  
    1 # include "ppImage.h"
     1#include "ppImage.h"
    22
    3 bool ppDetrendBias (pmCell *inputCell, pmReadout *inputReadout, pmReadout *pedestal, ppOptions *options) {
     3bool ppDetrendBias(pmReadout *inputReadout, pmReadout *bias, pmReadout *dark, ppOptions *options) {
    44
    5     psPolynomial1D *poly;
    6     psSpline1D *spline;
    7     psString coeffs;
    85
    9     // XXX EAM : renamed the general edge overscan concept
    10     if (options->overscanMode == PM_OVERSCAN_EDGE) {
    11         // Need to get the read direction
    12         int readdir = psMetadataLookupS32(NULL, inputCell->concepts, "CELL.READDIR");
    13         if (readdir == 1) {
    14             options->overscanMode = PM_OVERSCAN_ROWS;
    15         } else if (readdir == 2) {
    16             options->overscanMode = PM_OVERSCAN_COLUMNS;
    17         } else {
    18             psAbort("phase2", "CELL.READDIR (%d) is not 1 or 2", readdir);
    19         }
     6//    psMetadataPrint(inputCell->concepts, 7);
     7
     8    pmSubtractBias(inputReadout, options->overscan, bias, dark);
     9
     10    // Output overscan fit results, if required
     11    if (! options->doOverscan || ! options->overscan) {
     12        return true;
    2013    }
    2114
    22     // XXX : should this be a psArray?
    23     psList *inputOverscans = NULL;
    24     if (options->doOverscan) {
    25         inputOverscans = pmReadoutGetBias(inputReadout); // List of overscan bias regions
     15    if (!options->overscan->poly && !options->overscan->spline) {
     16        psLogMsg("ppImage", PS_LOG_WARN, "No fit generated!\n");
     17        return true;
    2618    }
    2719
    28     // supplies the fit result in 'overscanFit'
    29     pmSubtractBias(inputReadout,
    30                    options->overscanFit,
    31                    inputOverscans,
    32                    options->overscanMode,
    33                    options->overscanStats,
    34                    options->overscanBins,
    35                    options->overscanFitType,
    36                    pedestal);
    37     psFree(inputOverscans);
    38    
    39     // Output overscan fit results, if required
    40     if (! options->doOverscan) {
    41         return true;
     20    switch (options->overscan->fitType) {
     21      case PM_FIT_POLY_ORD:
     22      case PM_FIT_POLY_CHEBY:
     23        {
     24            psPolynomial1D *poly = options->overscan->poly; // The polynomial
     25            psString coeffs = NULL;     // String containing the coefficients
     26            for (int i = 0; i < poly->nX; i++) {
     27                psStringAppend(&coeffs, "%e ", poly->coeff[i]);
     28            }
     29            psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n", coeffs);
     30            psFree(coeffs);
     31            break;
     32        }
     33      case PM_FIT_SPLINE:
     34        {
     35            psSpline1D *spline = options->overscan->spline; // The spline
     36            psString coeffs = NULL;     // String containing the coefficients
     37            for (int i = 0; i < spline->n; i++) {
     38                psPolynomial1D *poly = spline->spline[i]; // i-th polynomial
     39                psStringAppend(&coeffs, "%d: ", i);
     40                for (int j = 0; j < poly->nX; j++) {
     41                    psStringAppend(&coeffs, "%e ", poly->coeff[i]);
     42                }
     43                psStringAppend(&coeffs, "\n");
     44            }
     45            psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n", coeffs);
     46            psFree(coeffs);
     47            break;
     48        }
     49      case PM_FIT_NONE:
     50        break;
     51      default:
     52        psAbort(__func__, "Should never get here!!!\n");
    4253    }
    4354
    44     if (! options->overscanFit) {
    45         psLogMsg("phase2", PS_LOG_WARN, "No fit generated!\n");
    46         return true;
    47     }
    48 
    49     switch (options->overscanFitType) {
    50       case PM_FIT_POLYNOMIAL:
    51         poly = (psPolynomial1D *) options->overscanFit; // The polynomial
    52         coeffs = NULL;     // String containing the coefficients
    53         for (int i = 0; i < poly->nX; i++) {
    54             psStringAppend(&coeffs, "%e ", poly->coeff[i]);
    55         }
    56         psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n",
    57                  coeffs);
    58         psFree(coeffs);
    59         break;
    60 
    61       case PM_FIT_SPLINE:
    62         spline = (psSpline1D *) options->overscanFit; // The spline
    63         coeffs = NULL;     // String containing the coefficients
    64         for (int i = 0; i < spline->n; i++) {
    65             psPolynomial1D *poly = spline->spline[i]; // i-th polynomial
    66             psStringAppend(&coeffs, "%d: ", i);
    67             for (int j = 0; j < poly->nX; j++) {
    68                 psStringAppend(&coeffs, "%e ", poly->coeff[i]);
    69             }
    70             psStringAppend(&coeffs, "\n");
    71         }
    72         psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n",
    73                  coeffs);
    74         psFree(coeffs);
    75         break;
    76 
    77       case PM_FIT_NONE:
    78         break;
    79 
    80       default:
    81         psAbort(__func__, "Should never get here!!!\n");
    82     }
    8355    return true;
    8456}
  • trunk/ppImage/src/ppImageDetrendCell.c

    r5858 r6064  
    11# include "ppImage.h"
     2#include "pmFPA.h"
    23
    34// mask, bias, dark, flat are defined per Cell
    45// pedestal is constructed for each readout, which may have different exposure times
    56
    6 pmReadout *ppDetrendSelectFirst (pmCell *cell, char *name, bool doThis) {
     7pmReadout *ppDetrendSelectFirst(pmCell *cell, char *name, bool doThis)
     8{
    79
    810    if (!doThis) {
    9         return NULL;
     11        return NULL;
    1012    }
    1113
    1214    if (cell->readouts->n > 1) {
    13         psLogMsg("phase2", PS_LOG_WARN, "%s contains multiple readouts: only the first will be used.", name);
     15        psLogMsg("phase2", PS_LOG_WARN, "%s contains multiple readouts: only the first will be used.", name);
    1416    }
    1517
     
    1921}
    2022
    21 bool ppDetrendCell (ppDetrend *detrend, ppOptions *options, ppConfig *config) {
     23bool ppDetrendCell(ppDetrend *detrend, ppOptions *options, ppConfig *config)
     24{
    2225
    23     pmReadout *mask = ppDetrendSelectFirst (detrend->mask, "mask", options->doMask);
    24     pmReadout *bias = ppDetrendSelectFirst (detrend->bias, "bias", options->doBias);
    25     pmReadout *dark = ppDetrendSelectFirst (detrend->dark, "dark", options->doDark);
    26     // pmReadout *flat = ppDetrendSelectFirst (detrend->flat, "flat", options->doFlat);
     26    pmCellSetWeights(detrend->input);
     27
     28    pmReadout *mask = ppDetrendSelectFirst(detrend->mask, "mask", options->doMask);
     29    pmReadout *bias = ppDetrendSelectFirst(detrend->bias, "bias", options->doBias);
     30    pmReadout *dark = ppDetrendSelectFirst(detrend->dark, "dark", options->doDark);
     31    pmReadout *flat = ppDetrendSelectFirst(detrend->flat, "flat", options->doFlat);
    2732
    2833    // Dark time for dark image
    29     float darkTime = 1.0;       
     34    float darkTime = 1.0;
    3035    if (options->doDark) {
    31         darkTime = psMetadataLookupF32(NULL, detrend->dark->concepts, "CELL.DARKTIME");
    32         if (darkTime <= 0.0) {
    33             psErrorStackPrint(stderr, "DARKTIME for dark image (%f) is non-positive.\n", darkTime);
    34             exit(EXIT_FAILURE);
    35         }
     36        darkTime = psMetadataLookupF32(NULL, detrend->dark->concepts, "CELL.DARKTIME");
     37        if (darkTime <= 0.0) {
     38            psErrorStackPrint(stderr, "DARKTIME for dark image (%f) is non-positive.\n", darkTime);
     39            exit(EXIT_FAILURE);
     40        }
    3641    }
    37 
    38     // the pedestal combines the bias and dark contributions for a single readout
    39     pmReadout *pedestal = NULL;
    4042
    4143    for (int k = 0; k < detrend->input->readouts->n; k++) {
    4244
    43         pmReadout *input = detrend->input->readouts->data[k]; // Readout of interest in input image
     45        pmReadout *input = detrend->input->readouts->data[k]; // Readout of interest in input image
    4446
    45         // Mask bad pixels
    46         if (options->doMask) {
    47             ppDetrendMask (detrend->input, input, mask);
    48         }
     47        // Mask bad pixels
     48        if (options->doMask) {
     49            ppDetrendMask (detrend->input, input, mask);
     50        }
    4951
    50         // Non-linearity correction
    51         if (options->doNonLin) {
    52             ppDetrendNonLinear (detrend->input, input, options);
    53         }
     52        // Non-linearity correction
     53        if (options->doNonLin) {
     54            ppDetrendNonLinear (detrend->input, input, options);
     55        }
    5456
    55         // generate the pedestal image (passes through the old pedestal if current exptime == last exptime)
    56         pedestal = ppDetrendPedestal (pedestal, detrend->input, bias, dark, darkTime, options);
     57        // Bias, dark and overscan subtraction are all merged.
     58        ppDetrendBias(input, bias, dark, options);
    5759
    58         // Bias, dark and overscan subtraction are all merged.
    59         ppDetrendBias (detrend->input, input, pedestal, options);
    60 
    61         // Flat-field correction (no options used?)
    62         if (options->doFlat) {
    63             psLogMsg("phase2", PS_LOG_INFO, "flat field disabled.\n");
    64             // pmFlatField (input, flat);
    65         }
     60        // Flat-field correction (no options used?)
     61        if (options->doFlat) {
     62#if 0
     63            psLogMsg("phase2", PS_LOG_INFO, "flat field disabled.\n");
     64#endif
     65            pmFlatField(input, flat);
     66        }
    6667    }
    6768    return true;
  • trunk/ppImage/src/ppImageOptions.c

    r5976 r6064  
    1717    options->doAstrom = false;          // Astrometry
    1818    // Overscan options
    19     options->overscanBins = 1;          // Number of pixels per bin for overscan
    20     options->overscanStats = NULL;      // Statistics for overscan
    21     options->overscanFit = NULL;        // Overscan fit (polynomial or spline)
    22     options->overscanFitType = PM_FIT_NONE; // Fit type for overscan
    23     options->overscanMode = PM_OVERSCAN_NONE; // Axis for overscan
     19    options->overscan = NULL;           // Overscan options
     20    bool overscanSingle = false;        // A single value for entire overscan?
     21    pmFit overscanFit = PM_FIT_NONE;    // Fit type for overscan
     22    int overscanOrder = 0;              // Order for overscan fit
     23    psStats *overscanStats = NULL;      // Statistics for overscan
    2424    // Non-linearity options
    2525    options->nonLinearType = 0;         // Type of non-linearity data (vector, string or metadata)
     
    2828    // Various others
    2929    options->imageLoadDepth = PP_LOAD_NONE; // No load depth specified yet
     30
    3031
    3132    bool mdStatus = false;              // Result of MD lookup
     
    122123    // XXX EAM : we should abort on invalid options. default options?
    123124    if (psMetadataLookupBool(NULL, config->recipe, "OVERSCAN")) {
    124         // XXX EAM : does 'overscanMode = NONE' mean doOverscan = false?
    125125        options->doOverscan = true;
    126         psString mode = psMetadataLookupStr(NULL, config->recipe, "OVERSCAN.MODE");
    127         if (! strcasecmp(mode, "INDIVIDUAL")) {
    128             options->overscanMode = PM_OVERSCAN_EDGE;
    129         } else if (! strcasecmp(mode, "ALL")) {
    130             options->overscanMode = PM_OVERSCAN_ALL;
    131         } else if (strcasecmp(mode, "NONE")) {
    132             psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.MODE (%s) is not one of NONE, INDIVIDUAL, or ALL:"
    133                      " assuming NONE.\n", mode);
    134         }
     126
     127        // Do the overscan as a single value?
     128        overscanSingle = psMetadataLookupBool(NULL, config->recipe, "OVERSCAN.SINGLE");
     129
     130        // How do we fit it?
    135131        psString fit = psMetadataLookupStr(NULL, config->recipe, "OVERSCAN.FIT");
    136132        if (! strcasecmp(fit, "POLYNOMIAL")) {
    137             options->overscanFitType = PM_FIT_POLYNOMIAL;
    138             int order = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
    139             options->overscanFit = psPolynomial1DAlloc(order, PS_POLYNOMIAL_ORD);
     133            overscanFit = PM_FIT_POLY_ORD;
     134            overscanOrder = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER");
     135        } else if (! strcasecmp(fit, "CHEBYSHEV")) {
     136            overscanFit = PM_FIT_POLY_CHEBY;
     137            overscanOrder = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER");
    140138        } else if (! strcasecmp(fit, "SPLINE")) {
    141             options->overscanFit = NULL;
    142             options->overscanFitType = PM_FIT_SPLINE;
    143             // int order = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.ORDER"); // Order of polynomial fit
    144             // XXX : not in psLib yet : options->overscanFit = psSpline1DAlloc();
     139            overscanFit = PM_FIT_SPLINE;
    145140        } else if (strcasecmp(fit, "NONE")) {
    146141            psLogMsg(__func__, PS_LOG_WARN, "OVERSCAN.FIT (%s) is not one of NONE, POLYNOMIAL, or SPLINE:"
    147142                     " assuming NONE.\n", fit);
    148143        }
    149         options->overscanBins = psMetadataLookupS32(NULL, config->recipe, "OVERSCAN.BIN");
    150         if (options->overscanBins <= 0) {
    151             psErrorStackPrint(stderr, "OVERSCAN.BIN (%d) is non-positive --- assuming 1.\n", options->overscanBins);
    152             options->overscanBins = 1;
    153         }
     144
    154145        psString stat = psMetadataLookupStr(NULL, config->recipe, "OVERSCAN.STAT");
    155146        if (! strcasecmp(stat, "MEAN")) {
    156             options->overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     147            overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    157148        } else if (! strcasecmp(stat, "MEDIAN")) {
    158             options->overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
     149            overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    159150        } else {
    160151            psErrorStackPrint(stderr, "OVERSCAN.STAT (%s) is not one of MEAN, MEDIAN: assuming MEAN\n", stat);
    161             options->overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
     152            overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    162153        }
     154
     155        // Fill in the options
     156        options->overscan = pmOverscanOptionsAlloc(overscanSingle, overscanFit, overscanOrder, overscanStats);
    163157    }
    164158
  • trunk/ppImage/src/ppImageOutput.c

    r5857 r6064  
    11# include "ppImage.h"
    22
    3 bool ppImageLoop (ppData *data, ppRecipe *options, ppConfig *config) {
     3bool ppImageOutput(ppData *data, ppConfig *config)
     4{
     5    const char *outname = psMetadataLookupStr(NULL, config->arguments, "-output"); // Name of output file
     6    psFits *outFile = psFitsOpen(outname, "w"); // File for writing
    47
    58    // Write the output
    6     pmFPAWrite(outputFile, input, database);
     9    pmFPAWrite(outFile, data->input->fpa, config->database);
     10#if 0
    711    pmFPAWriteMask(input, outputFile);
    812    pmFPAWriteWeight(input, outputFile);
     13#endif
    914
    10     psLogMsg("phase2", PS_LOG_INFO, "Output completed after %f sec.\n", psTimerMark("phase2"));
     15    psFitsClose(outFile);
     16    psLogMsg("ppImage", PS_LOG_INFO, "Output completed after %f sec.\n", psTimerMark("ppImage"));
    1117
    12     psFitsClose(outputFile);
    13 
    14     psFree(arguments);
    15     psFree(site);
    16     psFree(header);
    17     psFree(camera);
    18     psFree(recipe);
    19     psFree(input);
    20     psFree(mask);
    21     psFree(bias);
    22     psFree(dark);
    23     psFree(flat);
    24     psFree(overscanFit);
    25     psFree(overscanStats);
    26 
    27     psLogMsg("phase2", PS_LOG_INFO, "Output completed after %f sec.\n", psTimerMark("phase2"));
    2818    return true;
    2919}
Note: See TracChangeset for help on using the changeset viewer.