yt.data_objects.profiles module

class yt.data_objects.profiles.ParticleProfile(data_source, x_field, x_n, x_min, x_max, x_log, y_field, y_n, y_min, y_max, y_log, weight_field=None, deposition='ngp')[source]

Bases: Profile2D

An object that represents a deposited 2D profile. This is like a Profile2D, except that it is intended for particle data. Instead of just binning the particles, the added fields will be deposited onto the mesh using either the nearest-grid-point or cloud-in-cell interpolation kernels.

Parameters:
  • data_source (AMD3DData object) – The data object to be profiled

  • x_field (string field name) – The field to profile as a function of along the x axis.

  • x_n (integer) – The number of bins along the x direction.

  • x_min (float) – The minimum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_max (float) – The maximum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • y_field (string field name) – The field to profile as a function of along the y axis

  • y_n (integer) – The number of bins along the y direction.

  • y_min (float) – The minimum value of the y profile field. If supplied without units, assumed to be in the output units for y_field.

  • y_max (float) – The maximum value of the y profile field. If supplied without units, assumed to be in the output units for y_field.

  • weight_field (string field name) – The field to use for weighting. Default is None.

  • deposition (string, optional) – The interpolation kernel to be used for deposition. Valid choices: “ngp” : nearest grid point interpolation “cic” : cloud-in-cell interpolation

accumulation = False
add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
fractional = False
get_dependencies(fields)
items()
keys()
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.

plot()

This returns a :class:~yt.visualization.profile_plotter.PhasePlot with the fields that have been added to this object.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_y_unit(new_unit)

Sets a new unit for the y field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

class yt.data_objects.profiles.Profile1D(data_source, x_field, x_n, x_min, x_max, x_log, weight_field=None, override_bins_x=None)[source]

Bases: ProfileND

An object that represents a 1D profile.

Parameters:
  • data_source (AMD3DData object) – The data object to be profiled

  • x_field (string field name) – The field to profile as a function of

  • x_n (integer) – The number of bins along the x direction.

  • x_min (float) – The minimum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_max (float) – The maximum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_log (boolean) – Controls whether or not the bins for the x field are evenly spaced in linear (False) or log (True) space.

  • weight_field (string field name) – The field to weight the profiled fields by.

  • override_bins_x (array) – Array to set as xbins and ignore other parameters if set

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
get_dependencies(fields)
items()
keys()
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.

plot()[source]

This returns a ProfilePlot with the fields that have been added to this object.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)[source]

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

to_astropy_table(fields=None, only_used=False, include_std=False)[source]

Export the profile data to a 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, default None) – If this is supplied, it is the list of fields to be exported into the DataFrame. If not supplied, whatever fields exist in the profile, along with the bin field, will be exported.

  • only_used (boolean, optional) – If True, only the bins which are used are copied to the QTable as rows. If False, all bins are copied, but the bins which are not used are masked. Default: False

  • include_std (boolean, optional) – If True, include the standard deviation of the profile in the AstroPy QTable. It will appear in the table as the field name with “_stddev” appended, e.g. “velocity_x_stddev”. Default: False

Returns:

qt – The data contained in the profile.

Return type:

QTable

Examples

>>> sp = ds.sphere("c", (0.1, "unitary"))
>>> p = sp.profile(
...     ("index", "radius"), [("gas", "density"), ("gas", "temperature")]
... )
>>> qt1 = p.to_astropy_table()
>>> qt2 = p.to_astropy_table(fields=("gas", "density"), only_used=True)
to_dataframe(fields=None, only_used=False, include_std=False)[source]

Export a profile object to a pandas DataFrame.

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

Parameters:
  • fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the DataFrame. If not supplied, whatever fields exist in the profile, along with the bin field, will be exported.

  • only_used (boolean, default False) – If True, only the bins which have data will be exported. If False, all the bins will be exported, but the elements for those bins in the data arrays will be filled with NaNs.

  • include_std (boolean, optional) – If True, include the standard deviation of the profile in the pandas DataFrame. It will appear in the table as the field name with “_stddev” appended, e.g. “velocity_x_stddev”. Default: False

Returns:

df – The data contained in the profile.

Return type:

DataFrame

Examples

>>> sp = ds.sphere("c", (0.1, "unitary"))
>>> p = sp.profile(
...     ("index", "radius"), [("gas", "density"), ("gas", "temperature")]
... )
>>> df1 = p.to_dataframe()
>>> df2 = p.to_dataframe(fields=("gas", "density"), only_used=True)
class yt.data_objects.profiles.Profile1DFromDataset(ds)[source]

Bases: ProfileNDFromDataset, Profile1D

A 1D profile object loaded from a ytdata dataset.

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
get_dependencies(fields)
items()
keys()
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.

plot()

This returns a ProfilePlot with the fields that have been added to this object.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

to_astropy_table(fields=None, only_used=False, include_std=False)

Export the profile data to a 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, default None) – If this is supplied, it is the list of fields to be exported into the DataFrame. If not supplied, whatever fields exist in the profile, along with the bin field, will be exported.

  • only_used (boolean, optional) – If True, only the bins which are used are copied to the QTable as rows. If False, all bins are copied, but the bins which are not used are masked. Default: False

  • include_std (boolean, optional) – If True, include the standard deviation of the profile in the AstroPy QTable. It will appear in the table as the field name with “_stddev” appended, e.g. “velocity_x_stddev”. Default: False

Returns:

qt – The data contained in the profile.

Return type:

QTable

Examples

>>> sp = ds.sphere("c", (0.1, "unitary"))
>>> p = sp.profile(
...     ("index", "radius"), [("gas", "density"), ("gas", "temperature")]
... )
>>> qt1 = p.to_astropy_table()
>>> qt2 = p.to_astropy_table(fields=("gas", "density"), only_used=True)
to_dataframe(fields=None, only_used=False, include_std=False)

Export a profile object to a pandas DataFrame.

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

Parameters:
  • fields (list of strings or tuple field names, default None) – If this is supplied, it is the list of fields to be exported into the DataFrame. If not supplied, whatever fields exist in the profile, along with the bin field, will be exported.

  • only_used (boolean, default False) – If True, only the bins which have data will be exported. If False, all the bins will be exported, but the elements for those bins in the data arrays will be filled with NaNs.

  • include_std (boolean, optional) – If True, include the standard deviation of the profile in the pandas DataFrame. It will appear in the table as the field name with “_stddev” appended, e.g. “velocity_x_stddev”. Default: False

Returns:

df – The data contained in the profile.

Return type:

DataFrame

Examples

>>> sp = ds.sphere("c", (0.1, "unitary"))
>>> p = sp.profile(
...     ("index", "radius"), [("gas", "density"), ("gas", "temperature")]
... )
>>> df1 = p.to_dataframe()
>>> df2 = p.to_dataframe(fields=("gas", "density"), only_used=True)
class yt.data_objects.profiles.Profile2D(data_source, x_field, x_n, x_min, x_max, x_log, y_field, y_n, y_min, y_max, y_log, weight_field=None, override_bins_x=None, override_bins_y=None)[source]

Bases: ProfileND

An object that represents a 2D profile.

Parameters:
  • data_source (AMD3DData object) – The data object to be profiled

  • x_field (string field name) – The field to profile as a function of along the x axis.

  • x_n (integer) – The number of bins along the x direction.

  • x_min (float) – The minimum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_max (float) – The maximum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_log (boolean) – Controls whether or not the bins for the x field are evenly spaced in linear (False) or log (True) space.

  • y_field (string field name) – The field to profile as a function of along the y axis

  • y_n (integer) – The number of bins along the y direction.

  • y_min (float) – The minimum value of the y profile field. If supplied without units, assumed to be in the output units for y_field.

  • y_max (float) – The maximum value of the y profile field. If supplied without units, assumed to be in the output units for y_field.

  • y_log (boolean) – Controls whether or not the bins for the y field are evenly spaced in linear (False) or log (True) space.

  • weight_field (string field name) – The field to weight the profiled fields by.

  • override_bins_x (array) – Array to set as xbins and ignore other parameters if set

  • override_bins_y (array) – Array to set as ybins and ignore other parameters if set

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
get_dependencies(fields)
items()
keys()
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.

plot()[source]

This returns a :class:~yt.visualization.profile_plotter.PhasePlot with the fields that have been added to this object.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)[source]

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_y_unit(new_unit)[source]

Sets a new unit for the y field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

class yt.data_objects.profiles.Profile2DFromDataset(ds)[source]

Bases: ProfileNDFromDataset, Profile2D

A 2D profile object loaded from a ytdata dataset.

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
get_dependencies(fields)
items()
keys()
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.

plot()

This returns a :class:~yt.visualization.profile_plotter.PhasePlot with the fields that have been added to this object.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_y_unit(new_unit)

Sets a new unit for the y field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

class yt.data_objects.profiles.Profile3D(data_source, x_field, x_n, x_min, x_max, x_log, y_field, y_n, y_min, y_max, y_log, z_field, z_n, z_min, z_max, z_log, weight_field=None, override_bins_x=None, override_bins_y=None, override_bins_z=None)[source]

Bases: ProfileND

An object that represents a 2D profile.

