Comments (9)
Thanks a lot for reporting this @guillaumegrolleron.
I am surprised that the epsilon
array has dimension (30, 10)...
It is converted from the nu
that should be a one-dimensional array.
https://github.com/cosimoNigro/agnpy/blob/master/agnpy/synchrotron/synchrotron.py#L174
Do you encounter this problem only for the synchrotron SED?
This is the same problem you encountered in the fitting notebook, right?
from agnpy.
Thanks for your answer @cosimoNigro
In fact this bug is not specific for synchrotron because I have the same with inverse Compton.
This problem doesn't appear when I fit but when I try to simulate fake datasets, indeed when I use the fake()
method, npred_signal()
is called, which calls compute_flux_spectral()
and then integral()
and integrate_spectrum()
.
In this function the evaluator of the SpectralModel is computed with an energy defined as energy = np.geomspace(energy_min, energy_max, num=int(num), axis=-1)
https://github.com/gammapy/gammapy/blob/ddbc5dc8a4291f125996a9ce0e9b18ecdcc4c6e5/gammapy/modeling/models/spectral.py#L97
energy_min
and energy_max
are the bounds of my energy_axis
of size 30, and in this context num is equal to 10.
To sum up the problem is caused by the incompatibility between integrate_spectrum()
(https://github.com/gammapy/gammapy/blob/ddbc5dc8a4291f125996a9ce0e9b18ecdcc4c6e5/gammapy/modeling/models/spectral.py#L78) which will call the evaluator of Gammapy SpectralModel
on a multidimensional energy array and the fact that the evaluate_sed_flux()
method (
agnpy/agnpy/synchrotron/synchrotron.py
Line 123 in 86a28d4
from agnpy.
Hello @guillaumegrolleron,
first of all I am very sorry for such a slow reaction.
Finally I incorporated the sherpa and gammapy wrappers in the source code.
Could you retry now and tell me if you have the same problem?
If that's the case, in the source code of the gammapy wrapper I left an inline comment
https://github.com/cosimoNigro/agnpy/blob/master/agnpy/fit/gammapy_wrapper.py#L178
pointing to this issue, with a tentative solution.
Let me know, and sorry again that it took a while.
from agnpy.
Just to complement the discussion:
Following this tutorial
https://agnpy.readthedocs.io/en/latest/tutorials/ssc_gammapy_mcmc_fit.html
I was trying to use instead of just FluxPointsDataset, a MapDataset (Fermi data) and a SpectrumDatasetOnOff (VERITAS data)
and I was getting the same error, and found this solution. However, I would get the same error in the SSC calculation, not only synchrotron. I solved by changing
agnpy/agnpy/synchrotron/synchrotron.py
Line 182 in ee6c966
emissivity = integrator(integrand, gamma, axis=0)
to
emissivity = integrator(integrand, gamma, axis=0).reshape(epsilon.shape)
as suggested, but also in
integral_epsilon = integrator(integral_gamma, epsilon, axis=0)
to
integral_epsilon = integrator(integral_gamma, epsilon, axis=0).reshape(epsilon_s.shape)
But since I am not using SSA and/or EC, I am afraid that the same has to be done there, but I haven't checked.
from agnpy.
Hello @pivosb, thanks for reporting this.
Are you using the latest version of agnpy
with the wrappers incorporated?
If so, did you try the solution I suggested here in the code
https://github.com/cosimoNigro/agnpy/blob/master/agnpy/fit/gammapy_wrapper.py#L178
This problem never occurred to me while fitting flux points, it seems it is occurring either when using a MapDataset
or doing a simulation, so I guess in those cases some array with energy and some other axis is passed to the functions evaluating the SED.
Would you mind checking if my solution at the wrapper level works?
Thank you.
from agnpy.
Hi @cosimoNigro.
Yes, I am. And yes, I first tried the solution suggested in
https://github.com/cosimoNigro/agnpy/blob/master/agnpy/fit/gammapy_wrapper.py#L178
And you are correct, the problem is not with the flux points. It is specifically with any other dataset, and the error occurs before L178 in the wrapper. It happens when the code calls
sed_synch = Synchrotron.evaluate_sed_flux(
nu, z, d_L, delta_D, B, R_b, self._n_e, *args, ssa=self.ssa
)
sed_ssc = SynchrotronSelfCompton.evaluate_sed_flux(
nu, z, d_L, delta_D, B, R_b, self._n_e, *args, ssa=self.ssa
)
and then the evaluate is called in agnpy/agnpy/synchrotron/synchrotron.py and agnpy/agnpy/compton/synchrotron_self_compton.py.
So yes, it is related to using a MapDataset
and/or a SpectrumDatasetOnOff
(either a real one or a simulation)
from agnpy.
Ok, thanks, so it seems that my suggested fix will not help as the error occurs at the evaluate_sed_flux
function calls.
@pivosb would you mind fixing it in a PR?
from agnpy.
Yes, I can try! I will open a PR soon
from agnpy.
Should be solved by @pivosb PR #131.
from agnpy.
Related Issues (20)
- Introducing a Particle class HOT 1
- Incompatibility between astropy 5.0.1 and agnpy 0.1.8 ? HOT 1
- Absorption calculation stability HOT 1
- Add sherpa and gammapy among the dependencies (add them to install_requires in setup.py) HOT 4
- Add a CITATION.cff file?
- TypeError: __init__() got an unexpected keyword argument 'is_norm' HOT 3
- Bullet points of lists disappear on Read the Docs HOT 1
- Error in the EBL absorption HOT 1
- Error in InterpolatedDistribution HOT 11
- Discrepancy between AGNpy and LeHa code in proton synchrotron
- Add the synchrotron proton to the models available for fitting
- Issue with fitting MWL SED using agnpy HOT 7
- Return the different SED components after a fit HOT 2
- Problem about load_absorption_table in class EBL HOT 2
- Problem about load_absorption_table in class EBL
- Move the tests to the subdirectory of each module. HOT 1
- Fitting of a MWL BL Lac SED: Fit doesn't converge. HOT 1
- d_L parameter in blob definition spoiling older code and examples
- Logging is silently disabled on agnpy import HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agnpy.