Using yt to view and analyze Tipsy outputs from GasolineΒΆ

Notebook

Loading Files

Alright, let's start with some basics. Before we do anything, we will need to load a snapshot. You can do this using the load convenience function. yt will autodetect that you have a tipsy snapshot, and automatically set itself up appropriately.

In [1]:
import yt

We will be looking at a fairly low resolution dataset. In the next cell, the ds object has an atribute called n_ref that tells the oct-tree how many particles to refine on. The default is 64, but we'll get prettier plots (at the expense of a deeper tree) with 8. Just passing the argument n_ref=8 to load does this for us.

This dataset is available for download at http://yt-project.org/data/TipsyGalaxy.tar.gz (10 MB).

In [2]:
ds = yt.load('TipsyGalaxy/galaxy.00300', n_ref=8)

We now have a TipsyDataset object called ds. Let's see what fields it has.

In [3]:
ds.field_list
Out[3]:
[('DarkMatter', 'Coordinates'),
 ('DarkMatter', 'Epsilon'),
 ('DarkMatter', 'FeMassFrac'),
 ('DarkMatter', 'Mass'),
 ('DarkMatter', 'Phi'),
 ('DarkMatter', 'Velocities'),
 ('Gas', 'Coordinates'),
 ('Gas', 'Density'),
 ('Gas', 'Epsilon'),
 ('Gas', 'FeMassFrac'),
 ('Gas', 'Mass'),
 ('Gas', 'Metals'),
 ('Gas', 'Phi'),
 ('Gas', 'Temperature'),
 ('Gas', 'Velocities'),
 ('Stars', 'Coordinates'),
 ('Stars', 'Epsilon'),
 ('Stars', 'FeMassFrac'),
 ('Stars', 'FormationTime'),
 ('Stars', 'Mass'),
 ('Stars', 'Metals'),
 ('Stars', 'Phi'),
 ('Stars', 'Velocities'),
 ('all', 'Coordinates'),
 ('all', 'Epsilon'),
 ('all', 'FeMassFrac'),
 ('all', 'Mass'),
 ('all', 'Phi'),
 ('all', 'Velocities')]

yt also defines so-called "derived" fields. These fields are functions of the on-disk fields that live in the field_list. There is a derived_field_list attribute attached to the Dataset object - let's take look at the derived fields in this dataset:

In [4]:
ds.derived_field_list
Out[4]:
[('DarkMatter', 'Coordinates'),
 ('DarkMatter', 'Epsilon'),
 ('DarkMatter', 'FeMassFrac'),
 ('DarkMatter', 'Fe_fraction'),
 ('DarkMatter', 'Mass'),
 ('DarkMatter', 'Phi'),
 ('DarkMatter', 'Velocities'),
 ('DarkMatter', 'mesh_id'),
 ('DarkMatter', 'particle_angular_momentum'),
 ('DarkMatter', 'particle_angular_momentum_magnitude'),
 ('DarkMatter', 'particle_angular_momentum_x'),
 ('DarkMatter', 'particle_angular_momentum_y'),
 ('DarkMatter', 'particle_angular_momentum_z'),
 ('DarkMatter', 'particle_cylindrical_velocity_theta'),
 ('DarkMatter', 'particle_cylindrical_velocity_z'),
 ('DarkMatter', 'particle_mass'),
 ('DarkMatter', 'particle_ones'),
 ('DarkMatter', 'particle_position'),
 ('DarkMatter', 'particle_position_cylindrical_radius'),
 ('DarkMatter', 'particle_position_cylindrical_theta'),
 ('DarkMatter', 'particle_position_cylindrical_z'),
 ('DarkMatter', 'particle_position_relative'),
 ('DarkMatter', 'particle_position_relative_x'),
 ('DarkMatter', 'particle_position_relative_y'),
 ('DarkMatter', 'particle_position_relative_z'),
 ('DarkMatter', 'particle_position_spherical_phi'),
 ('DarkMatter', 'particle_position_spherical_radius'),
 ('DarkMatter', 'particle_position_spherical_theta'),
 ('DarkMatter', 'particle_position_x'),
 ('DarkMatter', 'particle_position_y'),
 ('DarkMatter', 'particle_position_z'),
 ('DarkMatter', 'particle_radial_velocity'),
 ('DarkMatter', 'particle_radius'),
 ('DarkMatter', 'particle_specific_angular_momentum'),
 ('DarkMatter', 'particle_specific_angular_momentum_x'),
 ('DarkMatter', 'particle_specific_angular_momentum_y'),
 ('DarkMatter', 'particle_specific_angular_momentum_z'),
 ('DarkMatter', 'particle_spherical_position_phi'),
 ('DarkMatter', 'particle_spherical_position_radius'),
 ('DarkMatter', 'particle_spherical_position_theta'),
 ('DarkMatter', 'particle_spherical_velocity_phi'),
 ('DarkMatter', 'particle_spherical_velocity_radius'),
 ('DarkMatter', 'particle_spherical_velocity_theta'),
 ('DarkMatter', 'particle_velocity'),
 ('DarkMatter', 'particle_velocity_cylindrical_radius'),
 ('DarkMatter', 'particle_velocity_cylindrical_theta'),
 ('DarkMatter', 'particle_velocity_cylindrical_z'),
 ('DarkMatter', 'particle_velocity_magnitude'),
 ('DarkMatter', 'particle_velocity_relative'),
 ('DarkMatter', 'particle_velocity_relative_x'),
 ('DarkMatter', 'particle_velocity_relative_y'),
 ('DarkMatter', 'particle_velocity_relative_z'),
 ('DarkMatter', 'particle_velocity_spherical_phi'),
 ('DarkMatter', 'particle_velocity_spherical_radius'),
 ('DarkMatter', 'particle_velocity_spherical_theta'),
 ('DarkMatter', 'particle_velocity_x'),
 ('DarkMatter', 'particle_velocity_y'),
 ('DarkMatter', 'particle_velocity_z'),
 ('Gas', 'Coordinates'),
 ('Gas', 'Density'),
 ('Gas', 'Epsilon'),
 ('Gas', 'FeMassFrac'),
 ('Gas', 'Fe_fraction'),
 ('Gas', 'H_nuclei_density'),
 ('Gas', 'He_nuclei_density'),
 ('Gas', 'Mass'),
 ('Gas', 'Metals'),
 ('Gas', 'Phi'),
 ('Gas', 'Temperature'),
 ('Gas', 'Velocities'),
 ('Gas', 'density'),
 ('Gas', 'mesh_id'),
 ('Gas', 'metallicity'),
 ('Gas', 'nearest_neighbor_distance_65'),
 ('Gas', 'particle_angular_momentum'),
 ('Gas', 'particle_angular_momentum_magnitude'),
 ('Gas', 'particle_angular_momentum_x'),
 ('Gas', 'particle_angular_momentum_y'),
 ('Gas', 'particle_angular_momentum_z'),
 ('Gas', 'particle_cylindrical_velocity_theta'),
 ('Gas', 'particle_cylindrical_velocity_z'),
 ('Gas', 'particle_mass'),
 ('Gas', 'particle_ones'),
 ('Gas', 'particle_position'),
 ('Gas', 'particle_position_cylindrical_radius'),
 ('Gas', 'particle_position_cylindrical_theta'),
 ('Gas', 'particle_position_cylindrical_z'),
 ('Gas', 'particle_position_relative'),
 ('Gas', 'particle_position_relative_x'),
 ('Gas', 'particle_position_relative_y'),
 ('Gas', 'particle_position_relative_z'),
 ('Gas', 'particle_position_spherical_phi'),
 ('Gas', 'particle_position_spherical_radius'),
 ('Gas', 'particle_position_spherical_theta'),
 ('Gas', 'particle_position_x'),
 ('Gas', 'particle_position_y'),
 ('Gas', 'particle_position_z'),
 ('Gas', 'particle_radial_velocity'),
 ('Gas', 'particle_radius'),
 ('Gas', 'particle_specific_angular_momentum'),
 ('Gas', 'particle_specific_angular_momentum_x'),
 ('Gas', 'particle_specific_angular_momentum_y'),
 ('Gas', 'particle_specific_angular_momentum_z'),
 ('Gas', 'particle_spherical_position_phi'),
 ('Gas', 'particle_spherical_position_radius'),
 ('Gas', 'particle_spherical_position_theta'),
 ('Gas', 'particle_spherical_velocity_phi'),
 ('Gas', 'particle_spherical_velocity_radius'),
 ('Gas', 'particle_spherical_velocity_theta'),
 ('Gas', 'particle_velocity'),
 ('Gas', 'particle_velocity_cylindrical_radius'),
 ('Gas', 'particle_velocity_cylindrical_theta'),
 ('Gas', 'particle_velocity_cylindrical_z'),
 ('Gas', 'particle_velocity_magnitude'),
 ('Gas', 'particle_velocity_relative'),
 ('Gas', 'particle_velocity_relative_x'),
 ('Gas', 'particle_velocity_relative_y'),
 ('Gas', 'particle_velocity_relative_z'),
 ('Gas', 'particle_velocity_spherical_phi'),
 ('Gas', 'particle_velocity_spherical_radius'),
 ('Gas', 'particle_velocity_spherical_theta'),
 ('Gas', 'particle_velocity_x'),
 ('Gas', 'particle_velocity_y'),
 ('Gas', 'particle_velocity_z'),
 ('Gas', 'smoothing_length'),
 ('Gas', 'temperature'),
 ('Stars', 'Coordinates'),
 ('Stars', 'Epsilon'),
 ('Stars', 'FeMassFrac'),
 ('Stars', 'Fe_fraction'),
 ('Stars', 'FormationTime'),
 ('Stars', 'Mass'),
 ('Stars', 'Metals'),
 ('Stars', 'Phi'),
 ('Stars', 'Velocities'),
 ('Stars', 'creation_time'),
 ('Stars', 'mesh_id'),
 ('Stars', 'metallicity'),
 ('Stars', 'particle_angular_momentum'),
 ('Stars', 'particle_angular_momentum_magnitude'),
 ('Stars', 'particle_angular_momentum_x'),
 ('Stars', 'particle_angular_momentum_y'),
 ('Stars', 'particle_angular_momentum_z'),
 ('Stars', 'particle_cylindrical_velocity_theta'),
 ('Stars', 'particle_cylindrical_velocity_z'),
 ('Stars', 'particle_mass'),
 ('Stars', 'particle_ones'),
 ('Stars', 'particle_position'),
 ('Stars', 'particle_position_cylindrical_radius'),
 ('Stars', 'particle_position_cylindrical_theta'),
 ('Stars', 'particle_position_cylindrical_z'),
 ('Stars', 'particle_position_relative'),
 ('Stars', 'particle_position_relative_x'),
 ('Stars', 'particle_position_relative_y'),
 ('Stars', 'particle_position_relative_z'),
 ('Stars', 'particle_position_spherical_phi'),
 ('Stars', 'particle_position_spherical_radius'),
 ('Stars', 'particle_position_spherical_theta'),
 ('Stars', 'particle_position_x'),
 ('Stars', 'particle_position_y'),
 ('Stars', 'particle_position_z'),
 ('Stars', 'particle_radial_velocity'),
 ('Stars', 'particle_radius'),
 ('Stars', 'particle_specific_angular_momentum'),
 ('Stars', 'particle_specific_angular_momentum_x'),
 ('Stars', 'particle_specific_angular_momentum_y'),
 ('Stars', 'particle_specific_angular_momentum_z'),
 ('Stars', 'particle_spherical_position_phi'),
 ('Stars', 'particle_spherical_position_radius'),
 ('Stars', 'particle_spherical_position_theta'),
 ('Stars', 'particle_spherical_velocity_phi'),
 ('Stars', 'particle_spherical_velocity_radius'),
 ('Stars', 'particle_spherical_velocity_theta'),
 ('Stars', 'particle_velocity'),
 ('Stars', 'particle_velocity_cylindrical_radius'),
 ('Stars', 'particle_velocity_cylindrical_theta'),
 ('Stars', 'particle_velocity_cylindrical_z'),
 ('Stars', 'particle_velocity_magnitude'),
 ('Stars', 'particle_velocity_relative'),
 ('Stars', 'particle_velocity_relative_x'),
 ('Stars', 'particle_velocity_relative_y'),
 ('Stars', 'particle_velocity_relative_z'),
 ('Stars', 'particle_velocity_spherical_phi'),
 ('Stars', 'particle_velocity_spherical_radius'),
 ('Stars', 'particle_velocity_spherical_theta'),
 ('Stars', 'particle_velocity_x'),
 ('Stars', 'particle_velocity_y'),
 ('Stars', 'particle_velocity_z'),
 ('all', 'Coordinates'),
 ('all', 'Epsilon'),
 ('all', 'FeMassFrac'),
 ('all', 'Fe_fraction'),
 ('all', 'Mass'),
 ('all', 'Phi'),
 ('all', 'Velocities'),
 ('all', 'mesh_id'),
 ('all', 'particle_angular_momentum'),
 ('all', 'particle_angular_momentum_magnitude'),
 ('all', 'particle_angular_momentum_x'),
 ('all', 'particle_angular_momentum_y'),
 ('all', 'particle_angular_momentum_z'),
 ('all', 'particle_cylindrical_velocity_theta'),
 ('all', 'particle_cylindrical_velocity_z'),
 ('all', 'particle_mass'),
 ('all', 'particle_ones'),
 ('all', 'particle_position'),
 ('all', 'particle_position_cylindrical_radius'),
 ('all', 'particle_position_cylindrical_theta'),
 ('all', 'particle_position_cylindrical_z'),
 ('all', 'particle_position_relative'),
 ('all', 'particle_position_relative_x'),
 ('all', 'particle_position_relative_y'),
 ('all', 'particle_position_relative_z'),
 ('all', 'particle_position_spherical_phi'),
 ('all', 'particle_position_spherical_radius'),
 ('all', 'particle_position_spherical_theta'),
 ('all', 'particle_position_x'),
 ('all', 'particle_position_y'),
 ('all', 'particle_position_z'),
 ('all', 'particle_radial_velocity'),
 ('all', 'particle_radius'),
 ('all', 'particle_specific_angular_momentum'),
 ('all', 'particle_specific_angular_momentum_x'),
 ('all', 'particle_specific_angular_momentum_y'),
 ('all', 'particle_specific_angular_momentum_z'),
 ('all', 'particle_spherical_position_phi'),
 ('all', 'particle_spherical_position_radius'),
 ('all', 'particle_spherical_position_theta'),
 ('all', 'particle_spherical_velocity_phi'),
 ('all', 'particle_spherical_velocity_radius'),
 ('all', 'particle_spherical_velocity_theta'),
 ('all', 'particle_velocity'),
 ('all', 'particle_velocity_cylindrical_radius'),
 ('all', 'particle_velocity_cylindrical_theta'),
 ('all', 'particle_velocity_cylindrical_z'),
 ('all', 'particle_velocity_magnitude'),
 ('all', 'particle_velocity_relative'),
 ('all', 'particle_velocity_relative_x'),
 ('all', 'particle_velocity_relative_y'),
 ('all', 'particle_velocity_relative_z'),
 ('all', 'particle_velocity_spherical_phi'),
 ('all', 'particle_velocity_spherical_radius'),
 ('all', 'particle_velocity_spherical_theta'),
 ('all', 'particle_velocity_x'),
 ('all', 'particle_velocity_y'),
 ('all', 'particle_velocity_z'),
 ('deposit', 'DarkMatter_cic'),
 ('deposit', 'DarkMatter_cic_velocity_x'),
 ('deposit', 'DarkMatter_cic_velocity_y'),
 ('deposit', 'DarkMatter_cic_velocity_z'),
 ('deposit', 'DarkMatter_count'),
 ('deposit', 'DarkMatter_density'),
 ('deposit', 'DarkMatter_mass'),
 ('deposit', 'DarkMatter_nn_velocity_x'),
 ('deposit', 'DarkMatter_nn_velocity_y'),
 ('deposit', 'DarkMatter_nn_velocity_z'),
 ('deposit', 'Gas_cic'),
 ('deposit', 'Gas_cic_velocity_x'),
 ('deposit', 'Gas_cic_velocity_y'),
 ('deposit', 'Gas_cic_velocity_z'),
 ('deposit', 'Gas_count'),
 ('deposit', 'Gas_density'),
 ('deposit', 'Gas_mass'),
 ('deposit', 'Gas_nn_velocity_x'),
 ('deposit', 'Gas_nn_velocity_y'),
 ('deposit', 'Gas_nn_velocity_z'),
 ('deposit', 'Gas_smoothed_Fe_fraction'),
 ('deposit', 'Gas_smoothed_density'),
 ('deposit', 'Gas_smoothed_metallicity'),
 ('deposit', 'Gas_smoothed_particle_velocity_x'),
 ('deposit', 'Gas_smoothed_particle_velocity_y'),
 ('deposit', 'Gas_smoothed_particle_velocity_z'),
 ('deposit', 'Gas_smoothed_temperature'),
 ('deposit', 'Stars_cic'),
 ('deposit', 'Stars_cic_velocity_x'),
 ('deposit', 'Stars_cic_velocity_y'),
 ('deposit', 'Stars_cic_velocity_z'),
 ('deposit', 'Stars_count'),
 ('deposit', 'Stars_density'),
 ('deposit', 'Stars_mass'),
 ('deposit', 'Stars_nn_velocity_x'),
 ('deposit', 'Stars_nn_velocity_y'),
 ('deposit', 'Stars_nn_velocity_z'),
 ('deposit', 'all_cic'),
 ('deposit', 'all_cic_velocity_x'),
 ('deposit', 'all_cic_velocity_y'),
 ('deposit', 'all_cic_velocity_z'),
 ('deposit', 'all_count'),
 ('deposit', 'all_density'),
 ('deposit', 'all_mass'),
 ('deposit', 'all_nn_velocity_x'),
 ('deposit', 'all_nn_velocity_y'),
 ('deposit', 'all_nn_velocity_z'),
 ('gas', 'Fe_fraction'),
 ('gas', 'H_nuclei_density'),
 ('gas', 'He_nuclei_density'),
 ('gas', 'angular_momentum_magnitude'),
 ('gas', 'angular_momentum_x'),
 ('gas', 'angular_momentum_y'),
 ('gas', 'angular_momentum_z'),
 ('gas', 'averaged_density'),
 ('gas', 'cell_mass'),
 ('gas', 'cell_volume'),
 ('gas', 'cutting_plane_velocity_x'),
 ('gas', 'cutting_plane_velocity_y'),
 ('gas', 'cutting_plane_velocity_z'),
 ('gas', 'cylindrical_radial_velocity'),
 ('gas', 'cylindrical_radial_velocity_absolute'),
 ('gas', 'cylindrical_tangential_velocity'),
 ('gas', 'cylindrical_tangential_velocity_absolute'),
 ('gas', 'density'),
 ('gas', 'density_gradient_magnitude'),
 ('gas', 'density_gradient_x'),
 ('gas', 'density_gradient_y'),
 ('gas', 'density_gradient_z'),
 ('gas', 'dx'),
 ('gas', 'dy'),
 ('gas', 'dynamical_time'),
 ('gas', 'dz'),
 ('gas', 'emission_measure'),
 ('gas', 'entropy'),
 ('gas', 'kT'),
 ('gas', 'kinetic_energy'),
 ('gas', 'mazzotta_weighting'),
 ('gas', 'metallicity'),
 ('gas', 'path_element_x'),
 ('gas', 'path_element_y'),
 ('gas', 'path_element_z'),
 ('gas', 'radial_velocity'),
 ('gas', 'radial_velocity_absolute'),
 ('gas', 'shear'),
 ('gas', 'specific_angular_momentum_magnitude'),
 ('gas', 'specific_angular_momentum_x'),
 ('gas', 'specific_angular_momentum_y'),
 ('gas', 'specific_angular_momentum_z'),
 ('gas', 'sz_kinetic'),
 ('gas', 'szy'),
 ('gas', 'tangential_over_velocity_magnitude'),
 ('gas', 'tangential_velocity'),
 ('gas', 'temperature'),
 ('gas', 'velocity_cylindrical_radius'),
 ('gas', 'velocity_cylindrical_theta'),
 ('gas', 'velocity_cylindrical_z'),
 ('gas', 'velocity_divergence'),
 ('gas', 'velocity_divergence_absolute'),
 ('gas', 'velocity_magnitude'),
 ('gas', 'velocity_spherical_phi'),
 ('gas', 'velocity_spherical_radius'),
 ('gas', 'velocity_spherical_theta'),
 ('gas', 'velocity_x'),
 ('gas', 'velocity_y'),
 ('gas', 'velocity_z'),
 ('gas', 'vertex_x'),
 ('gas', 'vertex_y'),
 ('gas', 'vertex_z'),
 ('gas', 'vorticity_magnitude'),
 ('gas', 'vorticity_squared'),
 ('gas', 'vorticity_stretching_magnitude'),
 ('gas', 'vorticity_stretching_x'),
 ('gas', 'vorticity_stretching_y'),
 ('gas', 'vorticity_stretching_z'),
 ('gas', 'vorticity_x'),
 ('gas', 'vorticity_y'),
 ('gas', 'vorticity_z'),
 ('gas', 'x'),
 ('gas', 'xray_emissivity'),
 ('gas', 'y'),
 ('gas', 'z'),
 ('index', 'cell_volume'),
 ('index', 'cylindrical_r'),
 ('index', 'cylindrical_radius'),
 ('index', 'cylindrical_theta'),
 ('index', 'cylindrical_z'),
 ('index', 'disk_angle'),
 ('index', 'dx'),
 ('index', 'dy'),
 ('index', 'dz'),
 ('index', 'grid_indices'),
 ('index', 'grid_level'),
 ('index', 'height'),
 ('index', 'morton_index'),
 ('index', 'ones'),
 ('index', 'ones_over_dx'),
 ('index', 'path_element_x'),
 ('index', 'path_element_y'),
 ('index', 'path_element_z'),
 ('index', 'radius'),
 ('index', 'spherical_phi'),
 ('index', 'spherical_r'),
 ('index', 'spherical_radius'),
 ('index', 'spherical_theta'),
 ('index', 'vertex_x'),
 ('index', 'vertex_y'),
 ('index', 'vertex_z'),
 ('index', 'virial_radius_fraction'),
 ('index', 'x'),
 ('index', 'y'),
 ('index', 'z'),
 ('index', 'zeros')]

