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

Add XSPEC table absorption model to spectral table model #824

Merged
merged 3 commits into from Dec 19, 2016

Conversation

Projects
None yet
3 participants
@jjlk
Contributor

jjlk commented Dec 18, 2016

Hi @cdeil and @joleroi ,
I added a class method to TableModel to import models from XSPEC (see flx2tab).

Maybe we could propose this format on https://gamma-astro-data-formats.readthedocs.io/en/latest/? @cdeil, @registerrier , some volunteers?

I also made optional the logarithm scale value on the y-axis and I added a plot function because, as I understood it, the SpectralModel plot method was really attached to have some physical units for the y-values.

Thanks!

@cdeil cdeil added the feature label Dec 19, 2016

@cdeil cdeil added this to the 0.6 milestone Dec 19, 2016

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Dec 19, 2016

Member

Please add $GAMMAPY_EXTRA/datasets/ebl/ebl_franceschini.fits.gz so that tests run:
https://travis-ci.org/gammapy/gammapy/jobs/184942465#L997

You can directly add the file to master in gammapy-extra, unless you want it reviewed.
The usual things are: please add a README file what it is in the folder, and don't commit too large files without discussion (ask first if it's >> 1 MB).

Concerning format -- yes, I'd pretty much always would prefer formats are described over at gamma-astro-data-formats, instead of in the Gammapy docs. Especially for things like this, where the same data is of interest to several science tools.
I don't have time for this one. If you do, the start would be to either make a pull request with a very short and simple description of what you have here (as a starting point) or an issue proposing it, and CC a few people that might be able to give useful feedback.

Member

cdeil commented Dec 19, 2016

Please add $GAMMAPY_EXTRA/datasets/ebl/ebl_franceschini.fits.gz so that tests run:
https://travis-ci.org/gammapy/gammapy/jobs/184942465#L997

You can directly add the file to master in gammapy-extra, unless you want it reviewed.
The usual things are: please add a README file what it is in the folder, and don't commit too large files without discussion (ask first if it's >> 1 MB).

Concerning format -- yes, I'd pretty much always would prefer formats are described over at gamma-astro-data-formats, instead of in the Gammapy docs. Especially for things like this, where the same data is of interest to several science tools.
I don't have time for this one. If you do, the start would be to either make a pull request with a very short and simple description of what you have here (as a starting point) or an issue proposing it, and CC a few people that might be able to give useful feedback.

@cdeil

I left a few inline comments.

Show outdated Hide outdated gammapy/spectrum/models.py Outdated
Show outdated Hide outdated gammapy/spectrum/models.py Outdated
Show outdated Hide outdated gammapy/spectrum/models.py Outdated
Show outdated Hide outdated gammapy/spectrum/models.py Outdated
@jjlk

This comment has been minimized.

Show comment
Hide comment
@jjlk

jjlk Dec 19, 2016

Contributor

Hi @cdeil ,

Please add $GAMMAPY_EXTRA/datasets/ebl/ebl_franceschini.fits.gz so that tests run:
https://travis-ci.org/gammapy/gammapy/jobs/184942465#L997

The files are already there. The test failed on Travis because of a precision problem. Locally it works fine for me. For now I just changed the parameter value for the test.

Concerning format -- yes, I'd pretty much always would prefer formats are described over at gamma-astro-data-formats, instead of in the Gammapy docs. Especially for things like this, where the same data is of interest to several science tools.
I don't have time for this one. If you do, the start would be to either make a pull request with a very short and simple description of what you have here (as a starting point) or an issue proposing it,
and CC a few people that might be able to give useful feedback.

Oké, I'll have a look at that later.

Thanks for your comments, I took all of them into account!

Contributor

jjlk commented Dec 19, 2016

Hi @cdeil ,

Please add $GAMMAPY_EXTRA/datasets/ebl/ebl_franceschini.fits.gz so that tests run:
https://travis-ci.org/gammapy/gammapy/jobs/184942465#L997

The files are already there. The test failed on Travis because of a precision problem. Locally it works fine for me. For now I just changed the parameter value for the test.

Concerning format -- yes, I'd pretty much always would prefer formats are described over at gamma-astro-data-formats, instead of in the Gammapy docs. Especially for things like this, where the same data is of interest to several science tools.
I don't have time for this one. If you do, the start would be to either make a pull request with a very short and simple description of what you have here (as a starting point) or an issue proposing it,
and CC a few people that might be able to give useful feedback.

Oké, I'll have a look at that later.

Thanks for your comments, I took all of them into account!

@joleroi