Parameters:
  • data_source (AMD3DData object) – The data object to be profiled

  • x_field (string field name) – The field to profile as a function of along the x axis.

  • x_n (integer) – The number of bins along the x direction.

  • x_min (float) – The minimum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_max (float) – The maximum value of the x profile field. If supplied without units, assumed to be in the output units for x_field.

  • x_log (boolean) – Controls whether or not the bins for the x field are evenly spaced in linear (False) or log (True) space.

  • y_field (string field name) – The field to profile as a function of along the y axis

  • y_n (integer) – The number of bins along the y direction.

  • y_min (float) – The minimum value of the y profile field. If supplied without units, assumed to be in the output units for y_field.

  • y_max (float) – The maximum value of the y profile field. If supplied without units, assumed to be in the output units for y_field.

  • y_log (boolean) – Controls whether or not the bins for the y field are evenly spaced in linear (False) or log (True) space.

  • z_field (string field name) – The field to profile as a function of along the z axis

  • z_n (integer) – The number of bins along the z direction.

  • z_min (float) – The minimum value of the z profile field. If supplied without units, assumed to be in the output units for z_field.

  • z_max (float) – The maximum value of thee z profile field. If supplied without units, assumed to be in the output units for z_field.

  • z_log (boolean) – Controls whether or not the bins for the z field are evenly spaced in linear (False) or log (True) space.

  • weight_field (string field name) – The field to weight the profiled fields by.

  • override_bins_x (array) – Array to set as xbins and ignore other parameters if set

  • override_bins_y (array) – Array to set as xbins and ignore other parameters if set

  • override_bins_z (array) – Array to set as xbins and ignore other parameters if set

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
get_dependencies(fields)
items()
keys()
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.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)[source]

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_y_unit(new_unit)[source]

Sets a new unit for the y field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_z_unit(new_unit)[source]

Sets a new unit for the z field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

class yt.data_objects.profiles.Profile3DFromDataset(ds)[source]

Bases: ProfileNDFromDataset, Profile3D

A 2D profile object loaded from a ytdata dataset.

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

property bounds
comm = None
get_dependencies(fields)
items()
keys()
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.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

set_x_unit(new_unit)

Sets a new unit for the x field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_y_unit(new_unit)

Sets a new unit for the y field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

set_z_unit(new_unit)

Sets a new unit for the z field

Parameters:

new_unit (string or Unit object) – The name of the new unit.

class yt.data_objects.profiles.ProfileFieldAccumulator(n_fields, size)[source]

Bases: object

class yt.data_objects.profiles.ProfileND(data_source, weight_field=None)[source]

Bases: ParallelAnalysisInterface

The profile object class

add_fields(fields)[source]

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

comm = None
get_dependencies(fields)
items()[source]
keys()[source]
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.

save_as_dataset(filename=None)[source]

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)[source]

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

class yt.data_objects.profiles.ProfileNDFromDataset(ds)[source]

Bases: ProfileND

An ND profile object loaded from a ytdata dataset.

add_fields(fields)

Add fields to profile

Parameters:

fields (list of field names) – A list of fields to create profile histograms for

comm = None
get_dependencies(fields)
items()
keys()
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.

save_as_dataset(filename=None)

Export a profile to a reloadable yt dataset.

This function will take a profile and output a dataset containing all relevant fields. 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 plus the type of object, e.g., Profile1D.

Returns:

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

Return type:

str

Examples

>>> import yt
>>> ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = yt.create_profile(
...     ad,
...     [("gas", "density"), ("gas", "temperature")],
...     ("gas", "mass"),
...     weight_field=None,
...     n_bins=(128, 128),
... )
>>> fn = profile.save_as_dataset()
>>> prof_ds = yt.load(fn)
>>> print(prof_ds.data[("gas", "mass")])
(128, 128)
>>> print(prof_ds.data[("index", "x")].shape)  # x bins as 1D array
(128,)
>>> print(prof_ds.data[("gas", "density")])  # x bins as 2D array
(128, 128)
>>> p = yt.PhasePlot(
...     prof_ds.data,
...     ("gas", "density"),
...     ("gas", "temperature"),
...     ("gas", "mass"),
...     weight_field=None,
... )
>>> p.save()
set_field_unit(field, new_unit)

Sets a new unit for the requested field

Parameters:
  • field (string or field tuple) – The name of the field that is to be changed.

  • new_unit (string or Unit object) – The name of the new unit.

yt.data_objects.profiles.create_profile(data_source, bin_fields, fields, n_bins=64, extrema=None, logs=None, units=None, weight_field=('gas', 'mass'), accumulation=False, fractional=False, deposition='ngp', override_bins=None)[source]

Create a 1, 2, or 3D profile object.

The dimensionality of the profile object is chosen by the number of fields given in the bin_fields argument.

Parameters:
  • data_source (YTSelectionContainer Object) – The data object to be profiled.

  • 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. Defaults to (“gas”, “mass”).

  • 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 (bool) – 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 (strings) – 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.

  • override_bins (dict of bins to profile plot with) – If set, ignores n_bins and extrema settings and uses the supplied bins to profile the field. If a units dict is provided, bins are understood to be in the units specified in the dictionary.

Examples

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

>>> ds = load("DD0046/DD0046")
>>> ad = ds.all_data()
>>> profile = create_profile(
...     ad, [("gas", "density")], [("gas", "temperature"), ("gas", "velocity_x")]
... )
>>> print(profile.x)
>>> print(profile["gas", "temperature"])
yt.data_objects.profiles.preserve_source_parameters(func)[source]
yt.data_objects.profiles.sanitize_field_tuple_keys(input_dict, data_source)[source]