In [ ]:
%matplotlib inline
import yt
import logging
logging.getLogger('yt').setLevel(logging.ERROR)
import numpy as np
import matplotlib
matplotlib.rcParams['font.family'] = 'stixgeneral'
matplotlib.rcParams['figure.dpi'] = 300
import matplotlib.pyplot as plt
import os
from mpl_toolkits.axes_grid1 import AxesGrid
from tools import setup_cl
In [ ]:
dirs = ['/home/ychen/data/0only_0525_hinf_nojiggle/',\
'/home/ychen/data/0only_0314_h1_nojiggle/',\
'/home/ychen/data/0only_0330_h0_nojiggle/',\
'/home/ychen/data/0only_0518_hydro_nojiggle/']
colors, labels = setup_cl(dirs)
filenumbers = [130, 260]
iterator = []
for dir in dirs:
for filenumber in filenumbers:
iterator.append((dir, filenumber))
proj_axis = 'x'
field = 'density'
In [ ]:
for i, (dir, fno) in enumerate(iterator[-1:]):
ds = yt.load(os.path.join(dir, 'MHD_Jet_nojiggle_hdf5_plt_cnt_%04d' % fno))# load data
ds.coordinates.x_axis['x'] = 2
ds.coordinates.x_axis[0] = 2
ds.coordinates.y_axis['x'] = 1
ds.coordinates.y_axis[0] = 1
In [ ]:
width = ds.arr([47, 24], 'kpc')
center = ds.arr([0, 0, width[0].v/2], 'kpc')
print(center)
p=yt.SlicePlot(ds, 'x', field, center=center, origin='center-domain').zoom(ds.domain_width[2]/width[0])
dx = ds.index.get_smallest_dx()
p.set_buff_size((int(width[0]/dx), int(width[1]/dx)))
p.annotate_grids()
p.show()
In [ ]:
fig = plt.figure()
grid = AxesGrid(fig, (0.075,0.075,0.85,0.85),
nrows_ncols = (4, 2),
axes_pad = 0.05,
label_mode = "L",
share_all = True,
cbar_location="right",
cbar_mode="single",
cbar_size="1%",
cbar_pad="0%")
for i, (dir, fno) in enumerate(iterator):
# Load the data and create a single plot
print(dir, fno)
ds = yt.load(os.path.join(dir, 'MHD_Jet_nojiggle_hdf5_plt_cnt_%04d' % fno))# load data
ds.coordinates.x_axis['x'] = 2
ds.coordinates.x_axis[0] = 2
ds.coordinates.y_axis['x'] = 1
ds.coordinates.y_axis[0] = 1
width = ds.arr([47, 12], 'kpc')
center = ds.arr([0, 0, width[0].v/2], 'kpc')
p=yt.SlicePlot(ds, proj_axis, field, center=center, width=width, origin='center-domain')
# Ensure the colorbar limits match for all plots
p.set_zlim('density', 3E-28, 2E-25)
p.set_cmap(field, 'arbre')
dx = ds.index.get_smallest_dx()
p.set_buff_size((int(width[0]/dx), int(width[1]/dx)))
p.set_font_size(9)
if i // len(filenumbers) == 0:
p.annotate_timestamp(0.80, 0.80, time_format="{time:6.2f} {units}", time_unit='Myr', text_args={'color':'k'})
if i % len(filenumbers) == 0:
p.annotate_text((0.04, 0.80), labels[dir], coord_system='axis', text_args={'color':'k'})
# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
plot = p.plots[field]
plot.figure = fig
plot.axes = grid[i].axes
plot.cax = grid.cbar_axes[i]
# Finally, this actually redraws the plot.
p._setup_plots()
fig.set_figwidth(8)
In [ ]:
for i, ax in enumerate(grid.axes_all):
ax.tick_params(axis='x', color='grey')
ax.tick_params(axis='y', color='grey')
ax.set_ylim(-6, 6)
ax.set_yticks([-5,0,5])
ax.set_yticklabels([-5,0,5])
ax.set_xlim(0,width[0].in_units('kpc').v)
ax.set_xticks(np.arange(0,50,5))
ax.set_xticklabels([0, '', 10, '', 20, '', 30, '', 40, ''])
ax.minorticks_off()
ax.tick_params(axis='x', color='grey')
ax.tick_params(axis='y', color='grey')
ax.grid(ls='--', alpha=0.5)
if i == 2:
ax.set_ylabel('y (kpc)')
else:
ax.set_ylabel('')
if i // len(filenumbers) == len(dirs)-1:
ax.set_xlabel('z (kpc)')
fig.set_figwidth(8)
fig.set_figheight(8)
fig.savefig('compare_4_nojiggle_density.pdf', bbox_inches='tight')
fig
In [ ]:
dirs = ['/home/ychen/data/0only_0525_hinf_nojiggle/',\
'/home/ychen/data/0only_0314_h1_nojiggle/',\
'/home/ychen/data/0only_0330_h0_nojiggle/',\
# '/home/ychen/data/0only_0518_hydro_nojiggle/'
]
filenumbers = [130, 260]
iterator = []
for dir in dirs:
for filenumber in filenumbers:
iterator.append((dir, filenumber))
colors, labels = setup_cl(dirs)
proj_axis = 'x'
field = 'magnetic_field_x'
fig = plt.figure()
grid = AxesGrid(fig, (0.075,0.075,0.85,0.85),
nrows_ncols = (3, 2),
axes_pad = 0.05,
label_mode = "L",
share_all = True,
cbar_location="right",
cbar_mode="single",
cbar_size="1%",
cbar_pad="0%")
for i, (dir, fno) in enumerate(iterator):
# Load the data and create a single plot
print(dir, fno)
ds = yt.load(os.path.join(dir, 'MHD_Jet_nojiggle_hdf5_plt_cnt_%04d' % fno))# load data
ds.coordinates.x_axis['x'] = 2
ds.coordinates.x_axis[0] = 2
ds.coordinates.y_axis['x'] = 1
ds.coordinates.y_axis[0] = 1
width = ds.arr([47, 12], 'kpc')
center = ds.arr([0, 0, width[0].v/2], 'kpc')
p=yt.SlicePlot(ds, proj_axis, field, center=center, width=width, origin='center-domain')
# Ensure the colorbar limits match for all plots
#p.set_zlim('density', 1.67E-28, 1.67E-25)
p.set_zlim(field, -1E-4, 1E-4)
p.set_cmap(field, 'seismic')
dx = ds.index.get_smallest_dx()
p.set_buff_size((int(width[0]/dx), int(width[1]/dx)))
p.set_font_size(9)
if i // len(filenumbers) == 0:
p.annotate_timestamp(0.80, 0.80, time_format="{time:6.2f} {units}", time_unit='Myr', text_args={'color':'k'})
if i % len(filenumbers) == 0:
p.annotate_text((0.04, 0.80), labels[dir], coord_system='axis', text_args={'color':'k'})
# This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
plot = p.plots[field]
plot.figure = fig
plot.axes = grid[i].axes
plot.cax = grid.cbar_axes[i]
# Finally, this actually redraws the plot.
p._setup_plots()
fig.set_figwidth(8)
In [ ]:
for i, ax in enumerate(grid.axes_all):
ax.tick_params(axis='x', color='grey')
ax.tick_params(axis='y', color='grey')
ax.set_ylim(-6, 6)
ax.set_yticks([-5,0,5])
ax.set_yticklabels([-5,0,5])
ax.set_xlim(0, width[0].in_units('kpc').v)
ax.set_xticks(np.arange(0,50,5))
ax.set_xticklabels([0,'',10,'',20,'',30,'',40,''])
ax.minorticks_off()
ax.tick_params(axis='x', color='grey')
ax.tick_params(axis='y', color='grey')
ax.grid(ls='--', alpha=0.3)
if i == 2:
ax.set_ylabel('y (kpc)')
else:
ax.set_ylabel('')
if i // len(filenumbers) == len(dirs)-1:
ax.set_xlabel('z (kpc)')
fig.set_figwidth(8)
fig.savefig('compare_3_nojiggle_magnetic_field_x.pdf', bbox_inches='tight')
fig
In [ ]:
In [ ]: