nanograv / enterprise

ENTERPRISE (Enhanced Numerical Toolbox Enabling a Robust PulsaR Inference SuitE) is a pulsar timing analysis code, aimed at noise analysis, gravitational-wave searches, and timing model analysis.
https://enterprise.readthedocs.io
MIT License
64 stars 65 forks source link

Handle paths specified using Path objects #332

Open aarchiba opened 1 year ago

aarchiba commented 1 year ago

Python has had for a while dedicated objects for working with paths (allowing things like if parfile.exists(): or timfile = parfile.with_suffix("tim")). Currently at least the Pulsar factory cannot accept these:

parfile = Path("file.par")
timfile = Path("file.tim")
Pulsar(parfile, timfile)

yields

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[9], line 1
----> 1 psr = Pulsar((parfile), (timfile))

File ~/software/miniconda3/envs/enterprise-development/lib/python3.10/site-packages/enterprise/pulsar.py:665, in Pulsar(*args, **kwargs)
    662         os.chdir(cwd)
    663         return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar, planets=planets)
--> 665 raise ValueError("Unknown arguments {}".format(args))

ValueError: Unknown arguments (PosixPath('../enterprise_files/J0023+0923.nb.par'), PosixPath('../enterprise_files/J0023+0923.nb.tim'))

The user must apply str to each before passing them to Pulsar(). It should work fine with these objects.

aarchiba commented 1 year ago

I think this could probably be fixed by broadening the check for strings in the Pulsar() function, but I'm hesitant to add any complication to the already complicated and unusual way it handles its arguments. Would it be okay to simplify the function? Specifically, accept exactly two positional arguments, with a preferred order but the ability to swap them if they are the wrong way around (optionally with a warning), plus some named keyword arguments, plus a **kwargs to be passed in to the eventual constructor?

I can put together a demo PR, though I can't run the test suite without segfaults (#339).

paulthebaker commented 1 year ago

I can't run the test suite without segfaults

Given what we've seen with the test segfaults, I would assume you could run make lint and pytest tests/test_pulsar.py successfully, even if make test fails. After those run locally, we can count on the CI PR tests to catch anything else.