- Timestamp:
- Aug 18, 2009, 6:24:53 AM (17 years ago)
- Location:
- branches/eam_branches/20090715/psphot/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psphotEllipticalContour.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090715/psphot/src
- Property svn:ignore
-
old new 18 18 psphotVersionDefinitions.h 19 19 psphotMomentsStudy 20 psphotPetrosianStudy
-
- Property svn:ignore
-
branches/eam_branches/20090715/psphot/src/psphotEllipticalContour.c
r25032 r25105 5 5 // model parameters 6 6 enum {PAR_PHI, PAR_EPSILON, PAR_RMIN}; 7 psF32 psphotEllipticalContourFunc (psVector *deriv, const psVector *params, const psVector *coord); 7 8 8 9 bool psphotEllipticalContour (pmPetrosian *petrosian) { … … 10 11 // use LMM to fit theta vs radius to an ellipse 11 12 psVector *theta = petrosian->theta; 12 psVector *radius = petrosian->isophotalRadi us;13 psVector *radius = petrosian->isophotalRadii; 13 14 14 15 // find Rmin and Rmax for the initial guess … … 20 21 psArray *x = psArrayAlloc(2*radius->n); 21 22 psVector *y = psVectorAlloc(2*radius->n, PS_TYPE_F32); 23 psVector *yErr = psVectorAlloc(2*radius->n, PS_TYPE_F32); 22 24 25 int n = 0; 23 26 for (int i = 0; i < radius->n; i++) { 24 27 … … 28 31 coord = psVectorAlloc (2, PS_TYPE_F32); 29 32 coord->data.F32[1] = 0.0; 30 coord->data.F32[0] = radius->data.F32[i]*cos(theta->data.F32[i]);33 coord->data.F32[0] = theta->data.F32[i]; 31 34 x->data[n] = coord; 32 y->data.F32[n] = theta->data.F32[i]; 35 y->data.F32[n] = radius->data.F32[i]*cos(theta->data.F32[i]); 36 yErr->data.F32[n] = 1000.0; 33 37 n++; 34 38 … … 36 40 coord = psVectorAlloc (2, PS_TYPE_F32); 37 41 coord->data.F32[1] = 1.0; 38 coord->data.F32[0] = radius->data.F32[i]*sin(theta->data.F32[i]);42 coord->data.F32[0] = theta->data.F32[i]; 39 43 x->data[n] = coord; 40 y->data.F32[n] = theta->data.F32[i]; 44 y->data.F32[n] = radius->data.F32[i]*sin(theta->data.F32[i]); 45 yErr->data.F32[n] = 1000.0; 41 46 n++; 42 47 … … 49 54 50 55 psVector *params = psVectorAlloc (3, PS_TYPE_F32); 56 57 // psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 7); 51 58 52 59 // create the minimization constraints … … 64 71 65 72 // XXX skip the weights for now 66 psMinimizeLMChi2(myMin, covar, params, constraint, x, y, NULL, psphotEllipticalContourFunc);73 psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, psphotEllipticalContourFunc); 67 74 68 75 fprintf (stderr, "# fitted values:\n"); 69 fprintf (stderr, "Po: %f\n", params->data.F32[PAR_PHI] );76 fprintf (stderr, "Po: %f\n", params->data.F32[PAR_PHI]*PS_DEG_RAD); 70 77 fprintf (stderr, "Ep: %f\n", params->data.F32[PAR_EPSILON]); 71 78 fprintf (stderr, "Rm: %f\n", params->data.F32[PAR_RMIN]); … … 75 82 petrosian->axes.minor = params->data.F32[PAR_RMIN]; 76 83 petrosian->axes.theta = params->data.F32[PAR_PHI]; 84 85 // show the results 86 psphotPetrosianVisualEllipticalContour (petrosian); 87 88 psFree (x); 89 psFree (y); 90 psFree (yErr); 77 91 78 92 return true; … … 88 102 psF32 psphotEllipticalContourFunc (psVector *deriv, const psVector *params, const psVector *coord) { 89 103 104 static int pass = 0; 105 90 106 psF32 *par = params->data.F32; 107 108 float alpha = coord->data.F32[0]; 91 109 92 110 float cs_alpha = cos(alpha); 93 111 float sn_alpha = sin(alpha); 94 112 95 float alpha = coord->data.F32[0];96 113 float cs_phi = cos(alpha - par[PAR_PHI]); 97 114 float sn_phi = sin(alpha - par[PAR_PHI]); … … 103 120 104 121 // value is X 105 if (coord->data.F32[1] == 0) { 122 // if (coord->data.F32[1] == 0) { 123 if (pass == 0) { 124 pass = 1; 106 125 107 126 float value = par[PAR_RMIN]*cs_alpha*r; … … 109 128 if (deriv) { 110 129 psF32 *dPAR = deriv->data.F32; 111 d par[PAR_RMIN] = r*cs_alpha;112 d par[PAR_EPSILON] = par[PAR_RMIN]*cs_alpha*drdE;113 d par[PAR_PHI] = 4.0*par[PAR_RMIN]*cs_alpha*drdP;130 dPAR[PAR_RMIN] = r*cs_alpha; 131 dPAR[PAR_EPSILON] = par[PAR_RMIN]*cs_alpha*drdE; 132 dPAR[PAR_PHI] = 4.0*par[PAR_RMIN]*cs_alpha*drdP; 114 133 } 115 134 return (value); … … 117 136 118 137 // value is Y 119 if (coord->data.F32[1] == 1) { 138 // if (coord->data.F32[1] == 1) { 139 if (pass == 1) { 140 pass = 0; 120 141 121 142 float value = par[PAR_RMIN]*sn_alpha*r; … … 123 144 if (deriv) { 124 145 psF32 *dPAR = deriv->data.F32; 125 d par[PAR_RMIN] = r*sn_alpha;126 d par[PAR_EPSILON] = par[PAR_RMIN]*sn_alpha*drdE;127 d par[PAR_PHI] = 4.0*par[PAR_RMIN]*sn_alpha*drdP;146 dPAR[PAR_RMIN] = r*sn_alpha; 147 dPAR[PAR_EPSILON] = par[PAR_RMIN]*sn_alpha*drdE; 148 dPAR[PAR_PHI] = 4.0*par[PAR_RMIN]*sn_alpha*drdP; 128 149 } 129 150 return (value);
Note:
See TracChangeset
for help on using the changeset viewer.
