aboutsummaryrefslogtreecommitdiffstats
path: root/mkcuts_dvp.py
blob: 508c5b884307490dbad303a619612147a4696d81 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
Make X and Z Cuts:
- Density
- Velocity
- Pressure
"""

import matplotlib as mpl
from pymses import RamsesOutput
from pymses.filters import CellsToPoints
from pymses.analysis.visualization import Camera, ScalarOperator, SliceMap
import matplotlib.pyplot as plt
import numpy as np
import sys


"""
Main Routine. Define Cameras. Take Slices. Plot.
"""
def main():

    # Defaults
    iout = 1

    # Parse Arguments
    if len(sys.argv) == 2:
    	iout = int(sys.argv[1])

    # Give Feedback
    print "Creating Cuts for Output %i." % iout
    print ""

    # Link AMR Data
    output = RamsesOutput(".", iout)
    source = output.amr_source(["rho", "vel", "P"])

    # Define Cameras
    camZ = Camera(center=[0.5, 0.5, 0.5], line_of_sight_axis='z',
    	region_size=[1., 1.], up_vector='y', map_max_size=512, log_sensitive=True)
    camX = Camera(center=[0.5, 0.5, 0.5], line_of_sight_axis='x',
    	region_size=[1., 1.], up_vector='y', map_max_size=512, log_sensitive=True)

    # Functions to Get Data
    func_rho = lambda dset: dset["rho"]
    func_vel = lambda dset: np.sqrt(np.sum(dset["vel"]**2, axis=1))
    # func_vel = lambda dset: dset["vel"][:,0]
    func_pre = lambda dset: dset["P"]

    # Operator to Get Data
    op_rho = ScalarOperator(func_rho)
    op_vel = ScalarOperator(func_vel)
    op_pre = ScalarOperator(func_pre)

    # Compute Slice Maps
    rhoZ = SliceMap(source, camZ, op_rho, z=0.0)
    rhoX = SliceMap(source, camX, op_rho, z=0.0)
    velZ = SliceMap(source, camZ, op_vel, z=0.0)
    velX = SliceMap(source, camX, op_vel, z=0.0)
    preZ = SliceMap(source, camZ, op_pre, z=0.0)
    preX = SliceMap(source, camX, op_pre, z=0.0)

    # Log10?
    rhoZ = np.log10(rhoZ)
    rhoX = np.log10(rhoX)
    preZ = np.log10(preZ)
    preX = np.log10(preX)

    # Mark Arrays vs. NaN
    rhoZ = np.ma.masked_array(rhoZ, mask=np.isnan(rhoZ))
    rhoX = np.ma.masked_array(rhoX, mask=np.isnan(rhoX))
    velZ = np.ma.masked_array(velZ, mask=np.isnan(velZ))
    velX = np.ma.masked_array(velX, mask=np.isnan(velX))
    preZ = np.ma.masked_array(preZ, mask=np.isnan(preZ))
    preX = np.ma.masked_array(preX, mask=np.isnan(preX))
    
    # Set Masked Colormap
    # cmap = mpl.cm.hot
    cmap = mpl.cm.jet
    cmap.set_bad([0.5, 0.5, 0.5])

    # Colormaps:
    # http://matplotlib.org/examples/pylab_examples/show_colormaps.html
    # rho_cm = 'hot'
    # vel_cm = 'hot'
    # pre_cm = 'hot'
    rho_cm = cmap
    vel_cm = cmap
    pre_cm = cmap

    # Compute Image Extent
    ext = output.info["boxlen"] * np.array([-0.5, 0.5, -0.5, 0.5])

    # Plot Density
    f1 = plt.figure(1)
    plt.imshow(rhoZ, cmap=rho_cm, extent=ext, interpolation='none')
    plt.colorbar()
    plt.grid()
    plt.title('Log10 Density Cut, t=%.2f' % output.info["time"])
    plt.xlabel('X')
    plt.ylabel('Y')

    f2 = plt.figure(2)
    plt.imshow(rhoX, cmap=rho_cm, extent=ext, interpolation='none')
    plt.colorbar()
    plt.grid()
    plt.title('Log10 Density Cut, t=%.2f' % output.info["time"])
    plt.xlabel('Y')
    plt.ylabel('Z')

    # Plot Velocity
    f3 = plt.figure(3)
    plt.imshow(velZ, cmap=vel_cm, extent=ext)
    plt.colorbar()
    plt.grid()
    plt.title('Angular Velocity Cut, t=%.2f' % output.info["time"])
    plt.xlabel('X')
    plt.ylabel('Y')

    f4 = plt.figure(4)
    plt.imshow(velX, cmap=vel_cm, extent=ext)
    plt.colorbar()
    plt.grid()
    plt.title('Angular XY-Velocity Cut, t=%.2f' % output.info["time"])
    plt.xlabel('Y')
    plt.ylabel('Z')

    # Plot Pressure
    f5 = plt.figure(5)
    plt.imshow(preZ, cmap=pre_cm, extent=ext, interpolation='none')
    plt.colorbar()
    plt.grid()
    plt.title('Log10 Pressure Cut, t=%.2f' % output.info["time"])
    plt.xlabel('X')
    plt.ylabel('Y')

    f6 = plt.figure(6)
    plt.imshow(preX, cmap=pre_cm, extent=ext, interpolation='none')
    plt.colorbar()
    plt.grid()
    plt.title('Log10 Pressure Cut, t=%.2f' % output.info["time"])
    plt.xlabel('Y')
    plt.ylabel('Z')

    #plt.close(f1)
    #plt.close(f2)
    # plt.close(f3)
    # plt.close(f4)
    #plt.close(f5)
    #plt.close(f6)
 
    plt.show()


"""
Jump into Main().
"""
if __name__ == "__main__":
    main()