IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29813


Ignore:
Timestamp:
Nov 23, 2010, 4:57:00 PM (15 years ago)
Author:
watersc1
Message:

Final non-linearity code.

Location:
branches/czw_branch/20100817
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100817/ppImage/src/ppImageDetrendReadout.c

    r29486 r29813  
    5151    }
    5252
     53    // Subtract the overscan
     54    if (options->doOverscan) {
     55      if (!pmOverscanSubtract (input, options->overscan)) {
     56        psError(PS_ERR_UNKNOWN, false, "Unable to subtract overscan.");
     57        psFree(detview);
     58        return false;
     59      }
     60    }
     61
    5362    // Non-linearity correction
    5463    if (options->doNonLin) {
     
    5968        return(false);
    6069      }
    61 /*       ppImageDetrendNonLinear(detrend->input, input, options); */
     70      /*       ppImageDetrendNonLinear(detrend->input, input, options); */
    6271    }
    6372
     
    8089    }
    8190
    82     // Bias, dark and overscan subtraction are all merged.
    83     if (options->doBias || options->doOverscan) {
    84         if (!pmBiasSubtract(input, options->overscan, bias, oldDark, view)) {
     91    // Bias and temperature-independent-dark subtraction are merged.
     92    if (options->doBias) {
     93        if (!pmBiasSubtract(input, bias, oldDark, view)) {
    8594            psError(PS_ERR_UNKNOWN, false, "Unable to subtract bias.");
    8695            psFree(detview);
     
    8897        }
    8998    }
    90 
     99   
    91100    // Weight on the basis of pixel value needs to be done after the overscan has been subtracted
    92101    if (options->doVarianceBuild) {
  • branches/czw_branch/20100817/psModules/src/detrend/pmBias.c

    r28405 r29813  
    163163}
    164164
    165 bool pmBiasSubtract(pmReadout *in, pmOverscanOptions *overscanOpts,
     165bool pmBiasSubtract(pmReadout *in,
    166166                    pmReadout *bias, pmReadout *dark, const pmFPAview *view)
    167167{
     
    184184
    185185    pmHDU *hdu = pmHDUFromReadout(in);  // HDU of interest
    186 
    187     if (!pmOverscanSubtract (in, overscanOpts)) {
    188         return false;
    189     }
    190186
    191187    // Bias frame subtraction
     
    247243    psString timeString = psTimeToISO(time); // String with time
    248244    psFree(time);
    249     psStringPrepend(&timeString, "Overscan/bias/dark processing completed at ");
     245    psStringPrepend(&timeString, "Bias/dark processing completed at ");
    250246    psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK,
    251247                     timeString, "");
  • branches/czw_branch/20100817/psModules/src/detrend/pmBias.h

    r19432 r29813  
    2121/// bias (if non-NULL) and dark (if non-NULL) scaled by the CELL.DARKTIME concept.
    2222bool pmBiasSubtract(pmReadout *in,      ///< Input readout, to be overscan/bias/dark corrected
    23                     pmOverscanOptions *overscanOpts, ///< Options for overscan subtraction, or NULL
    2423                    pmReadout *bias, ///< Bias to subtract, or NULL
    2524                    pmReadout *dark, ///< Dark to scale and subtract, or NULL
  • branches/czw_branch/20100817/psModules/src/detrend/pmNonLinear.c

    r29678 r29813  
    1010#include "pmNonLinear.h"
    1111
     12psF32 pmNonLinearityMeasureNoisy(psF32 flux, psVector *correction_fluxes, psVector *correction_factors);
    1213pmReadout *pmNonLinearityPolynomial(pmReadout *inputReadout, const psPolynomial1D *input1DPoly)
    1314{
     
    201202        int seq = -1;
    202203        if ((dir == 0) && (pos < image->numCols/2)) {
    203             seq = pos - 1;
     204          seq = pos ;
    204205            if (seq < 0) continue;
    205206            fluxVector = x_lo_flux->data[seq];
     
    207208        }
    208209        if ((dir == 0) && (pos > image->numCols/2)) {
    209             seq = pos - 1 + numBorder - image->numCols;
     210            seq = pos + numBorder - image->numCols;
    210211            if (seq >= image->numCols) continue;
    211212            fluxVector = x_hi_flux->data[seq];
     
    213214        }
    214215        if ((dir == 1) && (pos < image->numRows/2)) {
    215             seq = pos - 1;
     216            seq = pos;
    216217            if (seq < 0) continue;
    217218            fluxVector = y_lo_flux->data[seq];
     
    219220        }
    220221        if ((dir == 1) && (pos > image->numRows/2)) {
    221             seq = pos - 1 + numBorder - image->numRows;
     222            seq = pos + numBorder - image->numRows;
    222223            if (seq >= image->numRows) continue;
    223224            fluxVector = y_hi_flux->data[seq];
     
    244245        }
    245246        if (row_correction_fluxes == NULL) {
     247          row_correction_factors = default_row_correction_factors;
    246248            row_correction_fluxes = default_row_correction_fluxes;
    247249        }
     
    258260            }
    259261            if (col_correction_fluxes == NULL) {
    260                 col_correction_fluxes = default_col_correction_fluxes;
     262              col_correction_factors = default_col_correction_factors;
     263              col_correction_fluxes = default_col_correction_fluxes;
    261264            }
    262265
     
    264267            psF32 factor_row = pmNonLinearityMeasure(image->data.F32[i][j], row_correction_fluxes,row_correction_factors);
    265268            psF32 factor_col = pmNonLinearityMeasure(image->data.F32[i][j], col_correction_fluxes,col_correction_factors);
    266 
    267             if (((i <= 9)&&(j <= 9))||((i == 9)&&(j == 5))) { // Print out if we're looking at a test case.
    268                 psTrace("psModules.camera",6,"Linearity: %d %d %s %f %f %f %d %d\n",i,j,
     269#if (0)
     270            if (((i == 200)&&(j == 200))||((i == 9)&&(j == 5))) { // Print out if we're looking at a test case.
     271              psF32 factor_row = pmNonLinearityMeasureNoisy(image->data.F32[i][j], row_correction_fluxes,row_correction_factors);
     272              psF32 factor_col = pmNonLinearityMeasureNoisy(image->data.F32[i][j], col_correction_fluxes,col_correction_factors);
     273             
     274                psTrace("psModules.nonlin",6,"Linearity: %d %d %s %f %f %f %d %d\n",i,j,
    269275                        psMetadataLookupStr(NULL,inputReadout->parent->concepts,"CELL.NAME"),
    270276                        image->data.F32[i][j],factor_row,factor_col,numBorder,numSamples);
    271                 psTrace("psModules.camera",6,"Linearity: R: %d %d %d C: %d %d %d\n",
     277                psTrace("psModules.nonlin",6,"Linearity: R: %d %d %d C: %d %d %d\n",
    272278                        i,(i < numBorder),(image->numRows - i),
    273279                        j,(j < numBorder),(image->numCols - j));
    274280
    275 # if (0)
    276                 psTrace("psModules.camera",6,"Linearity: V: ");
     281                psTrace("psModules.nonlin",6,"Linearity: V: ");
    277282                for (int k = 0; k < numSamples; k++) {
    278                     psTrace("psModules.camera",6,"(%f %f) ",
    279                             col_correction_fluxes->data.F32[k],col_correction_factors->data.F32[k]);
     283                    psTrace("psModules.nonlin",6,"(%f %f) (%f %f) DDDD> (%f %f) (%f %f)",
     284                            col_correction_fluxes->data.F32[k],col_correction_factors->data.F32[k],
     285                            row_correction_fluxes->data.F32[k],row_correction_factors->data.F32[k],
     286                            default_col_correction_fluxes->data.F32[k],default_col_correction_factors->data.F32[k],
     287                            default_row_correction_fluxes->data.F32[k],default_row_correction_factors->data.F32[k]);
    280288                }
    281                 psTrace("psModules.camera",6,"\n");
     289                psTrace("psModules.nonlin",6,"\n");
     290            } // End Test case
     291#endif
     292            // Apply correction to image data
     293#if (0)
     294            if (((i == 200)&&(j == 200))||((i == 9)&&(j == 5))) { // Print out if we're looking at a test case.
     295              psTrace("psModules.nonlin",4,"Applied Linearity Correction: %s %d %d : %f %f -> %f\n",
     296                      psMetadataLookupStr(NULL,inputReadout->parent->concepts,"CELL.NAME"),
     297                      i,j,image->data.F32[i][j],(factor_row + factor_col) / 2.0,
     298                      image->data.F32[i][j] + (factor_row + factor_col) / 2.0);
     299            }
    282300# endif
    283             } // End Test case
    284 
    285             // Apply correction to image data
    286             image->data.F32[i][j] = image->data.F32[i][j] * ( factor_row * factor_col ) ;
     301            image->data.F32[i][j] = image->data.F32[i][j] - ( factor_row + factor_col ) / 2.0;
     302
    287303        } // End loop over columns
    288304    } // End loop over rows
     
    314330    bin = correction_fluxes->n - 1;
    315331    if (flux < correction_fluxes->data.F32[0]) {
    316         return(1.0);
    317     }
    318     if (flux > correction_fluxes->data.F32[bin]) {
    319         return(1.0);
    320     }
     332        return(0.0);
     333    }
     334/*     if (flux > correction_fluxes->data.F32[bin]) { */
     335/*      return(0.0); */
     336/*     } */
    321337 
    322338    for (int i = 0; i < correction_fluxes->n - 1; i++) {
     
    338354/*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
    339355    if (!isfinite(result)) {
    340         result = 1.0;
    341     }
    342     if (result <= 0) {
    343         result = 1.0;
    344     }
     356        result = 0.0;
     357    }
     358/*     if (result <= 0) { */
     359/*      result = 1.0; */
     360/*     } */
    345361    return(result);
    346362}
    347  
    348  
    349  
     363
     364psF32 pmNonLinearityMeasureNoisy(psF32 flux, psVector *correction_fluxes, psVector *correction_factors) {
     365    //  psS32 numPixels = 0;
     366    psF32 result = 0;
     367    psU32 bin = 0;
     368
     369    bin = correction_fluxes->n - 1;
     370    psTrace("psModules.nonlin",6,"NLMN: %f %d %f %f\n",flux,bin,correction_fluxes->data.F32[0],correction_fluxes->data.F32[bin]);
     371    if (flux < correction_fluxes->data.F32[0]) {
     372        return(0.0);
     373    }
     374/*     if (flux > correction_fluxes->data.F32[bin]) { */
     375/*      return(0.0); */
     376/*     } */
     377
     378    for (int i = 0; i < correction_fluxes->n - 1; i++) {
     379      psTrace("psModules.nonlin",6,"NLMN: %f %d %f %f %f %f\n",flux,i,correction_fluxes->data.F32[i],correction_fluxes->data.F32[i],
     380              correction_factors->data.F32[i],correction_factors->data.F32[i+1]);
     381        if ((flux >= correction_fluxes->data.F32[i])&&
     382            (flux <  correction_fluxes->data.F32[i+1])) {
     383            result = correction_factors->data.F32[i] +
     384                (flux - correction_fluxes->data.F32[i]) *
     385                ((correction_factors->data.F32[i+1] - correction_factors->data.F32[i]) /
     386                 (correction_fluxes->data.F32[i+1] - correction_fluxes->data.F32[i]));
     387            continue;
     388        }
     389    }
     390
     391/*   PS_BIN_FOR_VALUE(bin,correction_fluxes,flux); */
     392/*   if ((bin < 0)||(bin > correction_fluxes->n)) { */
     393/*     return(1.0); */
     394/*   } */
     395 
     396/*   PS_BIN_INTERPOLATE(result,correction_fluxes,correction_factors,bin,flux); */
     397    if (!isfinite(result)) {
     398        result = 0.0;
     399    }
     400/*     if (result <= 0) { */
     401/*      result = 1.0; */
     402/*     } */
     403    return(result);
     404}
     405
     406 
     407 
Note: See TracChangeset for help on using the changeset viewer.