IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 6, 2008, 10:11:39 AM (18 years ago)
Author:
eugene
Message:

fix algorithms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080324/psphot/src/psphotPetrosian.c

    r15800 r17335  
    1 # include "psphot.h"
     1# include "psphotInternal.h"
     2
     3static float PETROSIAN_R0 = NAN;
     4static float PETROSIAN_RF = NAN;
    25
    36bool psphotPetrosian (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
     
    1417
    1518  // flux at which to measure isophotal parameters
    16   // XXX cache this?
    17   float PETROSIAN_R0 = psMetadataLookupF32 (&status, recipe, "PETROSIAN_R0");
    18   float PETROSIAN_RF = psMetadataLookupF32 (&status, recipe, "PETROSIAN_FLUX_RATIO");
     19  if (!isfinite(PETROSIAN_R0)) {
     20    PETROSIAN_R0 = psMetadataLookupF32 (&status, recipe, "PETROSIAN_R0");
     21    PETROSIAN_RF = psMetadataLookupF32 (&status, recipe, "PETROSIAN_FLUX_RATIO");
     22    assert (status);
     23  }
    1924
    2025  // first find flux at R0
    21   int firstBelow = -1;
    22   int lastAbove = -1;
     26  int firstAbove = -1;
     27  int lastBelow = -1;
    2328  for (int i = 0; i < radius->n; i++) {
    24     if (radius->data.F32[i] > PETROSIAN_R0) lastAbove = i;
    25     if ((firstBelow < 0) && (flux->data.F32[i] < PETROSIAN_R0)) firstBelow = i;
     29    if (radius->data.F32[i] < PETROSIAN_R0) lastBelow = i;
     30    if ((firstAbove < 0) && (radius->data.F32[i] > PETROSIAN_R0)) firstAbove = i;
     31  }
     32  // if we don't go out far enough, we have a problem...
     33  if (lastBelow == radius->n - 1) {
     34    psTrace ("psphot", 5, "did not go out far enough to reach petrosian reference radius...");
     35    // XXX skip object? raise a flag ?
     36    return false;
     37  }
     38  if (firstAbove < 0) {
     39    psTrace ("psphot", 5, "did not go out far enough to bound petrosian reference radius");
     40    // XXX raise a flag ?
     41    return false;
    2642  }
    2743
     
    2945  float fluxR0 = 0.0;
    3046  int fluxRn = 0;
    31   for (int i = PS_MIN(firstBelow, lastAbove); i <= PS_MAX(firstBelow, lastAbove); i++) {
     47  for (int i = PS_MIN(firstAbove, lastBelow); i <= PS_MAX(firstAbove, lastBelow); i++) {
    3248    fluxR0 += flux->data.F32[i];
    3349    fluxRn ++;
     
    4258  // XXX do I need to worry about crazy outliers? 
    4359  // XXX should i be smoothing or fitting the curve?
    44   firstBelow = -1;
    45   lastAbove = -1;
     60  int firstBelow = -1;
     61  int lastAbove = -1;
    4662  for (int i = 0; i < flux->n; i++) {
    4763    if (flux->data.F32[i] > fluxRP) lastAbove = i;
    4864    if ((firstBelow < 0) && (flux->data.F32[i] < fluxRP)) firstBelow = i;
     65  }
     66  // if we don't go out far enough, we have a problem...
     67  if (lastAbove == radius->n - 1) {
     68    psTrace ("psphot", 5, "did not go out far enough to reach petrosian radius...");
     69    // XXX skip object? raise a flag ?
     70    return false;
     71  }
     72  if (firstBelow < 0) {
     73    psTrace ("psphot", 5, "did not go out far enough to bound petrosian radius");
     74    // XXX raise a flag ?
     75    return false;
    4976  }
    5077
     
    78105  source->extpars->petrosian->radErr = radErr;
    79106
     107  psTrace ("psphot", 5, "Petrosian flux:%f +/- %f @ %f +/- %f for %f, %f\n",
     108           source->extpars->petrosian->mag, source->extpars->petrosian->magErr,
     109           source->extpars->petrosian->rad, source->extpars->petrosian->radErr,
     110           source->peak->xf, source->peak->yf);
     111
    80112  return true;
    81113
Note: See TracChangeset for help on using the changeset viewer.