IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates to make radial profiles a bit more robust

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.