Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publication output #1621

Merged
merged 35 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
acb27f4
publish.py
abhisrkckl Aug 21, 2023
0a3ca91
param desc
abhisrkckl Aug 21, 2023
24c65a7
as_ufloat
abhisrkckl Aug 21, 2023
ea1021e
options
abhisrkckl Aug 21, 2023
be4ce42
fix descriptions
abhisrkckl Aug 21, 2023
a6280d2
exclude components
abhisrkckl Aug 21, 2023
8af98a4
fix param namess
abhisrkckl Aug 21, 2023
52bdcae
wideband
abhisrkckl Aug 21, 2023
a23008a
script
abhisrkckl Aug 21, 2023
5e2cadd
wave
abhisrkckl Aug 21, 2023
49466e3
log
abhisrkckl Aug 21, 2023
8d06f35
docs
abhisrkckl Aug 21, 2023
22de9e2
test
abhisrkckl Aug 21, 2023
4aca81b
Merge branch 'master' into publish
abhisrkckl Aug 21, 2023
9f1e4c1
changelog
abhisrkckl Aug 21, 2023
4669573
fix test
abhisrkckl Aug 22, 2023
7876c30
latex formatting
abhisrkckl Aug 22, 2023
1296d08
disable fraction
abhisrkckl Aug 22, 2023
1ca2246
desc
abhisrkckl Aug 22, 2023
715ad26
as_latex
abhisrkckl Aug 22, 2023
42b0beb
.gitignore
abhisrkckl Aug 22, 2023
a17e5ad
options
abhisrkckl Aug 22, 2023
80579c6
fix as_latex
abhisrkckl Aug 23, 2023
ab589ff
deal with old astropy
abhisrkckl Aug 23, 2023
e6a28d9
old astropy fix
abhisrkckl Aug 24, 2023
a4a7cbc
Merge branch 'nanograv:master' into publish
abhisrkckl Aug 24, 2023
6648c4a
--
abhisrkckl Aug 24, 2023
3f6f276
Merge branch 'publish' of https://github.com/abhisrkckl/PINT into pub…
abhisrkckl Aug 24, 2023
4181a21
Merge branch 'master' into publish
abhisrkckl Aug 25, 2023
e964d63
Merge branch 'nanograv:master' into publish
abhisrkckl Aug 28, 2023
8346e32
Merge branch 'nanograv:master' into publish
abhisrkckl Aug 29, 2023
13d6173
Merge branch 'nanograv:master' into publish
abhisrkckl Aug 31, 2023
bde240c
Merge branch 'master' into publish
abhisrkckl Aug 31, 2023
f303989
Merge branch 'master' into publish
abhisrkckl Sep 5, 2023
8f7792e
Merge branch 'master' into publish
abhisrkckl Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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:

Check warning on line 584 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L584

Added line #L584 was not covered by tests
# to deal with old astropy
unit_latex = (

Check warning on line 586 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L586

Added line #L586 was not covered by tests
""
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 @@
"""Convert to string."""
return str(val)

def value_as_latex(self):
return self.value

Check warning on line 892 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L892

Added line #L892 was not covered by tests


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

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

Check warning on line 962 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L962

Added line #L962 was not covered by tests


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

return ival

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

Check warning on line 1033 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L1033

Added line #L1033 was not covered by tests


class MJDParameter(Parameter):
"""Parameters for MJD quantities.
Expand Down Expand Up @@ -1166,6 +1195,18 @@
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 @@
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 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 @@
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:

Check warning on line 1972 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L1972

Added line #L1972 was not covered by tests
# `fraction` option is not available in old astropy versions.
unit_latex = (

Check warning on line 1974 in src/pint/models/parameter.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/parameter.py#L1974

Added line #L1974 was not covered by tests
""
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
Loading