IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 25, 2007, 3:20:29 PM (19 years ago)
Author:
magnier
Message:

incorporating updates from eam_02_branch (cached models, pmPSF FITS IO)

File:
1 edited

Legend:

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

    r12949 r13034  
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-04-21 19:47:14 $
     5 *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-04-26 01:20:29 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    106106    // replace source flux
    107107    // XXX need to be certain which model and size of mask for prior subtraction
     108    // XXX full model or just analytical?
     109    // XXX use pmSourceAdd instead?
    108110    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    109         pmModelAdd (source->pixels, source->mask, model, false, false);
     111        pmModelAdd (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL);
    110112    }
    111113
     
    180182    // set aperture mask circle to model radius
    181183    // XXX use a different radius for apertures and fits...
    182     psImageKeepCircle (source->mask, x, y, model->radiusFit, "OR", PM_MASK_MARK);
     184    // XXX can I remove this?  the source should have the mask defined when it is constructed or
     185    // when the fit / aperture radius is changed...
     186    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "OR", PM_MASK_MARK);
    183187
    184188    // measure the weight of included pixels
    185189    // XXX is this supposed to use the weight or the flux?
    186190    if (mode & PM_SOURCE_PHOT_WEIGHT) {
    187         pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->mask);
     191        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj);
    188192    }
    189193
    190194    // measure object aperture photometry
    191     status = pmSourcePhotometryAper  (&source->apMag, model, flux, source->mask);
     195    status = pmSourcePhotometryAper  (&source->apMag, model, flux, source->maskObj);
    192196
    193197    // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
     
    206210
    207211    // unmask aperture
    208     psImageKeepCircle (source->mask, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK));
     212    // XXX can I remove this?  this will probably break things downstream...
     213    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK));
    209214
    210215    // if source was originally subtracted, re-subtract object, leave local sky
     216    // XXX replace with pmSourceSub...
    211217    if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
    212         pmModelSub (source->pixels, source->mask, model, false, false);
     218        pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL);
    213219    }
    214220
     
    363369}
    364370
     371# if (0)
    365372double pmSourceCrossProduct (const pmSource *Mi,
    366373                             const pmSource *Mj,
     
    379386    const psImage *Wi = Mi->weight;
    380387
    381     const psImage *Ti = Mi->mask;
    382     const psImage *Tj = Mj->mask;
     388    const psImage *Ti = Mi->maskObj;
     389    const psImage *Tj = Mj->maskObj;
    383390
    384391    Xs = PS_MAX (Pi->col0, Pj->col0);
     
    435442    const psImage *Wi = Mi->weight;
    436443
    437     const psImage *Ti = Mi->mask;
    438     const psImage *Tj = Mj->mask;
     444    const psImage *Ti = Mi->maskObj;
     445    const psImage *Tj = Mj->maskObj;
    439446
    440447    Xs = PS_MAX (Pi->col0, Pj->col0);
     
    483490    const psImage *Pi = Mi->pixels;
    484491    const psImage *Wi = Mi->weight;
    485     const psImage *Ti = Mi->mask;
     492    const psImage *Ti = Mi->maskObj;
    486493
    487494    // note that this is addressing the same image pixels,
     
    521528    return flux;
    522529}
     530# endif
    523531
    524532bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight)
     
    543551}
    544552
    545 // given a source, which model is currently appropriate?
    546 // choose PSF or EXT based on source->type, but fall back on PSF
    547 // if the EXT model is NULL
    548 pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source)
    549 {
    550 
    551     pmModel *model;
    552 
    553     switch (source->type) {
    554     case PM_SOURCE_TYPE_STAR:
    555         model = source->modelPSF;
    556         if (model == NULL)
    557             return NULL;
    558         if (isPSF)
    559             *isPSF = true;
    560         return model;
    561 
    562     case PM_SOURCE_TYPE_EXTENDED:
    563         model = source->modelEXT;
    564         if (isPSF)
    565             *isPSF = false;
    566         if (model == NULL) {
    567             model = source->modelPSF;
    568             if (isPSF)
    569                 *isPSF = true;
    570         }
    571         if (model == NULL) {
    572             if (isPSF)
    573                 *isPSF = FALSE;
    574             return NULL;
    575         }
    576         return (model);
    577         break;
    578 
    579     default:
    580         if (isPSF)
    581             *isPSF = false;
    582         return NULL;
    583     }
    584     return NULL;
    585 }
     553
     554double pmSourceModelWeight(const pmSource *Mi,
     555                      int term,
     556                      const bool unweighted_sum) // should the cross product be weighted?
     557{
     558    double flux = 0, wt = 0, factor = 0;
     559
     560    const psImage *Pi = Mi->modelFlux;
     561    const psImage *Wi = Mi->weight;
     562    const psImage *Ti = Mi->maskObj;
     563
     564    for (int yi = 0; yi < Pi->numRows; yi++) {
     565        for (int xi = 0; xi < Pi->numCols; xi++) {
     566            if (Ti->data.U8[yi][xi])
     567                continue;
     568            if (!unweighted_sum) {
     569                wt = Wi->data.F32[yi][xi];
     570                if (wt == 0)
     571                    continue;
     572            }
     573
     574            switch (term) {
     575            case 0:
     576                factor = 1;
     577                break;
     578            case 1:
     579                factor = xi + Pi->col0;
     580                break;
     581            case 2:
     582                factor = yi + Pi->row0;
     583                break;
     584            default:
     585                psAbort("invalid term for pmSourceWeight");
     586            }
     587
     588            if (unweighted_sum) {
     589                flux += (factor * Pi->data.F32[yi][xi]);
     590            } else {
     591                flux += (factor * Pi->data.F32[yi][xi]) / wt;
     592            }
     593        }
     594    }
     595    return flux;
     596}
     597
     598double pmSourceModelDotModel (const pmSource *Mi,
     599                              const pmSource *Mj,
     600                              const bool unweighted_sum) // should the cross product be weighted?
     601{
     602    int Xs, Xe, Ys, Ye;
     603    int xi, xj, yi, yj;
     604    int xIs, xJs, yIs, yJs;
     605    int xIe, yIe;
     606    double flux, wt;
     607
     608    const psImage *Pi = Mi->modelFlux;
     609    const psImage *Pj = Mj->modelFlux;
     610
     611    const psImage *Wi = Mi->weight;
     612
     613    const psImage *Ti = Mi->maskObj;
     614    const psImage *Tj = Mj->maskObj;
     615
     616    Xs = PS_MAX (Pi->col0, Pj->col0);
     617    Xe = PS_MIN (Pi->col0 + Pi->numCols, Pj->col0 + Pj->numCols);
     618
     619    Ys = PS_MAX (Pi->row0, Pj->row0);
     620    Ye = PS_MIN (Pi->row0 + Pi->numRows, Pj->row0 + Pj->numRows);
     621
     622    xIs = Xs - Pi->col0;
     623    xJs = Xs - Pj->col0;
     624    yIs = Ys - Pi->row0;
     625    yJs = Ys - Pj->row0;
     626
     627    xIe = Xe - Pi->col0;
     628    yIe = Ye - Pi->row0;
     629
     630    // note that weight is addressing the same image pixels
     631    flux = 0;
     632    for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
     633        for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
     634            if (Ti->data.U8[yi][xi])
     635                continue;
     636            if (Tj->data.U8[yj][xj])
     637                continue;
     638
     639            // XXX skip the nonsense weight pixels?
     640            if (unweighted_sum) {
     641                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     642            } else {
     643                wt = Wi->data.F32[yi][xi];
     644                if (wt > 0) {
     645                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
     646                }
     647            }
     648        }
     649    }
     650    return flux;
     651}
     652
     653double pmSourceDataDotModel (const pmSource *Mi,
     654                             const pmSource *Mj,
     655                             const bool unweighted_sum) // should the cross product be weighted?
     656{
     657
     658    int Xs, Xe, Ys, Ye;
     659    int xi, xj, yi, yj;
     660    int xIs, xJs, yIs, yJs;
     661    int xIe, yIe;
     662    double flux, wt;
     663
     664    const psImage *Pi = Mi->pixels;
     665    const psImage *Pj = Mj->modelFlux;
     666
     667    const psImage *Wi = Mi->weight;
     668
     669    const psImage *Ti = Mi->maskObj;
     670    const psImage *Tj = Mj->maskObj;
     671
     672    Xs = PS_MAX (Pi->col0, Pj->col0);
     673    Xe = PS_MIN (Pi->col0 + Pi->numCols, Pj->col0 + Pj->numCols);
     674
     675    Ys = PS_MAX (Pi->row0, Pj->row0);
     676    Ye = PS_MIN (Pi->row0 + Pi->numRows, Pj->row0 + Pj->numRows);
     677
     678    xIs = Xs - Pi->col0;
     679    xJs = Xs - Pj->col0;
     680    yIs = Ys - Pi->row0;
     681    yJs = Ys - Pj->row0;
     682
     683    xIe = Xe - Pi->col0;
     684    yIe = Ye - Pi->row0;
     685
     686    // note that weight is addressing the same image pixels,
     687    flux = 0;
     688    for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) {
     689        for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) {
     690            if (Ti->data.U8[yi][xi])
     691                continue;
     692            if (Tj->data.U8[yj][xj])
     693                continue;
     694
     695            // XXX skip the nonsense weight pixels?
     696            if (unweighted_sum) {
     697                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
     698            } else {
     699                wt = Wi->data.F32[yi][xi];
     700                if (wt > 0) {
     701                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
     702                }
     703            }
     704        }
     705    }
     706    return flux;
     707}
     708
Note: See TracChangeset for help on using the changeset viewer.