pynbody.analysis.theoretical_profiles.AbstractBaseProfile#
- class pynbody.analysis.theoretical_profiles.AbstractBaseProfile[source]#
Bases:
ABCRepresents an analytic profile of a halo, and provides a method to fit the profile to data.
The class is organised a dictionary, i.e. profile parameters of a given instance can be accessed through
profile['...']and the available parameters are listed inprofile.keys(). The parameters are set at initialisation and cannot be changed afterwards.To define a new profile, create a new class inheriting from this base class and define your own profile_functional() method. The static version can be handy to avoid having to create and object every time. As a example, the NFW functional is implemented.
A generic fitting function is provided (
fit()). Given a binned quantity as a function of radius, it uses least-squares to fit the given functional form to the data.Methods
enclosed_mass(radius)Return the mass, M(r), enclosed within a given radius
fit(radial_data, profile_data[, ...])Fit the given profile using a least-squares method.
keys()Return the keys of the profile parameters
logarithmic_slope(radius)Return the logarithmic slope of the profile, d ln rho / d ln r, at a given radius
parameter_bounds(r_values, rho_values)Return bounds on the parameter values for the profile fit
- classmethod fit(radial_data, profile_data, profile_err=None, use_analytical_jac=True, guess=None, verbose=0, return_profile=True)[source]#
Fit the given profile using a least-squares method.
- Parameters:
radial_data (array_like) – The central radius of the bins in which the profile data is measured
profile_data (array_like) – The profile density values
profile_err (array_like, optional) – The error on the profile data
use_analytical_jac (bool) – Whether to use the analytical jacobian of the profile function. If False, finite differencing is used.
guess (array_like, optional) – An initial guess for the parameters of the profile. If None, the initial guess is taken to be all ones, according to the underlying
scipy.optimize.curve_fitfunction.verbose (int) – The verbosity level to pass to the underlying
scipy.optimize.curve_fitfunction.return_profile (bool) – Whether to return the profile object or just the parameters
- Returns:
fitted_profile (array_like | AbstractBaseProfile) – If return_profile is True, the fitted profile object. Otherwise, the fitted parameters.
cov (array_like) – The covariance matrix of the fit. The diagonal elements are the variance of the parameters.
- abstract logarithmic_slope(radius)[source]#
Return the logarithmic slope of the profile, d ln rho / d ln r, at a given radius
- abstract classmethod parameter_bounds(r_values, rho_values)[source]#
Return bounds on the parameter values for the profile fit
- Parameters:
r_values (array_like) – The radii at which the profile is measured
rho_values (array_like) – The density values of the profile
- Returns:
bounds – A 2-tuple containing lower and upper bounds respectively for the parameters of the profile
- Return type:
tuple[array_like]