Skip to content

Commit

Permalink
Merge pull request #1847 from abhisrkckl/script_allow_tcb
Browse files Browse the repository at this point in the history
Enable allow_tcb and allow_T2 by default in command line scripts
  • Loading branch information
dlakaplan authored Nov 22, 2024
2 parents 10cfbdb + 706f041 commit 96adf4b
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ the released changes.

## Unreleased
### Changed
- Command line scripts now automatically do `allow_tcb` and `allow_T2` while reading par files.
- Updated the `plot_chains` function in `event_optimize` so that the subplots are a fixed size to prevent the subplots from being condensed in the case of many fit parameters.
### Added
- Added an option `linearize_model` to speed up the photon phases calculation within `event_optimize` through the designmatrix.
Expand Down
8 changes: 6 additions & 2 deletions src/pint/pintk/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ def __contains__(self, key):
return key in self.prefit_model.params

def reset_model(self):
self.prefit_model = pint.models.get_model(self.parfile)
self.prefit_model = pint.models.get_model(
self.parfile, allow_T2=True, allow_tcb=True
)
self.add_model_params()
self.postfit_model = None
self.postfit_resids = None
Expand All @@ -172,7 +174,9 @@ def reset_TOAs(self):
self.update_resids()

def resetAll(self):
self.prefit_model = pint.models.get_model(self.parfile)
self.prefit_model = pint.models.get_model(
self.parfile, allow_T2=True, allow_tcb=True
)
self.postfit_model = None
self.postfit_resids = None
self.fitted = False
Expand Down
15 changes: 13 additions & 2 deletions src/pint/scripts/compare_parfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,25 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
level=pint.logging.get_level(args.loglevel, args.verbosity, args.quiet)
)

m1 = get_model(args.input1)
m2 = get_model(args.input2)
m1 = get_model(args.input1, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb)
m2 = get_model(args.input2, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb)

print(
m1.compare(
m2,
Expand Down
14 changes: 13 additions & 1 deletion src/pint/scripts/convert_parfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
Expand All @@ -83,7 +93,9 @@ def main(argv=None):
return

log.info(f"Reading '{args.input}'")
model = get_model(args.input)

model = get_model(args.input, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb)

if hasattr(model, "BINARY") and args.binary is not None:
log.info(f"Converting from {model.BINARY.value} to {args.binary}")
if args.binary == "ELL1H":
Expand Down
14 changes: 13 additions & 1 deletion src/pint/scripts/event_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,16 @@ def main(argv=None):
action="store_true",
dest="linearize_model",
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
Expand Down Expand Up @@ -739,7 +749,9 @@ def main(argv=None):
ncores = args.ncores

# Read in initial model
modelin = pint.models.get_model(parfile)
modelin = pint.models.get_model(
parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

# File name setup and clobber file check
filepath = args.filepath or os.getcwd()
Expand Down
15 changes: 14 additions & 1 deletion src/pint/scripts/event_optimize_MCMCFitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ def main(argv=None):
help="Logging level",
dest="loglevel",
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

global nwalkers, nsteps, ftr

args = parser.parse_args(argv)
Expand Down Expand Up @@ -164,7 +175,9 @@ def main(argv=None):
wgtexp = args.wgtexp

# Read in initial model
modelin = pint.models.get_model(parfile)
modelin = pint.models.get_model(
parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

# The custom_timing version below is to manually construct the TimingModel
# class, which allows it to be pickled. This is needed for parallelizing
Expand Down
14 changes: 13 additions & 1 deletion src/pint/scripts/event_optimize_multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ def main(argv=None):
help="Logging level",
dest="loglevel",
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

global nwalkers, nsteps, ftr

Expand Down Expand Up @@ -261,7 +271,9 @@ def main(argv=None):
wgtexp = args.wgtexp

# Read in initial model
modelin = pint.models.get_model(parfile)
modelin = pint.models.get_model(
parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

# Set the target coords for automatic weighting if necessary
if "ELONG" in modelin.params:
Expand Down
15 changes: 14 additions & 1 deletion src/pint/scripts/fermiphase.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
Expand All @@ -88,7 +98,10 @@ def main(argv=None):
args.addphase = True

# Read in model
modelin = pint.models.get_model(args.parfile)
modelin = pint.models.get_model(
args.parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

if "ELONG" in modelin.params:
tc = SkyCoord(
modelin.ELONG.quantity,
Expand Down
15 changes: 14 additions & 1 deletion src/pint/scripts/photonphase.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
Expand Down Expand Up @@ -153,7 +163,10 @@ def main(argv=None):
"Please barycenter the event file using the official mission tools before processing with PINT"
)
# Read in model
modelin = pint.models.get_model(args.parfile)
modelin = pint.models.get_model(
args.parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

use_planets = False
if "PLANET_SHAPIRO" in modelin.params:
if modelin.PLANET_SHAPIRO.value:
Expand Down
14 changes: 13 additions & 1 deletion src/pint/scripts/pintbary.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
Expand Down Expand Up @@ -105,7 +115,9 @@ def main(argv=None):
)

if args.parfile is not None:
m = pint.models.get_model(args.parfile)
m = pint.models.get_model(
args.parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)
else:
# Construct model by hand
m = pint.models.StandardTimingModel
Expand Down
14 changes: 13 additions & 1 deletion src/pint/scripts/pintempo.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,26 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
level=pint.logging.get_level(args.loglevel, args.verbosity, args.quiet)
)

log.info("Reading model from {0}".format(args.parfile))
m = pint.models.get_model(args.parfile)
m = pint.models.get_model(
args.parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

log.warning(m.params)

Expand Down
14 changes: 13 additions & 1 deletion src/pint/scripts/pintpublish.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,22 @@ def main(argv=None):
action="store_true",
default=False,
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)

model, toas = get_model_and_toas(args.parfile, args.timfile)
model, toas = get_model_and_toas(
args.parfile, args.timfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

output = publish(
model,
Expand Down
7 changes: 6 additions & 1 deletion src/pint/scripts/t2binary2pint.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ def main(argv=None):
default=True,
help="Whether to drop SINI if the model is DDK (True)",
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)

args = parser.parse_args(argv)

mb = ModelBuilder()

model = mb(args.input_par, allow_T2=True, allow_tcb=True)
model = mb(args.input_par, allow_T2=True, allow_tcb=args.allow_tcb)
model.write_parfile(args.output_par)
print(f"Output written to {args.output_par}")

Expand Down
7 changes: 6 additions & 1 deletion src/pint/scripts/tcb2tdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ def main(argv=None):
)
parser.add_argument("input_par", help="Input par file name (TCB)")
parser.add_argument("output_par", help="Output par file name (TDB)")
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)

mb = ModelBuilder()
model = mb(args.input_par, allow_tcb=True)
model = mb(args.input_par, allow_tcb=True, allow_T2=args.allow_T2)
model.write_parfile(args.output_par)

log.info(f"Output written to {args.output_par}.")
14 changes: 13 additions & 1 deletion src/pint/scripts/zima.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,26 @@ def main(argv=None):
parser.add_argument(
"-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
)
parser.add_argument(
"--allow_tcb",
action="store_true",
help="Convert TCB par files to TDB automatically",
)
parser.add_argument(
"--allow_T2",
action="store_true",
help="Guess the underlying binary model when T2 is given",
)

args = parser.parse_args(argv)
pint.logging.setup(
level=pint.logging.get_level(args.loglevel, args.verbosity, args.quiet)
)

log.info("Reading model from {0}".format(args.parfile))
m = pint.models.get_model(args.parfile)
m = pint.models.get_model(
args.parfile, allow_T2=args.allow_T2, allow_tcb=args.allow_tcb
)

out_format = args.format
error = args.error * u.microsecond
Expand Down

0 comments on commit 96adf4b

Please sign in to comment.