# yt.data_objects.construction_data_containers module¶

class yt.data_objects.construction_data_containers.LevelState[source]

Bases: object

base_dx = None
current_dims = None
current_dx = None
current_level = None
data_source = None
dds = None
domain_left_edge = None
domain_right_edge = None
domain_width = None
fields = None
global_startindex = None
left_edge = None
old_global_startindex = None
right_edge = None
class yt.data_objects.construction_data_containers.YTArbitraryGrid(left_edge, right_edge, dims, ds=None, field_parameters=None)[source]

A 3D region with arbitrary bounds and dimensions.

In contrast to the Covering Grid, this object accepts a left edge, a right edge, and dimensions. This allows it to be used for creating 3D particle deposition fields that are independent of the underlying mesh, whether that is yt-generated or from the simulation data. For example, arbitrary boxes around particles can be drawn and particle deposition fields can be created. This object will refuse to generate any fluid fields.

Parameters
• left_edge (array_like) – The left edge of the region to be extracted

• right_edge (array_like) – The left edge of the region to be extracted

• dims (array_like) – Number of cells along each axis of resulting grid.

Examples

>>> obj = ds.arbitrary_grid(
...     [0.0, 0.0, 0.0], [0.99, 0.99, 0.99], dims=[128, 128, 128]
... )

property LeftEdge
property RightEdge
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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> flux = dd.calculate_isocontour_flux(
...     ("gas", "density"),
...     rho,
...     ("gas", "velocity_x"),
...     ("gas", "velocity_y"),
...     ("gas", "velocity_z"),
...     ("gas", "metallicity"),
... )

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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

cut_region(field_cuts, field_parameters=None, locals=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[(‘gas’, ‘temperature’)] < 1e3”]

• field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

• locals (dictionary) – A dictionary of local variables to use when defining the cut region.

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.cut_region(["obj[('gas', 'temperature')] > 1e6"])
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

deposit(positions, fields=None, method=None, kernel_name='cubic')
exclude_above(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is above a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_below(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is below a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field below the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_below(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_equal(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field are equal to given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are inside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_nan(field, units=None)

This function will return a YTCutRegion where all of the regions whose field is NaN are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the NaN entries of the field masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are outside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> verts = dd.extract_isocontours(
...     ("gas", "density"), rho, "triangles.obj", True
... )

property fcoords
property fcoords_vertex
property fwidth
get_bbox()

Return the bounding box for this data container.

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.

get_global_startindex()

Get the global start index of the covering grid.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

property icoords
include_above(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is above a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_below(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is below a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with only regions with the field below the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_below(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_equal(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field are equal to given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are inside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are outside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property selector
set_field_parameter(name, val)

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

property shape
std(field, weight=None)

Compute the standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

to_fits_data(fields, length_unit=None)

Export a set of gridded fields to a FITS file.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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_xarray(fields=None)

Export this fixed-resolution object to an xarray Dataset

This function will take a regularized grid and optionally a list of fields and return an xarray Dataset object. If xarray 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

arr – The data contained in the object.

Return type

Dataset

Examples

>>> dd = ds.r[::256j, ::256j, ::256j]
>>> xf1 = dd.to_xarray([("gas", "density"), ("gas", "temperature")])
>>> dd[("gas", "velocity_magnitude")]
>>> xf2 = dd.to_xarray()

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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

write_to_gdf(gdf_path, fields, nprocs=1, field_units=None, **kwargs)

Write the covering grid data to a GDF file.

Parameters
• gdf_path (string) – Pathname of the GDF file to write.

• fields (list of strings) – Fields to write to the GDF file.

• nprocs (integer, optional) – Split the covering grid into nprocs subgrids before writing to the GDF file. Default: 1

• field_units (dictionary, optional) – Dictionary of units to convert fields to. If not set, fields are in their default units.

• remaining keyword arguments are passed to (All) –

• yt.utilities.grid_data_format.writer.write_to_gdf.

Examples

>>> cube.write_to_gdf(
...     "clumps.h5",
...     [("gas", "density"), ("gas", "temperature")],
...     nprocs=16,
...     overwrite=True,
... )

class yt.data_objects.construction_data_containers.YTCoveringGrid(level, left_edge, dims, fields=None, ds=None, num_ghost_zones=0, use_pbar=True, field_parameters=None)[source]

A 3D region with all data extracted to a single, specified resolution. Left edge should align with a cell boundary, but defaults to the closest cell boundary.

Parameters
• level (int) – The resolution level data to which data will be gridded. Level 0 is the root grid dx for that dataset.

• left_edge (array_like) – The left edge of the region to be extracted. Specify units by supplying a YTArray, otherwise code length units are assumed.

• dims (array_like) – Number of cells along each axis of resulting covering_grid

• fields (array_like, optional) – A list of fields that you’d like pre-generated for your object

• num_ghost_zones (integer, optional) – The number of padding ghost zones used when accessing fields.

Examples

>>> cube = ds.covering_grid(2, left_edge=[0.0, 0.0, 0.0], dims=[128, 128, 128])

property LeftEdge
property RightEdge
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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> flux = dd.calculate_isocontour_flux(
...     ("gas", "density"),
...     rho,
...     ("gas", "velocity_x"),
...     ("gas", "velocity_y"),
...     ("gas", "velocity_z"),
...     ("gas", "metallicity"),
... )

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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

cut_region(field_cuts, field_parameters=None, locals=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[(‘gas’, ‘temperature’)] < 1e3”]

• field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

• locals (dictionary) – A dictionary of local variables to use when defining the cut region.

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.cut_region(["obj[('gas', 'temperature')] > 1e6"])
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

deposit(positions, fields=None, method=None, kernel_name='cubic')[source]
exclude_above(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is above a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_below(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is below a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field below the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_below(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_equal(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field are equal to given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are inside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_nan(field, units=None)

This function will return a YTCutRegion where all of the regions whose field is NaN are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the NaN entries of the field masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are outside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> verts = dd.extract_isocontours(
...     ("gas", "density"), rho, "triangles.obj", True
... )

property fcoords
property fcoords_vertex
property fwidth
get_bbox()

Return the bounding box for this data container.

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.

get_global_startindex()[source]

Get the global start index of the covering grid.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

property icoords
include_above(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is above a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_below(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is below a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with only regions with the field below the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_below(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_equal(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field are equal to given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are inside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are outside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property selector
set_field_parameter(name, val)[source]

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

property shape
std(field, weight=None)

Compute the standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

to_fits_data(fields, length_unit=None)[source]

Export a set of gridded fields to a FITS file.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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_xarray(fields=None)[source]

Export this fixed-resolution object to an xarray Dataset

This function will take a regularized grid and optionally a list of fields and return an xarray Dataset object. If xarray 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

arr – The data contained in the object.

Return type

Dataset

Examples

>>> dd = ds.r[::256j, ::256j, ::256j]
>>> xf1 = dd.to_xarray([("gas", "density"), ("gas", "temperature")])
>>> dd[("gas", "velocity_magnitude")]
>>> xf2 = dd.to_xarray()

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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

write_to_gdf(gdf_path, fields, nprocs=1, field_units=None, **kwargs)[source]

Write the covering grid data to a GDF file.

Parameters
• gdf_path (string) – Pathname of the GDF file to write.

• fields (list of strings) – Fields to write to the GDF file.

• nprocs (integer, optional) – Split the covering grid into nprocs subgrids before writing to the GDF file. Default: 1

• field_units (dictionary, optional) – Dictionary of units to convert fields to. If not set, fields are in their default units.

• remaining keyword arguments are passed to (All) –

• yt.utilities.grid_data_format.writer.write_to_gdf.

Examples

>>> cube.write_to_gdf(
...     "clumps.h5",
...     [("gas", "density"), ("gas", "temperature")],
...     nprocs=16,
...     overwrite=True,
... )

class yt.data_objects.construction_data_containers.YTOctree(left_edge=None, right_edge=None, n_ref=32, ptypes=None, ds=None, field_parameters=None)[source]

A 3D region with all the data filled into an octree. This container will deposit particle fields onto octs using a kernel and SPH smoothing. The octree is built in a depth-first fashion. Depth-first search (DFS) means that tree starts refining at the root node (this is the largest node which contains every particles) and refines as far as possible along each branch before backtracking.

Parameters
• right_edge (array_like) – The right edge of the region to be extracted. Specify units by supplying a YTArray, otherwise code length units are assumed.

• left_edge (array_like) – The left edge of the region to be extracted. Specify units by supplying a YTArray, otherwise code length units are assumed.

• n_ref (int) – This is the maximum number of particles per leaf in the resulting octree.

• ptypes (list) – This is the type of particles to include when building the tree. This will default to all particles.

Examples

octree = ds.octree(n_ref=64) x_positions_of_cells = octree[(‘index’, ‘x’)] y_positions_of_cells = octree[(‘index’, ‘y’)] z_positions_of_cells = octree[(‘index’, ‘z’)] density_of_gas_in_cells = octree[(‘gas’, ‘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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> flux = dd.calculate_isocontour_flux(
...     ("gas", "density"),
...     rho,
...     ("gas", "velocity_x"),
...     ("gas", "velocity_y"),
...     ("gas", "velocity_z"),
...     ("gas", "metallicity"),
... )

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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

cut_region(field_cuts, field_parameters=None, locals=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[(‘gas’, ‘temperature’)] < 1e3”]

• field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

• locals (dictionary) – A dictionary of local variables to use when defining the cut region.

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.cut_region(["obj[('gas', 'temperature')] > 1e6"])
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_above(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is above a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_below(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is below a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field below the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_below(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_equal(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field are equal to given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are inside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_nan(field, units=None)

This function will return a YTCutRegion where all of the regions whose field is NaN are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the NaN entries of the field masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are outside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> verts = dd.extract_isocontours(
...     ("gas", "density"), rho, "triangles.obj", True
... )

property fcoords
property fcoords_vertex
property fwidth
get_bbox()

Return the bounding box for this data container.

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.

property icoords
include_above(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is above a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_below(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is below a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with only regions with the field below the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_below(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_equal(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field are equal to given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are inside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are outside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property selector
set_field_parameter(name, val)

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

property sph_normalize
property sph_num_neighbors
property sph_smoothing_style
std(field, weight=None)

Compute the standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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.

property tree

The Cython+Python octree instance

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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

class yt.data_objects.construction_data_containers.YTParticleProj(field, axis, weight_field=None, center=None, ds=None, data_source=None, style=None, method='integrate', field_parameters=None, max_level=None)[source]

A projection operation optimized for SPH particle data.

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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

property fcoords
property fcoords_vertex
property field
property 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.

property icoords
property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
plot(fields=None)
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property 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 standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

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(("gas", "density"), 0)
>>> frb = proj.to_frb((100.0, "kpc"), 1024)
>>> write_image(np.log10(frb[("gas", "density")]), "density_100kpc.png")

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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')

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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

class yt.data_objects.construction_data_containers.YTProj(field, axis, weight_field=None, center=None, ds=None, data_source=None, style=None, method='integrate', field_parameters=None, max_level=None)[source]
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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

property fcoords
property fcoords_vertex
property field
property 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.

property icoords
property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
plot(fields=None)[source]
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property 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 standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

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(("gas", "density"), 0)
>>> frb = proj.to_frb((100.0, "kpc"), 1024)
>>> write_image(np.log10(frb[("gas", "density")]), "density_100kpc.png")

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

class yt.data_objects.construction_data_containers.YTQuadTreeProj(field, axis, weight_field=None, center=None, ds=None, data_source=None, style=None, method='integrate', field_parameters=None, max_level=None)[source]

This is a data object corresponding to a line integral through the simulation domain.

This object is typically accessed through the proj object that hangs off of index objects. YTQuadTreeProj is a projection of a field along an axis. The field can have an associated weight_field, in which case the values are multiplied by a weight before being summed, and then divided by the sum of that weight; the two fundamental modes of operating are direct line integral (no weighting) and average along a line of sight (weighting.) What makes proj different from the standard projection mechanism is that it utilizes a quadtree data structure, rather than the old mechanism for projections. It will not run in parallel, but serial runs should be substantially faster. Note also that lines of sight are integrated at every projected finest-level cell.

Parameters
• field (string) – This is the field which will be “projected” along the axis. If multiple are specified (in a list) they will all be projected in the first pass.

• axis (int) – The axis along which to slice. Can be 0, 1, or 2 for x, y, z.

• weight_field (string) – If supplied, the field being projected will be multiplied by this weight value before being integrated, and at the conclusion of the projection the resultant values will be divided by the projected weight_field.

• center (array_like, optional) – The ‘center’ supplied to fields that use it. Note that this does not have to have coord as one value. Strictly optional.

• data_source (yt.data_objects.data_containers.YTSelectionContainer, optional) – If specified, this will be the data source used for selecting regions to project.

• method (string, optional) – The method of projection to be performed. “integrate” : integration along the axis “mip” : maximum intensity projection “sum” : same as “integrate”, except that we don’t multiply by the path length WARNING: The “sum” option should only be used for uniform resolution grid datasets, as other datasets may result in unphysical images.

• style (string, optional) – The same as the method keyword. Deprecated as of version 3.0.2. Please use method keyword instead.

• field_parameters (dict of items) – Values to be passed as field parameters that can be accessed by generated fields.

Examples

>>> ds = load("RedshiftOutput0005")
>>> prj = ds.proj(("gas", "density"), 0)
>>> print(proj[("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

deserialize(fields)[source]
property fcoords
property fcoords_vertex
property field
property 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.

property icoords
property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
plot(fields=None)
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property selector
serialize()[source]
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 standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

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(("gas", "density"), 0)
>>> frb = proj.to_frb((100.0, "kpc"), 1024)
>>> write_image(np.log10(frb[("gas", "density")]), "density_100kpc.png")

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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')

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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

class yt.data_objects.construction_data_containers.YTSmoothedCoveringGrid(*args, **kwargs)[source]

A 3D region with all data extracted and interpolated to a single, specified resolution. (Identical to covering_grid, except that it interpolates.)

Smoothed covering grids start at level 0, interpolating to fill the region to level 1, replacing any cells actually covered by level 1 data, and then recursively repeating this process until it reaches the specified level.

Parameters
• level (int) – The resolution level data is uniformly gridded at

• left_edge (array_like) – The left edge of the region to be extracted

• dims (array_like) – Number of cells along each axis of resulting covering_grid.

• fields (array_like, optional) – A list of fields that you’d like pre-generated for your object

Example

cube = ds.smoothed_covering_grid(2, left_edge=[0.0, 0.0, 0.0], dims=[128, 128, 128])

property LeftEdge
property RightEdge
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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> flux = dd.calculate_isocontour_flux(
...     ("gas", "density"),
...     rho,
...     ("gas", "velocity_x"),
...     ("gas", "velocity_y"),
...     ("gas", "velocity_z"),
...     ("gas", "metallicity"),
... )

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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

cut_region(field_cuts, field_parameters=None, locals=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[(‘gas’, ‘temperature’)] < 1e3”]

• field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

• locals (dictionary) – A dictionary of local variables to use when defining the cut region.

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.cut_region(["obj[('gas', 'temperature')] > 1e6"])
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

deposit(positions, fields=None, method=None, kernel_name='cubic')
exclude_above(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is above a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_below(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is below a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field below the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_below(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_equal(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field are equal to given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are inside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_nan(field, units=None)

This function will return a YTCutRegion where all of the regions whose field is NaN are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the NaN entries of the field masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are outside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> verts = dd.extract_isocontours(
...     ("gas", "density"), rho, "triangles.obj", True
... )

property fcoords
property fcoords_vertex
filename = None
property fwidth
get_bbox()

Return the bounding box for this data container.

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.

get_global_startindex()

Get the global start index of the covering grid.

has_field_parameter(name)

Checks if a field parameter is set.

has_key(key)

Checks if a data field already exists.

property icoords
include_above(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is above a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_below(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is below a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with only regions with the field below the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_below(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_equal(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field are equal to given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are inside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are outside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property selector
set_field_parameter(name, val)

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

property shape
std(field, weight=None)

Compute the standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

to_fits_data(fields, length_unit=None)

Export a set of gridded fields to a FITS file.

This will export a set of FITS images of either the fields specified or all the fields already in the object.

Parameters
• fields (list of strings) – These fields will be pixelized and output. If “None”, the keys of the FRB will be used.

• length_unit (string, optional) – the length units that the coordinates are written in. The default is to use the default length unit of the dataset.

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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_xarray(fields=None)

Export this fixed-resolution object to an xarray Dataset

This function will take a regularized grid and optionally a list of fields and return an xarray Dataset object. If xarray 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

arr – The data contained in the object.

Return type

Dataset

Examples

>>> dd = ds.r[::256j, ::256j, ::256j]
>>> xf1 = dd.to_xarray([("gas", "density"), ("gas", "temperature")])
>>> dd[("gas", "velocity_magnitude")]
>>> xf2 = dd.to_xarray()

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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

write_to_gdf(gdf_path, fields, nprocs=1, field_units=None, **kwargs)

Write the covering grid data to a GDF file.

Parameters
• gdf_path (string) – Pathname of the GDF file to write.

• fields (list of strings) – Fields to write to the GDF file.

• nprocs (integer, optional) – Split the covering grid into nprocs subgrids before writing to the GDF file. Default: 1

• field_units (dictionary, optional) – Dictionary of units to convert fields to. If not set, fields are in their default units.

• remaining keyword arguments are passed to (All) –

• yt.utilities.grid_data_format.writer.write_to_gdf.

Examples

>>> cube.write_to_gdf(
...     "clumps.h5",
...     [("gas", "density"), ("gas", "temperature")],
...     nprocs=16,
...     overwrite=True,
... )

class yt.data_objects.construction_data_containers.YTStreamline(positions, length=1.0, fields=None, ds=None, **kwargs)[source]

This is a streamline, which is a set of points defined as being parallel to some vector field.

This object is typically accessed through the Streamlines.path function. 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
• positions (array-like) – List of streamline positions

• length (float) – The magnitude of the distance; dts will be divided by this

• fields (list of strings, optional) – If you want the object to pre-retrieve a set of fields, supply them here. This is not necessary.

• ds (dataset object) – Passed in to access the index

• kwargs (dict of items) – Any additional values are passed as field parameters that can be accessed by generated fields.

Examples

>>> from yt.visualization.api import Streamlines
>>> streamlines = Streamlines(ds, [0.5] * 3)
>>> streamlines.integrate_through_volume()
>>> stream = streamlines.path(0)
>>> fig, ax = plt.subplots()
>>> ax.set_yscale("log")
>>> ax.plot(stream["t"], stream[("gas", "density")], "-x")

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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property 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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

property fcoords
property fcoords_vertex
property 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.

property icoords
property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property selector
set_field_parameter(name, val)

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

sort_by = 't'
std(field, weight=None)

Compute the standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])

class yt.data_objects.construction_data_containers.YTSurface(data_source, surface_field, field_value, ds=None)[source]

This surface object 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 object 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.) The object has the properties .vertices and will sample values if a field is requested. The values are interpolated to the center of a given face.

Parameters
• data_source (YTSelectionContainer) – This is the object which will used as a source

• surface_field (string) – Any field that can be obtained in a data object. This is the field which will be isocontoured.

• field_value (float, YTQuantity, or unit tuple) – The value at which the isocontour should be calculated.

Examples

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

>>> from yt.units import kpc
>>> sp = ds.sphere("max", (10, "kpc"))
>>> surf = ds.surface(sp, ("gas", "density"), 5e-27)
>>> print(surf[("gas", "temperature")])
>>> print(surf.vertices)
>>> bounds = [
...     (sp.center[i] - 5.0 * kpc, sp.center[i] + 5.0 * kpc) for i in range(3)
... ]
>>> surf.export_ply("my_galaxy.ply", bounds=bounds)

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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> max_rho_xyz = reg.argmax(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmax(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmax(("gas", "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(
...     ("gas", "density"), axis=("gas", "temperature")
... )
>>> min_rho_xyz = reg.argmin(("gas", "density"))
>>> t_mrho, v_mrho = reg.argmin(
...     ("gas", "density"),
...     axis=[("gas", "temperature"), ("gas", "velocity_magnitude")],
... )
>>> x, y, z = reg.argmin(("gas", "density"))

property blocks
calculate_flux(field_x, field_y, field_z, fluxing_field=None)[source]

This calculates the flux over the surface.

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_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.

Return type

YTQuantity

References

Examples

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

>>> sp = ds.sphere("max", (10, "kpc"))
>>> surf = ds.surface(sp, ("gas", "density"), 5e-27)
>>> flux = surf.calculate_flux(
...     ("gas", "velocity_x"),
...     ("gas", "velocity_y"),
...     ("gas", "velocity_z"),
...     ("gas", "metal_density"),
... )

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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> flux = dd.calculate_isocontour_flux(
...     ("gas", "density"),
...     rho,
...     ("gas", "velocity_x"),
...     ("gas", "velocity_y"),
...     ("gas", "velocity_z"),
...     ("gas", "metallicity"),
... )

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[("gas", "density")]
>>> print(sp.field_data.keys())
[("gas", "density")]
>>> print(sp_clone.field_data.keys())
[]

comm = None
create_firefly_object(path_to_firefly, fields_to_include=None, fields_units=None, default_decimation_factor=100, velocity_units='km/s', coordinate_units='kpc', show_unused_fields=0, dataset_name='yt')

This function links a region of data stored in a yt dataset to the Python frontend API for [Firefly](github.com/ageller/Firefly), a browser-based particle visualization platform.

Parameters
• path_to_firefly (string) – The (ideally) absolute path to the direction containing the index.html file of Firefly.

• fields_to_include (array_like of strings) – A list of fields that you want to include in your Firefly visualization for on-the-fly filtering and colormapping.

• default_decimation_factor (integer) – The factor by which you want to decimate each particle group by (e.g. if there are 1e7 total particles in your simulation you might want to set this to 100 at first). Randomly samples your data like shuffled_data[::decimation_factor] so as to not overtax a system. This is adjustable on a per particle group basis by changing the returned reader’s reader.particleGroup[i].decimation_factor before calling reader.dumpToJSON().

• velocity_units (string) – The units that the velocity should be converted to in order to show streamlines in Firefly. Defaults to km/s.

• coordinate_units (string) – The units that the coordinates should be converted to. Defaults to kpc.

• show_unused_fields (boolean) – A flag to optionally print the fields that are available, in the dataset but were not explicitly requested to be tracked.

• dataset_name (string) – The name of the subdirectory the JSON files will be stored in (and the name that will appear in startup.json and in the dropdown menu at startup). e.g. yt -> json files will appear in Firefly/data/yt.

Returns

Return type

Examples

>>> ramses_ds = yt.load(
...     "/Users/agurvich/Desktop/yt_workshop/"
...     + "DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt"
... )

>>> region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc"))

>>> reader = region.create_firefly_object(
...     path_to_firefly="/Users/agurvich/research/repos/Firefly",
...     fields_to_include=[
...         "particle_extra_field_1",
...         "particle_extra_field_2",
...     ],
...     fields_units=["dimensionless", "dimensionless"],
...     dataset_name="IsoGalaxyRamses",
... )

>>> reader.options["color"]["io"] = [1, 1, 0, 1]

cut_region(field_cuts, field_parameters=None, locals=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[(‘gas’, ‘temperature’)] < 1e3”]

• field_parameters (dictionary) – A dictionary of field parameters to be used when applying the field cuts.

• locals (dictionary) – A dictionary of local variables to use when defining the cut region.

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.cut_region(["obj[('gas', 'temperature')] > 1e6"])
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_above(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is above a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_below(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field is below a given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field below the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_below(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_equal(field, value, units=None)

This function will return a YTCutRegion where all of the regions whose field are equal to given value are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are inside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_nan(field, units=None)

This function will return a YTCutRegion where all of the regions whose field is NaN are masked.

Parameters
• field (string) – The field in which the conditional will be applied.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the NaN entries of the field masked.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

exclude_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where all of the regions whose field are outside the interval from min_value to max_value.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

export_blender(transparency=1.0, dist_fac=None, color_field=None, emit_field=None, color_map=None, color_log=True, emit_log=True, plot_index=None, color_field_max=None, color_field_min=None, emit_field_max=None, emit_field_min=None)[source]

This exports the surface to the OBJ format, suitable for visualization in many different programs (e.g., Blender). NOTE: this exports an .obj file and an .mtl file, both with the general ‘filename’ as a prefix. The .obj file points to the .mtl file in its header, so if you move the 2 files, make sure you change the .obj header to account for this. ALSO NOTE: the emit_field needs to be a combination of the other 2 fields used to have the emissivity track with the color.

Parameters
• transparency (float) – This gives the transparency of the output surface plot. Values from 0.0 (invisible) to 1.0 (opaque).

• dist_fac (float) – Divide the axes distances by this amount.

• color_field (string) – Should a field be sample and colormapped?

• emit_field (string) –

Should we track the emissivity of a field?

NOTE: this should be a combination of the other 2 fields being used.

• color_map (string) – Which color map should be applied?

• color_log (bool) – Should the color field be logged before being mapped?

• emit_log (bool) – Should the emitting field be logged before being mapped?

• plot_index (integer) – Index of plot for multiple plots. If none, then only 1 plot.

• color_field_max (float) – Maximum value of the color field across all surfaces.

• color_field_min (float) – Minimum value of the color field across all surfaces.

• emit_field_max (float) – Maximum value of the emitting field across all surfaces.

• emit_field_min (float) – Minimum value of the emitting field across all surfaces.

Examples

>>> sp = ds.sphere("max", (10, "kpc"))
>>> trans = 1.0
>>> surf = ds.surface(sp, ("gas", "density"), 5e-27)
>>> surf.export_obj("my_galaxy", transparency=trans)

>>> sp = ds.sphere("max", (10, "kpc"))
>>> mi, ma = sp.quantities.extrema("temperature")[0]
>>> rhos = [1e-24, 1e-25]
>>> trans = [0.5, 1.0]
>>> for i, r in enumerate(rhos):
...     surf = ds.surface(sp, "density", r)
...     surf.export_obj(
...         "my_galaxy",
...         transparency=trans[i],
...         color_field="temperature",
...         plot_index=i,
...         color_field_max=ma,
...         color_field_min=mi,
...     )

>>> sp = ds.sphere("max", (10, "kpc"))
>>> rhos = [1e-24, 1e-25]
>>> trans = [0.5, 1.0]
>>> def _Emissivity(field, data):
...     return (
...         data[("gas", "density")]
...         * data[("gas", "density")]
...         * np.sqrt(data[("gas", "temperature")])
...     )
>>> ds.add_field("emissivity", function=_Emissivity, units="g / cm**6")
>>> for i, r in enumerate(rhos):
...     surf = ds.surface(sp, "density", r)
...     surf.export_obj(
...         "my_galaxy",
...         transparency=trans[i],
...         color_field="temperature",
...         emit_field="emissivity",
...         plot_index=i,
...     )

export_obj(filename, transparency=1.0, dist_fac=None, color_field=None, emit_field=None, color_map=None, color_log=True, emit_log=True, plot_index=None, color_field_max=None, color_field_min=None, emit_field_max=None, emit_field_min=None)[source]

Export the surface to the OBJ format

Suitable for visualization in many different programs (e.g., Blender). NOTE: this exports an .obj file and an .mtl file, both with the general ‘filename’ as a prefix. The .obj file points to the .mtl file in its header, so if you move the 2 files, make sure you change the .obj header to account for this. ALSO NOTE: the emit_field needs to be a combination of the other 2 fields used to have the emissivity track with the color.

Parameters
• filename (string) – The file this will be exported to. This cannot be a file-like object. If there are no file extentions included - both obj & mtl files are created.

• transparency (float) – This gives the transparency of the output surface plot. Values from 0.0 (invisible) to 1.0 (opaque).

• dist_fac (float) – Divide the axes distances by this amount.

• color_field (string) – Should a field be sample and colormapped?

• emit_field (string) – Should we track the emissivity of a field? This should be a combination of the other 2 fields being used.

• color_map (string) – Which color map should be applied?

• color_log (bool) – Should the color field be logged before being mapped?

• emit_log (bool) – Should the emitting field be logged before being mapped?

• plot_index (integer) – Index of plot for multiple plots. If none, then only 1 plot.

• color_field_max (float) – Maximum value of the color field across all surfaces.

• color_field_min (float) – Minimum value of the color field across all surfaces.

• emit_field_max (float) – Maximum value of the emitting field across all surfaces.

• emit_field_min (float) – Minimum value of the emitting field across all surfaces.

Examples

>>> sp = ds.sphere("max", (10, "kpc"))
>>> trans = 1.0
>>> surf = ds.surface(sp, ("gas", "density"), 5e-27)
>>> surf.export_obj("my_galaxy", transparency=trans)

>>> sp = ds.sphere("max", (10, "kpc"))
>>> mi, ma = sp.quantities.extrema("temperature")
>>> rhos = [1e-24, 1e-25]
>>> trans = [0.5, 1.0]
>>> for i, r in enumerate(rhos):
...     surf = ds.surface(sp, "density", r)
...     surf.export_obj(
...         "my_galaxy",
...         transparency=trans[i],
...         color_field="temperature",
...         plot_index=i,
...         color_field_max=ma,
...         color_field_min=mi,
...     )

>>> sp = ds.sphere("max", (10, "kpc"))
>>> rhos = [1e-24, 1e-25]
>>> trans = [0.5, 1.0]
>>> def _Emissivity(field, data):
...     return (
...         data[("gas", "density")]
...         * data[("gas", "density")]
...         * np.sqrt(data[("gas", "temperature")])
...     )
...     "emissivity",
...     function=_Emissivity,
...     sampling_type="cell",
...     units=r"g**2*sqrt(K)/cm**6",
... )
>>> for i, r in enumerate(rhos):
...     surf = ds.surface(sp, "density", r)
...     surf.export_obj(
...         "my_galaxy",
...         transparency=trans[i],
...         color_field="temperature",
...         emit_field="emissivity",
...         plot_index=i,
...     )

export_ply(filename, bounds=None, color_field=None, color_map=None, color_log=True, sample_type='face', no_ghost=False)[source]

This exports the surface to the PLY format, suitable for visualization in many different programs (e.g., MeshLab).

Parameters
• filename (string) – The file this will be exported to. This cannot be a file-like object.

• bounds (list of tuples) – The bounds the vertices will be normalized to. This is of the format: [(xmin, xmax), (ymin, ymax), (zmin, zmax)]. Defaults to the full domain.

• color_field (string) – Should a field be sample and colormapped?

• color_map (string) – Which color map should be applied?

• color_log (bool) – Should the color field be logged before being mapped?

Examples

>>> from yt.units import kpc
>>> sp = ds.sphere("max", (10, "kpc"))
>>> surf = ds.surface(sp, ("gas", "density"), 5e-27)
>>> print(surf[("gas", "temperature")])
>>> print(surf.vertices)
>>> bounds = [
...     (sp.center[i] - 5.0 * kpc, sp.center[i] + 5.0 * kpc) for i in range(3)
... ]
>>> surf.export_ply("my_galaxy.ply", bounds=bounds)

export_sketchfab(title, description, api_key=None, color_field=None, color_map=None, color_log=True, bounds=None, no_ghost=False)[source]

This exports Surfaces to SketchFab.com, where they can be viewed interactively in a web browser.

SketchFab.com is a proprietary web service that provides WebGL rendering of models. This routine will use temporary files to construct a compressed binary representation (in .PLY format) of the Surface and any optional fields you specify and upload it to SketchFab.com. It requires an API key, which can be found on your SketchFab.com dashboard. You can either supply the API key to this routine directly or you can place it in the variable “sketchfab_api_key” in your ~/.config/yt/yt.toml file. This function is parallel-safe.

Parameters
• title (string) – The title for the model on the website

• description (string) – How you want the model to be described on the website

• api_key (string) – Optional; defaults to using the one in the config file

• color_field (string) – If specified, the field by which the surface will be colored

• color_map (string) – The name of the color map to use to map the color field

• color_log (bool) – Should the field be logged before being mapped to RGB?

• bounds (list of tuples) – [ (xmin, xmax), (ymin, ymax), (zmin, zmax) ] within which the model will be scaled and centered. Defaults to the full domain.

Returns

URL – The URL at which your model can be viewed.

Return type

string

Examples

>>> from yt.units import kpc
>>> dd = ds.sphere("max", (200, "kpc"))
>>> rho = 5e-27
>>> bounds = [
...     (dd.center[i] - 100.0 * kpc, dd.center[i] + 100.0 * kpc)
...     for i in range(3)
... ]
...
>>> surf = ds.surface(dd, ("gas", "density"), rho)
>>> rv = surf.export_sketchfab(
...     description="A simple test of the uploader",
...     color_field="temperature",
...     color_map="hot",
...     color_log=True,
...     bounds=bounds,
... )
...

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"](
...     ("gas", "density"), weight=("gas", "cell_mass")
... )
>>> verts = dd.extract_isocontours(
...     ("gas", "density"), rho, "triangles.obj", True
... )

property fcoords
property fcoords_vertex
property fwidth
get_bbox()

Return the bounding box for this data container.

get_data(fields=None, sample_type='face', no_ghost=False)[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.

property icoords
include_above(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is above a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field above the given value masked.

Return type

YTCutRegion

Examples

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

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_above(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_below(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field is below a given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with only regions with the field below the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_below(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_equal(field, value, units=None)

This function will return a YTCutRegion where only the regions whose field are equal to given value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• value (float) – The minimum value that will not be masked in the output YTCutRegion.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field equal to the given value included.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_equal(("gas", "temperature"), 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_inside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are inside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field inside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.include_inside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

include_outside(field, min_value, max_value, units=None)

This function will return a YTCutRegion where only the regions whose field are outside the interval from min_value to max_value are included.

Parameters
• field (string) – The field in which the conditional will be applied.

• min_value (float) – The minimum value inside the interval to be excluded.

• max_value (float) – The maximum value inside the interval to be excluded.

• units (string or None) – The units of the value threshold. None will use the default units given in the field.

Returns

cut_region – The YTCutRegion with the field outside the given interval excluded.

Return type

YTCutRegion

Examples

>>> ds = yt.load("RedshiftOutput0005")
>>> cr = ad.exclude_outside(("gas", "temperature"), 1e5, 1e6)
>>> print(cr.quantities.total_quantity(("gas", "cell_mass")).in_units("Msun"))

property 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(("gas", "density"), axis=("index", "z"))

property 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(("gas", "temperature"))
>>> max_temp_proj = reg.max(("gas", "temperature"), axis=("index", "x"))

property max_level
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(("gas", "density"), weight="cell_volume")
>>> rho_weighted_T = reg.mean(
...     ("gas", "temperature"), axis=("index", "y"), weight=("gas", "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(("gas", "temperature"))

property min_level
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.

property pf
profile(bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field='gas', '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")
...     [("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(("gas", "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
>>> sp = ds.sphere(ds.domain_center, (10, "Mpc"))
>>> fn = sp.save_as_dataset(fields=[("gas", "density"), ("gas", "temperature")])
>>> # the original data container is available as the data attribute
>>> print(sds.data[("gas", "density")])
[  4.46237613e-32   4.86830178e-32   4.46335118e-32 ...,   6.43956165e-30
3.57339907e-30   2.83150720e-30] g/cm**3
[  1.00000000e+00   1.00000000e+00   1.00000000e+00 ...,   4.40108359e+04
4.54380547e+04   4.72560117e+04] K

property 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 standard deviation of a field.

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

Parameters
• field (string or tuple field name) – The field to calculate the standard deviation of

• weight (string or tuple field name) – The field to weight the standard deviation 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(("index", "ones"), axis=("index", "x"))

property surface_area
property tiles
to_astropy_table(fields)

Export region data to a :class:~astropy.table.table.QTable, which is a Table object which is unit-aware. The QTable can then be exported to an ASCII file, FITS file, etc.

See the AstroPy Table docs for more details: http://docs.astropy.org/en/stable/table/

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the QTable.

Examples

>>> sp = ds.sphere("c", (1.0, "Mpc"))
>>> t = sp.to_astropy_table([("gas", "density"), ("gas", "temperature")])

to_dataframe(fields)

Export a data object to a DataFrame.

This function will take a data object and an optional list of fields and export them to a DataFrame object. If pandas is not importable, this will raise ImportError.

Parameters

fields (list of strings or tuple field names) – This is the list of fields to be exported into the DataFrame.

Returns

df – The data contained in the object.

Return type

DataFrame

Examples

>>> dd = ds.all_data()
>>> df = dd.to_dataframe([("gas", "density"), ("gas", "temperature")])

to_glue(fields, label='yt', data_collection=None)

Takes specific fields in the container and exports them to Glue (http://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.

property triangles
property vertices
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')

Write out the YTDataContainer object in a text file.

This function will take a data object and produce a tab delimited text file containing the fields presently existing and the fields given in the fields list.

Parameters
• filename (String) – The name of the file to write to.

• fields (List of string, Default = None) – If this is supplied, these fields will be added to the list of fields to be saved to disk. If not supplied, whatever fields presently exist will be used.

• format (String, Default = "%0.16e") – Format of numbers to be written in the file.

Raises
• ValueError – Raised when there is no existing field.

• YTException – Raised when field_type of supplied fields is inconsistent with the field_type of existing fields.

Examples

>>> ds = fake_particle_ds()
>>> sp = ds.sphere(ds.domain_center, 0.25)
>>> sp.write_out("sphere_1.txt")
>>> sp.write_out("sphere_2.txt", fields=["cell_volume"])