IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 9, 2007, 3:09:20 PM (19 years ago)
Author:
eugene
Message:

updating all changes from from eam_branch_20071023

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotPetrosian.c

    r13983 r15562  
    33bool psphotPetrosian (pmSource *source, psMetadata *recipe, psMaskType maskVal) {
    44
    5   psLogMsg ("psphot", PS_LOG_INFO, "not implemented\n");
     5  bool status;
     6
     7  assert (source->extpars);
     8  assert (source->extpars->profile);
     9  assert (source->extpars->profile->radius);
     10  assert (source->extpars->profile->flux);
     11
     12  psVector *radius = source->extpars->profile->radius;
     13  psVector *flux = source->extpars->profile->flux;
     14
     15  // 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
     20  // first find flux at R0
     21  int firstBelow = -1;
     22  int lastAbove = -1;
     23  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;
     26  }
     27
     28  // average flux in this range
     29  float fluxR0 = 0.0;
     30  int fluxRn = 0;
     31  for (int i = PS_MIN(firstBelow, lastAbove); i <= PS_MAX(firstBelow, lastAbove); i++) {
     32    fluxR0 += flux->data.F32[i];
     33    fluxRn ++;
     34  }
     35  fluxR0 /= (float)(fluxRn);
     36 
     37  // target flux for petrosian radius
     38  float fluxRP = fluxR0 * PETROSIAN_RF;
     39
     40  // find the first bin below the flux level and the last above the level
     41  // XXX can this be done faster with disection?
     42  // XXX do I need to worry about crazy outliers? 
     43  // XXX should i be smoothing or fitting the curve?
     44  firstBelow = -1;
     45  lastAbove = -1;
     46  for (int i = 0; i < flux->n; i++) {
     47    if (flux->data.F32[i] > fluxRP) lastAbove = i;
     48    if ((firstBelow < 0) && (flux->data.F32[i] < fluxRP)) firstBelow = i;
     49  }
     50
     51  // need to examine pixels in this vicinity
     52  float fluxFirst = 0;
     53  float fluxLast = 0;
     54  for (int i = 0; i <= PS_MAX(firstBelow, lastAbove); i++) {
     55    if (i <= firstBelow) {
     56      fluxFirst += flux->data.F32[i];
     57    }
     58    if (i <= lastAbove) {
     59      fluxLast += flux->data.F32[i];
     60    }
     61  }
     62  float fluxRPSum    = 0.5*(fluxLast + fluxFirst);
     63  float fluxRPSumErr = 0.5*fabs(fluxLast - fluxFirst);
     64  // XXX need to use the weight appropriately here...
     65
     66  float rad     = 0.5*(radius->data.F32[firstBelow] + radius->data.F32[lastAbove]);
     67  float radErr  = 0.5*fabs(radius->data.F32[firstBelow] - radius->data.F32[lastAbove]);
     68
     69  if (!source->extpars->petrosian) {
     70    source->extpars->petrosian = pmSourcePetrosianValuesAlloc ();
     71  }
     72 
     73  // these are uncalibrated: instrumental mags and pixel units
     74  source->extpars->petrosian->mag    = -2.5*log10(fluxRPSum);
     75  source->extpars->petrosian->magErr = fluxRPSumErr / fluxRPSum;
     76
     77  source->extpars->petrosian->rad    = rad;
     78  source->extpars->petrosian->radErr = radErr;
     79
    680  return true;
    781
Note: See TracChangeset for help on using the changeset viewer.