IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 8, 2006, 5:14:23 PM (20 years ago)
Author:
magnier
Message:

major rework of objects code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/objects/pmSourcePhotometry.c

    r6537 r6556  
    1 /** @file  pmSourcePhotometry.C
     1/** @file  pmSourcePhotometry.c
    22 *
    33 *  @author EAM, IfA; GLG, MHPCC
    44 *
    5  *  @version $Revision: 1.1.2.1 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-03-07 06:33:35 $
     5 *  @version $Revision: 1.1.2.2 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-03-09 03:14:23 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1010 */
    1111
    12 // XXX EAM : the apMag should only be calculated for the brighter sources?
    13 // XXX EAM : SN limit set by user?
     12#include <stdio.h>
     13#include <math.h>
     14#include <string.h>
     15#include "pslib.h"
     16#include "pmHDU.h"
     17#include "pmFPA.h"
     18#include "pmPeaks.h"
     19#include "pmMoments.h"
     20#include "pmGrowthCurve.h"
     21#include "pmModel.h"
     22#include "pmPSF.h"
     23#include "pmSource.h"
     24#include "pmModelGroup.h"
     25#include "pmSourcePhotometry.h"
     26
     27static float AP_MIN_SN = 0.0;
     28
     29bool pmSourceMagnitudesInit (psMetadata *config)
     30{
     31
     32    bool status;
     33
     34    float limit = psMetadataLookupF32 (&status, config, "AP_MIN_SN");
     35    if (status) {
     36        AP_MIN_SN = limit;
     37    }
     38    return true;
     39}
     40
     41/**
     42    this function is used to calculate the three defined source magnitudes:
     43    - apMag  : only if S/N > AP_MIN_SN
     44             : is optionally corrected for curve-of-growth if:
     45        - the source is a STAR (PSF)
     46        - the option is selected (how??)
     47    - psfMag : all sources with non-NULL modelPSF
     48             : is optionally corrected for aperture residual if:
     49        - the source is a STAR (PSF)
     50        - the option is selected (how??)
     51       
     52    - extMag : all sources with non-NULL modelEXT
     53**/
     54
    1455// XXX EAM : masked region should be (optionally) elliptical
     56// XXX curve of growth is corrected to
    1557pmModel *pmSourceMagnitudes (pmSource *source, pmPSF *psf, float apRadius)
    1658{
     
    2163    float rflux;
    2264    float radius;
     65    float SN;
    2366    pmModel *model;
    2467
    2568    switch (source->type) {
    26     case PM_SOURCE_STAR:
     69    case PM_SOURCE_TYPE_STAR:
    2770        model = source->modelPSF;
    2871        if (model == NULL)
     
    3275        break;
    3376
    34     case PM_SOURCE_EXTENDED:
     77    case PM_SOURCE_TYPE_EXTENDED:
    3578        model = source->modelEXT;
    3679        if (model == NULL)
     
    4487    }
    4588
     89    if (model->dparams->data.F32[1] > 0) {
     90        SN = model->params->data.F32[1] / model->dparams->data.F32[1];
     91        source->errMag = 1.0 / SN;
     92    } else {
     93        SN = 0.0;
     94        source->errMag = 0.0;
     95    }
    4696    x = model->params->data.F32[2];
    4797    y = model->params->data.F32[3];
    4898
    4999    // replace source flux
     100    // XXX test to see if source has been subtracted?
    50101    pmModelAdd (source->pixels, source->mask, model, false, false);
    51102
    52     // set aperture mask circle of PSF_FIT_RADIUS
    53     psImageKeepCircle (source->mask, x, y, radius, "OR", PSPHOT_MASK_MARKED);
    54 
    55     // measure object photometry
    56     status = pmSourcePhotometry (&source->fitMag, &source->apMag, model, source->pixels, source->mask);
    57 
    58     // for PSFs, correct both apMag and fitMag to same system, consistent with infinite flux star in aperture RADIUS
     103    // set aperture mask circle to scaled radius
     104    psImageKeepCircle (source->mask, x, y, model->radius, "OR", PM_SOURCE_MASK_MARKED);
     105
     106    // measure object model photometry
     107    status = pmSourcePhotometryModel (&source->psfMag, source->modelPSF);
     108    status = pmSourcePhotometryModel (&source->extMag, source->modelEXT);
     109
     110    // measure object aperture photometry
     111    if (SN > AP_MIN_SN) {
     112        status = pmSourcePhotometryAper  (&source->apMag,  model, source->pixels, source->mask);
     113    } else {
     114        source->apMag = 99.0;
     115    }
     116
     117    // for PSFs, correct both apMag and psfMag to same system, consistent with infinite flux star in aperture RADIUS
    59118    if (isPSF && (psf != NULL)) {
    60         if (psf->growth != NULL) {
    61             source->apMag += pmGrowthCurveCorrect (psf->growth, model->radius);
    62         }
    63 
    64         rflux   = pow (10.0, 0.4*source->fitMag);
    65         source->apMag  -= PS_SQR(model->radius)*rflux * psf->skyBias + psf->skySat / rflux;
    66         source->fitMag += psPolynomial4DEval (psf->ApTrend, x, y, 0.0, 0.0);
     119        if (SN > AP_MIN_SN) {
     120            if (psf->growth != NULL) {
     121                source->apMag += pmGrowthCurveCorrect (psf->growth, radius);
     122            }
     123            rflux   = pow (10.0, 0.4*source->psfMag);
     124            source->apMag  -= PS_SQR(model->radius)*rflux * psf->skyBias + psf->skySat / rflux;
     125        }
     126        source->psfMag += psPolynomial4DEval (psf->ApTrend, x, y, 0.0, 0.0);
    67127    }
    68128
    69129    // unmask aperture
    70     psImageKeepCircle (source->mask, x, y, radius, "AND", ~PSPHOT_MASK_MARKED);
     130    psImageKeepCircle (source->mask, x, y, model->radius, "AND", ~PM_SOURCE_MASK_MARKED);
    71131
    72132    // subtract object, leave local sky
     
    85145*/
    86146
    87 // XXX split into ap, psf, ext mags?
    88 bool pmSourcePhotometry (float *fitMag, float *obsMag, pmModel *model, psImage *image, psImage *mask)
     147// return source model magnitude
     148bool pmSourcePhotometryModel (float *fitMag, pmModel *model)
     149{
     150
     151    float fitSum = 0;
     152    *fitMag = 99.0;
     153
     154    if (model == NULL) {
     155        return false;
     156    }
     157
     158    // measure fitMag
     159    pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
     160    fitSum = modelFluxFunc (model->params);
     161    if (fitSum <= 0)
     162        return false;
     163    if (!isfinite(fitSum))
     164        return false;
     165    *fitMag = -2.5*log10(fitSum);
     166
     167    return (true);
     168}
     169
     170// return source aperture magnitude
     171bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask)
     172{
     173
     174    float apSum = 0;
     175    *apMag = 99.0;
     176
     177    if (model == NULL) {
     178        return false;
     179    }
     180
     181    float sky = model->params->data.F32[0];
     182
     183    // measure apMag
     184    for (int ix = 0; ix < image->numCols; ix++) {
     185        for (int iy = 0; iy < image->numRows; iy++) {
     186            if (mask->data.U8[iy][ix])
     187                continue;
     188            apSum += image->data.F32[iy][ix] - sky;
     189        }
     190    }
     191    if (apSum <= 0)
     192        return false;
     193    *apMag = -2.5*log10(apSum);
     194
     195    return (true);
     196}
     197
     198# if (0)
     199    // XXX split into ap, psf, ext mags?
     200    bool pmSourcePhotometry (float *fitMag, float *apMag, pmModel *model, psImage *image, psImage *mask)
    89201{
    90202
     
    96208    *obsMag = 99.0;
    97209
     210    // measure fitMag
    98211    pmModelFlux modelFluxFunc = pmModelFlux_GetFunction (model->type);
    99212    fitSum = modelFluxFunc (model->params);
     
    104217    *fitMag = -2.5*log10(fitSum);
    105218
     219    // measure apMag
    106220    for (int ix = 0; ix < image->numCols; ix++) {
    107221        for (int iy = 0; iy < image->numRows; iy++) {
     
    117231    return (true);
    118232}
     233# endif
    119234
    120235float pmSourceCrossProduct (pmSource *Mi, pmSource *Mj)
Note: See TracChangeset for help on using the changeset viewer.