-
Hi gammapy team! I'm Judit (the DM girl) and we are finally finishing the DM analysis pipeline we started some years ago. For this, I wanted also to include some features fo which I encountered some problems. To set up the discussion, I am using gammapy v-0.18.2 and I am performing a 3D simulation for CTA, including 5 different emission models (DM, CR, 2 AGNs + IRF-BKG), including emission templates for the DM and CR, and modelling the AGNs as point-like sources. This part seems to work perfectly, but I have some problems in the fitting. For the fit, I'm using a template fitting approach, where I leave free up to 8 parameters of these models (mainly amplitudes and spectral indices), and one of the things I would like to get as an output is the correlation matrix between these fitted parameters. The problem that I found is that, even I can obtain the correlation matrix, it only correlates parameters that belong to the same emission, like for example AGN amplitude & index, when I want also to obtain the correlation with the rest, like for example DM amplitude & CR amplitude. I'm obtaining this matrix after the fit though the models attached to the dataset (dataset.models.covariance.correlation). I'm also pretty convinced that I settled correctly the parameters I want to be free, and indeed I obtain them as a result of the fit, but not for the correlation matrix. Just for completeness, I think it maybe can be useful to show how I create the simulation and perform de fit. models = Models([model_simu,
cr_model_simu,
ps1_model_simu,
ps2_model_simu,
bkg_model])
dataset = maker.run(empty, obs)
dataset.models = models
# Poission fluctuate in memory
dataset.fake(random_state=int(time.time()))
# Fix to which DM model we want to fit the data
flux_model_fit = DarkMatterAnnihilationSpectralModel(
mass=m*u.Unit("GeV"),
channel=ch,
jfactor=JFAC,
z=redshift)
# Set max and min for fit to search
flux_model_fit.scale.max = 1e7
flux_model_fit.scale.min = -1e7
# Attach EBL
flux_fit = flux_model_fit * absorption
model_fit = SkyModel(spatial_model=spatial_model, spectral_model=flux_fit)
# Impose the model in the dataset
models_fit = Models([model_fit,
cr_model_simu,
ps1_model_simu,
ps2_model_simu,
bkg_model])
# Untab the ones you want be frozen
models_fit["dataset-simu-bkg"].spectral_model.norm.frozen = False
models_fit["dataset-simu-bkg"].spectral_model.tilt.frozen = False
models_fit["cr-model"].spectral_model.parameters['norm'].frozen = False
models_fit["ps-1"].spectral_model.parameters['amplitude'].frozen = False
models_fit["ps-1"].spectral_model.parameters['index'].frozen = False
models_fit["ps-1"].spatial_model.lon_0.frozen = True
models_fit["ps-1"].spatial_model.lat_0.frozen = True
models_fit["ps-2"].spectral_model.parameters['amplitude'].frozen = False
models_fit["ps-2"].spectral_model.parameters['index'].frozen = False
models_fit["ps-2"].spatial_model.lon_0.frozen = True
models_fit["ps-2"].spatial_model.lat_0.frozen = True
dataset.models = models_fit
# Instantiate the fitter
fit = Fit([dataset])
fit_result = fit.run()
# Save correlation matrix
np.savetxt(output+'correlation_trial_1.txt'.format(ch), dataset.models.covariance.correlation) I can also provide the definitions of the models. Thanks a lot for your help in advance! :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Thanks @peroju! Can you maybe attach a plot of the final correlation matrix, e.g. obtained with |
Beta Was this translation helpful? Give feedback.
-
Hi @peroju ! Sorry for the late reply! We realised that this was an issue in older versions of gammapy (#4149). Please try with gammapy 1.0 and using the Thanks! |
Beta Was this translation helpful? Give feedback.
Hi @peroju ! Sorry for the late reply! We realised that this was an issue in older versions of gammapy (#4149). Please try with gammapy 1.0 and using the
models
fromFitResult
as explained here https://docs.gammapy.org/1.0/tutorials/api/fitting.html#covariance-and-parameters-errorsThanks!