-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when extracting flux points with a CompoundSpectralModel #3690
Comments
Note that a workaround for v0.19 is shown in #3705 |
I think this still fails if one defines a custom model with a random name for the parameter to be scaled (e.g. Possible solutions that I see:
I tend to prefer the option 3. Opinions @registerrier @adonath @AtreyeeS @QRemy ? |
In principle the scaled parameter does not have to be one of the existing parameters as it is already defined by the ScaleModel so in the scaled_parameter = None
if "amplitude" in ref_model.parameters.names:
scaled_parameter = ref_model.parameters["amplitude"]
elif "norm" in ref_model.parameters.names:
scaled_parameter = ref_model.parameters["norm"]
if scaled_parameter is not None:
scale_model.norm = self._set_norm_parameter(scale_model.norm, scaled_parameter) |
Thanks for bringing this up again @luca-giunti ! I think we orally discussed during the dev calls that we need to clarify in the documentation that either norm or amplitude must be present, and then completely forgot to document it! I would go for (2) with the solution proposed by @QRemy . For external models without |
modifying def _set_norm_parameter(self, norm=None, scaled_parameter=None):
"""Define properties of the norm spectral parameter."""
if norm is None:
norm = Parameter("norm", 1, unit="", interp="log")
norm.value = 1.0
norm.frozen = False
if scaled_parameter is not None :
norm.min = scaled_parameter.min / scaled_parameter.value
norm.max = scaled_parameter.max / scaled_parameter.value
norm.interp = scaled_parameter.interp
norm.scan_values = self.norm_values
norm.scan_min = self.norm_min
norm.scan_max = self.norm_max
norm.scan_n_values = self.norm_n_values
return norm
def get_scale_model(self, models):
"""Set scale model
Parameters
----------
models : `Models`
Models
Returns
-------
model : `ScaleSpectralModel`
Scale spectral model
"""
ref_model = models[self.source].spectral_model
scale_model = ScaleSpectralModel(ref_model)
scaled_parameter = None
if "amplitude" in ref_model.parameters.names:
scaled_parameter = ref_model.parameters["amplitude"]
elif "norm" in ref_model.parameters.names:
scaled_parameter = ref_model.parameters["norm"]
scale_model.norm = self._set_norm_parameter(scale_model.norm, scaled_parameter)
return scale_model |
@AtreyeeS Yes this also makes sense. In that case this could be documented here I guess?
@QRemy I just opened a PR on this exact point: #3845. Perhaps you can also have a look |
Maybe it is better not to silently add scalable parameters but make the user do it ? |
Users now have to define the |
Gammapy version
v0.19
Bug description
If a compound model is used for the
FluxPointsEstimator
, an error occurs inFluxEstimator.get_scale_model()
because aCompoundSpectralModel
has nonorm
oramplitude
attribute.Expected behavior
Using a
CompoundSpectralModel
should work.The issue is caused by the mechanism introduced to scale the
norm
according to the input parameter. It does not work in general for aCompoundSpectralModel
which might have differentamplitude
andnorm
parameters. So that determining the actual range a priori might be ambiguous.Note that we miss a test for flux points extraction with a compound model.
To Reproduce
Other information
Any other information you think will be useful for us to fix the issue can go here.
The text was updated successfully, but these errors were encountered: