-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovieplugin.py
84 lines (78 loc) · 2.49 KB
/
movieplugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
import pylab as plt
import os,subprocess
import haloutils
from analysisplugin import AnalysisPluginBase
import pynbody as pnb
import mergertrees.MTCatalogue as MTC
from brendanlib.grifflib import makecolormap
import seaborn.apionly as sns
import gc,sys
#def get_open_fds():
# '''
# return the number of open file descriptors for current process
#
# .. warning: will only work on UNIX-like os-es.
# '''
#
# pid = os.getpid()
# procs = subprocess.check_output(
# [ "lsof", '-w', '-Ff', "-p", str( pid ) ] )
#
# nprocs = len(
# filter(
# lambda s: s and s[ 0 ] == 'f' and s[1: ].isdigit(),
# procs.split( '\n' ) )
# )
# return nprocs
def make_movie(hid,lx):
mycm = makecolormap()
hpath = haloutils.get_hpath_lx(hid,lx)
#if not os.path.exists(hpath+'/halos/trees/tree.bin'):
# print "No tree! Converting..."
# MTC.convertmt(hpath+'/trees',version=4,verbose=True)
mtc = MTC.MTCatalogue(hpath+'/halos/trees',version=4,numHosts=1)
mt = mtc[0]
zoomid = haloutils.load_zoomid(hpath)
if mt.rockstar_id != zoomid:
raise ValueError()
mb = mt.getMainBranch()
outdir = 'visualizations/movies/'+haloutils.hidstr(hid)+"_LX"+str(lx)
try:
os.makedirs(outdir)
except OSError as e:
if e[0]==17: pass #File exists
else: raise e
for row in mb:
snap = row['snap']
#if snap >= 223: continue
hpos = np.array([row['posX'],row['posY'],row['posZ']])
snapstr = str(snap).zfill(3)
snappath = hpath+'/outputs/snapdir_'+snapstr+'/snap_'+snapstr
print snapstr
imname = outdir+'/'+snapstr+'.png'
sim = pnb.load(snappath)
sim['pos'] -= hpos
width = 0.6 #comoving Mpc/h
im = pnb.plot.image(sim,qty='rho',units="Msol kpc^-2",
width=width,cmap=mycm,
vmin=2*10**6,vmax=7*10**8,show_cbar=False,
noplot=True)
#show_cbar=True)
plt.xlabel(''); plt.ylabel('')
plt.xticks([]); plt.yticks([])
#plt.savefig(imname,bbox_inches='tight')
plt.close('all')
sim.close()
sys.stdout.flush()
np.save(outdir+'/im'+snapstr,im)
gc.collect()
if __name__=="__main__":
#print 11
#make_movie(95289,11)
print "LX12"
make_movie(95289,12)
#print "LX13"
#make_movie(95289,13)
#print "LX14"
#make_movie(95289,14)