diff --git a/CHANGELOG.md b/CHANGELOG.md index 6412a5f7..509bf74b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Renamed `SPNTA.maxlike_params` -> `SPNTA.default_params` - Throw an error if the output directory exists in `pyvela` script - Save only the basename of input files in the summary file in in `pyvela` script +- Changed `par_tim-to-jlso.py` into an installable script `pyvela-jlso`. ## Fixed - Correctly avoid likelihood computation when the parameter is outside prior range. ## Removed diff --git a/pyproject.toml b/pyproject.toml index b915e8c6..9a89ba27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ Documentation = "https://abhisrkckl.github.io/Vela.jl/" pyvela = "pyvela.pyvela_script:main" pyvela-compare = "pyvela.pyvela_compare_script:main" pyvela-plot = "pyvela.pyvela_plot_script:main" +pyvela-jlso = "pyvela.pyvela_jlso_script:main" [tool.setuptools] zip-safe = false diff --git a/pyvela/pyvela/pyvela_jlso_script.py b/pyvela/pyvela/pyvela_jlso_script.py new file mode 100755 index 00000000..59086d45 --- /dev/null +++ b/pyvela/pyvela/pyvela_jlso_script.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +from argparse import ArgumentParser + +from .spnta import SPNTA + + +def parse_args(argv): + parser = ArgumentParser( + prog="pyvela-jlso", + description="Read a par file, tim file, and prior JSON file, and write a JLSO file.", + ) + parser.add_argument( + "par_file", + help="The pulsar ephemeris file. Should be readable using PINT. The " + "uncertainties listed in the file will be used for 'cheat' priors where applicable.", + ) + parser.add_argument( + "tim_file", help="The pulsar TOA file. Should be readable using PINT." + ) + parser.add_argument( + "-P", + "--prior_file", + help="A JSON file containing the prior distributions for each free parameter.", + ) + parser.add_argument( + "-C", + "--cheat_prior_scale", + default=50, + type=float, + help="The scale factor by which the frequentist uncertainties are multiplied to " + "get the 'cheat' prior distributions.", + ) + parser.add_argument( + "-o", + "--outfile", + help="The output file name. Will replace an existing file.", + required=True, + ) + + return parser.parse_args(argv) + + +def main(argv=None): + args = parse_args(argv) + + spnta = SPNTA( + args.par_file, + args.tim_file, + cheat_prior_scale=args.cheat_prior_scale, + custom_priors=(args.prior_file if args.prior_file is not None else {}), + ) + spnta.save_jlso(args.outfile) diff --git a/pyvela/scripts/par_tim-to-jlso.py b/pyvela/scripts/par_tim-to-jlso.py deleted file mode 100755 index 7bba386f..00000000 --- a/pyvela/scripts/par_tim-to-jlso.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python - -import sys - -from pyvela.spnta import par_tim_to_jlso - -parfile, timfile, jlsofile = sys.argv[1], sys.argv[2], sys.argv[3] - -par_tim_to_jlso(parfile, timfile, jlsofile) diff --git a/pyvela/tests/test_run_analysis.py b/pyvela/tests/test_run_analysis.py index 74a41d1e..9b4406ee 100644 --- a/pyvela/tests/test_run_analysis.py +++ b/pyvela/tests/test_run_analysis.py @@ -6,7 +6,12 @@ import pytest from pyvela.spnta import SPNTA -from pyvela import pyvela_compare_script, pyvela_script, pyvela_plot_script +from pyvela import ( + pyvela_compare_script, + pyvela_jlso_script, + pyvela_script, + pyvela_plot_script, +) from pint.models import get_model_and_toas prior_str = """ @@ -97,3 +102,21 @@ def test_compare_script(dataset): args = f"{parfile} {timfile} -P {prior_file}".split() pyvela_compare_script.main(args) + + +@pytest.mark.parametrize("dataset", ["NGC6440E"]) +def test_jlso_script(dataset): + datadir = os.path.dirname(os.path.realpath(__file__)) + "/datafiles" + parfile, timfile = f"{datadir}/{dataset}.par", f"{datadir}/{dataset}.tim" + + prior_file = "__prior.json" + with open(prior_file, "w") as pf: + print(prior_str, file=pf) + + outfile = f"__{dataset}.jlso" + + args = f"{parfile} {timfile} -P {prior_file} -o {outfile}".split() + + pyvela_jlso_script.main(args) + + assert os.path.isfile(outfile)