The following example creates a derived field for the square root of the cell volume.
No special unit logic needs to happen inside of the function - np.sqrt will convert the units of the density field appropriately:
That said, it is necessary to specify the units in the call to the
add_field
function. Not only does this ensure the returned units
will be exactly what you expect, it also allows an in-place conversion of units,
just in case the function returns a field with dimensionally equivalent units.
For example, let’s redo the above example but ask for units of
Mpc**(3/2)
: