Created
February 18, 2014 14:53
-
-
Save astrofrog/9072439 to your computer and use it in GitHub Desktop.
Find order to switch octree from xyz to zyx and vice-versa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_order(refined): | |
""" | |
Find the index array to use to sort the ``refined`` and ``density`` arrays. | |
""" | |
order = np.zeros(refined.shape) | |
if not refined[0]: | |
return [0] | |
def find_nested(i): | |
cells = [i] | |
for cell in range(8): | |
i += 1 | |
if refined[i]: | |
parent = i | |
i, sub_cells = find_nested(i) | |
cells.append(sub_cells) | |
else: | |
cells.append(i) | |
cells = [cells[j] for j in [0,1,5,3,7,2,6,4,8]] | |
return i, np.hstack(cells) | |
return find_nested(0)[1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs optimizing!