yt.fields.derived_field module

yt.fields.derived_field.DeprecatedFieldFunc(ret_field, func, since, removal)[source]
class yt.fields.derived_field.DerivedField(name: tuple[str, str], sampling_type, function, units: str | bytes | Unit | None = None, take_log=True, validators=None, vector_field=False, display_field=True, not_in_all=False, display_name=None, output_units=None, dimensions=None, ds=None, nodal_flag=None, *, alias: DerivedField | None = None)[source]

Bases: object

This is the base class used to describe a cell-by-cell derived field.

Parameters:
  • name (str) – is the name of the field.

  • function (callable) – A function handle that defines the field. Should accept arguments (field, data)

  • units (str) – A plain text string encoding the unit, or a query to a unit system of a dataset. Powers must be in Python syntax (** instead of ^). If set to ‘auto’ or None (default), units will be inferred from the return value of the field function.

  • take_log (bool) – Describes whether the field should be logged

  • validators (list) – A list of FieldValidator objects

  • sampling_type (string, default = "cell") – How is the field sampled? This can be one of the following options at present: “cell” (cell-centered), “discrete” (or “particle”) for discretely sampled data.

  • vector_field (bool) – Describes the dimensionality of the field. Currently unused.

  • display_field (bool) – Governs its appearance in the dropdowns in Reason

  • not_in_all (bool) – Used for baryon fields from the data that are not in all the grids

  • display_name (str) – A name used in the plots

  • output_units (str) – For fields that exist on disk, which we may want to convert to other fields or that get aliased to themselves, we can specify a different desired output unit than the unit found on disk.

  • dimensions (str or object from yt.units.dimensions) – The dimensions of the field, only used for error checking with units=’auto’.

  • nodal_flag (array-like with three components) – This describes how the field is centered within a cell. If nodal_flag is [0, 0, 0], then the field is cell-centered. If any of the components of nodal_flag are 1, then the field is nodal in that direction, meaning it is defined at the lo and hi sides of the cell rather than at the center. For example, a field with nodal_flag = [1, 0, 0] would be defined at the middle of the 2 x-faces of each cell. nodal_flag = [0, 1, 1] would mean the that the field defined at the centers of the 4 edges that are normal to the x axis, while nodal_flag = [1, 1, 1] would be defined at the 8 cell corners.

property alias_field: bool
property alias_name: tuple[str, str] | None
check_available(data)[source]

This raises an exception of the appropriate type if the set of validation mechanisms are not met, and otherwise returns True.

get_dependencies(*args, **kwargs)[source]

This returns a list of names of fields that this field depends on.

get_label(projected=False)[source]

Return a data label for the given field, including units.

get_latex_display_name()[source]
get_projected_units()[source]
get_source()[source]

Return a string containing the source of the function (if possible.)

get_units()[source]
property is_alias: bool
is_alias_to(other: DerivedField) bool[source]
property is_sph_field
property local_sampling
unit_registry(data)[source]
class yt.fields.derived_field.FieldValidator[source]

Bases: object

Base class for FieldValidator objects. Available subclasses include: ValidateParameter, ValidateDataField, ValidateProperty, ValidateSpatial, ValidateGridType

yt.fields.derived_field.NullFunc(field, data)[source]
yt.fields.derived_field.TranslationFunc(field_name)[source]
class yt.fields.derived_field.ValidateDataField(field)[source]

Bases: FieldValidator

A FieldValidator that ensures the output file has a given data field stored in it.

Parameters:

field (str, tuple[str, str], or any iterable of the previous types.) – the field or fields to require

class yt.fields.derived_field.ValidateGridType[source]

Bases: FieldValidator

A FieldValidator that ensures the data handed to the field is an actual grid patch, not a covering grid of any kind. Does not accept parameters.

class yt.fields.derived_field.ValidateParameter(parameters: str | Iterable[str], parameter_values: dict | None = None)[source]

Bases: FieldValidator

A FieldValidator that ensures the dataset has a given parameter.

Parameters:
  • parameters (str, iterable[str]) – a single parameter or list of parameters to require

  • parameter_values (dict) – If parameter_values is supplied, this dict should map from field parameter to a value or list of values. It will ensure that the field is available for all permutations of the field parameter.

class yt.fields.derived_field.ValidateProperty(prop: str | Iterable[str])[source]

Bases: FieldValidator

A FieldValidator that ensures the data object has a given python attribute.

Parameters:

prop (str, iterable[str]) – the required property or properties to require

class yt.fields.derived_field.ValidateSpatial(ghost_zones: int | None = 0, fields=None)[source]

Bases: FieldValidator

A FieldValidator that ensures the data handed to the field is of spatial nature – that is to say, 3-D.

Parameters:
  • ghost_zones (int) – If supplied, will validate that the number of ghost zones required for the field is <= the available ghost zones. Default is 0.

  • fields (Optional str, tuple[str, str], or any iterable of the previous types.) – The field or fields to validate.