Skip to content

Commit

Permalink
Merge pull request sunpy#251 from hayesla/ndcube_sequence_slicing
Browse files Browse the repository at this point in the history
First step to simplify NDCubeSequence slicing implementation
  • Loading branch information
DanRyanIrish committed Apr 13, 2020
1 parent 57397e3 commit c24fe2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog/251.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplify and speed up implementation of NDCubeSequence slicing.
21 changes: 17 additions & 4 deletions ndcube/ndcube_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,25 @@ def cube_like_world_axis_physical_types(self):
def __getitem__(self, item):
if isinstance(item, numbers.Integral):
return self.data[item]
elif isinstance(item, slice):
else:
result = copy.deepcopy(self)
result.data = self.data[item]
if isinstance(item, slice):
result.data = self.data[item]
else:
if isinstance(item[0], numbers.Integral):
result = result.data[item[0]][item[1:]]
else:
item0_is_length1_slice = False
if isinstance(item[0], slice):
start = 0 if item[0].start is None else item[0].start
stop = len(self.data) if item[0].stop is None else item[0].stop
if stop - start == 1:
item0_is_length1_slice = True
if item0_is_length1_slice:
result.data = [result.data[start][item[1:]]]
else:
result.data = [cube[item[1:]] for cube in result.data[item[0]]]
return result
else:
return utils.sequence.slice_sequence(self, item)

@property
def index_as_cube(self):
Expand Down

0 comments on commit c24fe2e

Please sign in to comment.