aboutsummaryrefslogtreecommitdiffstats
path: root/plots.py
blob: c4aae7afc0276537468bdaf7c1c74c6665a01313 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
"""
Plotting Functions.
"""

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import colormap_adjust as ca


"""
Plot/Save Q(X,Y).
"""
def plot_QXY(iout, show=True, save=False, ftype='pdf'):

    # Load File
    npz = np.load('QXY_%05d.npz' % iout)
    QXY = npz["QXY"]

    # Load Mask
    npzMask = np.load('DiskMaskXY_%05d.npz' % iout)

    # Apply Masks
    QXY[npzMask["DiskMaskXY"] == False] = np.nan
    QXY[QXY > 10] = np.nan

    # Mask Array
    QMask = np.ma.masked_array(QXY, mask=np.isnan(QXY))

    # Set Up Colormap
    cmap = mpl.cm.seismic
    cmap.set_bad([0.5, 0.5, 0.5], 1)

    # Make Plot
    plt.figure(1)
    plt.imshow(QMask,\
        extent = npz["ext"],\
        cmap = cmap)
    plt.colorbar()
    plt.clim([0, 10])
    plt.grid()
    plt.xlabel('X (Arbitrary Units)')
    plt.ylabel('Y (Arbitrary Units)')
    plt.title('Toomre Q, t = %.2f' % npz["tout"])

    if save:
        plt.savefig('QXY_%05d.%s' % ( iout, ftype ))
        plt.close()

    if show:
        plt.show()

    npz.close()


"""
Plot/Save Q(R).
"""
def plot_QR(iout, show=True, save=False):

    # Load File
    npz = np.load('QR_%05d.npz' % iout)

    # Cut Off Q>10, Q=0
    QR = npz["QR"]
    QR[QR > 10] = float('nan')
    QR[QR == 0] = float('nan')

    # Make Plot
    plt.figure(1)
    plt.plot(npz["rbins"], QR)
    plt.grid()
    plt.xlabel('Radius (Arbitrary Units)')
    plt.ylabel('Q')
    plt.title('Toomre Q, t = %.2f' % npz["tout"])

    if save:
        plt.savefig('QR_%05d.pdf' % iout)
        plt.close()

    if show:
        plt.show()

    npz.close()


"""
Plot/Save Omega(X,Y).
"""
def plot_OmegaXY(iout, show=True, save=False):

    # Load File
    npz = np.load('VelocitiesXY_%05d.npz' % iout)

    # Make Plot
    plt.figure(1)
    plt.imshow(npz["OmegaXY"],\
        extent = npz["ext"],\
        cmap = 'hot')
    plt.colorbar()
    plt.grid()
    plt.xlabel('X (Arbitrary Units)')
    plt.ylabel('Y (Arbitrary Units)')
    plt.title('Z-Averaged Planar Angular Velocity, t = %.2f' % npz["tout"])

    if save:
        plt.savefig('OmegaXY_%05d.pdf' % iout)
        plt.close()

    if show:
        plt.show()

    npz.close()


"""
Plot/Save Omega(R).
"""
def plot_OmegaR(iout0, iout1, \
                show=True, save=False, ftype='png',\
                vmin=float('nan'), vmax=float('nan')):

    # Load File
    npz0 = np.load('VelocitiesR_%05d.npz' % iout0)
    npz1 = np.load('VelocitiesR_%05d.npz' % iout1)

    # Make Plot
    plt.figure(1)
    h0, = plt.plot(npz0["rbins"], npz0["OmegaR"], 'b-')
    plt.hold(True)
    h1, = plt.plot(npz1["rbins"], npz1["OmegaR"], 'r-')
    plt.hold(False)
    plt.grid()
    # If Passed, Set Value Limits
    if (not np.isnan(vmin)) or (not np.isnan(vmax)):
        plt.ylim(0.75 * vmin, 1.25 * vmax)
    plt.xlabel('Radius (Arbitrary Units)')
    plt.ylabel('Omega (Arbitrary Units)')
    plt.title('Z-Averaged Planar Angular Velocity, t = %.2f' % npz0["tout"])
    plt.legend([h0,h1], ['Current', 'Reference'])
    
    if save:
        plt.savefig('OmegaR_%05d.%s' % ( iout0, ftype ))
        plt.close()

    if show:
        plt.show()

    npz0.close()
    npz1.close()


"""
Plot/Save Sigma(X,Y).
"""
def plot_SigmaXY(iout, show=True, save=False, ftype='pdf',\
                 cmin=float('nan'), cmax=float('nan'), mask=False,
                 cmapstr='jet'):

    # Load File
    npz = np.load('SigmaXY_%05d.npz' % iout)
    SigmaXY = npz["SigmaXY"]

    # Load & Apply Mask?
    if mask:
        npzMask = np.load('DiskMaskXY_%05d.npz' % iout)
        SigmaXY[npzMask["DiskMaskXY"] == False] = np.nan
        SigmaMask = np.ma.masked_array(SigmaXY, mask=np.isnan(SigmaXY))
    else:
        SigmaMask = SigmaXY

    # Set Up Colormap
    if cmapstr == 'jet':
        cmap = mpl.cm.jet
    elif cmapstr == 'hot':
        cmap = mpl.cm.hot

    # Set Bad Mask on Colormap
    cmap.set_bad([0.5, 0.5, 0.5], 1)

    # Make Plot
    plt.figure(1)
    plt.imshow(np.log10(SigmaMask),\
        extent = npz["ext"],\
        cmap = cmap)
    plt.colorbar()
    # If Passed, Set Colorbar Limits
    if (not np.isnan(cmin)) or (not np.isnan(cmax)):
        plt.clim(np.log10(cmin), np.log10(cmax))
    plt.grid()
    plt.xlabel('X (Arbitrary Units)')
    plt.ylabel('Y (Arbitrary Units)')
    plt.title('Log10 Surface Density, t = %.2f' % npz["tout"])

    if save:
        plt.savefig('SigmaXY_%05d.%s' % ( iout, ftype ))
        plt.close()

    if show:
        plt.show()

    npz.close()


