Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created February 18, 2014 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrofrog/9072439 to your computer and use it in GitHub Desktop.
Save astrofrog/9072439 to your computer and use it in GitHub Desktop.
Find order to switch octree from xyz to zyx and vice-versa
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]
@astrofrog
Copy link
Author

Needs optimizing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment