aboutsummaryrefslogtreecommitdiffstats
path: root/plots.py
blob: e92c1cecc937196e1375b0c620588c3b4812c4e2 (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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
"""
Plotting Functions.
"""

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import colormap_adjust as ca
from math import pi


"""
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')
    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"])
    plt.ylim([0, 10])

    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'),\
                absmin=[], absmax=[],\
                yscale='log'):

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

    # Initialize MinMax
    if iout0 == 1 and not show:
        absmin = npz0["SigmaR"]
        absmax = npz0["SigmaR"]

    # Compute New Maximum, Mininimum Arrrays
    if not show:
        absmin = np.minimum(absmin, npz0["SigmaR"])
        absmax = np.maximum(absmax, npz0["SigmaR"])

    # 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)
    plt.hold(True)
    plt.plot(npz0["rbins"], SigmaR0, 'bs-', label='Current')
    plt.plot(npz1["rbins"], SigmaR1, 'ks-', linewidth=0.5, label='Reference')
    if not show:
        if yscale == 'log':
            plt.plot(npz0["rbins"], np.log10(absmax), 'rs-', linewidth=0.5, label='Maximum')
            plt.plot(npz0["rbins"], np.log10(absmin), 'gs-' ,linewidth=0.5, label='Minimum')
        else:
            plt.plot(npz["rbins"], absmax, 'rs-', linewidth=0.5, label='Maximum')
            plt.plot(npz["rbins"], absmin, 'gs-' ,linewidth=0.5, label='Minimum')
    plt.hold(False)
    plt.grid()
    plt.legend(loc='lower center')
    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(vmin) - 1, np.log10(vmax) + 1)
        elif yscale == 'lin':
            plt.ylim(0.75 * vmin, 1.25 * vmax)
    plt.xlabel('Radius [AU]')
    plt.ylabel('Sigma [Mstar/AU^2]')
    if yscale == 'log':
        plt.title('Log10 Surface Density, t = %.2f [code] (%.2f [yr])' % ( npz0["tout"], npz0["tout"]/2./pi) )
    elif yscale == 'lin':
        plt.title('Surface Density, t = %.2f [code] (%.2f [yr])' % ( npz0["tout"], npz0["tout"]/2./pi) )
    
    if save:
        plt.savefig('SigmaR_%05d.%s' % ( iout0, ftype ))
        plt.close()

    if show:
        plt.show()

    npz0.close()
    npz1.close()

    return absmin, absmax


"""
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()


"""
Plot/Save Mdot(R).
"""
def plot_MdotR(iout, \
               show=True, save=False, ftype='png',\
               vmin=float('nan'), vmax=float('nan'),\
               absmin=[], absmax=[],\
               yscale='log'):

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

    # Initialize MinMax
    if iout == 2:
        absmin = np.abs(npz["MdotR"])
        absmax = np.abs(npz["MdotR"])

    # Compute New Maximum, Minimum Arrays
    absmin = np.minimum(absmin, np.abs(npz["MdotR"]))
    absmax = np.maximum(absmax, np.abs(npz["MdotR"]))

    # Log?
    if yscale == 'log':
        MdotR = np.log10(np.abs(npz["MdotR"])*2.*pi)
    elif yscale == 'lin':
        MdotR = npz["MdotR"]*2.*pi

    # Make Plot
    plt.figure(1)
    plt.hold(True)
    plt.plot(npz["rbins"], MdotR, 'bs-', label='Current')
    if yscale == 'log':
        plt.plot(npz["rbins"], np.log10(absmax*2.*pi), 'rs-', linewidth=0.5, label='Maximum')
        plt.plot(npz["rbins"], np.log10(absmin*2.*pi), 'gs-', linewidth=0.5, label='Minimum')
    else:
        plt.plot(npz["rbins"], absmax*2.*pi, 'rs-', label='Maximum')
        plt.plot(npz["rbins"], absmin*2.*pi, 'gs-', label='Minimum')
    plt.hold(False)
    plt.grid()
    plt.legend(loc='lower center')
    plt.xlim([0,4])
    # If Passed, Set Value Limits
    if (not np.isnan(vmin)) or (not np.isnan(vmax)):
        vmin=vmin*2.*pi
        vmax=vmax*2.*pi
        if yscale == 'log':
            plt.ylim(np.log10(vmin) - 1, np.log10(vmax) + 1)
        elif yscale == 'lin':
            if vmin > 0 and vmax > 0:
                plt.ylim(0.75 * vmin, 1.25 * vmax)
            elif vmin < 0 and vmax > 0:
                plt.ylim(1.25 * vmin, 1.25 * vmax)
            elif vmin < 0 and vmax < 0:
                plt.ylim(1.25 * vmin, 0.75 * vmax)
    plt.xlabel('Radius [AU]')
    plt.ylabel('Mass Flow [Mstar/yr]')
    if yscale == 'log':
        plt.title('Log10 Mass Flow, t = %.2f->%.2f [code] (%.2f->%.2f [yr])' % ( npz["tout1"], npz["tout2"], npz["tout1"]/2./pi, npz["tout2"]/2./pi ))
    elif yscale == 'lin':
        plt.title('Mass Flow, t = %.2f->%.2f [code] (%.2f->%.2f [yr])' % ( npz["tout1"], npz["tout2"], npz["tout1"]/2./pi, npz["tout2"]/2./pi ))
    
    if save:
        plt.savefig('MdotR_%05d.%s' % ( iout, ftype ))
        plt.close()

    if show:
        plt.show()

    npz.close()

    return absmin, absmax