IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 17, 2008, 12:58:41 PM (18 years ago)
Author:
eugene
Message:

average curve for grid of measuremetns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmGrowthCurveGenerate.c

    r20076 r20233  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2008-10-13 01:56:42 $
     7 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2008-10-17 22:58:41 $
    99 *
    1010 *  Copyright 2004 Institute for Astronomy, University of Hawaii
     
    3939#include "pmErrorCodes.h"
    4040
     41pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal, float xc, float yc);
     42
    4143/*****************************************************************************/
    4244/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
     
    4951    PS_ASSERT_PTR_NON_NULL(readout->image, false);
    5052
    51     // bool status;
    52     float xc, yc, dx, dy;
     53    // maskVal is used to test for rejected pixels, and must include markVal
     54    maskVal |= markVal;
     55
     56    // XXX something of a hack: measure the growth curve at a number of points in the field and
     57    // average them together
     58
     59    psArray *growths = psArrayAllocEmpty (100);
     60
     61    for (float ix = -0.4; ix <= +0.4; ix += 0.2) {
     62        for (float iy = -0.4; iy <= +0.4; iy += 0.2) {
     63
     64            // use the center of the center pixel of the image
     65            float xc = ix*readout->image->numCols + 0.5*readout->image->numCols + readout->image->col0 + 0.5;
     66            float yc = iy*readout->image->numRows + 0.5*readout->image->numRows + readout->image->row0 + 0.5;
     67
     68            pmGrowthCurve *growth = pmGrowthCurveForPosition (readout->image, psf, ignore, maskVal, markVal, xc, yc);
     69            if (!growth) continue;
     70
     71            psArrayAdd (growths, 100, growth);
     72            psFree (growth);
     73        }
     74    }
     75    psAssert (growths->n, "cannot build growth curve (psf model is invalid everywhere)");
     76
     77    // just use a simple sample median to get the 'best' value from each growth curve...
     78    psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     79
     80    psVector *values = psVectorAlloc (growths->n, PS_DATA_F32);
     81
     82    // median the values for the fitMags
     83    values->n = 0;
     84    for (int j = 0; j < growths->n; j++) {
     85        pmGrowthCurve *growth = growths->data[j];
     86        if (!isfinite(growth->fitMag)) continue;
     87        psVectorAppend (values, growth->fitMag);
     88    }
     89    psVectorStats (stats, values, NULL, NULL, 0);
     90    psf->growth->fitMag = stats->sampleMedian;
     91
     92    // loop over a range of source fluxes
     93    // no need to interpolate since we have forced the object center
     94    // to 0.5, 0.5 above
     95    for (int i = 0; i < psf->growth->radius->n; i++) {
     96
     97        // median the values for each radial bin
     98        values->n = 0;
     99        for (int j = 0; j < growths->n; j++) {
     100            pmGrowthCurve *growth = growths->data[j];
     101            if (!isfinite(growth->apMag->data.F32[i])) continue;
     102            psVectorAppend (values, growth->apMag->data.F32[i]);
     103        }
     104        psVectorStats (stats, values, NULL, NULL, 0);
     105        psf->growth->apMag->data.F32[i] = stats->sampleMedian;
     106    }
     107    psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
     108    psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
     109
     110    psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f (fitMag - apMag @ ref : %f - %f)\n", psf->growth->apLoss, psf->growth->fitMag, psf->growth->apRef);
     111
     112    psFree (growths);
     113    psFree (stats);
     114    psFree (values);
     115
     116    return true;
     117}
     118
     119pmGrowthCurve *pmGrowthCurveForPosition (psImage *image, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType markVal, float xc, float yc) {
     120
    53121    float fitMag, apMag;
    54122    float radius;
    55123
     124    assert (psf->growth);
     125
     126    float minRadius = psf->growth->radius->data.F32[0];
     127    pmGrowthCurve *growth = pmGrowthCurveAlloc (minRadius, psf->growth->maxRadius, psf->growth->refRadius);
     128
     129    float dx = growth->maxRadius + 1;
     130    float dy = growth->maxRadius + 1;
     131
    56132    // create template model
    57133    pmModel *modelRef = pmModelAlloc(psf->type);
    58134
    59     // maskVal is used to test for rejected pixels, and must include markVal
    60     maskVal |= markVal;
    61 
    62     // XXXX A Serious hack: the psf might not be determined in the field center.
    63     // for the moment, just try a few locations until it is defined!
    64 
    65     pmModel *model = NULL;
    66     for (int ix = -1; ix <= +1; ix ++) {
    67         for (int iy = -1; iy <= +1; iy ++) {
    68 
    69             // use the center of the center pixel of the image
    70             xc = (0.5 + 0.3*ix)*readout->image->numCols + readout->image->col0 + 0.5;
    71             yc = (0.5 + 0.3*ix)*readout->image->numRows + readout->image->row0 + 0.5;
    72             dx = psf->growth->maxRadius + 1;
    73             dy = psf->growth->maxRadius + 1;
    74 
    75             // assign the x and y coords to the image center
    76             // create an object with center intensity of 1000
    77             modelRef->params->data.F32[PM_PAR_SKY] = 0;
    78             modelRef->params->data.F32[PM_PAR_I0] = 1000;
    79             modelRef->params->data.F32[PM_PAR_XPOS] = xc;
    80             modelRef->params->data.F32[PM_PAR_YPOS] = yc;
    81 
    82             // create modelPSF from this model
    83             model = pmModelFromPSF (modelRef, psf);
    84             if (model) goto got_model;
    85         }
    86     }
    87     psAssert (model, "cannot build growth curve (psf model is invalid everywhere)");
    88 
    89 got_model:
     135    // assign the x and y coords to the image center
     136    // create an object with center intensity of 1000
     137    modelRef->params->data.F32[PM_PAR_SKY] = 0;
     138    modelRef->params->data.F32[PM_PAR_I0] = 1000;
     139    modelRef->params->data.F32[PM_PAR_XPOS] = xc;
     140    modelRef->params->data.F32[PM_PAR_YPOS] = yc;
     141
     142    // create modelPSF from this model
     143    pmModel *model = pmModelFromPSF (modelRef, psf);
     144    if (!model) {
     145        psFree (growth);
     146        return NULL;
     147    }
     148
    90149    // measure the fitMag for this model
    91150    pmSourcePhotometryModel (&fitMag, model);
    92     psf->growth->fitMag = fitMag;
     151    growth->fitMag = fitMag;
    93152
    94153    // generate working image for this source
     
    96155
    97156    // force region to stop at dimensions of image
    98     region = psRegionForImage (readout->image, region);
     157    region = psRegionForImage (image, region);
    99158
    100159    // the view, image, and mask retain col0,row0
    101     psImage *view = psImageSubset (readout->image, region);
    102     psImage *image = psImageCopy (NULL, view, PS_TYPE_F32);
     160    psImage *view = psImageSubset (image, region);
     161    psImage *pixels = psImageCopy (NULL, view, PS_TYPE_F32);
    103162    psImage *mask = psImageCopy (NULL, view, PS_TYPE_U8);
    104163
    105     psImageInit (image, 0.0);
     164    psImageInit (pixels, 0.0);
    106165    psImageInit (mask, 0);
    107166
     
    109168    // no need to mask the source here
    110169    // XXX should we measure this for the analytical model only or the full model?
    111     pmModelAdd (image, NULL, model, PM_MODEL_OP_FULL, maskVal);
    112 
    113     // loop over a range of source fluxes
    114     // no need to interpolate since we have forced the object center
    115     // to 0.5, 0.5 above
    116     bool completeGrowthCurve = true;            // do we have a complete curve of growth?
    117     for (int i = 0; i < psf->growth->radius->n; i++) {
    118 
    119         radius = psf->growth->radius->data.F32[i];
     170    pmModelAdd (pixels, NULL, model, PM_MODEL_OP_FULL, maskVal);
     171
     172    // Loop over a range of radii.  No need to interpolate since we have forced the object
     173    // center to 0.5, 0.5 above
     174    for (int i = 0; i < growth->radius->n; i++) {
     175
     176        radius = growth->radius->data.F32[i];
    120177
    121178        // mask the given aperture and measure the apMag
    122179        psImageKeepCircle (mask, xc, yc, radius, "OR", markVal);
    123         if (!pmSourcePhotometryAper (&apMag, model, image, mask, maskVal)) {
    124             psError(PM_ERR_PHOTOM, false, "Measuring apMag for radius == %g", radius);
    125             psErrorStackPrint (stderr, "failure to get growth curve");
    126             psErrorClear();
    127             completeGrowthCurve = false;
    128             break;
     180        if (!pmSourcePhotometryAper (&apMag, model, pixels, mask, maskVal)) {
     181            psFree (growth);
     182            psFree (view);
     183            psFree (pixels);
     184            psFree (mask);
     185            psFree (model);
     186            psFree (modelRef);
     187            return NULL;
    129188        }
    130189        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(markVal));
     
    132191        // the 'ignore' mode is for testing
    133192        if (ignore) {
    134             psf->growth->apMag->data.F32[i] = fitMag;
     193            growth->apMag->data.F32[i] = fitMag;
    135194        } else {
    136             psf->growth->apMag->data.F32[i] = apMag;
     195            growth->apMag->data.F32[i] = apMag;
    137196        }
    138197    }
    139 
    140     if (completeGrowthCurve) {
    141         psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
    142         psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
    143     } else {
    144         psf->growth->apRef = NAN;
    145         psf->growth->apLoss = 0;
    146     }
    147 
    148     psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f\n", psf->growth->apLoss);
    149 
     198   
    150199    psFree (view);
    151     psFree (image);
     200    psFree (pixels);
    152201    psFree (mask);
    153202    psFree (model);
    154203    psFree (modelRef);
    155204
    156     return completeGrowthCurve ? true : false;
     205    // psLogMsg ("psModules", 4, "GrowthCurve for %f,%f\n", xc, yc);
     206
     207    return growth;
    157208}
Note: See TracChangeset for help on using the changeset viewer.