IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25128


Ignore:
Timestamp:
Aug 19, 2009, 12:16:54 PM (17 years ago)
Author:
eugene
Message:

updates to make radial profiles a bit more robust

Location:
branches/eam_branches/20090715/psphot/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/psphot/src/psphotPetrosianProfile.c

    r25105 r25128  
    1313
    1414  int Nsec = 24;
    15   float Rmax = 64;
     15  float Rmax = 200;
    1616  float fluxMin = 0.0;
    17   float fluxMax = 1000.0;
     17  float fluxMax = source->peak->flux;
    1818
    1919  // generate a series of radial profiles at Nsec evenly spaced angles.  the profile flux
  • branches/eam_branches/20090715/psphot/src/psphotPetrosianStudy.c

    r25105 r25128  
    11# include "psphotInternal.h"
     2
     3# define DX 512
     4# define DY 512
     5
     6// XXX add noise and seeing.
     7// XXX double check on sersic functional form
     8// XXX modify ratio if ratio > 1.0 (swap major and minor)
     9
     10pmPeak *psphotLocalPeak(pmReadout *readout, int Xo, int Yo);
    211
    312int main (int argc, char **argv) {
     
    716
    817  int N;
    9 
    10   // XXX add noise and seeing.
    11   // XXX double check on sersic functional form
    12   // XXX modify ratio if ratio > 1.0 (swap major and minor)
     18  float Xo = 0.5*DX;
     19  float Yo = 0.5*DY;
     20  char *image = NULL;
     21  pmSource *source = NULL;
    1322
    1423  float peak = 1000.0;
     
    1827  float sersic = 0.5;
    1928  float skynoise = 0.0;
    20 
     29 
    2130  if ((N = psArgumentGet (argc, argv, "-peak"))) {
    2231    psArgumentRemove (N, &argc, argv);
     
    5362    pmVisualSetVisual(true);
    5463  }
     64  if ((N = psArgumentGet (argc, argv, "-coords"))) {
     65    psArgumentRemove (N, &argc, argv);
     66    Xo = atof(argv[N]);
     67    psArgumentRemove (N, &argc, argv);
     68    Yo = atof(argv[N]);
     69    psArgumentRemove (N, &argc, argv);
     70  }
     71  if ((N = psArgumentGet (argc, argv, "-image"))) {
     72    psArgumentRemove (N, &argc, argv);
     73    image = psStringCopy (argv[N]);
     74    psArgumentRemove (N, &argc, argv);
     75  }
    5576
    5677  if (argc != 1) {
     
    6182  // create a containing image & associated readout
    6283  pmReadout *readout = pmReadoutAlloc(NULL);
    63   readout->image = psImageAlloc(128, 128, PS_TYPE_F32);
     84  if (!image) {
     85      readout->image = psImageAlloc(DX, DY, PS_TYPE_F32);
    6486
    65   // create a dummy variance, but don't populate -- it is not used by pmSourceMoments if the sigma parameters is set to 0.0
    66   readout->variance = psImageAlloc(128, 128, PS_TYPE_F32);
     87      // create a dummy variance, but don't populate -- it is not used by pmSourceMoments if the sigma parameters is set to 0.0
     88      readout->variance = psImageAlloc(DX, DY, PS_TYPE_F32);
    6789
    68   // create a model & associated source
    69   pmModelType type = pmModelClassGetType("PS_MODEL_SERSIC");
    70   pmModel *model = pmModelAlloc(type);
     90      // create a model & associated source
     91      pmModelType type = pmModelClassGetType("PS_MODEL_SERSIC");
     92      pmModel *model = pmModelAlloc(type);
    7193
    72   // set the model parameters
    73   model->params->data.F32[PM_PAR_SKY]  = 0.0;
    74   model->params->data.F32[PM_PAR_I0]   = peak;
    75   model->params->data.F32[PM_PAR_XPOS] = 64.0;
    76   model->params->data.F32[PM_PAR_YPOS] = 64.0;
     94      // set the model parameters
     95      model->params->data.F32[PM_PAR_SKY]  = 0.0;
     96      model->params->data.F32[PM_PAR_I0]   = peak;
     97      model->params->data.F32[PM_PAR_XPOS] = Xo;
     98      model->params->data.F32[PM_PAR_YPOS] = Yo;
    7799
    78   psEllipseAxes axes;
    79   axes.major = sigma;
    80   axes.minor = sigma*ARatio;
    81   axes.theta = angle;
     100      psEllipseAxes axes;
     101      axes.major = sigma;
     102      axes.minor = sigma*ARatio;
     103      axes.theta = angle;
    82104
    83   psEllipseShape shape = psEllipseAxesToShape (axes);
     105      psEllipseShape shape = psEllipseAxesToShape (axes);
    84106
    85   // XXX set the sigma with user input
    86   model->params->data.F32[PM_PAR_SXX]  = shape.sx * M_SQRT2;
    87   model->params->data.F32[PM_PAR_SYY]  = shape.sy * M_SQRT2;
    88   model->params->data.F32[PM_PAR_SXY]  = shape.sxy;
     107      // XXX set the sigma with user input
     108      model->params->data.F32[PM_PAR_SXX]  = shape.sx * M_SQRT2;
     109      model->params->data.F32[PM_PAR_SYY]  = shape.sy * M_SQRT2;
     110      model->params->data.F32[PM_PAR_SXY]  = shape.sxy;
    89111
    90   if (model->params->n > 7) {
    91     model->params->data.F32[PM_PAR_7]  = sersic;
     112      if (model->params->n > 7) {
     113          model->params->data.F32[PM_PAR_7]  = sersic;
     114      }
     115
     116      // generate source container & populate image
     117      source = pmSourceFromModel(model, readout, Xo, PM_SOURCE_TYPE_STAR);
     118
     119      // generate the modelFlux
     120      pmSourceCacheModel(source, 0);
     121
     122      // instantiate the source
     123      pmSourceAdd(source, PM_MODEL_OP_FUNC, 0);
     124
     125      // XXX add noise here...
     126      psphotSaveImage(NULL, readout->image, "sersic.fits");
     127
     128  } else {
     129      psRegion full = psRegionSet(0,0,0,0);
     130      psFits *fits = psFitsOpen(image, "r");
     131      readout->image = psFitsReadImage(fits, full, 0);
     132
     133      source = pmSourceAlloc();
     134      source->peak = psphotLocalPeak(readout, Xo, Yo);
     135      pmSourceDefinePixels (source, readout, Xo, Yo, 64);
    92136  }
    93 
    94   pmSource *source = pmSourceFromModel(model, readout, 32.0, PM_SOURCE_TYPE_STAR);
    95 
    96   // generate the modelFlux
    97   pmSourceCacheModel(source, 0);
    98 
    99   // instantiate the source
    100   pmSourceAdd(source, PM_MODEL_OP_FUNC, 0);
    101 
    102   // XXX add noise here...
    103 
    104   psphotSaveImage(NULL, readout->image, "sersic.fits");
    105137
    106138  psphotPetrosianProfile (source);
     
    110142  exit (0);
    111143}
     144
     145// Xo, Yo are in parent coords
     146pmPeak *psphotLocalPeak(pmReadout *readout, int Xo, int Yo) {
     147
     148    int Xp = Xo;
     149    int Yp = Yo;
     150    float peakFlux = readout->image->data.F32[Yp][Xp];
     151
     152    // find local peak within +/- 3 pix of the given coordinate
     153    for (int iy = Yo - 3; iy <= Yo + 3; iy++) {
     154        for (int ix = Xo - 3; ix <= Xo + 3; ix++) {
     155            if (peakFlux < readout->image->data.F32[iy][ix]) {
     156                Xp = ix;
     157                Yp = iy;
     158                peakFlux = readout->image->data.F32[Yp][Xp];
     159            }
     160        }
     161    }
     162
     163    pmPeak *peak = pmPeakAlloc(Xp, Yp, peakFlux, PM_PEAK_LONE);
     164
     165    // calculate fractional peak position relative to Xp,Yp
     166    psPolynomial2D *bicube = psImageBicubeFit (readout->image, Xp, Yp);
     167    psPlane min = psImageBicubeMin (bicube);
     168    psFree (bicube);
     169
     170    // if min point is too deviant, use the peak value
     171    if ((fabs(min.x) < 1.5) && (fabs(min.y) < 1.5)) {
     172        peak->xf = min.x + Xp;
     173        peak->yf = min.y + Yp;
     174
     175        // xf,yf must land on image with 0 pixel border
     176        peak->xf = PS_MAX (PS_MIN (peak->xf, readout->image->numCols - 1), readout->image->col0);
     177        peak->yf = PS_MAX (PS_MIN (peak->yf, readout->image->numRows - 1), readout->image->row0);
     178    } else {
     179        peak->xf = Xp;
     180        peak->yf = Yp;
     181    }
     182
     183    return peak;
     184}
  • branches/eam_branches/20090715/psphot/src/psphotPetrosianVisual.c

    r25105 r25128  
    2626        graphdata->xmin = graphdata->xmax = xVec->data.F32[0];
    2727        for (int i = 1; i < xVec->n; i++) {
     28            if (!isfinite(xVec->data.F32[i])) continue;
    2829            graphdata->xmin = PS_MIN (graphdata->xmin, xVec->data.F32[i]);
    2930            graphdata->xmax = PS_MAX (graphdata->xmax, xVec->data.F32[i]);
     
    3637        graphdata->ymin = graphdata->ymax = yVec->data.F32[0];
    3738        for (int i = 1; i < yVec->n; i++) {
     39            if (!isfinite(yVec->data.F32[i])) continue;
    3840            graphdata->ymin = PS_MIN (graphdata->ymin, yVec->data.F32[i]);
    3941            graphdata->ymax = PS_MAX (graphdata->ymax, yVec->data.F32[i]);
  • branches/eam_branches/20090715/psphot/src/psphotRadialProfileByAngle.c

    r25105 r25128  
    55
    66// XXX choices for rMax and Nsec?
    7 // XXX where does the output go?
    8 // XXX how does this fit in context?
    97
    108bool psphotRadialProfilesByAngles (pmPetrosian *petrosian, pmSource *source, int Nsec, float Rmax) {
    119
     10    // we want to have an even number of sectors so we can do 180 deg symmetrizing
     11    Nsec = (Nsec % 2) ? Nsec + 1 : Nsec;
    1212    float dtheta = 2.0*M_PI / Nsec;
    1313
     
    4646            // value is NAN if we run off the image
    4747            float value = psImageInterpolatePixelBilinear(x, y, source->pixels);
    48             if (isnan(value)) continue;
     48
     49            // keep the nan values so all vectors are matched
     50            // if (isnan(value)) continue;
    4951
    5052            psVectorAppend (radius, r);
     
    6264    }
    6365
     66    for (int i = 0; i < Nsec / 2; i++) {
     67
     68        psVector *r1 = petrosian->radii->data[i];
     69        psVector *r2 = petrosian->radii->data[i+Nsec/2];
     70
     71        psVector *f1 = petrosian->fluxes->data[i];
     72        psVector *f2 = petrosian->fluxes->data[i+Nsec/2];
     73
     74        psAssert (r1->n == r2->n, "mis-matched vectors");
     75        psAssert (f1->n == f2->n, "mis-matched vectors");
     76
     77        // we have a pair of vectors i, i+Nsec/2; replace them with the finite minimum of the pair
     78        for (int j = 0; j < r1->n; j++) {
     79           
     80            float flux;
     81
     82            if (!isfinite(f1->data.F32[j]) && !isfinite(f2->data.F32[j])) {
     83                flux = NAN;
     84                goto setflux;
     85            }
     86
     87            if (!isfinite(f1->data.F32[j])) {
     88                flux = f2->data.F32[j];
     89                goto setflux;
     90            }
     91            if (!isfinite(f2->data.F32[j])) {
     92                flux = f1->data.F32[j];
     93                goto setflux;
     94            }
     95
     96            flux = PS_MIN(f1->data.F32[j], f2->data.F32[j]);
     97
     98        setflux:
     99            f1->data.F32[j] = flux;
     100            f2->data.F32[j] = flux;
     101        }
     102    }   
    64103    return true;
    65104}
  • branches/eam_branches/20090715/psphot/src/psphotRadiiFromProfiles.c

    r25105 r25128  
    3030
    3131    // examine data in the two ranges Fm - Fo and Fo - Fp to define the bin size
     32    // XXX reconsider the fractional isophote value
    3233    float Fm = fluxMin + 0.25*fluxRange;
    3334    float Fp = fluxMin + 0.75*fluxRange;
    3435    float Fo = fluxMin + 0.50*fluxRange;
     36    int Rbin = 1;
    3537     
    36     // find the mean radius of the points in the flux range Fm - Fp:
    37     float Rsum = 0;
    38     float Rnpt = 0;
    39     for (int i = 0; i < flux->n; i++) {
    40         if (flux->data.F32[i] < Fm) continue;
    41         if (flux->data.F32[i] > Fp) continue;
    42      
    43         Rsum += radius->data.F32[i];
    44         Rnpt ++;
    45     }
     38    // find the median radius of the points in the flux range Fm - Fp:
     39    {
     40        // storage vector for stats
     41        psVector *values = psVectorAllocEmpty (flux->n, PS_TYPE_F32);
     42        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    4643
    47     // rebin with bins 1/2 the size of the mean radius
    48     int Rbin = 0;
    49     if (Rnpt == 0) {
    50         Rbin = 1;
    51     } else {
    52         Rbin = MAX(1, 0.5*(Rsum / Rnpt));
     44        for (int i = 0; i < flux->n; i++) {
     45            if (!isfinite(flux->data.F32[i])) continue;
     46            if (flux->data.F32[i] < Fm) continue;
     47            if (flux->data.F32[i] > Fp) continue;
     48           
     49            psVectorAppend (values, radius->data.F32[i]);
     50        }
     51        psVectorStats (stats, values, NULL, NULL, 0);
     52
     53        // if we have a valid range, rebin with bin size 1/2 of median radius
     54        if (isfinite(stats->sampleMedian)) {
     55            Rbin = MAX(1, 0.5*stats->sampleMedian);
     56        }
    5357    }
    5458
     
    9498                psStatsInit(stats);
    9599            }
     100            if (!isfinite(flux->data.F32[i])) continue;
    96101            psVectorAppend (values, flux->data.F32[i]);
    97102        }
     
    105110    bool above = true;
    106111    for (int i = 0; i < fluxBinned->n; i++) {
     112
     113        if (!isfinite(fluxBinned->data.F32[i])) continue;
    107114
    108115        // find the largest radius that matches the flux transition
Note: See TracChangeset for help on using the changeset viewer.