def add_derived_quantity(self, derived_quantity, func, *quantities):
if derived_quantity in self._quantity_modifiers:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(derived_quantity))<EOL><DEDENT>if set(quantities).issubset(self._native_quantities):<EOL><INDENT>new_modifier = (func,) + quantities<EOL><DEDENT>else:<EOL><INDENT>functions = []<EOL>quantities_needed = []<EOL>quantity_count = []<EOL>for q in quantities:<EOL><INDENT>modifier = self.get_normalized_quantity_modifier(q)<EOL>functions.append(modifier[<NUM_LIT:0>])<EOL>quantities_needed.extend(modifier[<NUM_LIT:1>:])<EOL>quantity_count.append(len(modifier)-<NUM_LIT:1>)<EOL><DEDENT>def _new_func(*x):<EOL><INDENT>assert len(x) == sum(quantity_count)<EOL>count_current = <NUM_LIT:0><EOL>new_args = []<EOL>for func_this, count in zip(functions, quantity_count):<EOL><INDENT>new_args.append(func_this(*x[count_current:count_current+count]))<EOL>count_current += count<EOL><DEDENT>return func(*new_args)<EOL><DEDENT>new_modifier = (_new_func,) + tuple(quantities_needed)<EOL><DEDENT>self.add_quantity_modifier(derived_quantity, new_modifier)<EOL>
Add a derived quantify modifier.

Parameters
----------
derived_quantity : str
    name of the derived quantity to be added

func : callable
    function to calculate the derived quantity
    the number of arguments should equal number of following `quantities`

quantities : list of str
    quantities to pass to the callable