pint.models.parameter.funcParameter
- class pint.models.parameter.funcParameter(name=None, description=None, func=None, params=None, units=None, inpar=False, long_double=False, unit_scale=False, scale_factor=None, scale_threshold=None, aliases=None, **kwargs)[source]
Bases:
floatParameter
Parameter defined as a read-only function operating on other parameters that returns a float or long double value.
Can access the result of the function through the
.quantity
attribute, and the value without units through the.value
attribute.On its own this parameter will not be useful, but when inserted into a
pint.models.timing_model.Component
object it can operate on any parameters within that component or others in the samepint.models.timing_model.TimingModel
.- Parameters:
name (str) – The name of the parameter.
func (function) – Returns the desired value
params (iterable) – List or tuple of parameter names. Each can optionally also be a tuple including the attribute to access (default is
quantity
)units (str or astropy.units.Quantity) – Parameter default unit. Parameter .value and .uncertainty_value attribute will associate with the default units. If unit is dimensionless, use “’’” as its unit.
description (str, optional) – A short description of what this parameter means.
inpar (bool, optional) – Whether to include in par-file printouts, or to comment out
long_double (bool, optional, default False) – A flag specifying whether value is float or long double.
aliases (list, optional) – An optional list of strings specifying alternate names that can also be accepted for this parameter.
Examples
>>> import pint.models.parameter >>> p = pint.models.parameter.funcParameter( name="AGE", description="Spindown age", params=("F0", "F1"), func=lambda f0, f1: -f0 / 2 / f1, units="yr", ) >>> m.components["Spindown"].add_param(p) >>> print(m.AGE)
>>> import pint.models.parameter >>> import pint.derived_quantities >>> p2 = pint.models.parameter.funcParameter( name="PSREDOT", description="Spindown luminosity", params=("F0", "F1"), func=pint.derived_quantities.pulsar_edot, units="erg/s", ) >>> m.components["Spindown"].add_param(p2) >>> print(m.PSREDOT)
Notes
Defining functions through
lambda
functions may result in unpickleable modelsFuture versions may include derivative functions to calculate uncertainties.
Methods
add_alias
(alias)Add a name to the list of aliases for this parameter.
as_latex
()as_parfile_line
([format])Return a parfile line giving the current state of the parameter.
as_ufloat
([units])Return the parameter as a
uncertainties.ufloat
from_parfile_line
(line)Ignore reading from par file
from_ufloat
(value[, units])Set the parameter from the value of a
uncertainties.ufloat
Return a help line containing parameter name, description and units.
name_matches
(name)Whether or not the parameter name matches the provided name
prior_pdf
([value, logpdf])Return the prior probability density.
set
(value)Deprecated - just assign to .value.
str_quantity
(quan)Quantity as a string (for floating-point values).
value_as_latex
()Attributes
Whether the parameter has long double precision.
Return a list of tuples of parameter names and attributes
prior distribution for this parameter.
The result of the function
repeatable
Parameter uncertainty value with units.
Return a pure value from .uncertainty.
If True, the parameter can automatically scale some values upon assignment.
Units associated with this parameter.
The result of the function without units.
- add_alias(alias)
Add a name to the list of aliases for this parameter.
- as_ufloat(units=None)
Return the parameter as a
uncertainties.ufloat
Will cast to the specified units, or the default If the uncertainty is not set will be returned as 0
- Parameters:
units (astropy.units.core.Unit, optional) – Units to cast the value
- Return type:
uncertainties.ufloat
Notes
Currently
ufloat
does not support double precision values, so some precision may be lost.
- from_ufloat(value, units=None)
Set the parameter from the value of a
uncertainties.ufloat
Will cast to the specified units, or the default If the uncertainty is 0 it will be set to
None
- Parameters:
value (uncertainties.ufloat) –
units (astropy.units.core.Unit, optional) – Units to cast the value
- help_line()
Return a help line containing parameter name, description and units.
- name_matches(name)
Whether or not the parameter name matches the provided name
- property prior
prior distribution for this parameter.
This should be a
Prior
object describing the prior distribution of the quantity, for use in Bayesian fitting.
- prior_pdf(value=None, logpdf=False)
Return the prior probability density.
Evaluated at the current value of the parameter, or at a proposed value.
- Parameters:
value (array-like or float, optional) – Where to evaluate the priors; should be a unitless number. If not provided the prior is evaluated at
self.value
.logpdf (bool) – If True, return the logarithm of the PDF instead of the PDF; this can help with densities too small to represent in floating-point.
- set(value)
Deprecated - just assign to .value.
- str_quantity(quan)
Quantity as a string (for floating-point values).
- property uncertainty_value
Return a pure value from .uncertainty.
This will be interpreted as having units
self.units
.
- property units
Units associated with this parameter.
Should be a
astropy.units.Unit
object, or None if never set.
- property long_double
Whether the parameter has long double precision.
- property unit_scale
If True, the parameter can automatically scale some values upon assignment.
- property uncertainty
Parameter uncertainty value with units.
- property quantity
The result of the function
- property value
The result of the function without units.
- property params
Return a list of tuples of parameter names and attributes
- from_parfile_line(line)[source]
Ignore reading from par file
For
funcParameter
, it is for information only so is ignored on reading
- as_parfile_line(format='pint')[source]
Return a parfile line giving the current state of the parameter.
- Parameters:
format (str, optional) – Parfile output format. PINT outputs in ‘tempo’, ‘tempo2’ and ‘pint’ formats. The default format is pint.
- Return type:
Notes
Format differences between tempo, tempo2, and pint at [1]