MPFIT2DPEAK with constraints [message #36644] |
Thu, 09 October 2003 15:40  |
c.carrano
Messages: 2 Registered: October 2003
|
Junior Member |
|
|
Greetings. I'm trying to understand how Craig
Markwardt's peak fitting function MPFIT2DPEAK
works when you wish to require that certain
parameters be held constant.
Specifically, I know that my data should peak
at the origin and so I'd like to force the
fitted Gaussian to peak there as well.
Despite specifying that A[4] and A[5] be
fixed using the PARINFO structure, the fitted
Gaussian is not centered at the origin.
Supplying PARINFO to MPFIT2DPEAK does change
the fit but it actually makes it slighly worse.
Anyone know what I might be doing wrong?
Here's my sample code:
;------------------------------------------------
; Construct a sample gaussian surface in range [-5,5] centered at
[0,0]
x = findgen(100)*0.1 - 5. & y = x
xx = x # (y*0 + 1)
yy = (x*0 + 1) # y
rr = sqrt((xx-0*2.)^2 + (yy+0*3.)^2)
; Gaussian surface with sigma=0.5, peak value of 3, noise with
sigma=0.2
seed=6
z = 3.*exp(-(rr/0.5)^2) + randomn(seed,100,100)*.2
pi = replicate({value:0.D, fixed:0, limited:[0,0], $
limits:[0.D,0]}, 7)
pi(4).fixed = 1
pi(5).fixed = 1
a0=[0., 3., 1.0, 1.0, 0.0, 0.0, 0.0]
pi(*).value = a0
; Fit gaussian parameters A
zfit = mpfit2dpeak(z, a1, x, y, /tilt, PARINFO=pi)
zfit = mpfit2dpeak(z, a2, x, y, /tilt)
print,a1
print,a2
------------------------------------------------
IDL prints:
a1=[-0.000156282, 2.82180, 0.382853, 0.347286, -0.0999999, 0.0999999,
0.716917]
a2=[-0.000266513, 3.06073, 0.345753, 0.351519, -0.000407959,
0.00455947, 1.98130]
|
|
|
|
Re: MPFIT2DPEAK [message #44575 is a reply to message #36644] |
Thu, 23 June 2005 00:50  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Greetings,
"angela" <Angeliki.Pollatou@gmail.com> writes:
> Hello,
>
> I was wondering if someone can help me out with a problem I have in
> MPFIT2DPEAK.
> Fist I am describing the problem: I have an image with stars and I am
> trying to fit the distribution to a gaussian and determine the
> coordinates of which there is a peak density of stars.
> I have an array of 400x400 pixels (centered where I believe the center
> shoud be) and I have calculated the number density of the stars in a
> specific radius for all the coordinate combinations starting from the
> (0,0) coordinates.
> I am using the MPFIT2DPEAK to fit a gaussian and to get a better handle
> on the center I am trying to find.
> I have two questions:
>
> 1. When I am using MPFIT2DPEAK without a 'guess' about the center (I
> use it with the tilt keyword), I get:
> 3.02628 3.92726 40.2412 13.1586 37.6854
> 24.7872 2.99398
> I have read from the tutorial that if you do not give an initial guess
> the program will try to guess what is the center. How do I know what
> the program thinks as a center? In other words, this result tells me
> that the center is at
> (x,y)=(37.6854,24.7872) or it understands that the center that I used
> is (200,200), so the result is that the center is at
> (200+37.6854,200+24.7872)?
*You* assign X and Y according to the arrays you pass when you call
MPFIT2DPEAK. The routine returns the centroid using the same
coordinate system. So if the command was called like this,
MPFIT2DPEAK(START,A,X,Y)
then (37.6854,24.7872) should refer to a position in the (X,Y)
coordinate system.
> 2.I tried to run the MPFIT2DPEAK using the estimates keyword :
> result=mpfit2dpeak(start,B,start(200,*),start(*,200),/TILT)
> where (200,200) is approximately where I think the center is and
> 'start' is my 400x400 array that has all the densities stored (they are
> all integers). ...
First of all, you didn't actually use the ESTIMATES keyword in your
example, so it's hard to comment. Second of all, you are not passing
proper X and Y values. These should be the *coordinate labels*, not
rows and columns of the array itself. Look at how CONTOUR is
called... same thing here.
> ... I get this message:
> % Attempt to subscript XX with WHMAX is out of range.
> % Execution halted at: MPFIT2DPEAK 390
> /raid1/home/angeliki/IDL/mpfit2dpeak.pro
> % $MAIN$
Yes, fix the problems above and you should be okay. The other thing
is that you passed START(200,*) as a column vector, when it should be
a row vector, and vice versa for START(*,200).
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|