Structure Function API
- class structurefunction.SFResult(med, err_low, err_high, count, c_bins)
- c_bins: ndarray
Alias for field number 4
- count: ndarray
Alias for field number 3
- err_high: ndarray
Alias for field number 2
- err_low: ndarray
Alias for field number 1
- med: ndarray
Alias for field number 0
- class structurefunction.TqdmToLogger(logger, level=None)[source]
Output stream for TQDM which will output to logger module instead of the StdOut.
- structurefunction.bilby_fit(x: ~numpy.ndarray, y: ~numpy.ndarray, y_err: ~numpy.ndarray, outdir: str, label: str, model=<function broken_power_law>, **kwargs) Result[source]
Bilby fit
- Parameters:
x (np.ndarray) – X data
y (np.ndarray) – Y data
y_err (np.ndarray) – Y error
outdir (str) – Output directory
label (str) – Label
model (func, optional) – Model function. Defaults to broken_power_law.
- Raises:
NotImplementedError – If model is not implemented
- Returns:
Fitting result
- Return type:
bilby.core.result.Result
- structurefunction.broken_power_law(x: ndarray, amplitude: float, x_break: float, alpha_1: float, alpha_2: float) ndarray[source]
Broken power law model
- Parameters:
x (np.ndarray) – Frequency
amplitude (float) – Amplitude
x_break (float) – Break frequency
alpha_1 (float) – Power law index below break frequency
alpha_2 (float) – Power law index above break frequency
- Returns:
Model array
- Return type:
np.ndarray
- structurefunction.combinate(data: ndarray) Tuple[ndarray, ndarray][source]
Return all combinations of data with itself
- Parameters:
data (np.ndarray) – Data to combine.
- Returns:
Data_1 matched with Data_2
- Return type:
Tuple[np.ndarray, np.ndarray]
- structurefunction.fit_data(sf_result: SFResult, fit: str = 'bilby', outdir: str | None = None, model_name: str | None = None, n_point: int = 2, show_plots: bool = False, save_plots: bool = False, **kwargs) None | Result[source]
Fit the structure function data
- Parameters:
sf_result (SFResult) – Structure function result
fit (str, optional) – Fit type. Defaults to “bilby”.
outdir (str, optional) – Output directory for bilby. Defaults to None.
model_name (str, optional) – Model to fit. Defaults to None.
n_point (int, optional) – Number of points in SF. Defaults to 2.
show_plots (bool, optional) – Show fitting plots. Defaults to False.
save_plots (bool, optional) – Save fitting plots. Defaults to False.
- Raises:
NotImplementedError – If model_name is not implemented
ValueError – If fit is not implemented.
- Returns:
_description_
- Return type:
Union[None, bilby.core.result.Result]
- structurefunction.lsq_fit(x: ~numpy.ndarray, y: ~numpy.ndarray, outdir: str, label: str, model=<function broken_power_law>) Result[source]
Least squares fit
- Parameters:
x (np.ndarray) – X data
y (np.ndarray) – Y data
outdir (str) – Output directory
label (str) – Fitting label
model (func, optional) – Model function. Defaults to broken_power_law.
- Raises:
NotImplementedError – if model is not implemented
- Returns:
Fitting result
- Return type:
Result
- structurefunction.lsq_weight_fit(x: ~numpy.ndarray, y: ~numpy.ndarray, yerr: ~numpy.ndarray, outdir: str, label: str, model=<function broken_power_law>) Result[source]
Weighted least squares fit
- Parameters:
x (np.ndarray) – X data
y (np.ndarray) – Y data
yerr (np.ndarray) – Y error
outdir (str) – Output directory
label (str) – Label
model (func, optional) – Model function. Defaults to broken_power_law.
- Raises:
NotImplementedError – If model is not implemented
- Returns:
Fiting result
- Return type:
bilby.core.result.Result
- structurefunction.mc_sample(data: ndarray, errors: ndarray, samples: int = 1000) ndarray[source]
Sample errors using Monte-Carlo Assuming Gaussian distribution.
- Parameters:
data (np.ndarray) – Measurements
errors (np.ndarray) – Errors
samples (int, optional) – Samples of the distribution. Defaults to 1000.
- Returns:
Sample array. Shape (len(data/errors),samples)
- Return type:
np.ndarray
- structurefunction.nanvar(data: ndarray | Quantity) ndarray | Quantity[source]
Compute the variance of an array, ignoring NaNs
- Parameters:
data (Union[np.ndarray, u.Quantity]) – Array
- Returns:
Variance
- Return type:
Union[np.ndarray, u.Quantity]
- structurefunction.power_law(x: ndarray, amplitude: float, x_break: float, alpha: float) ndarray[source]
Power law model
- Parameters:
x (np.ndarray) – Frequency
amplitude (float) – Amplitude
x_break (float) – Reference frequency
alpha (float) – Power law index
- Returns:
Model array
- Return type:
np.ndarray
- structurefunction.sf_three_point(rm_1: ndarray, rm_2: ndarray, rm_err_1: ndarray, rm_err_2: ndarray, src_1: ndarray, src_2: ndarray, dtheta: Quantity, bins: Quantity, bin_unit: Quantity) SFResult[source]
Compute the three-point structure function
- Parameters:
rm_1 (np.ndarray) – RMs of source 1 in pair (n_samples, n_pairs)
rm_2 (np.ndarray) – RMs of source 2 in pair (n_samples, n_pairs)
rm_err_1 (np.ndarray) – RM errors of source 1 in pair (n_samples, n_pairs)
rm_err_2 (np.ndarray) – RM errors of source 2 in pair (n_samples, n_pairs)
src_1 (np.ndarray) – Source 1 in pair (n_pairs)
src_2 (np.ndarray) – Source 2 in pair (n_pairs)
dtheta (u.Quantity) – Separation between sources in pair (n_pairs)
bins (u.Quantity) – Angular (or 3D Euclidean) separation bins
bin_unit (u.Quantity) – Unit to set bins to when resolving units
- Returns:
Structure function result
- Return type:
- structurefunction.sf_two_point(rm_1: ndarray, rm_2: ndarray, rm_err_1: ndarray, rm_err_2: ndarray, dtheta: Quantity, bins: Quantity, bin_unit: Quantity) SFResult[source]
Compute the two-point structure function
- Parameters:
rm_1 (np.ndarray) – RMs of source 1 in pair (n_samples, n_pairs)
rm_2 (np.ndarray) – RMs of source 2 in pair (n_samples, n_pairs)
rm_err_1 (np.ndarray) – RM errors of source 1 in pair (n_samples, n_pairs)
rm_err_2 (np.ndarray) – RM errors of source 2 in pair (n_samples, n_pairs)
dtheta (u.Quantity) – Separation between sources in pair (n_pairs)
bins (u.Quantity) – Angular (or 3D Euclidean) separation bins
bin_unit (u.Quantity) – Unit to set bins to when resolving units
- Returns:
Structure function results
- Return type:
- structurefunction.structure_function(data: Quantity, errors: Quantity, coords: SkyCoord, samples: int, bins: Quantity | int, show_plots: bool = False, save_plots: bool = False, verbose: bool = False, fit: str | None = None, outdir: str | None = None, model_name: str | None = None, n_point: int = 2, **kwargs) Tuple[SFResult, Result][source]
Compute the second or third order structure function with Monte-Carlo error propagation.
- Parameters:
data (u.Quantity) – 1D array of data values.
errors (u.Quantity) – 1D array of errors.
coords (SkyCoord) – 1D array of coordinates.
samples (int) – Number of samples to use for Monte-Carlo error propagation.
bins (Union[u.Quantity, int]) – Bin edges of the structure function, or number of bins.
show_plots (bool, optional) – Show plots. Defaults to False.
save_plots (bool, optional) – Save plots. Defaults to False.
verbose (bool, optional) – Print progress. Defaults to False.
fit (str, optional) – How to fit the broken powerlaw. Can be ‘astropy’, ‘astropy_mc’ or ‘bilby’. Defaults to None.
outdir (str, optional) – Output directory for bilby. Defaults to None.
model_name (str, optional) – Name of the model. Defaults to None. Can be ‘broken_power_law’ or ‘power_law’.
**kwargs – Additional keyword arguments to pass to the bilby.core.run_sampler function.
- Returns:
The structure function result and the fitting result.
- Return type:
Tuple[SFResult, bilby.core.result.Result]