This comment has been minimized.

Show comment
Hide comment
@joleroi

joleroi Dec 19, 2016

Contributor

I added a plot function because, as I understood it, the SpectralModel plot method was really attached to have some physical units for the y-values.

Doesn't it work if you pass flux_unit=''?

I had a discussion with @adonath about this and we decided it might be better do rename flux_unit -> y_unit everywhere. Its just not top priority I think, but if you want to do it, go ahead (would also need to be done in gammapy/spectrum/results.py)

Contributor

joleroi commented Dec 19, 2016

I added a plot function because, as I understood it, the SpectralModel plot method was really attached to have some physical units for the y-values.

Doesn't it work if you pass flux_unit=''?

I had a discussion with @adonath about this and we decided it might be better do rename flux_unit -> y_unit everywhere. Its just not top priority I think, but if you want to do it, go ahead (would also need to be done in gammapy/spectrum/results.py)

Show outdated Hide outdated gammapy/spectrum/models.py Outdated
Show outdated Hide outdated gammapy/spectrum/models.py Outdated
energy = energy_bounds.log_centers
# Get spectrum values (no interpolation, take closest value for param)
table_spectra = Table.read(filename, hdu='SPECTRA')

This comment has been minimized.

@joleroi

joleroi Dec 19, 2016

Contributor

Is it ok to hardcode the hdu names? Is this always the same for the format you're using, or is it better to pass the hdu names as kwargs?

@joleroi

joleroi Dec 19, 2016

Contributor

Is it ok to hardcode the hdu names? Is this always the same for the format you're using, or is it better to pass the hdu names as kwargs?

Show outdated Hide outdated gammapy/spectrum/models.py Outdated
@cdeil

Left two minor inline comments.

Show outdated Hide outdated gammapy/spectrum/models.py Outdated
Show outdated Hide outdated gammapy/spectrum/tests/test_models.py Outdated
@jjlk

This comment has been minimized.

Show comment
Hide comment
@jjlk

jjlk Dec 19, 2016

Contributor

Hi @joleroi and @cdeil ,

Doesn't it work if you pass flux_unit=''?
I had a discussion with @adonath about this and we decided it might be better do rename flux_unit -> y_unit everywhere. Its just not top priority I think, but if you want to do it, go ahead (would also need to be done in gammapy/spectrum/results.py)

I tried that and it didn't work. I didn't push a lot to investiguate where the problem was.

Maybe call the method read_ instead of from_file?
E.g. read_xspec_absorbed or read_ebl?

Done, read_xspec_model

I don't think this docstring will render correctly.

Fixed

A coding rule for Gammapy (and Astropy / ... most projects): Never use assert to check inputs, raise an exception instead.

Fixed

Is it ok to hardcode the hdu names? Is this always the same for the format you're using, or is it better to pass the hdu names as kwargs?

Yes, it is a standard

No need for local variables here IMO, since only used once.
Just pass as keyword arguments below.

Fixed

And multiple typos fixed.

Thanks!

Contributor

jjlk commented Dec 19, 2016

Hi @joleroi and @cdeil ,

Doesn't it work if you pass flux_unit=''?
I had a discussion with @adonath about this and we decided it might be better do rename flux_unit -> y_unit everywhere. Its just not top priority I think, but if you want to do it, go ahead (would also need to be done in gammapy/spectrum/results.py)

I tried that and it didn't work. I didn't push a lot to investiguate where the problem was.

Maybe call the method read_ instead of from_file?
E.g. read_xspec_absorbed or read_ebl?

Done, read_xspec_model

I don't think this docstring will render correctly.

Fixed

A coding rule for Gammapy (and Astropy / ... most projects): Never use assert to check inputs, raise an exception instead.

Fixed

Is it ok to hardcode the hdu names? Is this always the same for the format you're using, or is it better to pass the hdu names as kwargs?

Yes, it is a standard

No need for local variables here IMO, since only used once.
Just pass as keyword arguments below.

Fixed

And multiple typos fixed.

Thanks!

@cdeil

cdeil approved these changes Dec 19, 2016

Looks good to me.

@joleroi - Do you want to do a final review, or should we merge?

(I'd suggest postponing plot y-axis clean-up to a separate issue / PR)

@joleroi joleroi merged commit 1fec65b into gammapy:master Dec 19, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@jjlk jjlk deleted the jjlk:xspec_model branch Dec 19, 2016

@cdeil cdeil changed the title from Modify TableModel to handle absorption model from XSPEC table to Add XSPEC table absorption model to spectral table model Dec 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment