Removed spectral fit without background from spectrum_simulation notebook
"print(sim.obs)"
]
},
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Spectral analysis\n",
- "\n",
- "Now that we have some simulated CTA counts spectrum, let's analyse it."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "# Fit data\n",
- "model = model_ref.copy()\n",
- "dataset = sim.obs\n",
- "dataset.model = model\n",
- "\n",
- "fit = Fit([dataset])\n",
- "result = fit.run()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "print(result)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "To see the best fit parameters:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "print(dataset.model)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In order to plot a model you can use the plot function. It expects an energy range as argument. You can also chose flux and energy units as well as an energy power for the plot, as well as `matplotlib.pyplot.plot` keywords."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "energy_range = [0.1, 100] * u.TeV\n",
- "model_ref.plot(energy_range=energy_range, energy_power=2, color=\"blue\", label=\"simulated\", ls=\"--\")\n",
- "\n",
- "model.parameters.covariance = result.parameters.covariance\n",
- "model.plot(energy_range=energy_range, energy_power=2, color=\"black\", label=\"fitted\")\n",
- "model.plot_error(energy_range=energy_range, energy_power=2)\n",
- "plt.legend();"
- ]
- },
{
"cell_type": "markdown",
"metadata": {},
"%%time\n",
"results = []\n",
"for obs in sim.result:\n",
- " dataset = obs.to_spectrum_dataset()\n",
+ " dataset = obs\n",
" dataset.model = model_ref.copy()\n",
" fit = Fit([dataset])\n",
" result = fit.optimize()\n",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.1"
+ "version": "3.7.0"
}
},
"nbformat": 4,
