yt is a python module for visualizing and analyzing numerical simulations. It can be downloaded from yt-project.org which also includes extensive documentation. The first important thing to understand about a simulation is that data can be stored in two ways. Particles can represent quantities and then these particles move in the simulation. Alternatively, information can be stored in a grid. The fluid then flows through the grid and quantities correspond to a cell in the grid. There is a third way of representing quantities called moving mesh, that combines the features of the above two. For now yt treats moving mesh data as particle data. When yt refers to a field (which is just a generic name for a quantity) it can be either a grid field or a particle field. However, the two types of fields are treated very differently. Some commands will work on both, some won't, so you must pay attention to what type of field you are dealing with. For more information about the fields in some common types of simulations you can look here.
The first thing one will want to do in yt is load a dataset. Note that loading a dataset does not read the file into memory, it just sets this up so that the files contents can be read latter when needed. The filename to be given depends on the type of simulation output. Loading can be done with either of the following two commands depending on if you want only one timestep or multiple timesteps.
ds = ytm.load(filename, n_ref=64)
ts = ytm.DatasetSeries.from_filenames(file????)
Visualizing
To visualize a slice there are two basic commands, with one the field chosen is projected along the line of sight, with the other there is no projection.
p=ytm.ProjectionPlot(ds, 'x', 'field', weight_field=field, center=center, data_source=region)
s=ytm.SlicePlot(ds,'x','field',weight_field=field,center=center)
If center is set to equal 'm', it will be centered at the location of the maximum value of the density field.
To find the maximum value of a field and its location: value, location=ds.find_max('field')
The location can then be used as the center for the plot.
To add a title: p.annotate_title('title')
To make an off-axis projection or slice plot you need to give a vector pointing in the direction of the projection, like L=[0,0,1]. You can also set what direction will be the top (north) of the plot with the north_vector key word. Then
p = yt.OffAxisProjectionPlot(ds,L,'field',width=(25, 'kpc'),center,north_vector=north_vector)
would give you an off axis projection plot.
There are two histogram-type plots, which most useful when called upon a smaller region. One is the average of a field within bins of another field, called a Profile Plot. The other is similar, but accepts a third field, and is called a Phase Plot.
plt=ytm.ProfilePlot(ds, 'xfield', 'yfield', weight_field='field')
ad=ds.all_data()
plt=ytm.PhasePlot(ad, 'xfield', 'yfield', 'zfield', weight_field='field')
To add a title for a Phase Plot:
plt.set_title('zfield', 'title')
To set limits on the axes:
plt.set_xlim(min, max)
plt.set_ylim(min, max)
plt.set_zlim('zfield', min, max)
Often we want to study a particular region of a simulation. Note that once a region has been set the region now replaces the dataset when calling methods on it.
region = ds.region(center, left_corner, right_corner)
sp=ds.sphere(center,(R,'unit'))
sp.quantities.keys()
sp.quantites.extrema()
density=sp['density'] # no need for all_data() call
YT array has methods to deal with units
dd[field].in_units(string) or dd[field].in_cgs() or dd[field].in_mks() return arrays in the specified units
dd[field].convert_to_units(string) or dd[field].convert_to_cgs or dd[field].convert_to_mks change the values in the YT array. You can create an array or variable with units using YTArray or YTQuantity
masses = YTArray(my_list,'kg')
M_earth = YTQuantity(5.972e24,'kg')
np_array=yt.array.d to give a copy of just the numbers no units
np_array=yt.array.v to get a view of the array without units. Altering this array changes the original.
YT allows you to add new fields that are most likely some function you want of the data. To create a new field first create your function and then add it to your dataset.
def my_new_field(field, data):
return data[field1]/data[fields2]*my_constant
ds = yt.load(filename)
ds.add_field("field_name", function=my_new_field, take_log=False, units=SOME_UNITS)
YT in Parallel
To run yt in parallel simply make sure that mpi4py is installed if not pip install mpi4py and then
mpiexec -n N python script.py --parallel For more help look here.