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 tests for spectral_cube.integral_flux_image #188

Merged
merged 6 commits into from Sep 16, 2014

Conversation

Projects
None yet
2 participants
@ellisowen
Contributor

ellisowen commented Aug 26, 2014

Adds the unit test changes suggested in PR #178 comment.

Show outdated Hide outdated gammapy/data/spectral_cube.py Outdated

@cdeil cdeil changed the title from Implements additional unit tests for integral_flux_image in spectral_cub... to Add more unit tests for spectral_cube.integral_flux_image Aug 26, 2014

@@ -229,7 +266,7 @@ def test_analytical_npred_cube():
# Exposure = 1, so solid angle only factor which varies.
# Result should be 0.5 * 1 * solid_angle_array from integrating analytically
energies = Quantity([1, 2], 'GeV')
energies = Quantity([1, 2], 'MeV')

This comment has been minimized.

@cdeil

cdeil Aug 26, 2014

Member

Why can you change the unit here but tests still pass on travis-ci ... is this not covered by unit tests?
If so, please add a test for this.

@cdeil

cdeil Aug 26, 2014

Member

Why can you change the unit here but tests still pass on travis-ci ... is this not covered by unit tests?
If so, please add a test for this.

This comment has been minimized.

@ellisowen

ellisowen Aug 26, 2014

Contributor

The test fails with 'GeV' as the unit, as the energy should be 'MeV'. (It was passing before because there was no conversion being done and 'MeV' was just assumed somewhere along the line)

@ellisowen

ellisowen Aug 26, 2014

Contributor

The test fails with 'GeV' as the unit, as the energy should be 'MeV'. (It was passing before because there was no conversion being done and 'MeV' was just assumed somewhere along the line)

This comment has been minimized.

@cdeil

cdeil Aug 26, 2014

Member

