relations¶
relations.fit module¶
-
xga.relations.fit.
scaling_relation_curve_fit
(model_func, y_values, y_errs, x_values, x_errs=None, y_norm=None, x_norm=None, x_lims=None, start_pars=None, y_name='Y', x_name='X')[source]¶ A function to fit a scaling relation with the scipy non-linear least squares implementation (curve fit), generate an XGA ScalingRelation product, and return it.
- Parameters
model_func (FunctionType) – The function object of the model you wish to fit. PLEASE NOTE, the function must be defined in the style used in xga.models.misc; i.e. powerlaw(x: np.ndarray, k: float, a: float), where the first argument is for x values, and the following arguments are all fit parameters.
y_values (Quantity) – The y data values to fit to.
y_errs (Quantity) – The y error values of the data. These should be supplied as either a 1D Quantity with length N (where N is the length of y_values), or an Nx2 Quantity with lower and upper errors.
x_values (Quantity) – The x data values to fit to.
x_errs (Quantity) – The x error values of the data. These should be supplied as either a 1D Quantity with length N (where N is the length of x_values), or an Nx2 Quantity with lower and upper errors.
y_norm (Quantity) – Quantity to normalise the y data by.
x_norm (Quantity) – Quantity to normalise the x data by.
x_lims (Quantity) – The range of x values in which this relation is valid, default is None. If this information is supplied, please pass it as a Quantity array, with the first element being the lower bound and the second element being the upper bound.
start_pars (list) – The start parameters for the curve_fit run, default is None, which means curve_fit will use all ones.
y_name (str) – The name to be used for the y-axis of the scaling relation (DON’T include the unit, that will be inferred from the astropy Quantity.
x_name (str) – The name to be used for the x-axis of the scaling relation (DON’T include the unit, that will be inferred from the astropy Quantity.
- Returns
An XGA ScalingRelation object with all the information about the data and fit, a view method, and a predict method.
- Return type
-
xga.relations.fit.
scaling_relation_odr
(model_func, y_values, y_errs, x_values, x_errs=None, y_norm=None, x_norm=None, x_lims=None, start_pars=None, y_name='Y', x_name='X')[source]¶ A function to fit a scaling relation with the scipy orthogonal distance regression implementation, generate an XGA ScalingRelation product, and return it.
- Parameters
model_func (FunctionType) – The function object of the model you wish to fit. PLEASE NOTE, the function must be defined in the style used in xga.models.misc; i.e. powerlaw(x: np.ndarray, k: float, a: float), where the first argument is for x values, and the following arguments are all fit parameters. The scipy ODR implementation requires functions of a different style, and I try to automatically convert the input function to that style, but to help that please avoid using one letter parameter names in any custom function you might want to use.
y_values (Quantity) – The y data values to fit to.
y_errs (Quantity) – The y error values of the data. These should be supplied as either a 1D Quantity with length N (where N is the length of y_values), or an Nx2 Quantity with lower and upper errors.
x_values (Quantity) – The x data values to fit to.
x_errs (Quantity) – The x error values of the data. These should be supplied as either a 1D Quantity with length N (where N is the length of x_values), or an Nx2 Quantity with lower and upper errors.
y_norm (Quantity) – Quantity to normalise the y data by.
x_norm (Quantity) – Quantity to normalise the x data by.
x_lims (Quantity) – The range of x values in which this relation is valid, default is None. If this information is supplied, please pass it as a Quantity array, with the first element being the lower bound and the second element being the upper bound.
start_pars (list) – The start parameters for the ODR run, default is all ones.
y_name (str) – The name to be used for the y-axis of the scaling relation (DON’T include the unit, that will be inferred from the astropy Quantity.
x_name (str) – The name to be used for the x-axis of the scaling relation (DON’T include the unit, that will be inferred from the astropy Quantity.
- Returns
An XGA ScalingRelation object with all the information about the data and fit, a view method, and a predict method.
- Return type
-
xga.relations.fit.
scaling_relation_lira
(y_values, y_errs, x_values, x_errs=None, y_norm=None, x_norm=None, x_lims=None, y_name='Y', x_name='X', num_steps=100000, num_chains=4, num_burn_in=10000)[source]¶ A function to fit a power law scaling relation with the excellent R fitting package LIRA (https://doi.org/10.1093/mnras/stv2374), this function requires a valid R installation, along with LIRA (and its dependencies such as JAGS), as well as the Python module rpy2.
- Parameters
y_values (Quantity) – The y data values to fit to.
y_errs (Quantity) – The y error values of the data. These should be supplied as either a 1D Quantity with length N (where N is the length of y_values), or an Nx2 Quantity with lower and upper errors.
x_values (Quantity) – The x data values to fit to.
x_errs (Quantity) – The x error values of the data. These should be supplied as either a 1D Quantity with length N (where N is the length of x_values), or an Nx2 Quantity with lower and upper errors.
y_norm (Quantity) – Quantity to normalise the y data by.
x_norm (Quantity) – Quantity to normalise the x data by.
x_lims (Quantity) – The range of x values in which this relation is valid, default is None. If this information is supplied, please pass it as a Quantity array, with the first element being the lower bound and the second element being the upper bound.
y_name (str) – The name to be used for the y-axis of the scaling relation (DON’T include the unit, that will be inferred from the astropy Quantity.
x_name (str) – The name to be used for the x-axis of the scaling relation (DON’T include the unit, that will be inferred from the astropy Quantity.
num_steps (int) – The number of steps to take in each chain.
num_chains (int) – The number of chains to run.
num_burn_in (int) – The number of steps to discard as a burn in period. This is also used as the adapt parameter of the LIRA fit.
- Returns
An XGA ScalingRelation object with all the information about the data and fit, a view method, and a predict method.
- Return type