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

Fix and unify Map.iter_by_image #1731

Merged
merged 11 commits into from Aug 22, 2018

Conversation

2 participants
@adonath
Member

adonath commented Aug 22, 2018

This PR fixes and unifies the Map.iter_by_image() behaviour by returning a reversed idx. The behaviour is now documented and used uniformly in .convolve(), .smooth() and .reproject().
This PR also fixes #1728.

@adonath adonath added this to the 0.8 milestone Aug 22, 2018

@adonath adonath self-assigned this Aug 22, 2018

@adonath adonath added this to To do in Map analysis via automation Aug 22, 2018

@cdeil

This comment has been minimized.

Show comment
Hide comment
@cdeil

cdeil Aug 22, 2018

Member

@adonath - Thanks!

I find this code in the iter_by_pix and iter_by_coord very complex and non-obvious:

       pix = list(self.geom.get_idx(flat=True))
        vals = self.data[np.isfinite(self.data)]
        return unpack_seq(np.nditer([vals] + pix,
                                    flags=['external_loop', 'buffered'],
                                    buffersize=buffersize))

I realise you didn't add it in this PR, so OK to merge as-is.

@adonath - Do you understand it? Is it used / tested? Does it make sense to subset data this ways?
If you've thought about this, please leave a code comment.

cc @woodmd

Member

cdeil commented Aug 22, 2018

@adonath - Thanks!

I find this code in the iter_by_pix and iter_by_coord very complex and non-obvious:

       pix = list(self.geom.get_idx(flat=True))
        vals = self.data[np.isfinite(self.data)]
        return unpack_seq(np.nditer([vals] + pix,
                                    flags=['external_loop', 'buffered'],
                                    buffersize=buffersize))

I realise you didn't add it in this PR, so OK to merge as-is.

@adonath - Do you understand it? Is it used / tested? Does it make sense to subset data this ways?
If you've thought about this, please leave a code comment.

cc @woodmd

@cdeil

cdeil approved these changes Aug 22, 2018

@adonath - Thanks!

@cdeil cdeil merged commit 8863e82 into gammapy:master Aug 22, 2018

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

Map analysis automation moved this from To do to Done Aug 22, 2018

assert m.data.shape == m_r.data.shape
for img, idx in m_r.iter_by_image():
ref = idx[1] + 0.5 * idx[0]
assert_allclose(np.nanmean(img.data), ref)

This comment has been minimized.

@cdeil

cdeil Aug 22, 2018

Member

@adonath - This is failing in one build: https://travis-ci.org/gammapy/gammapy/jobs/419332370#L1773
It's because you're calling .data on the Numpy array, resulting in a buffer object.
It would be nice if this were failing also on Python 3, but hey: those Python 2 builds have to be good for something.

I'll fix via a commit in master.

@cdeil

cdeil Aug 22, 2018

Member

@adonath - This is failing in one build: https://travis-ci.org/gammapy/gammapy/jobs/419332370#L1773
It's because you're calling .data on the Numpy array, resulting in a buffer object.
It would be nice if this were failing also on Python 3, but hey: those Python 2 builds have to be good for something.

I'll fix via a commit in master.

@cdeil cdeil changed the title from Fix and unify `Map.iter_by_image()` behaviour to Fix and unify Map.iter_by_image Sep 9, 2018

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