cwitools.measurement.first_moment

cwitools.measurement.first_moment(x, y, y_var=None, get_err=False, method='basic', mu1_init=None, window_size=25, window_min=10, window_step=1)

Calculate first moment.

Parameters:
  • x (np.array) – Input coordinate values (e.g. wavelength).
  • y (np.array) – Input weights (i.e. intensity)
  • 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
  • method (str) – The method to use for calculating the moment. ‘basic’: Use all input x and y data. ‘clw’: Use the closing-window method (O’Sullivan+20, FLASHES Survey)
  • mu1_init (float) – Initial estimate for mu1, required if using ‘clw’ method or restricting calculatio to a certain window size.
  • window_size (float) – The default window size for the moment calculation if using mu1_init, or the initial window size of using ‘clw’ method.
  • window_min (float) – The minimum window size if using ‘clw’ method.
  • window_step (float) – The decrement in window size each iteration if using the ‘clw’ method.
Returns:

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

Return type:

float

Example

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

>>> mu1 = measurement.first_moment(wav, spec)

To get the error on the measurement, provide the input variance using the y_var argument, available:

>>> mu1, mu1_err = measurement.first_moment(wav, spec, y_var=spec_var)

or, if you do not have error on the input flux, it can be (roughly) esitmated from the data:

>>> mu1, mu1_err = measurement.first_moment(wav, spec, get_err=True)