cwitools.measurement.second_moment

cwitools.measurement.second_moment(x, y, mu1=None, y_var=None, get_err=False)

Calculate first moment.

Parameters:
  • x (np.array) – Input coordinate values (e.g. wavelength).
  • y (np.array) – Input weights (i.e. intensity)
  • mu1 (float) – The first moment. Calculated if not provided.
  • y_var (np.array) – Variance on y. Taken as var(y) if not provided.
  • get_err (bool) – Set to TRUE to return (moment, error), tuple
Returns:

The second moment in x. float: The error on the second moment (if get_err == True)

Return type:

float

Example

To get the first moment of a spectrum ‘spec’ with wavelength axis ‘wav’

>>> mu2 = measurement.second_moment(wav, spec)

If you want to use a custom value for the first moment, provide it with ‘mu1=’

>>> mu2, mu2_err = measurement.second_moment(wav, spec, mu1=4240)

As with first_moment, error can be estimated if variance is provided or roughly estimated from the input data itself.