Adapt tutorial hess
"from regions import CircleSkyRegion\n",
"from gammapy.data import DataStore\n",
"from gammapy.maps import Map, MapAxis, WcsGeom, WcsNDMap\n",
- "from gammapy.cube import MapMaker, MapFit, PSFKernel\n",
- "from gammapy.cube.models import SkyModel\n",
+ "from gammapy.cube import MapMaker, MapDataset, PSFKernel\n",
+ "from gammapy.cube.models import SkyModel, BackgroundModel\n",
"from gammapy.spectrum.models import PowerLaw, ExponentialCutoffPowerLaw\n",
"from gammapy.image.models import SkyGaussian, SkyPointSource\n",
"from gammapy.detect import TSMapEstimator\n",
- "from gammapy.scripts import SpectrumAnalysisIACT"
+ "from gammapy.scripts import SpectrumAnalysisIACT\n",
+ "from gammapy.utils.fitting import Fit"
]
},
{
"source": [
"## Map fit\n",
"\n",
- "Let's fit this source assuming a Gaussian spatial shape and a power-law spectral shape"
+ "Let's fit this source assuming a Gaussian spatial shape and a power-law spectral shape, and a background with a flexible normalisation"
]
},
{
"spectral_model = PowerLaw(\n",
" index=2.6, amplitude=\"5e-11 cm-2 s-1 TeV-1\", reference=\"1 TeV\"\n",
")\n",
- "model = SkyModel(spatial_model=spatial_model, spectral_model=spectral_model)"
+ "model = SkyModel(spatial_model=spatial_model, spectral_model=spectral_model)\n",
+ "background_model = BackgroundModel(maps[\"background\"], norm=1.0)"
]
},
{
"outputs": [],
"source": [
"%%time\n",
- "fit = MapFit(\n",
+ "dataset = MapDataset(\n",
" model=model,\n",
" counts=maps[\"counts\"],\n",
" exposure=maps[\"exposure\"],\n",
- " background=maps[\"background\"],\n",
+ " background_model=background_model,\n",
" psf=psf_kernel,\n",
")\n",
+ "fit = Fit(dataset)\n",
"result = fit.run()\n",
"print(result)\n",
- "print(result.model.parameters.to_table())"
+ "print(\"\\n\\n Parameters\\n\")\n",
+ "print(dataset.parameters.to_table())\n",
+ "print(\"\\n\\n Covariance Matrix\")\n",
+ "print(dataset.parameters.covariance_to_table())"
]
},
{
"metadata": {},
"outputs": [],
"source": [
- "npred = fit.evaluator.compute_npred()\n",
+ "npred = dataset.npred\n",
"residual = Map.from_geom(maps[\"counts\"].geom)\n",
- "residual.data = maps[\"counts\"].data - npred"
+ "residual.data = maps[\"counts\"].data - npred.data"
]
},
{
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.0"
+ "version": "3.6.8"
}
},
"nbformat": 4,
