Source code for yt.data_objects.level_sets.clump_info_items

import numpy as np

from yt.utilities.operator_registry import OperatorRegistry

clump_info_registry = OperatorRegistry()

[docs]def add_clump_info(name, function): clump_info_registry[name] = ClumpInfoCallback(name, function)
[docs]class ClumpInfoCallback: r""" A ClumpInfoCallback is a function that takes a clump, computes a quantity, and returns a string to be printed out for writing clump info. """ def __init__(self, name, function, args=None, kwargs=None): = name self.function = function self.args = args if self.args is None: self.args = [] self.kwargs = kwargs if self.kwargs is None: self.kwargs = {} def __call__(self, clump): if not in[] = self.function(clump, *self.args, **self.kwargs) rv =[] return rv[0] % rv[1]
def _center_of_mass(clump, units="code_length", **kwargs): p = clump.quantities.center_of_mass(**kwargs) return "Center of mass: %s.", add_clump_info("center_of_mass", _center_of_mass) def _total_cells(clump): n_cells =["index", "ones"].size return "Cells: %d.", n_cells add_clump_info("total_cells", _total_cells) def _cell_mass(clump): cell_mass =["gas", "cell_mass"].sum().in_units("Msun") return "Mass: %e Msun.", cell_mass add_clump_info("cell_mass", _cell_mass) def _mass_weighted_jeans_mass(clump): jeans_mass = "jeans_mass", ("gas", "cell_mass") ).in_units("Msun") return "Jeans Mass (mass-weighted): %.6e Msolar.", jeans_mass add_clump_info("mass_weighted_jeans_mass", _mass_weighted_jeans_mass) def _volume_weighted_jeans_mass(clump): jeans_mass = "jeans_mass", ("index", "cell_volume") ).in_units("Msun") return "Jeans Mass (volume-weighted): %.6e Msolar.", jeans_mass add_clump_info("volume_weighted_jeans_mass", _volume_weighted_jeans_mass) def _max_grid_level(clump): max_level =["index", "grid_level"].max() return "Max grid level: %d.", max_level add_clump_info("max_grid_level", _max_grid_level) def _min_number_density(clump): min_n =["gas", "number_density"].min().in_units("cm**-3") return "Min number density: %.6e cm^-3.", min_n add_clump_info("min_number_density", _min_number_density) def _max_number_density(clump): max_n =["gas", "number_density"].max().in_units("cm**-3") return "Max number density: %.6e cm^-3.", max_n add_clump_info("max_number_density", _max_number_density) def _distance_to_main_clump(clump, units="pc"): master = clump while master.parent is not None: master = master.parent master_com = my_com = distance = np.sqrt(((master_com - my_com) ** 2).sum()) distance.convert_to_units("pc") return ( "Distance from master center of mass: %%.6e %s." % units, distance.in_units(units), ) add_clump_info("distance_to_main_clump", _distance_to_main_clump)