yt.data_objects.selection_data_containers module

Data containers based on geometric selection

class yt.data_objects.selection_data_containers.YTCutRegion(data_source, conditionals, ds=None, field_parameters=None, base_object=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

This is a data object designed to allow individuals to apply logical operations to fields and filter as a result of those cuts.

Parameters:
  • data_source (YTSelectionContainer3D) – The object to which cuts will be applied.
  • conditionals (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> sp = ds.sphere("max", (1.0, 'Mpc'))
>>> cr = ds.cut_region(sp, ["obj['temperature'] < 1e3"])
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)[source]
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)[source]
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTCuttingPlane(normal, center, north_vector=None, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer2D

This is a data object corresponding to an oblique slice through the simulation domain.

This object is typically accessed through the cutting object that hangs off of index objects. A cutting plane is an oblique plane through the data, defined by a normal vector and a coordinate. It attempts to guess an ‘north’ vector, which can be overridden, and then it pixelizes the appropriate data onto the plane without interpolation.

Parameters:
  • normal (array_like) – The vector that defines the desired plane. For instance, the angular momentum of a sphere.
  • center (array_like) – The center of the cutting plane, where the normal vector is anchored.
  • north_vector (array_like, optional) – An optional vector to describe the north-facing direction in the resulting plane.
  • ds (Dataset, optional) – An optional dataset to use rather than self.ds
  • field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.
  • data_source (optional) – Draw the selection from the provided data source rather than all data associated with the data_set

Notes

This data object in particular can be somewhat expensive to create. It’s also important to note that unlike the other 2D data objects, this object provides px, py, pz, as some cells may have a height from the plane.

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> cp = ds.cutting([0.1, 0.2, -0.9], [0.5, 0.42, 0.6])
>>> print cp["Density"]
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
normal
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_frb(width, resolution, height=None, periodic=False)[source]

This function returns a FixedResolutionBuffer generated from this object.

An ObliqueFixedResolutionBuffer is an object that accepts a variable-resolution 2D object and transforms it into an NxM bitmap that can be plotted, examined or processed. This is a convenience function to return an FRB directly from an existing 2D data object. Unlike the corresponding to_frb function for other YTSelectionContainer2D objects, this does not accept a ‘center’ parameter as it is assumed to be centered at the center of the cutting plane.

Parameters:
  • width (width specifier) – This can either be a floating point value, in the native domain units of the simulation, or a tuple of the (value, unit) style. This will be the width of the FRB.
  • height (height specifier, optional) – This will be the height of the FRB, by default it is equal to width.
  • resolution (int or tuple of ints) – The number of pixels on a side of the final FRB.
  • periodic (boolean) – This can be true or false, and governs whether the pixelization will span the domain boundaries.
Returns:

frb – A fixed resolution buffer, which can be queried for fields.

Return type:

ObliqueFixedResolutionBuffer

Examples

>>> v, c = ds.find_max("density")
>>> sp = ds.sphere(c, (100.0, 'au'))
>>> L = sp.quantities.angular_momentum_vector()
>>> cutting = ds.cutting(L, c)
>>> frb = cutting.to_frb( (1.0, 'pc'), 1024)
>>> write_image(np.log10(frb["Density"]), 'density_1pc.png')
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

to_pw(fields=None, center='c', width=None, axes_unit=None)[source]

Create a PWViewerMPL from this object.

This is a bare-bones mechanism of creating a plot window from this object, which can then be moved around, zoomed, and on and on. All behavior of the plot window is relegated to that routine.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTDataCollection(obj_list, ds=None, field_parameters=None, data_source=None, center=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

By selecting an arbitrary object_list, we can act on those grids. Child cells are not returned.

apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTDataObjectUnion(data_objects, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

This is a more efficient method of selecting the union of multiple data selection objects.

Creating one of these objects returns the union of all of the sub-objects; it is designed to be a faster method than chaining | (or) operations to create a single, large union.

Parameters:data_objects (Iterable of YTSelectionContainer3D) – The data objects to union

Examples

>>> import yt
>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp1 = ds.sphere((0.4, 0.5, 0.6), 0.1)
>>> sp2 = ds.sphere((0.3, 0.5, 0.15), 0.1)
>>> sp3 = ds.sphere((0.5, 0.5, 0.9), 0.1)
>>> new_obj = ds.union((sp1, sp2, sp3))
>>> print(new_obj.sum("cell_volume"))
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTDisk(center, normal, radius, height, fields=None, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

By providing a center, a normal, a radius and a height we can define a cylinder of any proportion. Only cells whose centers are within the cylinder will be selected.

Parameters:
  • center (array_like) – coordinate to which the normal, radius, and height all reference
  • normal (array_like) – the normal vector defining the direction of lengthwise part of the cylinder
  • radius (float) – the radius of the cylinder
  • height (float) – the distance from the midplane of the cylinder to the top and bottom planes
  • fields (array of fields, optional) – any fields to be pre-loaded in the cylinder object
  • ds (Dataset, optional) – An optional dataset to use rather than self.ds
  • field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.
  • data_source (optional) – Draw the selection from the provided data source rather than all data associated with the data_set

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> c = [0.5,0.5,0.5]
>>> disk = ds.disk(c, [1,0,0], (1, 'kpc'), (10, 'kpc'))
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTEllipsoid(center, A, B, C, e0, tilt, fields=None, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

By providing a center,*A*,*B*,*C*,*e0*,*tilt* we can define a ellipsoid of any proportion. Only cells whose centers are within the ellipsoid will be selected.

Parameters:
  • center (array_like) – The center of the ellipsoid.
  • A (float) – The magnitude of the largest axis (semi-major) of the ellipsoid.
  • B (float) – The magnitude of the medium axis (semi-medium) of the ellipsoid.
  • C (float) – The magnitude of the smallest axis (semi-minor) of the ellipsoid.
  • e0 (array_like (automatically normalized)) – the direction of the largest semi-major axis of the ellipsoid
  • tilt (float) – After the rotation about the z-axis to allign e0 to x in the x-y plane, and then rotating about the y-axis to align e0 completely to the x-axis, tilt is the angle in radians remaining to rotate about the x-axis to align both e1 to the y-axis and e2 to the z-axis.

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> c = [0.5,0.5,0.5]
>>> ell = ds.ellipsoid(c, 0.1, 0.1, 0.1, np.array([0.1, 0.1, 0.1]), 0.2)
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
t2 = None

calculate the original e1 given the tilt about the x axis when e0 was aligned to x after t1, t2 rotations about z, y

tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTIntersectionContainer3D(data_objects, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

This is a more efficient method of selecting the intersection of multiple data selection objects.

Creating one of these objects returns the intersection of all of the sub-objects; it is designed to be a faster method than chaining & (“and”) operations to create a single, large intersection.

Parameters:data_objects (Iterable of YTSelectionContainer3D) – The data objects to intersect

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> sp1 = ds.sphere((0.4, 0.5, 0.6), 0.15)
>>> sp2 = ds.sphere((0.38, 0.51, 0.55), 0.1)
>>> sp3 = ds.sphere((0.35, 0.5, 0.6), 0.15)
>>> new_obj = ds.intersection((sp1, sp2, sp3))
>>> print(new_obj.sum("cell_volume"))
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTOrthoRay(axis, coords, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer1D

This is an orthogonal ray cast through the entire domain, at a specific coordinate.

This object is typically accessed through the ortho_ray object that hangs off of index objects. The resulting arrays have their dimensionality reduced to one, and an ordered list of points at an (x,y) tuple along axis are available.

Parameters:
  • axis (int or char) – The axis along which to slice. Can be 0, 1, or 2 for x, y, z.
  • coords (tuple of floats) – The (plane_x, plane_y) coordinates at which to cast the ray. Note that this is in the plane coordinates: so if you are casting along x, this will be (y, z). If you are casting along y, this will be (z, x). If you are casting along z, this will be (x, y).
  • ds (Dataset, optional) – An optional dataset to use rather than self.ds
  • field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.
  • data_source (optional) – Draw the selection from the provided data source rather than all data associated with the data_set

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> oray = ds.ortho_ray(0, (0.2, 0.74))
>>> print oray["Density"]

Note: The low-level data representation for rays are not guaranteed to be spatially ordered. In particular, with AMR datasets, higher resolution data is tagged on to the end of the ray. If you want this data represented in a spatially ordered manner, manually sort it by the “t” field, which is the value of the parametric variable that goes from 0 at the start of the ray to 1 at the end:

>>> my_ray = ds.ortho_ray(...)
>>> ray_sort = np.argsort(my_ray["t"])
>>> density = my_ray["density"][ray_sort]
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

coords
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTPoint(p, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer0D

A 0-dimensional object defined by a single point

Parameters:
  • p (array_like) – A points defined within the domain. If the domain is periodic its position will be corrected to lie inside the range [DLE,DRE) to ensure one and only one cell may match that point
  • ds (Dataset, optional) – An optional dataset to use rather than self.ds
  • field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.
  • data_source (optional) – Draw the selection from the provided data source rather than all data associated with the data_set

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> c = [0.5,0.5,0.5]
>>> point = ds.point(c)
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTRay(start_point, end_point, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer1D

This is an arbitrarily-aligned ray cast through the entire domain, at a specific coordinate.

This object is typically accessed through the ray object that hangs off of index objects. The resulting arrays have their dimensionality reduced to one, and an ordered list of points at an (x,y) tuple along axis are available, as is the t field, which corresponds to a unitless measurement along the ray from start to end.

Parameters:
  • start_point (array-like set of 3 floats) – The place where the ray starts.
  • end_point (array-like set of 3 floats) – The place where the ray ends.
  • ds (Dataset, optional) – An optional dataset to use rather than self.ds
  • field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.
  • data_source (optional) – Draw the selection from the provided data source rather than all data associated with the data_set

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> ray = ds.ray((0.2, 0.74, 0.11), (0.4, 0.91, 0.31))
>>> print ray["Density"], ray["t"], ray["dts"]

Note: The low-level data representation for rays are not guaranteed to be spatially ordered. In particular, with AMR datasets, higher resolution data is tagged on to the end of the ray. If you want this data represented in a spatially ordered manner, manually sort it by the “t” field, which is the value of the parametric variable that goes from 0 at the start of the ray to 1 at the end:

>>> my_ray = ds.ray(...)
>>> ray_sort = np.argsort(my_ray["t"])
>>> density = my_ray["density"][ray_sort]
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTRegion(center, left_edge, right_edge, fields=None, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

A 3D region of data with an arbitrary center.

Takes an array of three left_edge coordinates, three right_edge coordinates, and a center that can be anywhere in the domain. If the selected region extends past the edges of the domain, no data will be found there, though the object’s left_edge or right_edge are not modified.

Parameters:
  • center (array_like) – The center of the region
  • left_edge (array_like) – The left edge of the region
  • right_edge (array_like) – The right edge of the region
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTSlice(axis, coord, center=None, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer2D

This is a data object corresponding to a slice through the simulation domain.

This object is typically accessed through the slice object that hangs off of index objects. Slice is an orthogonal slice through the data, taking all the points at the finest resolution available and then indexing them. It is more appropriately thought of as a slice ‘operator’ than an object, however, as its field and coordinate can both change.

Parameters:
  • axis (int or char) – The axis along which to slice. Can be 0, 1, or 2 for x, y, z.
  • coord (float) – The coordinate along the axis at which to slice. This is in “domain” coordinates.
  • center (array_like, optional) – The ‘center’ supplied to fields that use it. Note that this does not have to have coord as one value. optional.
  • ds (Dataset, optional) – An optional dataset to use rather than self.ds
  • field_parameters (dictionary) – A dictionary of field parameters than can be accessed by derived fields.
  • data_source (optional) – Draw the selection from the provided data source rather than all data associated with the data_set

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> slice = ds.slice(0, 0.25)
>>> print slice["Density"]
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

hub_upload()[source]
icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
plot(fields=None)[source]
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_frb(width, resolution, center=None, height=None, periodic=False)

This function returns a FixedResolutionBuffer generated from this object.

A FixedResolutionBuffer is an object that accepts a variable-resolution 2D object and transforms it into an NxM bitmap that can be plotted, examined or processed. This is a convenience function to return an FRB directly from an existing 2D data object.

Parameters:
  • width (width specifier) – This can either be a floating point value, in the native domain units of the simulation, or a tuple of the (value, unit) style. This will be the width of the FRB.
  • height (height specifier) – This will be the physical height of the FRB, by default it is equal to width. Note that this will not make any corrections to resolution for the aspect ratio.
  • resolution (int or tuple of ints) – The number of pixels on a side of the final FRB. If iterable, this will be the width then the height.
  • center (array-like of floats, optional) – The center of the FRB. If not specified, defaults to the center of the current object.
  • periodic (bool) – Should the returned Fixed Resolution Buffer be periodic? (default: False).
Returns:

frb – A fixed resolution buffer, which can be queried for fields.

Return type:

FixedResolutionBuffer

Examples

>>> proj = ds.proj("Density", 0)
>>> frb = proj.to_frb( (100.0, 'kpc'), 1024)
>>> write_image(np.log10(frb["Density"]), 'density_100kpc.png')
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

to_pw(fields=None, center='c', width=None, origin='center-window')[source]

Create a PWViewerMPL from this object.

This is a bare-bones mechanism of creating a plot window from this object, which can then be moved around, zoomed, and on and on. All behavior of the plot window is relegated to that routine.

write_out(filename, fields=None, format='%0.16e')
class yt.data_objects.selection_data_containers.YTSphere(center, radius, ds=None, field_parameters=None, data_source=None)[source]

Bases: yt.data_objects.data_containers.YTSelectionContainer3D

A sphere of points defined by a center and a radius.

Parameters:
  • center (array_like) – The center of the sphere.
  • radius (float) – The radius of the sphere.

Examples

>>> import yt
>>> ds = yt.load("RedshiftOutput0005")
>>> c = [0.5,0.5,0.5]
>>> sphere = ds.sphere(c, (1., "kpc"))
apply_units(arr, units)
argmax(field, axis=None)

Return the values at which the field is maximized.

This will, in a parallel-aware fashion, find the maximum value and then return to you the values at that maximum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_max_rho = reg.argmax("density", axis="temperature")
>>> max_rho_xyz = reg.argmax("density")
>>> t_mrho, v_mrho = reg.argmax("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmax("density")
argmin(field, axis=None)

Return the values at which the field is minimized.

This will, in a parallel-aware fashion, find the minimum value and then return to you the values at that minimum location that are requested for “axis”. By default it will return the spatial positions (in the natural coordinate system), but it can be any field

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string or list of strings, optional) – If supplied, the fields to sample along; if not supplied, defaults to the coordinate fields. This can be the name of the coordinate fields (i.e., ‘x’, ‘y’, ‘z’) or a list of fields, but cannot be 0, 1, 2.
Returns:

Return type:

A list of YTQuantities as specified by the axis argument.

Examples

>>> temp_at_min_rho = reg.argmin("density", axis="temperature")
>>> min_rho_xyz = reg.argmin("density")
>>> t_mrho, v_mrho = reg.argmin("density", axis=["temperature",
...                 "velocity_magnitude"])
>>> x, y, z = reg.argmin("density")
blocks
calculate_isocontour_flux(field, value, field_x, field_y, field_z, fluxing_field=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and calculates the flux over those contours.

This function will conduct marching cubes on all the cells in a given data container (grid-by-grid), and then for each identified triangular segment of an isocontour in a given cell, calculate the gradient (i.e., normal) in the isocontoured field, interpolate the local value of the “fluxing” field, the area of the triangle, and then return:

area * local_flux_value * (n dot v)

Where area, local_value, and the vector v are interpolated at the barycenter (weighted by the vertex values) of the triangle. Note that this specifically allows for the field fluxing across the surface to be different from the field being contoured. If the fluxing_field is not specified, it is assumed to be 1.0 everywhere, and the raw flux with no local-weighting is returned.

Additionally, the returned flux is defined as flux into the surface, not flux out of the surface.

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured and used as the “local_value” in the flux equation.
  • value (float) – The value at which the isocontour should be calculated.
  • field_x (string) – The x-component field
  • field_y (string) – The y-component field
  • field_z (string) – The z-component field
  • fluxing_field (string, optional) – The field whose passage over the surface is of interest. If not specified, assumed to be 1.0 everywhere.
Returns:

flux – The summed flux. Note that it is not currently scaled; this is simply the code-unit area times the fields.

Return type:

float

Examples

This will create a data object, find a nice value in the center, and calculate the metal flux over it.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> flux = dd.calculate_isocontour_flux("Density", rho,
...     "velocity_x", "velocity_y", "velocity_z", "Metal_Density")
chunks(fields, chunking_style, **kwargs)
clear_data()

Clears out all data from the YTDataContainer instance, freeing memory.

clone()

Clone a data object.

This will make a duplicate of a data object; note that the field_parameters may not necessarily be deeply-copied. If you modify the field parameters in-place, it may or may not be shared between the objects, depending on the type of object that that particular field parameter is.

Notes

One use case for this is to have multiple identical data objects that are being chunked over in different orders.

Examples

>>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
>>> sp = ds.sphere("c", 0.1)
>>> sp_clone = sp.clone()
>>> sp["density"]
>>> print sp.field_data.keys()
[("gas", "density")]
>>> print sp_clone.field_data.keys()
[]
comm = None
convert(datatype)

This will attempt to convert a given unit to cgs from code units. It either returns the multiplicative factor or throws a KeyError.

cut_region(field_cuts, field_parameters=None)

Return a YTCutRegion, where the a cell is identified as being inside the cut region based on the value of one or more fields. Note that in previous versions of yt the name ‘grid’ was used to represent the data object used to construct the field cut, as of yt 3.0, this has been changed to ‘obj’.

Parameters:
  • field_cuts (list of strings) – A list of conditionals that will be evaluated. In the namespace available, these conditionals will have access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance, conditionals = [“obj[‘temperature’] < 1e3”]
  • field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

Examples

To find the total mass of hot gas with temperature greater than 10^6 K in your volume:

>>> ds = yt.load("RedshiftOutput0005")
>>> ad = ds.all_data()
>>> cr = ad.cut_region(["obj['temperature'] > 1e6"])
>>> print cr.quantities.total_quantity("cell_mass").in_units('Msun')
extract_connected_sets(field, num_levels, min_val, max_val, log_space=True, cumulative=True)

This function will create a set of contour objects, defined by having connected cell structures, which can then be studied and used to ‘paint’ their source grids, thus enabling them to be plotted.

Note that this function can return a connected set object that has no member values.

extract_isocontours(field, value, filename=None, rescale=False, sample_values=None)

This identifies isocontours on a cell-by-cell basis, with no consideration of global connectedness, and returns the vertices of the Triangles in that isocontour.

This function simply returns the vertices of all the triangles calculated by the marching cubes algorithm; for more complex operations, such as identifying connected sets of cells above a given threshold, see the extract_connected_sets function. This is more useful for calculating, for instance, total isocontour area, or visualizing in an external program (such as MeshLab.)

Parameters:
  • field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.
  • value (float) – The value at which the isocontour should be calculated.
  • filename (string, optional) – If supplied, this file will be filled with the vertices in .obj format. Suitable for loading into meshlab.
  • rescale (bool, optional) – If true, the vertices will be rescaled within their min/max.
  • sample_values (string, optional) – Any field whose value should be extracted at the center of each triangle.
Returns:

  • verts (array of floats) – The array of vertices, x,y,z. Taken in threes, these are the triangle vertices.
  • samples (array of floats) – If sample_values is specified, this will be returned and will contain the values of the field specified at the center of each triangle.

Examples

This will create a data object, find a nice value in the center, and output the vertices to “triangles.obj” after rescaling them.

>>> dd = ds.all_data()
>>> rho = dd.quantities["WeightedAverageQuantity"](
...     "Density", weight="CellMassMsun")
>>> verts = dd.extract_isocontours("Density", rho,
...             "triangles.obj", True)
fcoords
fcoords_vertex
fwidth
get_data(fields=None)
get_dependencies(fields)
get_field_parameter(name, default=None)

This is typically only used by derived field functions, but it returns parameters used to generate fields.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

icoords
index
integrate(field, weight=None, axis=None)

Compute the integral (projection) of a field along an axis.

This projects a field along an axis.

Parameters:
  • field (string or tuple field name) – The field to project.
  • weight (string or tuple field name) – The field to weight the projection by
  • axis (string) – The axis to project along.
Returns:

Return type:

YTProjection

Examples

>>> column_density = reg.integrate("density", axis="z")
ires
keys()
max(field, axis=None)

Compute the maximum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the maximum of the given field. Supplying an axis will result in a return value of a YTProjection, with method ‘mip’ for maximum intensity. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to maximize.
  • axis (string, optional) – If supplied, the axis to project the maximum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> max_temp = reg.max("temperature")
>>> max_temp_proj = reg.max("temperature", axis="x")
mean(field, axis=None, weight=None)

Compute the mean of a field, optionally along an axis, with a weight.

This will, in a parallel-aware fashion, compute the mean of the given field. If an axis is supplied, it will return a projection, where the weight is also supplied. By default the weight field will be “ones” or “particle_ones”, depending on the field being averaged, resulting in an unweighted average.

Parameters:
  • field (string or tuple field name) – The field to average.
  • axis (string, optional) – If supplied, the axis to compute the mean along (i.e., to project along)
  • weight (string, optional) – The field to use as a weight.
Returns:

Return type:

Scalar or YTProjection.

Examples

>>> avg_rho = reg.mean("density", weight="cell_volume")
>>> rho_weighted_T = reg.mean("temperature", axis="y", weight="density")
min(field, axis=None)

Compute the minimum of a field.

This will, in a parallel-aware fashion, compute the minimum of the given field. Supplying an axis is not currently supported. If the max has already been requested, it will use the cached extrema value.

Parameters:
  • field (string or tuple field name) – The field to minimize.
  • axis (string, optional) – If supplied, the axis to compute the minimum along.
Returns:

Return type:

Scalar.

Examples

>>> min_temp = reg.min("temperature")
paint_grids(field, value, default_value=None)

This function paints every cell in our dataset with a given value. If default_value is given, the other values for the given in every grid are discarded and replaced with default_value. Otherwise, the field is mandated to ‘know how to exist’ in the grid.

Note that this only paints the cells in the dataset, so cells in grids with child cells are left untouched.

particles
partition_index_2d(axis)
partition_index_3d(ds, padding=0.0, rank_ratio=1)
partition_index_3d_bisection_list()

Returns an array that is used to drive _partition_index_3d_bisection, below.

partition_region_3d(left_edge, right_edge, padding=0.0, rank_ratio=1)

Given a region, it subdivides it into smaller regions for parallel analysis.

pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='cell_mass', accumulation=False, fractional=False, deposition='ngp')

Create a 1, 2, or 3D profile object from this data_source.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument. This simply calls yt.data_objects.profiles.create_profile().

Parameters:
  • bin_fields (list of strings) – List of the binning fields for profiling.
  • fields (list of strings) – The fields to be profiled.
  • n_bins (int or list of ints) – The number of bins in each dimension. If None, 64 bins for each bin are used for each bin field. Default: 64.
  • extrema (dict of min, max tuples) – Minimum and maximum values of the bin_fields for the profiles. The keys correspond to the field names. Defaults to the extrema of the bin_fields of the dataset. If a units dict is provided, extrema are understood to be in the units specified in the dictionary.
  • logs (dict of boolean values) – Whether or not to log the bin_fields for the profiles. The keys correspond to the field names. Defaults to the take_log attribute of the field.
  • units (dict of strings) – The units of the fields in the profiles, including the bin_fields.
  • weight_field (str or tuple field identifier) – The weight field for computing weighted average for the profile values. If None, the profile values are sums of the data in each bin.
  • accumulation (bool or list of bools) – If True, the profile values for a bin n are the cumulative sum of all the values from bin 0 to n. If -True, the sum is reversed so that the value for bin n is the cumulative sum from bin N (total bins) to n. If the profile is 2D or 3D, a list of values can be given to control the summation in each dimension independently. Default: False.
  • fractional (If True the profile values are divided by the sum of all) – the profile data such that the profile represents a probability distribution function.
  • deposition (Controls the type of deposition used for ParticlePhasePlots.) – Valid choices are ‘ngp’ and ‘cic’. Default is ‘ngp’. This parameter is ignored the if the input fields are not of particle type.

Examples

Create a 1d profile. Access bin field from profile.x and field data from profile[<field_name>].

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = ad.profile(ad, [("gas", "density")],
...                          [("gas", "temperature"),
...                          ("gas", "velocity_x")])
>>> print (profile.x)
>>> print (profile["gas", "temperature"])
>>> plot = profile.plot()
ptp(field)

Compute the range of values (maximum - minimum) of a field.

This will, in a parallel-aware fashion, compute the “peak-to-peak” of the given field.

Parameters:field (string or tuple field name) – The field to average.
Returns:
Return type:Scalar

Examples

>>> rho_range = reg.ptp("density")
save_as_dataset(filename=None, fields=None)

Export a data object to a reloadable yt dataset.

This function will take a data object and output a dataset containing either the fields presently existing or fields given in the fields list. The resulting dataset can be reloaded as a yt dataset.

Parameters:
  • filename (str, optional) – The name of the file to be written. If None, the name will be a combination of the original dataset and the type of data container.
  • fields (list of string or tuple field names, optional) – If this is supplied, it is the list of fields to be saved to disk. If not supplied, all the fields that have been queried will be saved.
Returns:

filename – The name of the file that has been created.

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=["density", "temperature"])
>>> sphere_ds = yt.load(fn)
>>> # the original data container is available as the data attribute
>>> print (sds.data["density"])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
   3.57339907e-30   2.83150720e-30] g/cm**3
>>> ad = sphere_ds.all_data()
>>> print (ad["temperature"])
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
   4.54380547e+04   4.72560117e+04] K
save_object(name, filename=None)

Save an object. If filename is supplied, it will be stored in a shelve file of that name. Otherwise, it will be stored via yt.data_objects.api.GridIndex.save_object().

selector
set_field_parameter(name, val)

Here we set up dictionaries that get passed up and down and ultimately to derived fields.

std(field, weight=None)

Compute the variance of a field.

This will, in a parallel-ware fashion, compute the variance of the given field.

Parameters:
  • field (string or tuple field name) – The field to calculate the variance of
  • weight (string or tuple field name) – The field to weight the variance calculation by. Defaults to unweighted if unset.
Returns:

Return type:

Scalar

sum(field, axis=None)

Compute the sum of a field, optionally along an axis.

This will, in a parallel-aware fashion, compute the sum of the given field. If an axis is specified, it will return a projection (using method type “sum”, which does not take into account path length) along that axis.

Parameters:
  • field (string or tuple field name) – The field to sum.
  • axis (string, optional) – If supplied, the axis to sum along.
Returns:

Return type:

Either a scalar or a YTProjection.

Examples

>>> total_vol = reg.sum("cell_volume")
>>> cell_count = reg.sum("ones", axis="x")
tiles
to_dataframe(fields=None)

Export a data object to a pandas DataFrame.

This function will take a data object and construct from it and optionally a list of fields a pandas DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters:fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the data frame. If not supplied, whatever fields presently exist will be used.
Returns:df – The data contained in the object.
Return type:DataFrame

Examples

>>> dd = ds.all_data()
>>> df1 = dd.to_dataframe(["density", "temperature"])
>>> dd["velocity_magnitude"]
>>> df2 = dd.to_dataframe()
to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://www.glueviz.org) for interactive analysis. Optionally add a label. If you are already within the Glue environment, you can pass a data_collection object, otherwise Glue will be started.

volume()

Return the volume of the data container. This is found by adding up the volume of the cells with centers in the container, rather than using the geometric shape of the container, so this may vary very slightly from what might be expected from the geometric volume.

write_out(filename, fields=None, format='%0.16e')