From 5be3e48b19b03cb3dd71365f0f40430fad967ed5 Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Thu, 19 Oct 2023 10:54:08 -0500 Subject: [PATCH] pintk can swap inputs --- CHANGELOG-unreleased.md | 1 + src/pint/scripts/pintk.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index 8200caa75..cb7e698a8 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -29,6 +29,7 @@ the released changes. - Piecewise orbital model (`BinaryBTPiecewise`) - `TimingModel.fittable_params` property - Simulate correlated noise using `pint.simulation` (also available via the `zima` script) +- `pintk` will recognize when timfile and parfile inputs are switched and swap them ### Fixed - Wave model `validate()` can correctly use PEPOCH to assign WAVEEPOCH parameter - Fixed RTD by specifying theme explicitly. diff --git a/src/pint/scripts/pintk.py b/src/pint/scripts/pintk.py index 96cf6ee5c..9f0899ccc 100644 --- a/src/pint/scripts/pintk.py +++ b/src/pint/scripts/pintk.py @@ -3,11 +3,13 @@ import argparse import sys +import os import tkinter as tk import tkinter.filedialog as tkFileDialog import tkinter.messagebox as tkMessageBox import matplotlib as mpl +from loguru import logger as log import pint.logging @@ -260,6 +262,24 @@ def main(argv=None): pint.logging.setup( level=pint.logging.get_level(args.loglevel, args.verbosity, args.quiet) ) + # see if the arguments were flipped + if ( + os.path.splitext(args.parfile)[1] == ".tim" + and os.path.splitext(args.timfile)[1] == ".par" + ): + log.debug( + f"Swapping inputs: parfile='{args.timfile}' and timfile='{args.parfile}'" + ) + args.parfile, args.timfile = args.timfile, args.parfile + else: + if os.path.splitext(args.timfile)[1] != ".tim": + log.info( + f"Input timfile '{args.timfile}' has unusual extension '{os.path.splitext(args.timfile)[1]}': is this intended?" + ) + if os.path.splitext(args.parfile)[1] != ".par": + log.info( + f"Input parfile '{args.parfile}' has unusual extension '{os.path.splitext(args.parfile)[1]}': is this intended?" + ) root = tk.Tk() root.minsize(1000, 800)