But then you need to add a conversion to MeV somewhere, no?
(I don't see any relevant code change in this PR, only the test change)

@cdeil

cdeil Aug 26, 2014

Member

But then you need to add a conversion to MeV somewhere, no?
(I don't see any relevant code change in this PR, only the test change)

This comment has been minimized.

@cdeil

cdeil Aug 26, 2014

Member

I'll be offline now and have another look at this PR tomorrow.

@cdeil

cdeil Aug 26, 2014

Member

I'll be offline now and have another look at this PR tomorrow.

This comment has been minimized.

@ellisowen

ellisowen Aug 26, 2014

Contributor

So, I've had look into the code more carefully: The 'MeV' is just specific to this test which shouldn't be energy-scale independent to test units. It correctly fails with 'GeV' where it didn't before because of the previous bug fix (before this, it assumed the 'GeV' energy was 'MeV' - and in the npred code & elsewhere I used 'MeV' as the internal assumption because this is the energy unit usually used by cubes produced by the Fermi science tools).

Running the test on the version of the code in master currently fails, but this test is skipped by Travis CI because of the reproject dependency, which is why Travis CI passes.

@ellisowen

ellisowen Aug 26, 2014

Contributor

So, I've had look into the code more carefully: The 'MeV' is just specific to this test which shouldn't be energy-scale independent to test units. It correctly fails with 'GeV' where it didn't before because of the previous bug fix (before this, it assumed the 'GeV' energy was 'MeV' - and in the npred code & elsewhere I used 'MeV' as the internal assumption because this is the energy unit usually used by cubes produced by the Fermi science tools).

Running the test on the version of the code in master currently fails, but this test is skipped by Travis CI because of the reproject dependency, which is why Travis CI passes.

This comment has been minimized.

@cdeil

cdeil Aug 27, 2014

Member

travis-ci does install reproject and should run any unit tests that require reproject :
https://travis-ci.org/gammapy/gammapy/jobs/33666780#L618

@cdeil

cdeil Aug 27, 2014

Member

travis-ci does install reproject and should run any unit tests that require reproject :
https://travis-ci.org/gammapy/gammapy/jobs/33666780#L618

This comment has been minimized.

@ellisowen

ellisowen Aug 27, 2014

Contributor

I still think Travis CI skips these tests:

gammapy/data/tests/test_spectral_cube.py ssssssssssssss

There is also a scipy dependency on them (due to interpolation I think), so if reproject is OK, does Travis CI skip scipy tests?

@ellisowen

ellisowen Aug 27, 2014

Contributor

I still think Travis CI skips these tests:

gammapy/data/tests/test_spectral_cube.py ssssssssssssss

There is also a scipy dependency on them (due to interpolation I think), so if reproject is OK, does Travis CI skip scipy tests?

@ellisowen ellisowen referenced this pull request Aug 28, 2014

Merged

Add iterative kernel background estimator #186

5 of 5 tasks complete
# Compute image with fraction of pixel area at equator
glat = coordinates(image)[1]
area_fraction = np.cos(np.radians(glat))
result = area_fraction * equator_area
result = area_fraction * equator_area.to('sr')
return result

This comment has been minimized.

@ellisowen

ellisowen Aug 28, 2014

Contributor

I moved this change from PR #186 so that the changes were easier to keep track of. Also changed corresponding unit tests to call the correct units.

@ellisowen

ellisowen Aug 28, 2014

Contributor

I moved this change from PR #186 so that the changes were easier to keep track of. Also changed corresponding unit tests to call the correct units.

@ellisowen

This comment has been minimized.

Show comment
Hide comment
@ellisowen

ellisowen Aug 28, 2014

Contributor

It was getting hard to keep track of the small fixes to ensure they were consistent, so I have moved them to this PR.

Contributor

ellisowen commented Aug 28, 2014

It was getting hard to keep track of the small fixes to ensure they were consistent, so I have moved them to this PR.

@ellisowen

This comment has been minimized.

Show comment
Hide comment
@ellisowen

ellisowen Aug 28, 2014

Contributor

I think these corrections are all consistent now. The tests seem to pass when I expect them too, and the results in the npred_cube are unchanged - again, as I would expect. Does this seem OK to you?

Contributor

ellisowen commented Aug 28, 2014

I think these corrections are all consistent now. The tests seem to pass when I expect them too, and the results in the npred_cube are unchanged - again, as I would expect. Does this seem OK to you?

Show outdated Hide outdated docs/tutorials/npred/npred_general.py Outdated
assert_allclose(actual, expected)
# Test integral flux for energy bands with units.
energy_band_check = Quantity([1000, 10000], 'MeV')

This comment has been minimized.

@cdeil

cdeil Aug 31, 2014

Member

Write this as 1 to 10 GeV ... easier to read if there's fewer 0s and everything should still work (that's the whole point of using quantities ... results don't depend on the units of inputs)

@cdeil

cdeil Aug 31, 2014

Member

Write this as 1 to 10 GeV ... easier to read if there's fewer 0s and everything should still work (that's the whole point of using quantities ... results don't depend on the units of inputs)

This comment has been minimized.

@ellisowen

ellisowen Sep 16, 2014

Contributor

This was the test to show the bug was fixed (where Quantity([1000, 10000], 'MeV') was giving a different result to Quantity([1, 10], 'GeV')) so in this case, I will have to keep the 0s

@ellisowen

ellisowen Sep 16, 2014

Contributor

This was the test to show the bug was fixed (where Quantity([1000, 10000], 'MeV') was giving a different result to Quantity([1, 10], 'GeV')) so in this case, I will have to keep the 0s

@ellisowen

This comment has been minimized.

Show comment
Hide comment
@ellisowen

ellisowen Sep 16, 2014

Contributor

I think this addresses your comments

Contributor

ellisowen commented Sep 16, 2014

I think this addresses your comments

cdeil added a commit that referenced this pull request Sep 16, 2014

Merge pull request #188 from ellisowen/issue_178_test
Add more unit tests for spectral_cube.integral_flux_image

@cdeil cdeil merged commit 3e14c12 into gammapy:master Sep 16, 2014

1 check passed

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

@cdeil cdeil changed the title from Add more unit tests for spectral_cube.integral_flux_image to Add tests for spectral_cube.integral_flux_image Apr 8, 2015

@cdeil cdeil added the tests label Apr 8, 2015

@cdeil cdeil added this to the 0.2 milestone Apr 8, 2015

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