yt_xarray.YtAccessor

To use the YtAccessor methods, simply import yt_xarray before loading your dataset. Accessor methods will then be available at ds.yt. For example:

import xarray as xr
import yt_xarray

ds = xr.open_datset(...)
ds.yt.load_grid(...)

The full method definitions are as follows:

class yt_xarray.YtAccessor(xarray_obj)[source]

Bases: object

PhasePlot(x_field: str, y_field: str, z_fields: str | List[str], weight_field: str | None = None, x_bins: int = 128, y_bins: int = 128, accumulation: bool = False, fractional: bool = False, fontsize: int | float = 18, figure_size: int | float = 8.0, shading: str = 'nearest')[source]

Construct a yt.PhasePlot.

Parameters

x_fieldstr

The x binning field for the profile.

y_fieldstr

The y binning field for the profile.

z_fieldsstr or list

The field or fields to be profiled.

weight_fieldstr

The weight field for calculating weighted averages. If None, the profile values are the sum of the field values within the bin. Otherwise, the values are a weighted average. Default : (“gas”, “mass”)

x_binsint

The number of bins in x field for the profile. Default: 128.

y_binsint

The number of bins in y field for the profile. Default: 128.

accumulationbool 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. A list of values can be given to control the summation in each dimension independently. Default: False.

fractionalIf True the profile values are divided by the sum of all

the profile data such that the profile represents a probability distribution function.

fontsizeint

Font size for all text in the plot. Default: 18.

figure_sizeint

Size in inches of the image. Default: 8 (8x8)

shadingstr

This argument is directly passed down to matplotlib.axes.Axes.pcolormesh see https://matplotlib.org/3.3.1/gallery/images_contours_and_fields/pcolormesh_grids.html#sphx-glr-gallery-images-contours-and-fields-pcolormesh-grids-py # noqa Default: ‘nearest’

ProfilePlot(x_field, y_fields, weight_field=None, n_bins=64, accumulation=False, fractional=False, label=None, plot_spec=None, x_log=True, y_log=True)[source]

Construct a yt.ProfilePlot.

Parameters

x_fieldstr

The binning field for the profile.

y_fieldsstr or list

The field or fields to be profiled.

weight_fieldstr

The weight field for calculating weighted averages. If None, the profile values are the sum of the field values within the bin. Otherwise, the values are a weighted average. Default : None

n_binsint

The number of bins in the profile. Default: 64.

accumulationbool

If True, the profile values for a bin N are the cumulative sum of all the values from bin 0 to N. Default: False.

fractionalIf True the profile values are divided by the sum of all

the profile data such that the profile represents a probability distribution function.

labelstr or list of strings

If a string, the label to be put on the line plotted. If a list, this should be a list of labels for each profile to be overplotted. Default: None.

plot_specdict or list of dicts

A dictionary or list of dictionaries containing plot keyword arguments. For example, dict(color=”red”, linestyle=”:”). Default: None.

x_logbool

Whether the x_axis should be plotted with a logarithmic scaling (True), or linear scaling (False). Default: True.

y_logdict or bool

A dictionary containing field:boolean pairs, setting the logarithmic property for that field. May be overridden after instantiation using set_log A single boolean can be passed to signify all fields should use logarithmic (True) or linear scaling (False). Default: True.

Returns

ProjectionPlot(normal, field, **im_kwargs)[source]

Wrapper of yt.ProjectionPlot. For off-axis plots, first construct a yt dataset object with ds.yt.load_grid and then use yt.ProjectionPlot

Parameters

normal: str or int or 3-element tuple

The normal to the slice.

field: str

The field to plot

im_kwargs

any of the keyword arguments accepted by yt.ProjectionPlot

Returns

yt PlotWindow

SlicePlot(normal, field, **im_kwargs)[source]

Wrapper of yt.SlicePlot. For off-axis plots, first construct a yt dataset object with ds.yt.load_grid and then use yt.SlicePlot

Parameters

normal: str or int

The normal to the slice.

field: str

The field to plot

im_kwargs

any additional keyword arguments accepted by yt.SlicePlot

Returns

yt PlotWindow

property geometry: str

the dataset geometry

get_bbox(field: str, sel_dict: dict[str, Any] | None = None, sel_dict_type: str = 'isel') ndarray[tuple[int, ...], dtype[_ScalarType_co]][source]

return the bounding box array for a field, with possible selections

Parameters

field

the field to check the bounding box for

sel_dict: dict

an optional selection dictionary to apply to the fields before yt dataset initialization

sel_dict_type: str

either “isel” (default) or “sel” to indicate index or value selection for sel_dict.

Returns

np.ndarray

an array with shape (3, 2) with the min, max values for each dimension of the coordinates of a field.

load_grid(fields: str | List[str] | None = None, geometry: str | None = None, use_callable: bool = True, sel_dict: dict[str, Any] | None = None, sel_dict_type: str = 'isel', chunksizes: int | _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, **kwargs)[source]

Initializes a yt gridded dataset for the supplied fields.

Parameters

fieldsstr, list[str]

list of fields to include. If None, will try to use all fields

geometrystr

the geometry to pass to yt.load_uniform grid. If not provided, will attempt to infer.

use_callablebool

if True (default), then the yt dataset will utilize links to the open xarray Dataset handle to avoid copying data.

sel_dict: dict

an optional selection dictionary to apply to the fields before yt dataset initialization

sel_dict_type: str

either “isel” (default) or “sel” to indicate index or value selection for sel_dict.

chunksizes: int or ArrayLike

if set, will decompose the grid into multiple grids with grid dimensions of chunksizes. Can be a single integer (same chunksize in each dimensions) or an ArrayLike object of the same length as the number of dimensions.

kwargs :

any additional keyword arguments to pass to yt.load_uniform_grid

Returns

yt StreamDataset

set_geometry(geometry: str)[source]

Set the geometry for the dataset.

Parameters

geometry: str the dataset’s coordinate type. See yt_xarray.valid_geometries for possible values.