Custom Validators and Info Items
In [4]: import numpy as np
import yt
from yt.analysis_modules.level_sets.api import *ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")

Set up the same as before.
In [5]: data_source = ds.disk([0.5, 0.5, 0.5], [0., 0., 1.],
(8, 'kpc'), (1, 'kpc'))
field = ("gas", "density")
step = 2.0
c_min = 10**np.floor(np.log10(data_source[field]).min() )c_max = 10**np.floor(np.log10(data_source[field]).max()+1)
master_clump = Clump(data_source, field)

Make a custom validator function.
The function must take at least one argument.
In [6]: def min_cell_mass(clump, m_min):# clumps are data containers
cell_mass = clump.quantities.total_quantity("cell_mass")
return cell_mass >= m_min

Add this to the list of available validators.
In [7]: add_validator("minimum_cell_mass", min_cell_mass)

Now make this the validator to use here.
In [8]: master_clump.add_validator("minimum_cell_mass", ds.quan(1e7, "Msun"))Make a custom info item to write out for each clump.

This is similar to making a new validator. It is a function that must take at least
one argument.
In [10]: def average_temperature(clump):
t_mean = clump.quantities.weighted_average_quantity("temperature","cell_mass")
return "Mean temperature: %e K." % t_mean

Add this to the list of available info items.
In [11]: add_clump_info("average_temperature", average_temperature)

Now add it to the list of used info items.
In [13]: master_clump.add_info_item("average_temperature")

Begin clump ﬁnding!
In [14]: find_clumps(master_clump, c_min, c_max, step)

Write out clump information.
In [15]: write_clump_index(master_clump, 0, "%s_clump_hierarchy.txt" % ds)
write_clumps(master_clump,0, "%s_clumps.txt" % ds)
In [16]: !cat galaxy0030_clump_hierarchy.txt
Clump at level 0:
Cells: 100134.
Mass: 1.296926e+09 Msun.
Jeans Mass (mass-weighted): 4.746875e+09 Msolar.
Jeans Mass (volume-weighted): 1.223489e+11 Msolar.
Max grid level: 8.
Min number density: 1.661908e-04 cm^-3.
Max number density: 5.601262e+00 cm^-3.
Mean temperature: 1.349015e+04 K.
Mean temperature: 1.349015e+04 K.
Clump at level 1:
Cells: 94.
Mass: 1.784123e+07 Msun.
Jeans Mass (mass-weighted): 6.287895e+07 Msolar.
Jeans Mass (volume-weighted): 6.269044e+07 Msolar.
Max grid level: 8.
Min number density: 3.149490e+00 cm^-3.

Max number density: 4.996931e+00 cm^-3.
Mean temperature: 1.344124e+04 K.
Mean temperature: 1.344124e+04 K.
Clump at level 1:
Cells: 106.
Mass: 2.025443e+07 Msun.
Jeans Mass (mass-weighted): 6.306800e+07 Msolar.
Jeans Mass (volume-weighted): 6.325248e+07 Msolar.
Max grid level: 8.
Min number density: 3.251722e+00 cm^-3.
Max number density: 4.065772e+00 cm^-3.
Mean temperature: 1.426605e+04 K.
Mean temperature: 1.426605e+04 K.
Clump at level 1:
Cells: 104.
Mass: 1.966537e+07 Msun.
Jeans Mass (mass-weighted): 8.874298e+07 Msolar.
Jeans Mass (volume-weighted): 8.754599e+07 Msolar.
Max grid level: 8.
Min number density: 3.161182e+00 cm^-3.
Max number density: 5.285985e+00 cm^-3.
Mean temperature: 1.558691e+04 K.
Mean temperature: 1.558691e+04 K.
Clump at level 1:
Cells: 179.
Mass: 3.434637e+07 Msun.
Jeans Mass (mass-weighted): 8.451847e+07 Msolar.
Jeans Mass (volume-weighted): 8.390353e+07 Msolar.
Max grid level: 8.
Min number density: 3.178488e+00 cm^-3.
Max number density: 5.601262e+00 cm^-3.
Mean temperature: 1.520796e+04 K.
Mean temperature: 1.520796e+04 K.

In [17]: !cat galaxy0030_clumps.txt

Clump:Cells: 94.
Mass: 1.784123e+07 Msun.
Jeans Mass (mass-weighted): 6.287895e+07 Msolar.
Jeans Mass (volume-weighted): 6.269044e+07 Msolar.
Max grid level: 8.
Min number density: 3.149490e+00 cm^-3.
Max number density: 4.996931e+00 cm^-3.
Mean temperature: 1.344124e+04 K.
Mean temperature: 1.344124e+04 K.
Clump:
Cells: 106.
Mass: 2.025443e+07 Msun.
Jeans Mass (mass-weighted): 6.306800e+07 Msolar.
Jeans Mass (volume-weighted): 6.325248e+07 Msolar.
Max grid level: 8.
Min number density: 3.251722e+00 cm^-3.
Max number density: 4.065772e+00 cm^-3.
Mean temperature: 1.426605e+04 K.
Mean temperature: 1.426605e+04 K.
Clump:
Cells: 104.
Mass: 1.966537e+07 Msun.
Jeans Mass (mass-weighted): 8.874298e+07 Msolar.
Jeans Mass (volume-weighted): 8.754599e+07 Msolar.
Max grid level: 8.
Min number density: 3.161182e+00 cm^-3.
Max number density: 5.285985e+00 cm^-3.
Mean temperature: 1.558691e+04 K.
Mean temperature: 1.558691e+04 K.
Clump:
Cells: 179.
Mass: 3.434637e+07 Msun.
Jeans Mass (mass-weighted): 8.451847e+07 Msolar.
Jeans Mass (volume-weighted): 8.390353e+07 Msolar.
Max grid level: 8.
Min number density: 3.178488e+00 cm^-3.
Max number density: 5.601262e+00 cm^-3.
Mean temperature: 1.520796e+04 K.
Mean temperature: 1.520796e+04 K.

Get a list of the leaf clumps and display them in a projection.

In [18]: leaf_clumps = get_lowest_clumps(master_clump)
prj = yt.ProjectionPlot(ds, 2, field, center='c', width=(20,'kpc'))
prj.annotate_clumps(leaf_clumps)
prj.show()In []: