IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 6, 2006, 11:11:12 PM (20 years ago)
Author:
magnier
Message:

added code to perform the subpixel shift, if requested; changed special magnitude values to NAN; test for prior subtraction of source before replacing; subtracts at the end if it was subtracted

File:
1 edited

Legend:

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

    r9866 r9883  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-11-06 02:11:04 $
     5 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-11-07 09:11:12 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5151             : is optionally corrected for curve-of-growth if:
    5252        - the source is a STAR (PSF)
    53         - the option is selected (how??)
     53        - the option is selected (mode & PM_SOURCE_PHOT_GROWTH)
    5454    - psfMag : all sources with non-NULL modelPSF
    5555             : is optionally corrected for aperture residual if:
    5656        - the source is a STAR (PSF)
    57         - the option is selected (how??)
     57        - the option is selected (mode & PM_SOURCE_PHOT_APCORR)
    5858 
    5959    - extMag : all sources with non-NULL modelEXT
    6060**/
    6161
    62 // XXX EAM : masked region should be (optionally) elliptical
     62// XXX masked region should be (optionally) elliptical
    6363bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode)
    6464{
     
    7171    pmModel *model;
    7272
    73     source->psfMag = 99.0;
    74     source->extMag = 99.0;
    75     source->errMag = 99.0;
    76     source->apMag  = 99.0;
    77 
     73    source->psfMag = NAN;
     74    source->extMag = NAN;
     75    source->errMag = NAN;
     76    source->apMag  = NAN;
     77
     78    // XXX these tests prevent aperture photometry without valid model.  is
     79    // this reasonable?  probably not...
    7880    switch (source->type) {
    7981    case PM_SOURCE_TYPE_STAR:
     
    99101        source->errMag = 1.0 / SN;
    100102    } else {
    101         SN = 0.0;
    102         source->errMag = 0.0;
     103        SN = NAN;
     104        source->errMag = NAN;
    103105    }
    104106    x = model->params->data.F32[PM_PAR_XPOS];
     
    114116    }
    115117
    116     if (SN < AP_MIN_SN)
     118    if (!isfinite(SN) || (SN < AP_MIN_SN))
    117119        return false;
    118120
    119121    // replace source flux
    120     // XXX test to see if source has been subtracted?
    121     pmModelAdd (source->pixels, source->mask, model, false, false);
     122    // XXX need to be certain which model and size of mask for prior subtraction
     123    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     124        pmModelAdd (source->pixels, source->mask, model, false, false);
     125    }
     126
     127    // if we are measuring aperture photometry and applying the growth correction,
     128    // we need to shift the flux in the selected pixels (but not the mask)
     129    // psImageShift ();
     130    psImage *flux;
     131    if (mode & PM_SOURCE_PHOT_INTERP) {
     132        float dx = 0.5 - x + (int)x;
     133        float dy = 0.5 - y + (int)y;
     134        flux = psImageShift (NULL, source->pixels, dx, dy, 0.0, PS_INTERPOLATE_BICUBE);
     135    } else {
     136        flux = source->pixels;
     137    }
    122138
    123139    // set aperture mask circle to model radius
     140    // XXX use a different radius for apertures and fits...
    124141    psImageKeepCircle (source->mask, x, y, model->radiusFit, "OR", PM_MASK_MARK);
    125142
    126143    // measure the weight of included pixels
     144    // XXX is this supposed to use the weight or the flux?
    127145    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    128146        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->mask);
     
    130148
    131149    // measure object aperture photometry
    132     status = pmSourcePhotometryAper  (&source->apMag, model, source->pixels, source->mask);
     150    status = pmSourcePhotometryAper  (&source->apMag, model, flux, source->mask);
    133151
    134152    // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
     
    142160        }
    143161    }
     162    if (mode & PM_SOURCE_PHOT_INTERP) {
     163        psFree (flux);
     164    }
    144165
    145166    // unmask aperture
    146167    psImageKeepCircle (source->mask, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK));
    147168
    148     // subtract object, leave local sky
    149     pmModelSub (source->pixels, source->mask, model, false, false);
     169    // if source was originally subtracted, re-subtract object, leave local sky
     170    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
     171        pmModelSub (source->pixels, source->mask, model, false, false);
     172    }
    150173
    151174    return status;
     
    164187
    165188    float fitSum = 0;
    166     *fitMag = 99.0;
     189    *fitMag = NAN;
    167190
    168191    if (model == NULL) {
     
    183206
    184207// return source aperture magnitude
    185 // interpolate the image pixels to place the center at xi+0.5,yi+0.5
    186208bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask)
    187209{
    188210    float apSum = 0;
    189211    float sky = 0;
    190     *apMag = 99.0;
     212    *apMag = NAN;
    191213
    192214    if (model == NULL) {
     
    200222    }
    201223
    202     // shift image to have centroid at xi+0.5, yi+0.5
    203     # if (0)
    204         // this is necessary to make the measurement consistent with the growth model.
    205         // only do this if we are applying the model?
    206         float dx = 0.5 - model->params->data.F32[PM_PAR_XPOS] + (int)model->params->data.F32[PM_PAR_XPOS];
    207     float dy = 0.5 - model->params->data.F32[PM_PAR_YPOS] + (int)model->params->data.F32[PM_PAR_YPOS];
    208     psImage *tmpImage = psImageShift (NULL, image, dx, dy, 0.0, PS_INTERPOLATE_BICUBE);
    209     # else
    210 
    211         psImage *tmpImage = psImageCopy (NULL, image, PS_TYPE_F32);
    212     # endif
    213 
    214224    // measure apMag
    215225    for (int ix = 0; ix < image->numCols; ix++) {
     
    217227            if (mask->data.U8[iy][ix])
    218228                continue;
    219             apSum += tmpImage->data.F32[iy][ix] - sky;
    220         }
    221     }
    222     psFree (tmpImage);
     229            apSum += image->data.F32[iy][ix] - sky;
     230        }
     231    }
    223232    if (apSum <= 0)
    224233        return false;
Note: See TracChangeset for help on using the changeset viewer.