Changeset 25128
- Timestamp:
- Aug 19, 2009, 12:16:54 PM (17 years ago)
- Location:
- branches/eam_branches/20090715/psphot/src
- Files:
-
- 5 edited
-
psphotPetrosianProfile.c (modified) (1 diff)
-
psphotPetrosianStudy.c (modified) (6 diffs)
-
psphotPetrosianVisual.c (modified) (2 diffs)
-
psphotRadialProfileByAngle.c (modified) (3 diffs)
-
psphotRadiiFromProfiles.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090715/psphot/src/psphotPetrosianProfile.c
r25105 r25128 13 13 14 14 int Nsec = 24; 15 float Rmax = 64;15 float Rmax = 200; 16 16 float fluxMin = 0.0; 17 float fluxMax = 1000.0;17 float fluxMax = source->peak->flux; 18 18 19 19 // generate a series of radial profiles at Nsec evenly spaced angles. the profile flux -
branches/eam_branches/20090715/psphot/src/psphotPetrosianStudy.c
r25105 r25128 1 1 # 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 10 pmPeak *psphotLocalPeak(pmReadout *readout, int Xo, int Yo); 2 11 3 12 int main (int argc, char **argv) { … … 7 16 8 17 int N; 9 10 // XXX add noise and seeing.11 // XXX double check on sersic functional form12 // 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; 13 22 14 23 float peak = 1000.0; … … 18 27 float sersic = 0.5; 19 28 float skynoise = 0.0; 20 29 21 30 if ((N = psArgumentGet (argc, argv, "-peak"))) { 22 31 psArgumentRemove (N, &argc, argv); … … 53 62 pmVisualSetVisual(true); 54 63 } 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 } 55 76 56 77 if (argc != 1) { … … 61 82 // create a containing image & associated readout 62 83 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); 64 86 65 // create a dummy variance, but don't populate -- it is not used by pmSourceMoments if the sigma parameters is set to 0.066 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); 67 89 68 // create a model & associated source69 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); 71 93 72 // set the model parameters73 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; 77 99 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; 82 104 83 psEllipseShape shape = psEllipseAxesToShape (axes);105 psEllipseShape shape = psEllipseAxesToShape (axes); 84 106 85 // XXX set the sigma with user input86 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; 89 111 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); 92 136 } 93 94 pmSource *source = pmSourceFromModel(model, readout, 32.0, PM_SOURCE_TYPE_STAR);95 96 // generate the modelFlux97 pmSourceCacheModel(source, 0);98 99 // instantiate the source100 pmSourceAdd(source, PM_MODEL_OP_FUNC, 0);101 102 // XXX add noise here...103 104 psphotSaveImage(NULL, readout->image, "sersic.fits");105 137 106 138 psphotPetrosianProfile (source); … … 110 142 exit (0); 111 143 } 144 145 // Xo, Yo are in parent coords 146 pmPeak *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 26 26 graphdata->xmin = graphdata->xmax = xVec->data.F32[0]; 27 27 for (int i = 1; i < xVec->n; i++) { 28 if (!isfinite(xVec->data.F32[i])) continue; 28 29 graphdata->xmin = PS_MIN (graphdata->xmin, xVec->data.F32[i]); 29 30 graphdata->xmax = PS_MAX (graphdata->xmax, xVec->data.F32[i]); … … 36 37 graphdata->ymin = graphdata->ymax = yVec->data.F32[0]; 37 38 for (int i = 1; i < yVec->n; i++) { 39 if (!isfinite(yVec->data.F32[i])) continue; 38 40 graphdata->ymin = PS_MIN (graphdata->ymin, yVec->data.F32[i]); 39 41 graphdata->ymax = PS_MAX (graphdata->ymax, yVec->data.F32[i]); -
branches/eam_branches/20090715/psphot/src/psphotRadialProfileByAngle.c
r25105 r25128 5 5 6 6 // XXX choices for rMax and Nsec? 7 // XXX where does the output go?8 // XXX how does this fit in context?9 7 10 8 bool psphotRadialProfilesByAngles (pmPetrosian *petrosian, pmSource *source, int Nsec, float Rmax) { 11 9 10 // we want to have an even number of sectors so we can do 180 deg symmetrizing 11 Nsec = (Nsec % 2) ? Nsec + 1 : Nsec; 12 12 float dtheta = 2.0*M_PI / Nsec; 13 13 … … 46 46 // value is NAN if we run off the image 47 47 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; 49 51 50 52 psVectorAppend (radius, r); … … 62 64 } 63 65 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 } 64 103 return true; 65 104 } -
branches/eam_branches/20090715/psphot/src/psphotRadiiFromProfiles.c
r25105 r25128 30 30 31 31 // examine data in the two ranges Fm - Fo and Fo - Fp to define the bin size 32 // XXX reconsider the fractional isophote value 32 33 float Fm = fluxMin + 0.25*fluxRange; 33 34 float Fp = fluxMin + 0.75*fluxRange; 34 35 float Fo = fluxMin + 0.50*fluxRange; 36 int Rbin = 1; 35 37 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); 46 43 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 } 53 57 } 54 58 … … 94 98 psStatsInit(stats); 95 99 } 100 if (!isfinite(flux->data.F32[i])) continue; 96 101 psVectorAppend (values, flux->data.F32[i]); 97 102 } … … 105 110 bool above = true; 106 111 for (int i = 0; i < fluxBinned->n; i++) { 112 113 if (!isfinite(fluxBinned->data.F32[i])) continue; 107 114 108 115 // find the largest radius that matches the flux transition
Note:
See TracChangeset
for help on using the changeset viewer.
