Custom profiles
Creating a custom profile is easy. As an example, let’s define a simple power-law profile with two free parameters, the normalization and the slope:
The code should look as follows:
from profiley import Profile
from profiley.helpers.decorators import array, inMpc
class PowerLaw(Profile):
def __init__(self, norm, slope, **kwargs):
self._set_shape(norm*slope)
super().__init__(**kwargs)
self.norm = norm
self.slope = slope
@array
@inMpc
def profile(self, r):
return self.norm * r**self.slope
That’s it! The __init__() method needs only two lines of code (in addition to attribute definitions).
Note
There are three things to pay attention to:
The first line is necessary to allow
profileyto automatically handle arbitrary shapes, through the definition of ashapeattribute, and must be called beforesuper. Note that_set_shapetakes only one argument (besidesself): the product of the arguments in__init__. That is, if the arguments are arrays, their dimensions must be such that a product can be carried out without any manipulation - be sure to include empty dimensions as needed.The
arraydecorator allows manipulation of arrays of arbitrary shape, as specified above.The
inMpcdecorator is optional and allows the method to receive an astropyQuantityobject, which will be converted to Mpc before calculating the profile.
Profile projections
If the projection of this profile is analytical, any or all of the following methods can also be specified:
cumulative(self, R, **kwargs)
mass_cumulative(self, R, **kwargs)
projected(self, R, **kwargs)
projected_cumulative(self, R, **kwargs)
projected_excess(self, R, **kwargs)
Those projections that do not have analytical expressions will also exist in the newly-built profile object thanks to the call to super, but they will be calculated numerically, so they may be somewhat slower depending on the precision required.
Note
For methods defined explicitly, the **kwargs constructor is convenient as it allows easy integration with the generic numerical implementations in the Profile base class.