-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_recent_stars.py
84 lines (64 loc) · 3.21 KB
/
plot_recent_stars.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
#!/usr/bin/env python
# coding: utf-8
############################################
# Plot narrow FOV thin slab projections with
# new (w/in last dataset) and
# recent (between last two datasets) stars
############################################
import yt
yt.enable_parallelism()
import numpy as np
@yt.particle_filter(requires=["particle_type"], filtered_type='all')
def new_stars(pfilter, data):
dt = data.ds.quan(data.ds.index.parameters['dtDataDump'], 'code_time')
min_creation_time = data.ds.current_time - dt
filter1 = data[(pfilter.filtered_type, "particle_type")] == 2
filter2 = data[(pfilter.filtered_type, "creation_time")] > min_creation_time
filter = np.logical_and(filter1, filter2)
return filter
@yt.particle_filter(requires=["particle_type"], filtered_type='all')
def recent_stars(pfilter, data):
dt = data.ds.quan(data.ds.index.parameters['dtDataDump'], 'code_time')
max_creation_time = data.ds.current_time - dt
min_creation_time = data.ds.current_time - dt*2 # use 3 for past 2 outputs
filter1 = data[(pfilter.filtered_type, "particle_type")] == 2
filter2 = data[(pfilter.filtered_type, "creation_time")] > min_creation_time
filter3 = data[(pfilter.filtered_type, "creation_time")] <= max_creation_time
bracket = np.logical_and(filter2, filter3)
filter = np.logical_and(filter1, bracket)
return filter
if __name__=="__main__":
datasets = yt.load("DD????/DD????")
for ds in datasets.piter(dynamic=False, ):
stars = ('io', 'particle_type') in ds.field_list
if stars:
ds.add_particle_filter('new_stars')
ds.add_particle_filter('recent_stars')
center = ds.quan(0.5,'code_length')
rs = ds.quan(3.5,'kpc')
width = ds.quan(100,'kpc')
thickness = rs
# Edge on
rect = ds.region([center, center, center],
[center-thickness/2, center-width/2, center-width/2],
[center+thickness/2, center+width/2, center+width/2])
assert (rect.get_field_parameter("center") == center).all()
p1 = yt.ProjectionPlot(ds, 'x', 'density', width=width,
data_source=rect, weight_field ='ones')
p1.set_zlim("density", 1e-32, 1e-24)
if stars:
p1.annotate_particles(width=width, ptype='recent_stars', p_size=9, col='dimgray')
p1.annotate_particles(width=width, ptype='new_stars', p_size=9)
p1.save(ds.basename+"_edge_on_stars.png")
# Face on
rect = ds.region([center, center, center],
[center-width/2, center-width/2, center-thickness/2],
[center+width/2, center+width/2, center+thickness/2])
assert (rect.get_field_parameter("center") == center).all()
p2 = yt.ProjectionPlot(ds, 'z', 'density', width=width,
data_source=rect, weight_field ='ones')
p2.set_zlim("density", 1e-29, 1e-23)
if stars:
p2.annotate_particles(width=width, ptype='recent_stars', p_size=9, col='dimgray')
p2.annotate_particles(width=width, ptype='new_stars', p_size=9)
p2.save(ds.basename+"_face_on_stars.png")