forked from christopherlovell/flares_vis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotating_sphere.py
executable file
·143 lines (98 loc) · 4.49 KB
/
rotating_sphere.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
import os
import numpy as np
import matplotlib as ml
ml.use('Agg')
import matplotlib.pyplot as plt
import sphviewer as sph
from sphviewer.tools import cmaps, Blend, camera_tools
from flaresvis import spherical_region, get_normalized_image, get_particle_data, cutout_particles
def getimage(snap, num, data, part_type, overwrite=False, P=None, S=None):
if overwrite:
i = data[num]
i['xsize'] = 5000
i['ysize'] = 5000
i['roll'] = 0
S.update_camera(**i)
R = sph.Render(S)
R.set_logscale()
img = R.get_image()
extent = R.get_extent()
np.save('animationdata/ptype%s_animationdata_reg%s_snap%s_angle%05d.npy'%(part_type,reg,snap,num), img)
else:
img = np.load('animationdata/ptype%s_animationdata_reg%s_snap%s_angle%05d.npy'%(part_type,reg,snap,num))
extent = [-45,45,45,-45]
return img, extent
def apply_cmap(img,cmap,vlims):
print("Setting fixed vmin and vmax")
# vmin = 3.5
# vmax = 7
vmin,vmax = vlims
# vmax = img.max()
# vmin = vmax * 0.5
print("vmin:",vmin,"| vmax:",vmax)
rgb = cmap(get_normalized_image(img, vmin=vmin, vmax=vmax))
return rgb
def single_sphere(reg, snap, soft, num, part_type, cmap, vlims, runall=True):
if runall:
# Define path
path = '/cosma/home/dp004/dc-rope1/FLARES/FLARES-1/G-EAGLE_' + reg + '/data'
poss, masses, smls = get_particle_data(path, snap, part_type=part_type, soft=soft)
# Get the spheres centre
centre, radius, mindist = spherical_region(path, snap)
# Cutout particles
poss, masses, smls = cutout_particles(poss, masses, smls, centre, radius)
print('There are %i particles (type %s) in the region'%(len(masses),part_type))
# Set up particle objects
P = sph.Particles(poss, mass=masses, hsml=smls)
# Initialise the scene
S = sph.Scene(P)
targets = [[0,0,0]]#,0,0,0,0,0,0]
# Define the box size
lbox = (15 / 0.677) * 2
# Define anchors dict for camera parameters
anchors = {}
anchors['sim_times'] = [0.0, 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']
anchors['id_frames'] = [0, 90, 180, 270, 360, 450, 540, 630, 720]
anchors['id_targets'] = [0, 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']
anchors['r'] = [lbox * 3 / 4, 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']
anchors['t'] = [0, 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']
anchors['p'] = [0, 'pass', 'pass', 'pass', 'pass', 'pass', 'pass', 'pass', 360]
anchors['zoom'] = [1., 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']
anchors['extent'] = [10, 'same', 'same', 'same', 'same', 'same', 'same', 'same', 'same']
# Define the camera trajectory
data = camera_tools.get_camera_trajectory(targets, anchors)
for N in np.arange(num*N_block,(num*N_block)+N_block):
print("N:",N,'| p:',data[N]['p'])
# Get images
if runall:
img, extent = getimage(snap, N, data, part_type=part_type, overwrite=True, P=P, S=S)
else:
img, extent = getimage(snap, N, data, part_type=part_type, overwrite=False)
rgb = apply_cmap(img,cmap,vlims)
fig = plt.figure(figsize=(16,9), frameon=False)
ax = fig.add_subplot(111)
# set extent to 16:9 ratio
ax.set_xlim(extent[0] * 16/9, extent[1] * 16/9)
ax.imshow(rgb, origin='lower', aspect='equal', extent=extent)
ax.tick_params(axis='both', left=False, top=False, right=False,
bottom=False, labelleft=False, labeltop=False,
labelright=False, labelbottom=False)
ax.set_facecolor(cmap(0.0)) # (0.95588623, 0.91961077, 0.95812116))
fname = 'plots/spheres/All/all_parts_animation_reg%s_snap%s_ptype%s_angle%05d.png'%(reg,snap,part_type,N)
print("Saving:",fname)
fig.savefig(fname, dpi=300, bbox_inches='tight')
plt.close(fig)
# Define softening lengths
csoft = 0.001802390 / 0.677
N_block = 20
reg, snap = 0, '010_z005p000'
if len(sys.argv) > 2:
part_type = int(sys.argv[2])
else:
part_type = 1
_cmaps = [cmaps.desert(),cmaps.twilight(),None,None,cmaps.mars()]
_cmap = _cmaps[part_type]
_vlims = [[10,14],[3.5,7],None,None,[8,14.4]]
_vlim = _vlims[part_type]
single_sphere("%02d"%reg, snap, soft=csoft, num=int(sys.argv[1]), part_type=part_type, cmap=_cmap, vlims=_vlim, runall=True)