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', dim_hubb_ind=None, point_names=None, third_dim_info=None, third_dim_name=None, x_en_bounds=None, y_en_bounds=None)[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.

  • dim_hubb_ind (float/int) – This is used to tell the ScalingRelation which power of E(z) has been applied to the y-axis data, this can then be used by the predict method to remove the E(z) contribution from predictions. The default is None.

  • point_names (np.ndarray/list) – The source names associated with the data points passed in to this scaling relation, can be used for diagnostic purposes (i.e. identifying which source an outlier belongs to).

  • third_dim_info (np.ndarray/Quantity) – A set of data points which represent a faux third dimension. They should not have been involved in the fitting process, and the relation should not be in three dimensions, but these can be used to colour the data points in a view method.

  • third_dim_name (str) – The name of the third dimension data.

  • x_en_bounds (Tuple[Quantity]) – If the value on the x-axis of this relation is ‘energy bound’, those bounds can be specified here (e.g. if the value is 0.5-2.0 keV luminosity you would pass a non-scalar quantity with the first entry being 0.5 and the second 2.0; Quantity([0.5, 2.0], ‘keV’). The default is None.

  • y_en_bounds (Tuple[Quantity]) – If the value on the y-axis of this relation is ‘energy bound’, those bounds can be specified here (e.g. if the value is 0.5-2.0 keV luminosity you would pass a non-scalar quantity with the first entry being 0.5 and the second 2.0; Quantity([0.5, 2.0], ‘keV’). The default is None.

Returns

An XGA ScalingRelation object with all the information about the data and fit, a view method, and a predict method.

Return type

ScalingRelation

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', dim_hubb_ind=None, point_names=None, third_dim_info=None, third_dim_name=None, x_en_bounds=None, y_en_bounds=None)[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.

  • dim_hubb_ind (float/int) – This is used to tell the ScalingRelation which power of E(z) has been applied to the y-axis data, this can then be used by the predict method to remove the E(z) contribution from predictions. The default is None.

  • point_names (np.ndarray/list) – The source names associated with the data points passed in to this scaling relation, can be used for diagnostic purposes (i.e. identifying which source an outlier belongs to).

  • third_dim_info (np.ndarray/Quantity) – A set of data points which represent a faux third dimension. They should not have been involved in the fitting process, and the relation should not be in three dimensions, but these can be used to colour the data points in a view method.

  • third_dim_name (str) – The name of the third dimension data.

  • x_en_bounds (Tuple[Quantity]) – If the value on the x-axis of this relation is ‘energy bound’, those bounds can be specified here (e.g. if the value is 0.5-2.0 keV luminosity you would pass a non-scalar quantity with the first entry being 0.5 and the second 2.0; Quantity([0.5, 2.0], ‘keV’). The default is None.

  • y_en_bounds (Tuple[Quantity]) – If the value on the y-axis of this relation is ‘energy bound’, those bounds can be specified here (e.g. if the value is 0.5-2.0 keV luminosity you would pass a non-scalar quantity with the first entry being 0.5 and the second 2.0; Quantity([0.5, 2.0], ‘keV’). The default is None.

Returns

An XGA ScalingRelation object with all the information about the data and fit, a view method, and a predict method.

Return type

ScalingRelation

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, dim_hubb_ind=None, point_names=None, third_dim_info=None, third_dim_name=None, x_en_bounds=None, y_en_bounds=None)[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.

  • dim_hubb_ind (float/int) – This is used to tell the ScalingRelation which power of E(z) has been applied to the y-axis data, this can then be used by the predict method to remove the E(z) contribution from predictions. The default is None.

  • point_names (np.ndarray/list) – The source names associated with the data points passed in to this scaling relation, can be used for diagnostic purposes (i.e. identifying which source an outlier belongs to).

  • third_dim_info (np.ndarray/Quantity) – A set of data points which represent a faux third dimension. They should not have been involved in the fitting process, and the relation should not be in three dimensions, but these can be used to colour the data points in a view method.

  • third_dim_name (str) – The name of the third dimension data.

  • x_en_bounds (Tuple[Quantity]) – If the value on the x-axis of this relation is ‘energy bound’, those bounds can be specified here (e.g. if the value is 0.5-2.0 keV luminosity you would pass a non-scalar quantity with the first entry being 0.5 and the second 2.0; Quantity([0.5, 2.0], ‘keV’). The default is None.

  • y_en_bounds (Tuple[Quantity]) – If the value on the y-axis of this relation is ‘energy bound’, those bounds can be specified here (e.g. if the value is 0.5-2.0 keV luminosity you would pass a non-scalar quantity with the first entry being 0.5 and the second 2.0; Quantity([0.5, 2.0], ‘keV’). The default is None.

Returns

An XGA ScalingRelation object with all the information about the data and fit, a view method, and a predict method.

Return type

ScalingRelation

xga.relations.fit.scaling_relation_emcee()[source]