# [AstroPy] Ellipse2D fit

Andrzej Szary aszary at gmail.com
Wed Feb 8 10:40:07 EST 2017

```Hello,

I am struggling with  fitting an ellipse using Ellipse2D model. The fitting
procedure does not seem to have any effect on ellipse parameters (maybe
except amplitude).

Please find a test code at the end of this email.

Best wishes,
Andrzej Szary

import numpy as np
from astropy.modeling import models, fitting
import matplotlib.pyplot as pl

# data
num = 100
x, y = np.meshgrid(np.linspace(-5., 5., num), np.linspace(-5, 5, num))
e0 = models.Ellipse2D(amplitude=1., x_0=0., y_0=0., a=2, b=1, theta=0.)
z0 = e0(x, y)
print 'DATA:\n', e0, '\n\n'

# initial model
ei = models.Ellipse2D(amplitude=1., x_0=0.1, y_0=0.1, a=3, b=2, theta=0.2)
fi = fitting.LevMarLSQFitter()

# fitted model?
e1 = fi(ei, x, y, z0)
z1 = e1(x, y)
print 'MODEL:\n', e1, '\n\n'

pl.imshow(z0, extent=[-5, 5, -5, 5], alpha=0.5)
pl.imshow(z1, extent=[-5, 5, -5, 5], alpha=0.2)
pl.show()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170208/dd96824c/attachment.html>
```

More information about the AstroPy mailing list