Skip to content
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
Merged

Fix and unify Map.iter_by_image #1731

merged 11 commits into from Aug 22, 2018

Conversation

@adonath
Copy link
Member

@adonath 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 gammapy.maps via automation Aug 22, 2018
@cdeil
Copy link
Member

@cdeil 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

cubes['off'] = self._off_cube(counts, exclusion, kernels)
cubes['alpha_approx'] = self._alpha_approx_cube(cubes)
if not counts.geom.is_image:
raise NotImplementedError('Adaptive ring background estimation only'

This comment has been minimized.

@cdeil

cdeil Aug 22, 2018
Member

In other places we always raised ValueError for functions that only work on 2D images. Do it here as well for uniformity?

This comment has been minimized.

@adonath

adonath Aug 22, 2018
Author Member

Done

@cdeil
cdeil approved these changes Aug 22, 2018
Copy link
Member

@cdeil cdeil left a comment

@adonath - Thanks!

@cdeil cdeil merged commit 8863e82 into gammapy:master Aug 22, 2018
0 of 2 checks passed
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
gammapy.maps 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 changed the title Fix and unify Map.iter_by_image() behaviour Fix and unify Map.iter_by_image Sep 9, 2018
@adonath adonath deleted the adonath:fix_issue_#1728 branch Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
gammapy.maps
  
Done
Linked issues

Successfully merging this pull request may close these issues.

2 participants