-
Notifications
You must be signed in to change notification settings - Fork 19
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
Improve interpolation method and edge case handling in SpecFromDat: #191
Conversation
krishnatejavedula
commented
Jun 21, 2024
- Use 'fill_value' in interp1d for better extrapolation.
- Remove normalization of dataFlux to use raw data.
- Use 'fill_value' in interp1d for better extrapolation. - Remove normalization of dataFlux to use raw data.
Thanks for working on this @krishnatejavedula. About the normalization: However, this change will break some tutorials. I think only the extended source model fit tutorial. Can you make the appropriate change such that it returns the same result? It's probably only a matter of changing the values in the input file to account with a constant in front. About the fill_value: |
The above changes will remove the line
|
I'm a bit confused about the changes being made here. I am trying to understand why dataFlux was initially normalized, and what the motivation is for changing it. Ultimately, the |
@ckarwin Since I suggested this change, let me explain it. I think there are 3 sensible ways to define the normalization
The current version that this PR is replacing is close to option 3, but only when the points are sampled every 1 keV. The normalization was the sum of the y values, without taking into account the bin size. Since it is bin and unit-dependent, I suggested changing it to option 1, which is in line with astromodel's TemplateModel. |
@israelmcmc Thanks for the clarification. It makes sense. I see now that the way this was implemented in example 3 of the extended source spectral fit tutorial for DC2 was not completely correct. I agree that the first approach you described is probably the most straight forward way. It would be helpful to specify the requirements for the file type and corresponding normalization factor I guess then that modifying the input spectral files for the DC2 tutorial will be a quick and easy patch to reproduce the originally published results. But I think the files still need to be changed directly, and there is no need to supply the code for users to do it themselves. We can revisit the details of the extended source fit later on (and in future examples). I also note that some of the automatic tests are failing now, but it seems related to the issue that is fixed with PR #192. |
Thanks, @ckarwin
Yes, I agree. @krishnatejavedula can you add this to the docstring, please? The file energy units should be keV, and flux units 1/cm2/s/kev. The normalization K is unitless.
Indeed. I opened an issue about it: #194. I think it's a "good first issue" and labeled it as such.
@krishnatejavedula I just merged #192. Can you sync this PR with the develop branch in order to fix the unit tests, please? |
The latest of @krishnatejavedula commit (which I asked him to) made me realize that I screwed this up. I hadn't realize that the .dat file was using the pre-defined MEGAlib format. From the cosima manual: That is, the normalization constant Andreas had reasons to do it this way for simulations, and although I'm not sure it's the best definition for the analysis, I think we should stick to the previously-defined file format definition, otherwise, it will be really error-prone. Summarizing, the spectrum points, in 1/cm2/s/keV should be: Since all energy bins in the current file are equal, the current code works. However, it should be fixed to work in the general case. Also, we should make sure the docstring matches the cosima documentation. @ckarwin Can you please double-check that I got it right this time, since you've used this spectrum file format before? |
@israelmcmc Ok yes, if we are going to stick with the same convention as MEGAlib, then that should help to make things less error prone. Everything you said makes sense for the most part, but I don't think the differential flux ( The spectral file has the form:
where The normalization of the spectrum is given by So the function should take the input spectral values from the file and normalize them by the integral: where Then the differential flux is given by
And we have
The function would return the differential flux as a function of energy. Do you know what threeml expects? If this is the convention we are using, then I think the units of Please let me know if this all makes sense. |
@ckarwin @israelmcmc I think this makes sense. I was trying to figure out the units for the differential flux and K too. With Using This would also mean in the |
Thank you, both. No delta E in the numerator sounds indeed correct. @krishnatejavedula can you please implement this and, as a test, make sure the source injector returns what's expected? I think 3ML expects the output of evaluate() to be differential flux, but I'm on my phone right now. |
@israelmcmc I believe the output of the evaluate() to be differential flux too. I have already tested the changes with the source injector. I think it's the |
Great! Thanks |
@krishnatejavedula I opened a PR into your branch for this PR adding a test and syncing with the develop branch. Please take a look. When you incorporate those changes we can merge this PR, assuming the tests will pass. |
Add test for SpecFromDat
I'll close and reopen this PR to see if the kick fixes codecov. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
|
It worked. I am merging this now. |