RasterFairy
RasterFairy copied to clipboard
Error "slice indices must be integers or None or have an __index__ method"
Hi Mario
first of all: thanks for RasterFairy. Very much appreciated!
I can install and use RasterFairy with Python 2.7. Unfortunately I get this error when I try to to use it with v3.5 (trying to follow Gene Kogans TSNE notebooks with Keras, TF1.0). I am using a conda environment on Windows 10.
Any idea what might be the cause and how to fix this?
Many thanks in advance.
<ipython-input-28-842e2c585a53> in <module>()
6
7 # assign to grid
----> 8 grid_assignment = rasterfairy.transformPointCloud2D(tsne, target=(nx, ny))
H:\KI\keras\rasterfairy.py in transformPointCloud2D(points2d, target, autoAdjustCount, proportionThreshold)
107 if ( len(quadrants[i]['points']) > 1 ):
108 slices = sliceQuadrant(quadrants[i], mask = rasterMask)
--> 109 if len(slices)>1:
110 del quadrants[i]
111 quadrants += slices
H:\KI\keras\rasterfairy.py in sliceQuadrant(quadrant, mask)
170 order = np.lexsort((xy[:,0],xy[:,1]))
171 sliceCount = sliceYCount
--> 172 sliceSize = grid[3] / sliceCount
173 pointsPerSlice = grid[2] * sliceSize
174 gridOffset = grid[1]
TypeError: slice indices must be integers or None or have an __index__ method```
It might be the case that one of the libraries used has become stricter since I released the code and does not automatically convert floats to ints. I remember having seen that error at some point in the past but adding a few int() casts had solved it - maybe it needs a few more of those. From the stack trace you posted it's not really clear to me at which point the error occurs, since at least in the marked lines I don't see any operation that uses slicing, except maybe for that
order = np.lexsort((xy[:,0],xy[:,1])) line.
I don't know, maybe you try change that line to
order = np.lexsort((int(xy[:,0]),int(xy[:,1])))
and see what happens?
Great! Thanks. That fixed this error.
It is still not working with Python 3.5 though. I get all sorts of new errors (mainly print statements without parentheses that i can fix) and than this one:
not enough memory for amount of possible permutations, creating grouped set
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-78-661d9e5abb3e> in <module>()
1 import rasterfairy
2 print(tsne.shape)
----> 3 arrangements = rasterfairy.getRectArrangements(tsne.shape[0])
4 print(arrangements)
5
H:\KI\keras\rasterfairy.py in getRectArrangements(n)
382 arrangements.add((min(v1, v2),max(v1, v2)))
383
--> 384 return sorted(list(arrangements), cmp=proportion_sort, reverse=True)
385
386 def getShiftedAlternatingRectArrangements(n):
TypeError: 'cmp' is an invalid keyword argument for this function`
Just to make a sure I again did a clean install of RF from my conda 3.5 environment with "python setup.py install" and I get these errors:
File "build\bdist.win-amd64\egg\rasterfairy\prime.py", line 123
print "not enough memory for amount of possible permutations, creating grouped set"
^
SyntaxError: Missing parentheses in call to 'print'
byte-compiling build\bdist.win-amd64\egg\rasterfairy\rasterfairy.py to rasterfairy.cpython-35.pyc
File "build\bdist.win-amd64\egg\rasterfairy\rasterfairy.py", line 54
print "no good rectangle found for",pointCount,"points, using incomplete square",width,"*",height
^
SyntaxError: Missing parentheses in call to 'print'
byte-compiling build\bdist.win-amd64\egg\rasterfairy\rfoptimizer.py to rfoptimizer.cpython-35.pyc
File "build\bdist.win-amd64\egg\rasterfairy\rfoptimizer.py", line 98
print "ERROR:",(cx,cy)," doubled"
^
SyntaxError: invalid syntax`
Looking at last years commits I assumed that RF should work with 3.5. Any hint what I do wrong?
(And please excuse if I somehow don´t see the forest for the trees...)
Ah okay - so yes, this is written for Python 2.7 and I have not made sure that it also works with Python 3+
Ok. I see. No problem. I just have to split the processing to two environments then.
Really cool plugin btw. Thanks for sharing this.