Add note about shared parameters in the models notebook
Solve
"regions = [gauss.to_region(), gauss_elongated.to_region()]\n",
"\n",
"filename = \"regions.reg\"\n",
- "write_ds9(regions, filename, coordsys=\"galactic\", fmt=\".4f\", radunit=\"deg\")"
+ "write_ds9(regions, filename, coordsys=\"galactic\", fmt=\".4f\", radunit=\"deg\", overwrite=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "Additionally the models can exported and imported togeter with the data using the `Datasets.read()` and `Datasets.write()` methods as shown in the [analysis_mwl](../analysis/3D/analysis_mwl.ipynb) notebook."
+ "Additionally the models can exported and imported togeter with the data using the `Datasets.read()` and `Datasets.write()` methods as shown in the [analysis_mwl](../analysis/3D/analysis_mwl.ipynb) notebook.\n",
+ "\n",
+ "## Models with shared parameter\n",
+ "\n",
+ "A model parameter can be shared with other models, for example we can define two power-law models with the same spectral index but different amplitudes: "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "run_control": {
+ "marked": false
+ }
+ },
+ "outputs": [],
+ "source": [
+ "pwl2 = PowerLawSpectralModel()\n",
+ "pwl2.index = pwl.index\n",
+ "pwl.index.value = 2.3 # also update pwl2 as the parameter object is now the same as shown below\n",
+ "print(pwl.index)\n",
+ "print(pwl2.index)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "In the YAML files the shared parameter is flagged by the additional `link` entry that follows the convention `parameter.name@unique_id`:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "models = Models([SkyModel(pwl, name=\"source1\"), SkyModel(pwl2, name=\"source2\")])\n",
+ "models_yaml = models.to_yaml()\n",
+ "print(models_yaml)"
]
},
{
