Advertisement
Guest User

Untitled

a guest
Mar 9th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. from yt.analysis_modules.ppv_cube.api import PPVCube
  2. import yt.units as u
  3. import cPickle
  4.  
  5. if 0:
  6. nx,ny,nz = (256,256,256) # domain dimensions
  7. R = 10. # outer radius of disk, kpc
  8. r_0 = 3. # scale radius, kpc
  9. beta = 1.4 # for the tangential velocity profile
  10. alpha = -1. # for the radial density profile
  11. x, y = np.mgrid[-R:R:nx*1j,-R:R:ny*1j] # cartesian coordinates of x-y plane of disk
  12. r = np.sqrt(x*x+y*y) # polar coordinates
  13. theta = np.arctan2(y, x) # polar coordinates
  14.  
  15. dens = np.zeros((nx,ny,nz))
  16. dens[:,:,nz/2-3:nz/2+3] = (r**alpha).reshape(nx,ny,1) # the density profile of the disk
  17. temp = np.zeros((nx,ny,nz))
  18. temp[:,:,nz/2-3:nz/2+3] = 1.0e5 # Isothermal
  19. vel_theta = 100.*r/(1.+(r/r_0)**beta) # the azimuthal velocity profile of the disk
  20. velx = np.zeros((nx,ny,nz))
  21. vely = np.zeros((nx,ny,nz))
  22. velx[:,:,nz/2-3:nz/2+3] = (-vel_theta*np.sin(theta)).reshape(nx,ny,1) # convert polar to cartesian
  23. vely[:,:,nz/2-3:nz/2+3] = (vel_theta*np.cos(theta)).reshape(nx,ny,1) # convert polar to cartesian
  24. dens[r > R] = 0.0
  25. temp[r > R] = 0.0
  26. velx[r > R] = 0.0
  27. vely[r > R] = 0.0
  28.  
  29. data = {}
  30. data["density"] = (dens,"g/cm**3")
  31. data["temperature"] = (temp, "K")
  32. data["velocity_x"] = (velx, "km/s")
  33. data["velocity_y"] = (vely, "km/s")
  34. data["velocity_z"] = (np.zeros((nx,ny,nz)), "km/s") # zero velocity in the z-direction
  35. bbox = np.array([[-0.5,0.5],[-0.5,0.5],[-0.5,0.5]]) # bbox of width 1 on a side with center (0,0,0)
  36. ds_round = yt.load_uniform_grid(data, (nx,ny,nz), length_unit=(2*R,"kpc"), nprocs=1, bbox=bbox)
  37.  
  38. if 0:
  39. master_clump = Clump(ds_round.all_data(),'density')
  40. find_clumps(master_clump,16,300,2)
  41. leaf_clumps = get_lowest_clumps(master_clump) #if both min_cells and grav_bound are used, this is empty.
  42.  
  43. if 0:
  44. pickle_name = 'test_sphere_clump.pickle'
  45. fptr = open(pickle_name, 'wb')
  46. #Works and writes a set
  47. cPickle.dump(leaf_clumps[0].data,fptr, protocol=-1)
  48. fptr.close()
  49.  
  50.  
  51. if 1:
  52. pickle_name = 'test_sphere_clump.pickle'
  53. fptr = open(pickle_name, 'rb')
  54. new_clump=cPickle.load(fptr)
  55. fptr.close()
  56. #THis works if you run in the same python interpreter instance,
  57. #but fails if you launch a new python.
  58. print new_clump[1]['density']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement