Jenifer Millard - 1 year ago 60

Python Question

I have managed to use

`astropy.modeling`

`m2`

<Gaussian2D(amplitude=0.0009846091239480168, x_mean=30.826676737477573, y_mean=31.004045976953222, x_stddev=2.5046722491074536, y_stddev=3.163048479350727, theta=-0.0070295894129793896)>

I can also tell you this:

`type(m2)`

<class 'astropy.modeling.functional_models.Gaussian2D'>

Name: Gaussian2D

Inputs: (u'x', u'y')

Outputs: (u'z',)

Fittable parameters: ('amplitude', 'x_mean', 'y_mean', 'x_stddev', 'y_stddev', 'theta')

What I need is a method to extract the parameters of the model, namely:

`x_mean`

y_mean

x_stddev

y_stddev

I am not familiar with this form output so I am really stuck on how to extract the parameters.

Answer Source

The models have attributes you can access:

```
from astropy.modeling import models
g2d = models.Gaussian2D(1,2,3,4,5)
g2d.amplitude.value # 1.0
g2d.x_mean.value # 2.0
g2d.y_mean.value # 3.0
g2d.x_stddev.value # 4.0
g2d.y_stddev.value # 5.0
```

You need to extract these values after you fitted the model but you can access them in the same way: `.<name>.value`

.

You can also extract them in one go but then you need to keep track which parameter is in which position:

```
g2d.parameters # array([ 1., 2., 3., 4., 5., 0.])
# Amplitude
g2d.parameters[0] # 1.0
# x-mean
g2d.parameters[1] # 2.0
# ...
```