IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8884


Ignore:
Timestamp:
Sep 22, 2006, 11:00:53 AM (20 years ago)
Author:
magnier
Message:

nearly done with pmShutterCorrection

Location:
trunk/psModules/src/detrend
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/Makefile.am

    r8569 r8884  
    1111        pmSubtractBias.c \
    1212        pmDetrendDB.c \
     13        pmShutterCorrection.c \
    1314        psPipe.c \
    1415        psIOBuffer.c
     
    2627        pmNonLinear.h \
    2728        pmSubtractBias.h \
    28         pmDetrendDB.h
     29        pmDetrendDB.h \
     30        pmShutterCorrection.h
    2931
    3032#       pmSubtractSky.c
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r8866 r8884  
    5151*/
    5252
     53#if HAVE_CONFIG_H
     54#include <config.h>
     55#endif
     56
     57#include <stdio.h>
     58#include <math.h>
     59#include <strings.h>
     60#include <pslib.h>
     61
     62#include "pmShutterCorrection.h"
     63
    5364static void pmShutterCorrParsFree (pmShutterCorrPars *pars)
    5465{
     
    133144    return (pars);
    134145}
     146
     147// linear fit to the counts and exptime, given a value for offref
     148pmShutterCorrPars *pmShutterCorrectionLinFit (psVector *exptime, psVector *counts, float offref)
     149{
     150
     151    // this step is identical for all pixels: do it once and save?
     152    psVector *x = psVectorAlloc (exptime->n, PS_TYPE_F32);
     153    psVector *y = psVectorAlloc (exptime->n, PS_TYPE_F32);
     154
     155    for (int i = 0; i < exptime->n; i++) {
     156        value = 1.0 / (exptime->data.F32[i] + offref);
     157        x->data.F32[i] = exptime->data.F32[i] * value;
     158        y->data.F32[i] = value;
     159    }
     160
     161    psPolynomial2D *line = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, 1, 1);
     162
     163    // mask out the terms we will not fit
     164    line->mask[0][0] = 1;
     165    line->mask[1][1] = 1;
     166    line->coeff[0][0] = 0;
     167    line->coeff[1][1] = 0;
     168
     169    psVectorFitPolynomial2D (line, NULL, 0, counts, NULL, x, y);
     170
     171    pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
     172
     173    pars->offref = guess->offref;
     174    pars->scale  = line->coeff[1][0];
     175    pars->offset = line->coeff[0][1] / line->coeff[1][0];
     176
     177    return (pars);
     178}
     179
     180static psF32 pmShutterCorrectionModel(psVector *deriv,
     181                                      const psVector *params,
     182                                      const psVector *x)
     183{
     184    psF32 A  = params->data.F32[0];
     185    psF32 p  = x->data.F32[0] + params->data.F32[1];
     186    psF32 q  = 1.0 / (x->data.F32[0] + params->data.F32[2]);
     187    psF32 f  = A*p*q;
     188
     189    if (deriv != NULL) {
     190        deriv->data.F32[0] = p*q;
     191        deriv->data.F32[1] = A*q;
     192        deriv->data.F32[2] = -A*p*q*q;
     193    }
     194    return(f);
     195}
     196
     197// non-linear fit to the counts and exptime, given a guess for the three parameters
     198pmShutterCorrPars *pmShutterCorrectionFullFit (psVector *exptime, psVector *counts, pmShutterCorrPars *guess)
     199{
     200
     201    psMinimization *myMin = psMinimizationAlloc(15, 0.1);
     202
     203    psVector *params = psVectorAlloc (3, PS_TYPE_F32);
     204    params->data.F32[0] = guess->scale;
     205    params->data.F32[1] = guess->offset;
     206    params->data.F32[2] = guess->offref;
     207    params->n = 3;
     208
     209    // XXX for the moment, don't set any constraints
     210    // psMinConstrain *constrain = psMinConstrainAlloc();
     211    // constrain->paramDelta = psVectorAlloc (3, PS_TYPE_F32);
     212    // constrain->paramMin   = psVectorAlloc (3, PS_TYPE_F32);
     213    // constrain->paramMax   = psVectorAlloc (3, PS_TYPE_F32);
     214    // constrain->paramMask  = NULL;
     215    psMinConstrain *constrain = NULL;
     216
     217    // XXX ignore covariance matrix for the moment
     218    // psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F64);
     219    psImage *covar = NULL;
     220
     221    // construct the coordinate and value entries (y is counts)
     222    psArray *x = psArrayAlloc(exptime->n);
     223    psVector *y = counts;
     224    psVector *yErr = psVectorAlloc(exptime->n, PS_TYPE_F32);
     225    x->n = yErr->n = exptime->n;
     226
     227    for (int i = 0; i < exptime->n; i++) {
     228        psVector *coord = psVectorAlloc(1, PS_TYPE_F32);
     229        coord->n = 1;
     230
     231        coord->data.F32[0] = exptime->data.F32[i];
     232
     233        x->data[i] = coord;
     234        yErr->data.F32[i] = sqrt(y->data.F32[i]);
     235    }
     236
     237    fitStatus = psMinimizeLMChi2(myMin, covar, params, constrain, x, y, yErr, pmShutterCorrectionModel);
     238
     239    pmShutterCorrPars *pars = pmShutterCorrParsAlloc ();
     240
     241    pars->scale  = params->data.F32[0];
     242    pars->offset = params->data.F32[1];
     243    pars->offref = params->data.F32[2];
     244
     245    return (pars);
     246}
  • trunk/psModules/src/detrend/pmShutterCorrection.h

    r8866 r8884  
    4848 *  @author Eugene Magnier, IfA
    4949 *
    50  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    51  *  @date $Date: 2006-09-21 02:18:19 $
     50 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     51 *  @date $Date: 2006-09-22 21:00:53 $
    5252 *
    5353 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5555
    5656#include "pslib.h"
    57 
    58 /** Execute flat field module.
    59  *
    60  *  Given an input image and a flat-field image, pmFlatField shall divide the input image by the flat field
    61  *  image.
    62  *
    63  *  @return  bool: True or false for success or failure
    64  */
    6557
    6658typedef struct
     
    7163}
    7264pmShutterCorrPars;
     65
     66pmShutterCorrPars *pmShutterCorrParsAlloc ();
     67pmShutterCorrPars *pmShutterCorrectionGuess (psVector *exptime, psVector *counts);
     68pmShutterCorrPars *pmShutterCorrectionLinFit (psVector *exptime, psVector *counts, float offref);
     69pmShutterCorrPars *pmShutterCorrectionFullFit (psVector *exptime, psVector *counts, pmShutterCorrPars *guess);
Note: See TracChangeset for help on using the changeset viewer.