This tutorial shows some basic Sherpa features.

Workflow:

- create synthetic data: a parabola with noise and error bars
- load data in Sherpa
- plot data using matplotlib
- set, inspect, edit a model to fit the data
- fit the data
- compute the confidence intervals for the parameters
- explore the parameter space

In [1]:

```
%matplotlib inline
```

The following commands just avoid some unnecessary logging duplication when using Sherpa:

In [2]:

```
import logging
logging.getLogger('sherpa').propagate = 0
```

In [3]:

```
import numpy as np
x = np.arange(-5, 5.1)
y = x*x + 23.2 + np.random.normal(size=x.size)
e = np.ones(x.size)
```

Let's import Sherpa:

In [4]:

```
from sherpa.astro import ui as sherpa
```

`mydata`

to the dataset we are loading. We will use this ID to refer to the same dataset in the rest of the tutorial. Sherpa can deal with multiple datasets, fit them simultaneously with the same model, and even link parameters between models. Sherpa can read ASCII table and FITS files (provided the `pyfits`

package is installed).

In [5]:

```
sherpa.load_arrays("mydata", x, y, e)
sherpa.plot_data("mydata")
```

`set_model`

call. There are different ways to instantiate the models: in this case, we just use the string `polynom1d`

to refer to a 1D polynomial. The name of the model will be `poly`

, and will be accessible as a Python variable. One can use more object oriented patterns to access and instantiate built-in models. Also, new models can be added by the user as Python functions or from tabular data.

In [6]:

```
sherpa.set_model("mydata", "polynom1d.poly")
```

`print`

to get a summary of the model and its components.

In [7]:

```
print(poly)
```

**thawed**, i.e. is free to vary in the fit. This corresponds to a constant function. In order to fit a parabola, we need to **thaw** the coefficients of the first two orders in the polynomial, as shown below.

In [8]:

```
sherpa.thaw(poly.c1, poly.c2)
```

In [9]:

```
sherpa.fit("mydata")
```

In [10]:

```
sherpa.plot_fit_resid("mydata")
```

We can now compute the confidence intervals for the free parameters in the fit:

In [11]:

```
sherpa.conf("mydata")
```

`c0`

and `c1`

parameters. The contours are configurable by the user: by default they show the confidence curves at 1, 2, and 3 $\sigma$

In [12]:

```
sherpa.reg_proj(poly.c0, poly.c1)
```

`c0`

parameter, i.e. a plot of the error for each value of the parameter, around the minimum found by the optimization method during the fit.

In [13]:

```
sherpa.int_proj(poly.c0)
```