import yt

ds = yt.load('/home/ychen/d9/2018_production_runs/20180802_L438_rc10_beta07/data/Group_L438_hdf5_plt_cnt_0100')

print(ds.parameters['run_comment'])

"""
Explanation: 1. Loading file and basic information
End of explanation
"""


ds.print_stats()

"""
Explanation: Print some basic information about the grid
End of explanation
"""


ds.field_list

"""
Explanation: List all fields in this plot file
End of explanation
"""


ds.derived_field_list

"""
Explanation: List all derived fields in the plot file
End of explanation
"""


print(ds.domain_width)

# in different units
print(ds.domain_width.in_units('Mpc'))
print(ds.domain_width.in_units('ly'))
print(ds.domain_width.in_units('cm'))

"""
Explanation: What is the size of the domain?
End of explanation
"""


print(ds.domain_center)

"""
Explanation: Where is the center of the domain?
This is the coordinate of the central point
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='density')
slc.show()

"""
Explanation: Excersice

What is the coordinate of the left edge of the domain? 
    (hint: use tab to auto-complete and list possible options)

2. Let's do some visualizations
Slice through the center of the simulation box and show the density
End of explanation
"""


slc.zoom(32)
slc.show()

"""
Explanation: The box is probably too big. We should zoom in to the center.
End of explanation
"""


slc = yt.SlicePlot(ds, normal='z', fields='density')
slc.zoom(32)
slc.show()

"""
Explanation: That's much better. We can see a bubble is being drilled by the jets.
We can also slice through a different axis.
End of explanation
"""


slc = yt.SlicePlot(ds, normal='z', fields='density', center=([0,0,10], 'kpc'))
slc.zoom(32)
slc.show()

"""
Explanation: We can also slice at a different location.
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='velocity_magnitude')
slc.zoom(32)
slc.show()

"""
Explanation: Excersice

What do the slices of temperature and pressure look like?

How to visualize the velocity (which is a vector)
(Refer to ds.derived_field_list for all available properties)
We can show the magnitude of the velocity
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='velocity_z')
slc.zoom(32)
slc.show()

"""
Explanation: Or just one component of the velocity
(velocity_z in this example)
End of explanation
"""


slc.set_cmap('velocity_z', 'seismic')
slc.show()

"""
Explanation: Maybe we can change the color map for a better representation of the positive and negative values
See yt colormap or matplotlib colormap reference for all available colormpas.
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='velocity_z')
slc.zoom(32)
slc.set_cmap('velocity_z', 'seismic')
slc.annotate_velocity()
slc.show()

"""
Explanation: We see positive velocity_z (going toward right in this case) in red and negative (going toward left) in blue
We can put some arrow to indicate the direction of the flow
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='velocity_z', center=([0,0,10], 'kpc'), width=(10, 'kpc'))
slc.set_cmap('velocity_z', 'seismic')
slc.annotate_velocity()
slc.show()

"""
Explanation: The velocity in the jet is too large compared to other region. Let's focus at some other region away from the center.
End of explanation
"""


slc.set_zlim('velocity_z', -6E9, 6E9)

"""
Explanation: We need to specify the range of the velocity so that the 0 velocity will be in the middle.
(The velocity of the jet is 0.2c = 0.2*3E10 cm = 6E9 cm.)
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='density', width=(40, 'kpc'))

slc.annotate_grids()
slc.show()

"""
Explanation: 3. Inspect Grid Structure
We can show the grid boundary in a slice plot
End of explanation
"""


slc = yt.SlicePlot(ds, normal='y', fields='density', width=(1, 'kpc'), center=([0,0,10], 'kpc'))
slc.annotate_grids()
slc.show()

"""
Explanation: In this simulation, each box (which is called grid) represents 8x8x8 cells that are the most basic resolution elements.
We can zoom in to see the cells inside a grid.
End of explanation
"""