All of the field in the field_list are arrays containing the values for the associated particles. These haven't been smoothed or gridded in any way. We can grab the array-data for these particles using ds.all_data(). For example, let's take a look at a temperature-colored scatterplot of the gas particles in this output.

In [5]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [6]:
dd = ds.all_data()
xcoord = dd['Gas','Coordinates'][:,0].v
ycoord = dd['Gas','Coordinates'][:,1].v
logT = np.log10(dd['Gas','Temperature'])
plt.scatter(xcoord, ycoord, c=logT, s=2*logT, marker='o', edgecolor='none', vmin=2, vmax=6)
plt.xlim(-20,20)
plt.ylim(-20,20)
cb = plt.colorbar()
cb.set_label('$\log_{10}$ Temperature')
plt.gcf().set_size_inches(15,10)

Making Smoothed Images

yt will automatically generate smoothed versions of these fields that you can use to plot. Let's make a temperature slice and a density projection.

In [7]:
yt.SlicePlot(ds, 'z', ('gas','density'), width=(40, 'kpc'), center='m')
Out[7]:

In [8]:
yt.ProjectionPlot(ds, 'z', ('gas','density'), width=(40, 'kpc'), center='m')
Out[8]:

Not only are the values in the tipsy snapshot read and automatically smoothed, the auxiliary files that have physical significance are also smoothed. Let's look at a slice of Iron mass fraction.

In [9]:
yt.SlicePlot(ds, 'z', ('gas', 'Fe_fraction'), width=(40, 'kpc'), center='m')
Out[9]: