Skip to content

Commit

Permalink
Merge pull request #1621 from abhisrkckl/publish
Browse files Browse the repository at this point in the history
Publication output
  • Loading branch information
paulray authored Sep 21, 2023
2 parents 5b2c911 + 8f7792e commit f4cbedc
Show file tree
Hide file tree
Showing 17 changed files with 602 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ docs/examples/*.ipynb
docs/examples-rendered/*.py

# VSCode wants to put virtualenvs here
.env
.env

# pintpublish output
*.tex
*.aux
*.log
*.pdf
5 changes: 3 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ build:

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
builder: html
configuration: docs/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
formats:
Expand All @@ -29,4 +30,4 @@ python:
- requirements: requirements_dev.txt
- requirements: requirements.txt
- method: pip
path: .
path: .
4 changes: 3 additions & 1 deletion CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ the released changes.
- Moved design matrix normalization code from `pint.fitter` to the new `pint.utils.normalize_designmatrix()` function.
- Made `Residuals` independent of `GLSFitter` (GLS chi2 is now computed using the new function `Residuals._calc_gls_chi2()`).
### Added
- Added WaveX model as DelayComponent with wave amplitudes as fitted parameters
- Added `WaveX` model as a `DelayComponent` with Fourier amplitudes as fitted parameters
- `Parameter.as_latex` method for latex representation of a parameter.
- `pint.output.publish` module and `pintpublish` script for generating publication (LaTeX) output.
- Added radial velocity methods for binary models
### Fixed
- Wave model `validate()` can correctly use PEPOCH to assign WAVEEPOCH parameter
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ console_scripts =
convert_parfile = pint.scripts.convert_parfile:main
compare_parfiles = pint.scripts.compare_parfiles:main
tcb2tdb = pint.scripts.tcb2tdb:main
pintpublish = pint.scripts.pintpublish:main


# See the docstring in versioneer.py for instructions. Note that you must
Expand Down
8 changes: 5 additions & 3 deletions src/pint/models/absolute_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ def __init__(self):
super().__init__()
self.add_param(
MJDParameter(
name="TZRMJD", description="Epoch of the zero phase.", time_scale="utc"
name="TZRMJD",
description="Epoch of the zero phase TOA.",
time_scale="utc",
)
)
self.add_param(
strParameter(
name="TZRSITE", description="Observatory of the zero phase measured."
name="TZRSITE", description="Observatory of the zero phase TOA."
)
)
self.add_param(
floatParameter(
name="TZRFRQ",
units=u.MHz,
description="The frequency of the zero phase measured.",
description="The frequency of the zero phase TOA.",
)
)
self.tz_cache = None
Expand Down
4 changes: 2 additions & 2 deletions src/pint/models/binary_ell1.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self):
floatParameter(
name="EPS1",
units="",
description="First Laplace-Lagrange parameter, ECC x sin(OM) for ELL1 model",
description="First Laplace-Lagrange parameter, ECC*sin(OM)",
long_double=True,
)
)
Expand All @@ -126,7 +126,7 @@ def __init__(self):
floatParameter(
name="EPS2",
units="",
description="Second Laplace-Lagrange parameter, ECC x cos(OM) for ELL1 model",
description="Second Laplace-Lagrange parameter, ECC*cos(OM)",
long_double=True,
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/frequency_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
name="FD1",
units="second",
value=0.0,
description="Coefficient of delay as a polynomial function of log-frequency",
description="Polynomial coefficient of log-frequency-dependent delay",
# descriptionTplt=lambda x: (
# "%d term of frequency" " dependent coefficients" % x
# ),
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self):
maskParameter(
name="JUMP",
units="second",
description="Amount to jump the selected TOAs by.",
description="Phase jump for selection.",
)
)
self.phase_funcs_component += [self.jump_phase]
Expand Down
16 changes: 4 additions & 12 deletions src/pint/models/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def __init__(
name="EFAC",
units="",
aliases=["T2EFAC", "TNEF"],
description="A multiplication factor on"
" the measured TOA uncertainties,",
description="A multiplication factor for the measured TOA uncertainties,",
)
)

Expand All @@ -68,20 +67,15 @@ def __init__(
name="EQUAD",
units="us",
aliases=["T2EQUAD"],
description="An error term added in "
"quadrature to the scaled (by"
" EFAC) TOA uncertainty.",
description="An error term added in quadrature to the TOA uncertainty.",
)
)

self.add_param(
maskParameter(
name="TNEQ",
units=u.LogUnit(physical_unit=u.second),
description="An error term added in "
"quadrature to the scaled (by"
" EFAC) TOA uncertainty in "
" the unit of log10(second).",
description="A log10-scale error term added in quadrature to the TOA uncertainty",
)
)
self.covariance_matrix_funcs += [self.sigma_scaled_cov_matrix]
Expand Down Expand Up @@ -307,9 +301,7 @@ def __init__(
name="ECORR",
units="us",
aliases=["TNECORR"],
description="An error term added that"
" correlated all TOAs in an"
" observing epoch.",
description="An error term that is correlated among all TOAs in an observing epoch.",
)
)

Expand Down
89 changes: 89 additions & 0 deletions src/pint/models/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,26 @@ def from_parfile_line(self, line):
self.uncertainty = self._set_uncertainty(ucty)
return True

def value_as_latex(self):
return f"${self.as_ufloat():.1uSL}$" if not self.frozen else f"{self.value:f}"

def as_latex(self):
try:
unit_latex = (
""
if self.units == "" or self.units is None
else f" ({self.units.to_string(format='latex', fraction=False)})"
)
except TypeError:
# to deal with old astropy
unit_latex = (
""
if self.units == "" or self.units is None
else f" ({self.units.to_string(format='latex')})"
)
value_latex = self.value_as_latex()
return f"{self.name}, {self.description}{unit_latex}", value_latex

def add_alias(self, alias):
"""Add a name to the list of aliases for this parameter."""
self.aliases.append(alias)
Expand Down Expand Up @@ -868,6 +888,9 @@ def _set_quantity(self, val):
"""Convert to string."""
return str(val)

def value_as_latex(self):
return self.value


class boolParameter(Parameter):
"""Boolean-valued parameter.
Expand Down Expand Up @@ -935,6 +958,9 @@ def _set_quantity(self, val):
return bool(float(val))
return bool(val)

def value_as_latex(self):
return "Y" if self.value else "N"


class intParameter(Parameter):
"""Integer parameter values.
Expand Down Expand Up @@ -1003,6 +1029,9 @@ def _set_quantity(self, val):

return ival

def value_as_latex(self):
return str(self.value)


class MJDParameter(Parameter):
"""Parameters for MJD quantities.
Expand Down Expand Up @@ -1166,6 +1195,18 @@ def as_ufloats(self):
error = self.uncertainty.to_value(u.d) if self.uncertainty is not None else 0
return ufloat(value1, 0), ufloat(value2, error)

def as_ufloat(self):
"""Return the parameter as a :class:`uncertainties.ufloat`
value.
If the uncertainty is not set will be returned as 0
Returns
-------
uncertainties.ufloat
"""
return ufloat(self.value, self.uncertainty_value)


class AngleParameter(Parameter):
"""Parameter in angle units.
Expand Down Expand Up @@ -1300,6 +1341,32 @@ def _print_uncertainty(self, unc):
angle_arcsec /= 15.0
return angle_arcsec.to_string(decimal=True, precision=20)

def as_ufloat(self, units=None):
"""Return the parameter as a :class:`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
Returns
-------
uncertainties.ufloat
Notes
-----
Currently :class:`~uncertainties.ufloat` does not support double precision values,
so some precision may be lost.
"""
if units is None:
units = self.units
value = self.quantity.to_value(units) if self.quantity is not None else 0
error = self.uncertainty.to_value(units) if self.uncertainty is not None else 0
return ufloat(value, error)


class prefixParameter:
"""Families of parameters identified by a prefix like ``DMX_0123``.
Expand Down Expand Up @@ -1547,6 +1614,9 @@ def name_matches(self, name):
def as_parfile_line(self, format="pint"):
return self.param_comp.as_parfile_line(format=format)

def as_latex(self):
return self.param_comp.as_latex()

def help_line(self):
return self.param_comp.help_line()

Expand Down Expand Up @@ -1892,6 +1962,25 @@ def as_parfile_line(self, format="pint"):
line += " 1"
return line + "\n"

def as_latex(self):
try:
unit_latex = (
""
if self.units == "" or self.units is None
else f" ({self.units.to_string(format='latex', fraction=False)})"
)
except TypeError:
# `fraction` option is not available in old astropy versions.
unit_latex = (
""
if self.units == "" or self.units is None
else f" ({self.units.to_string(format='latex')})"
)
return (
f"{self.prefix} {self.key} {' '.join(self.key_value)}, {self.description}{unit_latex}",
self.value_as_latex(),
)

def new_param(self, index, copy_all=False):
"""Create a new but same style mask parameter"""
return (
Expand Down
8 changes: 5 additions & 3 deletions src/pint/models/pulsar_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def __init__(self):
)
self.add_param(
floatParameter(
name="A1", units=ls, description="Projected semi-major axis, a*sin(i)"
name="A1",
units=ls,
description="Projected semi-major axis of pulsar orbit, ap*sin(i)",
)
)
# NOTE: the DOT here takes the value and times 1e-12, tempo/tempo2 can
Expand All @@ -112,7 +114,7 @@ def __init__(self):
name="A1DOT",
aliases=["XDOT"],
units=ls / u.s,
description="Derivative of projected semi-major axis, da*sin(i)/dt",
description="Derivative of projected semi-major axis, d[ap*sin(i)]/dt",
unit_scale=True,
scale_factor=1e-12,
scale_threshold=1e-7,
Expand Down Expand Up @@ -158,7 +160,7 @@ def __init__(self):
floatParameter(
name="M2",
units=u.M_sun,
description="Mass of companion in the unit Sun mass",
description="Companion mass",
)
)
self.add_param(
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/spindown.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def F_terms(self):

def F_description(self, n):
"""Template function for description"""
return "Spin-frequency %d derivative" % n # if n else "Spin-frequency"
return "Spin-frequency derivative %d" % n if n > 0 else "Spin-frequency"

def F_unit(self, n):
"""Template function for unit"""
Expand Down
5 changes: 4 additions & 1 deletion src/pint/models/timing_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__(self, name="", components=[]):
self.add_param_from_top(
strParameter(
name="BINARY",
description="The Pulsar System/Binary model to use.",
description="Pulsar System/Binary model",
value=None,
),
"",
Expand Down Expand Up @@ -3003,6 +3003,9 @@ def add_param(self, param, deriv_func=None, setup=False):
param.name = prefix + str(idx)
param.index = idx

if hasattr(self, f"{prefix}1"):
param.description = getattr(self, f"{prefix}1").description

# A more general check
if param.name in self.params:
exist_par = getattr(self, param.name)
Expand Down
Loading

0 comments on commit f4cbedc

Please sign in to comment.