Hi Gaia,
I have taken a look at your script and here are a few things to consider:
1. Move the creation of `ecpl` model inside the simulation loop. When fitting a model in Gammapy the model parameters
are changed in place. In case the fit fails and the parameters are set to NaN and the model cannot be reused. This should
fix the problem you see.
2. Use `sim.simulate_obs(seed=)` to use a different seed for each of the simulations, otherwise you'll always get the same result.
3. I would split the simulation and fitting part into two steps: first do the simulation, write the results to file, then read the data in
again and fit it to get your parameter distributions.
4. For the fitting part it's probably useful to use an astropy.Table object to collect your fitting results. So define a table with the values and
errors of the model parameters as table columns and the add one fitted observation per row. Again you can then write the table to file
and read again e.g. to plot the parameter distributions.
5. The `FitSpectrum` class will be removed in the next Gammapy version `v.012` and you'll have to adapt your script, if you want to update
Gammapy (it's just a small API change, but let us know, when you want to update and have problems with the transition).
Hope this helps, Axel