"""
Plot/Save Sigma(R).
"""
def plot_SigmaR(iout0, iout1, \
                show=True, save=False, ftype='png',\
                vmin=float('nan'), vmax=float('nan'),\
                yscale='log'):

    # Load File
    npz0 = np.load('SigmaR_%05d.npz' % iout0)
    npz1 = np.load('SigmaR_%05d.npz' % iout1)

    # Log?
    if yscale == 'log':
        SigmaR0 = np.log10(npz0["SigmaR"])
        SigmaR1 = np.log10(npz1["SigmaR"])
    elif yscale == 'lin':
        SigmaR0 = npz0["SigmaR"]
        SigmaR1 = npz1["SigmaR"]

    # Make Plot
    plt.figure(1)
    h0, = plt.plot(npz0["rbins"], SigmaR0, 'b-')
    plt.hold(True)
    h1, = plt.plot(npz1["rbins"], SigmaR1, 'r-')
    plt.hold(False)
    plt.grid()
    plt.xlim([0,4])
    # If Passed, Set Value Limits
    if (not np.isnan(vmin)) or (not np.isnan(vmax)):
        if yscale == 'log':
            plt.ylim(np.log10(0.75 * vmin), np.log10(1.25 * vmax))
        elif yscale == 'lin':
            plt.ylim(0.75 * vmin, 1.25 * vmax)
    plt.xlabel('Radius (Arbitrary Units)')
    plt.ylabel('Sigma (Arbitrary Units)')
    if yscale == 'log':
        plt.title('Log10 Surface Density, t = %.2f' % npz0["tout"])
    elif yscale == 'lin':
        plt.title('Surface Density, t = %.2f' % npz0["tout"])
    plt.legend([h0,h1], ['Current', 'Reference'])
    
    if save:
        plt.savefig('SigmaR_%05d.%s' % ( iout0, ftype ))
        plt.close()

    if show:
        plt.show()

    npz0.close()
    npz1.close()


"""
Plot/Save P(X,Y).
"""
def plot_PXY(iout, show=True, save=False):

    # Load File
    npz = np.load('PXY_%05d.npz' % iout)

    # Make Plot
    plt.figure(1)
    plt.imshow(np.log10(npz["PXY"]),\
        extent = npz["ext"],\
        cmap = 'hot')
    plt.colorbar()
    plt.grid()
    plt.xlabel('X (Arbitrary Units)')
    plt.ylabel('Y (Arbitrary Units)')
    plt.title('Log10 2D (Z-Integrated) Pressure, t = %.2f' % npz["tout"])
    
    if save:
        plt.savefig('PXY_%05d.pdf' % iout)
        plt.close()

    if show:
        plt.show()

    npz.close()


"""
Plot/Save rho(R,Z).
"""
def plot_rhoRZ(iout, show=True, save=False, ftype='png',\
               cmin=float('nan'), cmax=float('nan')):

    # Load File
    npz = np.load('rhoRZ_%05d.npz' % iout)

    # Make Plot
    plt.figure(1)
    plt.imshow(np.log10(npz["rhoRZ"]),\
        extent = npz["boxlen"] * npz["ext"],\
        cmap = 'hot')
    # If Passed, Set Colorbar Limits
    if (not np.isnan(cmin)) or (not np.isnan(cmax)):
        plt.clim(np.log10(cmin), np.log10(cmax))
    plt.colorbar()
    plt.grid()
    plt.xlabel('Radius (Arbitrary Units)')
    plt.ylabel('Z (Arbitrary Units)')
    plt.title('Log10 Azimuthally Averaged Volume Density, t = %.2f' % \
               npz["tout"])

    if save:
        plt.savefig('rhoRZ_%05d.%s' % ( iout, ftype ))
        plt.close()

    if show:
        plt.show()

    npz.close()


"""
Plot/Save Mdot(X,Y).
"""
def plot_MdotXY(iout, show=True, save=False, ftype='pdf',\
                cmin=float('nan'), cmax=float('nan')):

    # Load File
    npz = np.load('MdotXY_%05d.npz' % iout)

    # Determine Colorbar Limits
    if np.isnan(cmin):
        cmin = npz["MdotXY"].min()
    if np.isnan(cmax):
        cmax = npz["MdotXY"].max()

    # Adjust Colorbar
    cmap = mpl.cm.seismic
    cmap = ca.cmap_center_point_adjust(cmap, [ cmin, cmax ], 0)

    # Make Plot
    plt.figure(1)
    plt.imshow(npz["MdotXY"],\
        extent = npz["ext"],\
        cmap = cmap)
    plt.clim(cmin, cmax)
    plt.colorbar()
    plt.grid()
    plt.xlabel('X')
    plt.ylabel('Y')
    plt.title('Mass Flow, t = (%.2f, %.2f)' % ( npz["tout1"], npz["tout2"] ))

    if save:
        plt.savefig('MdotXY_%05d.%s' % ( iout, ftype ))
        plt.close()

    if show:
        plt.show()

    npz.close()