#NEWLINE# def test_construct_octree( ) : #NEWLINE# #INDENT# np . random . seed ( 0 ) #NEWLINE# N = 5000 #NEWLINE# px = np . random . uniform ( ( - 10.0 ) , 10.0 , N ) #NEWLINE# py = np . random . uniform ( ( - 10.0 ) , 10.0 , N ) #NEWLINE# pz = np . random . uniform ( ( - 10.0 ) , 10.0 , N ) #NEWLINE# mass = np . random . uniform ( 0.0 , 1.0 , N ) #NEWLINE# sigma = np . random . uniform ( 0.0 , 0.1 , N ) #NEWLINE# o = construct_octree ( 0.1 , 0.2 , 0.3 , 6.0 , 5.0 , 4.0 , px , py , pz , sigma , mass , n_levels = 10 ) #NEWLINE# from hyperion.grid import OctreeGrid #NEWLINE# f = h5py . File ( os . path . join ( DATA , 'reference_octree.hdf5' ) , 'r' ) #NEWLINE# o_ref = OctreeGrid ( ) #NEWLINE# o_ref . read ( f ) #NEWLINE# f . close ( ) #NEWLINE# assert np . all ( ( o_ref . refined == o . refined ) ) #NEWLINE# assert_allclose ( o_ref [ 'density' ] [ 0 ] . array , o [ 'density' ] [ 0 ] . array ) #NEWLINE# ( xmin , xmax , ymin , ymax , zmin , zmax ) = o . limits #NEWLINE# volumes = o . volumes #NEWLINE# assert_allclose ( volumes , ( ( ( xmax - xmin ) * ( ymax - ymin ) ) * ( zmax - zmin ) ) ) #NEWLINE# def get_volumes( current_i , current_volume , refined ) : #NEWLINE# #INDENT# volumes = [ ] #NEWLINE# i = current_i #NEWLINE# for sub in range ( 8 ) : #NEWLINE# #INDENT# volumes += [ current_volume ] #NEWLINE# if refined [ i ] : #NEWLINE# #INDENT# ( sub_volumes , i ) = get_volumes ( ( i + 1 ) , ( current_volume / 8.0 ) , refined ) #NEWLINE# volumes += sub_volumes #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i += 1 #NEWLINE# #UNINDENT# #UNINDENT# return ( volumes , i ) #NEWLINE# #UNINDENT# ( volumes_ref , last_i ) = get_volumes ( 1 , ( ( 6 * 5 ) * 4 ) , o . refined ) #NEWLINE# volumes_ref . insert ( 0 , ( ( ( 6 * 5 ) * 4 ) * 8.0 ) ) #NEWLINE# assert_allclose ( volumes , volumes_ref )