fix for case of single slice with start, stop or step that is not none
This commit is contained in:
parent
e565a71e88
commit
ec15eb5ad0
1 changed files with 15 additions and 11 deletions
|
|
@ -790,19 +790,22 @@ class Jp2k(Jp2kBox):
|
||||||
area = (row, 0, row + 1, numcols)
|
area = (row, 0, row + 1, numcols)
|
||||||
return self.read(area=area).squeeze()
|
return self.read(area=area).squeeze()
|
||||||
|
|
||||||
#if isinstance(pargs, slice) or pargs is ...:
|
if pargs is Ellipsis:
|
||||||
if isinstance(pargs, slice) or pargs is Ellipsis:
|
# Case of jp2[...]
|
||||||
# Case of jp2[:] or jp2[...], i.e. retrieve the entire image.
|
|
||||||
#
|
|
||||||
# Should have a slice object where start = stop = step = None
|
|
||||||
return self.read()
|
return self.read()
|
||||||
|
|
||||||
if isinstance(pargs, tuple) and any(x is Ellipsis for x in pargs):
|
if isinstance(pargs, slice):
|
||||||
# Search out and remove any Ellipsis objects.
|
if pargs.start is None and pargs.stop is None and pargs.step is None:
|
||||||
lst = list(pargs)
|
# Case of jp2[:]
|
||||||
predicate = lambda x: x[1] is not Ellipsis
|
return self.read()
|
||||||
g = filterfalse(predicate, enumerate(pargs))
|
|
||||||
|
|
||||||
|
# Corner case of jp2[x] where x is a slice object with non-null
|
||||||
|
# members. Just augment it with an ellipsis and let the code
|
||||||
|
# below handle it.
|
||||||
|
pargs = (pargs, Ellipsis)
|
||||||
|
|
||||||
|
if isinstance(pargs, tuple) and any(x is Ellipsis for x in pargs):
|
||||||
|
# Remove the first ellipsis we find.
|
||||||
rows = slice(0, numrows)
|
rows = slice(0, numrows)
|
||||||
cols = slice(0, numcols)
|
cols = slice(0, numcols)
|
||||||
bands = slice(0, numbands)
|
bands = slice(0, numbands)
|
||||||
|
|
@ -817,6 +820,7 @@ class Jp2k(Jp2kBox):
|
||||||
else:
|
else:
|
||||||
newindex = (pargs[0], cols, pargs[2])
|
newindex = (pargs[0], cols, pargs[2])
|
||||||
else:
|
else:
|
||||||
|
# Assume that we don't have 4D imagery, of course.
|
||||||
newindex = (pargs[0], pargs[1], bands)
|
newindex = (pargs[0], pargs[1], bands)
|
||||||
|
|
||||||
# Run once again because it is possible that there's another
|
# Run once again because it is possible that there's another
|
||||||
|
|
@ -828,7 +832,7 @@ class Jp2k(Jp2kBox):
|
||||||
lst = list(pargs)
|
lst = list(pargs)
|
||||||
predicate = lambda x: not isinstance(x[1], int)
|
predicate = lambda x: not isinstance(x[1], int)
|
||||||
g = filterfalse(predicate, enumerate(pargs))
|
g = filterfalse(predicate, enumerate(pargs))
|
||||||
idx = list(g)[0][0]
|
idx = next(g)[0]
|
||||||
lst[idx] = slice(pargs[idx], pargs[idx] + 1)
|
lst[idx] = slice(pargs[idx], pargs[idx] + 1)
|
||||||
newindex = tuple(lst)
|
newindex = tuple(lst)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue