Skip to content

Add MockPulsar class, for easy use of Mock data with Enterprise - #361

Merged
vhaasteren merged 41 commits into
nanograv:devfrom
vhaasteren:mockpulsar
Jul 15, 2026
Merged

Add MockPulsar class, for easy use of Mock data with Enterprise#361
vhaasteren merged 41 commits into
nanograv:devfrom
vhaasteren:mockpulsar

Conversation

@vhaasteren

@vhaasteren vhaasteren commented Sep 29, 2023

Copy link
Copy Markdown
Member

This adds a very rudimentary MockPulsar class: a class that can be easily instantiated without a timing package (PINT/Tempo2). All Enterprise models can be run on this type of pulsar object, but it can be instantiated from mock data very quickly. This is useful for anyone who wants to use Enterprise on fake data. Previously, one had to rely on fake par/tim files, created through libstempo.toasim or otherwise.

Note: this is coded up as part of Enterprise, and not Enterprise_extensions, because the pulsar class is essential for usage of Enterprise. Allowing Enterprise to be useful without a timing package was a big plus, but with libstempo/PINT optional I guess that's less of an advantage now

Todo:

  • Create unit tests
  • Add Astrometry parameters, aside from only Spindown

Additional todo, perhaps not part of this PR:

  • Add helper functions to enterprise_extensions so this class can be instantiated easily
  • Resolve unit disparity of PMRA / PMDEC between Tempo2 and PINT
  • Add documentation for Tempo2Pulsar and PintPulsar

As in the test suite, a typical way to add this pulsar is:

toas = np.linspace(53000.0, 58000.0, 4005)
flags = {"f": np.array(["nosystem"] * 4005), "fe": np.array(["nofrontend"] * 4005)}
decj, raj = (0.16848694562363042, 4.9533700839400492)
# Can also define elong/elat

psr = MockPulsar(
    obs_times_mjd=toas,
    raj=raj,
    decj=decj,
    ssbfreqs=1440.0 * np.ones_like(toas),
    residuals=np.zeros_like(toas),
    toaerrs=1e-6 * np.ones_like(toas),
    sort=True,
    flags=flags,
    telescope="GBT",
    spindown_order=2,
    inc_astrometry=True,
)

This pulsar now has psr.name == 'J1855+0939', and the design matrix contains astrometry and spin models (so 8 parameters). Residuals can be set with:

psr.set_residuals(residuals)

This pulsar is extremely fast to make, and can be combined with most Enterprise functionality. Astrometry parameters depend on Astropy (optional dependency).

@vhaasteren
vhaasteren marked this pull request as draft September 29, 2023 06:58
@vhaasteren
vhaasteren changed the base branch from master to dev November 7, 2023 08:57
@codecov

codecov Bot commented Nov 28, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.62069% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.42%. Comparing base (544a737) to head (7a164ad).
⚠️ Report is 6 commits behind head on dev.

Files with missing lines Patch % Lines
enterprise/pulsar.py 94.44% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #361      +/-   ##
==========================================
+ Coverage   72.85%   74.42%   +1.56%     
==========================================
  Files          13       13              
  Lines        3489     3632     +143     
==========================================
+ Hits         2542     2703     +161     
+ Misses        947      929      -18     
Files with missing lines Coverage Δ
enterprise/signals/utils.py 85.89% <100.00%> (+2.94%) ⬆️
enterprise/pulsar.py 37.63% <94.44%> (+7.71%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8227442...7a164ad. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vhaasteren
vhaasteren marked this pull request as ready for review March 28, 2025 14:44
@vhaasteren

Copy link
Copy Markdown
Member Author

This is still ready to be reviewed

@vhaasteren
vhaasteren merged commit c8062c3 into nanograv:dev Jul 15, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant