API#
- equations(equation, **kwargs)#
This function generates a
EquationBase
class holding a requested equation. This should always be used to generate an equation rather than using theEquationBase
class itself.
- class EquationBase(**kwargs)#
Bases:
object
- calculate_fiducial(**kwargs)#
Calculate and return the product of the fiducial components of the equation (excluding the constants) in SI units.
Keyword arguments can be passed using the keys of the
EquationBase.default_fiducial_values
giving the values at which to perform the calculation. Otherwise the default values, or values set at initialisation are used. These can be 1d arrays. If the arrays have different lengths, or the “mesh” keyword argument is given and is True, then a mesh grid will be created over the space and the values returned on that mesh. If arrays of equal length are given, and the “mesh” keyword is not given, then values will be calculated assuming for each set of equivalently positioned values in the array.
- static check_for_alias(key, **kwargs)#
Check whether any alias of the key is given in the keyword arguments.
- property constant#
Return the constant coefficient factor in the equation in SI units (if it has dimensions).
- property eqn#
The equation as a string.
- equation(displaytype='string', nocomment=False, **latexkwargs)#
Generate the LaTeX string for the equation.
- Parameters
displaytype (str) – By default this will return a string containing the LaTeX equation text (without bounding “$” symbols). If using a Jupyter Notebook this will show as a formatted LaTeX equation. Alternatively, set to “matplotlib” to have the output returned as a Matplotlib figure object containing the equation.
nocomment (bool) – By default the output LaTeX string will contain a comment line giving the cweqgen version and call signature from the equations function. To turn this off, set this argument to True.
latexkwargs (dict) – Keyword parameters that can be passed to the
sympy.printing.latex.latex()
function. By default thefold_frac_powers
option is set to True, theroot_notation
option is set to False and the LaTeX symbol names are defined by the equation definition values.
- evaluate(**kwargs)#
Evaluate the equation using the given values.
Keyword arguments can be passed using the keys of the
EquationBase.default_fiducial_values
giving the values at which to perform the calculation. Otherwise the default values, or values set at initialisation are used. These can be 1d arrays, where if more that one value is an array of then a mesh grid will be created over the space and the values returned on that mesh.- Parameters
value (bool) – If value is False (the default) the evaluated equation will be returned as an
astropy.units.Quantity
object. If True just the values will be returned.
- fiducial_equation(dp=2, brackets='()', displaytype='string', nocomment=False, **kwargs)#
Generate the LaTeX string for the equation inserting in fiducial values.
- Parameters
dp (int) – The number of decimal places to use for non-integer fiducial values.
brackets (str) – The style of brackets to use, e.g., “()”, “{}” or “[]”. Defaults is round parentheses “()”.
displaytype (string) – By default this will return a string containing the LaTeX equation text (without bounding “$” symbols). If using a Jupyter Notebook this will show as a formatted LaTeX equation. Alternatively, set to “matplotlib” to have the output returned as a Matplotlib figure object containing the equation.
nocomment (bool) – By default the output LaTeX string will contain a comment line giving the cweqgen version and call signature from the equations function. To turn this off, set this argument to True.
- static generate_parts(eqn, pow=1)#
Generate a list of “parts” from a Sympy equation.
- parse_kwargs(**kwargs)#
Get the required values for the specific equation.
- rearrange(newvar, fidval=None, equal=None)#
Rearrange the equation so that a different variable is on the left hand side, i.e., solve the equation for the given variable.
- Parameters
newvar (str) – The variable should be rearranged to the LHS of the equation.
fidval (float, Quantity) – The value to use for the original LHS value. If not given this will be based on the original fiducial values.
equal (EquationBase) – You can pass another equation to set as equal to the current equation before rearranging.
- Returns
neweq – Returns a new equation. The current equation is left unchanged.
- Return type
Example
For example rearrange the braking index equation to put the frequency derivative \(\dot{f}\) on the left hand side:
>>> eqn = equations("brakingindex") >>> reqn = eqn.rearrange("rotationfdot")
which gives:
\[\dot{f}_{\rm rot} = \frac{1}{n^{1/2}} \left(\ddot{f}_{\rm rot} f_{\rm rot}\right)^{1/2}\]
- substitute(other)#
Substitute another equation into the current equation.
- Parameters
other (EquationBase) – The other equation to substitute into the current equation.
- Returns
neweq – Returns a new equation. The current equation is left unchanged.
- Return type
Example
For example put the \(h_0\) spin-down limit in terms of the braking index \(n\) and second frequency derivative \(\ddot{f}\) (with the help of
rearrange()
):>>> # get braking index equation >>> eqn = equations("brakingindex") >>> # rearrange to put fdot on lhs >>> reqn = eqn.rearrange("rotationfdot") >>> # get h0 spindown equation >>> eqnh0sd = equations("h0spindown") >>> # substitute in the rearranged equation >>> neweq = eqnh0sd.substitute(reqn)
with gives:
\[h_0^{\rm sd} = \frac{\sqrt{10} \sqrt{G}}{2 c^{3/2}}\frac{I_{zz}^{1/2} \ddot{f}_{\rm rot}^{1/4}}{d \left(n f_{\rm rot}\right)^{1/4}}\]
- property sympy#
Construct and return the equation as a
sympy.core.relational.Equality
.
- property sympy_const#
Construct and return a
sympy.core.mul.Mul
containing the constants in the equation.
- property sympy_var#
Construct and return a
sympy.core.mul.Mul
containing the variables in the equation.
- to(newvariable)#
Return a new version of the equation in terms of a new variable. Currently this is designed to convert between frequency-like and frequency first derivative parameters (it does not do higher frequency derivatives), e.g., converting an equation from using frequency and frequency derivative, to one using period and period derivative.
- Parameters
newvariable (str) – The new parameterisation of the equation. This can be one of: “rotationfrequency”, “rotationperiod”, “gwfrequency”, “angularrotationfrequency”, or “angulargwfrequency” (or any of the allowed aliases for these in
ALLOWED_VARIABLES
). If the equation contains equivalents of the variable and/or their first frequency derivative then both will be converted.- Returns
neweqn – The equation in the new parameterisation.
- Return type
- property var_names#
Get variable names from Sympy representation.