Skip to content

Commit

Permalink
Merge 4f27d66 into 6e8d71b
Browse files Browse the repository at this point in the history
  • Loading branch information
keflavich committed Jan 15, 2020
2 parents 6e8d71b + 4f27d66 commit 2946da3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.5 (unreleased)
----------------

- Bugfix: subcubes from compound regions previously did not work. #601

- Refactor tests to use fixtures for accessing data instead of needing to
run a script to generate test files. #598

Expand Down
9 changes: 6 additions & 3 deletions spectral_cube/spectral_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -3988,9 +3988,12 @@ def spectral_smooth(self, *args, **kwargs):


def _regionlist_to_single_region(region_list):
"""
Recursively merge a region list into a single compound region
"""
import regions
if len(region_list) == 1:
return region_list[0]
return regions.CompoundPixelRegion(_regionlist_to_single_region(region_list[:len(region_list)/2]),
_regionlist_to_single_region(region_list[len(region_list)/2:])
)
left = _regionlist_to_single_region(region_list[:len(region_list)//2])
right = _regionlist_to_single_region(region_list[len(region_list)//2:])
return regions.CompoundPixelRegion(left, right, operator.or_)
5 changes: 5 additions & 0 deletions spectral_cube/tests/data/fk5_twoboxes.reg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Region file format: DS9 version 4.1
global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
fk5
box(24.063014,29.934653,4.61661",2.6001614",0.43894166)
box(24.033333,29.933333,4.61661",2.9",0.43894166)
1 change: 1 addition & 0 deletions spectral_cube/tests/test_subcubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_ds9region_255(regfile, data_255):
@pytest.mark.skipif('not REGIONS_GT_03', reason='regions version should be >= 0.3')
@pytest.mark.parametrize(('regfile', 'result'),
(('fk5.reg', (slice(None), 1, 1)),
('fk5_twoboxes.reg', (slice(None), 1, 1)),
('image.reg', (slice(None), 1, slice(None))),
(
'partial_overlap_image.reg', (slice(None), 1, 1)),
Expand Down

0 comments on commit 2946da3

Please sign in to comment.