Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed default toa errors for event files. can also set explicitly #1591

Merged
merged 13 commits into from
Jun 15, 2023

Conversation

dlakaplan
Copy link
Contributor

Default errors are 1 us for all event files. Can also set as a Quantity or float

@dlakaplan dlakaplan linked an issue Jun 13, 2023 that may be closed by this pull request
@dlakaplan
Copy link
Contributor Author

It's sort of weird to have errors associated with individual photons, but I agree they probably need to be > 0 to make basic fitting/chi^2 calculations work.

@paulray
Copy link
Member

paulray commented Jun 13, 2023

Looks good to me! Thanks for the quick fix!

@paulray
Copy link
Member

paulray commented Jun 13, 2023

Oops, the CI doesn't like the repeated errors kwarg

@dlakaplan
Copy link
Contributor Author

Yes, I fixed that. I was actually thinking that an explicit test of this for non-Fermi satellites would also be useful (I hadn't had time/found the right test yet). For the Fermi case it is tested.

@scottransom
Copy link
Member

@dlakaplan The time tagging of Fermi photons is only guaranteed to about that level, though, right? So there really is an error. @paulray probably knows the exact number.

@scottransom
Copy link
Member

Fermi LAT webpage says "<10us, relative to spacecraft time"
https://fermi.gsfc.nasa.gov/ssc/data/analysis/documentation/Cicerone/Cicerone_Introduction/LAT_overview.html

@paulray
Copy link
Member

paulray commented Jun 13, 2023

Smith et al. (2008) says: "Ground tests using cosmic ray muons demonstrated that the LAT measures event times with precision relative to UTC significantly better than a microsecond (Smith et al. 2006). On orbit, satellite
telemetry indicates comparable accuracy. The contribution to the barycentered time resolution from uncertainty in the LAT’s position is negligible."

@dlakaplan
Copy link
Contributor Author

I guess my point was more about hard-coding a single value for all spacecraft, rather than having some uncertainty present. But this is fine in any case.

@codecov
Copy link

codecov bot commented Jun 13, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05 🎉

Comparison is base (b8511a3) 68.07% compared to head (09f6e8b) 68.13%.

❗ Current head 09f6e8b differs from pull request most recent head c20c525. Consider uploading reports for the commit c20c525 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1591      +/-   ##
==========================================
+ Coverage   68.07%   68.13%   +0.05%     
==========================================
  Files          98       98              
  Lines       22608    22618      +10     
  Branches     3881     3883       +2     
==========================================
+ Hits        15391    15410      +19     
+ Misses       6270     6260      -10     
- Partials      947      948       +1     
Impacted Files Coverage Δ
src/pint/event_toas.py 80.10% <100.00%> (+7.08%) ⬆️
src/pint/fermi_toas.py 61.62% <100.00%> (+1.38%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

src/pint/event_toas.py Outdated Show resolved Hide resolved
src/pint/event_toas.py Outdated Show resolved Hide resolved
src/pint/event_toas.py Outdated Show resolved Hide resolved
src/pint/event_toas.py Outdated Show resolved Hide resolved
src/pint/event_toas.py Outdated Show resolved Hide resolved
src/pint/event_toas.py Outdated Show resolved Hide resolved
@dlakaplan
Copy link
Contributor Author

I made all of the uncertainties separate and set by instrument. It would actually be better to turn the instrument-by-instrument functions into some factory functions.

@paulray
Copy link
Member

paulray commented Jun 14, 2023

I made all of the uncertainties separate and set by instrument. It would actually be better to turn the instrument-by-instrument functions into some factory functions.

Looks good! I might be better to make a factory function, but I don't think it needs to be part of this PR. I'm in favor of merging this once the tests pass.

@dlakaplan
Copy link
Contributor Author

I can probably use functools to do that quickly. Let me try while I'm on another call - I can probably do it before the tests pass

@dlakaplan
Copy link
Contributor Author

It's pretty easy using functools.partial. The only downside is that the signature changes to it's less clear what the arguments are:

functools.partial(<function get_event_TOAs at 0x...60d0>, mission='nicer', errors=<Quantity 0.1 us>)
    Read photon event times out of a NICER file as a :class:`pint.toa.TOAs` object
    
    Correctly handles raw event files, or ones processed with axBary to have
    barycentered TOAs. Different conditions may apply to different missions.
    
    The minmjd/maxmjd parameters can be used to avoid instantiation of TOAs
    we don't want, which can otherwise be very slow.
    
    Parameters
    ----------
    eventname : str
        File name of the FITS event list
    minmjd : float, default "-infinity"
        minimum MJD timestamp to return
    maxmjd : float, default "infinity"
        maximum MJD timestamp to return
    errors : astropy.units.Quantity or float, optional
        The uncertainty on the TOA; if it's a float it is assumed to be
        in microseconds
    ephem : str, optional
        The name of the solar system ephemeris to use; defaults to "DE421".
    planets : bool, optional
        Whether to apply Shapiro delays based on planet positions. Note that a
        long-standing TEMPO2 bug in this feature went unnoticed for years.
        Defaults to False.

Do you think this is OK? The docstring can still be correct. This is easier to update/maintain.

@dlakaplan
Copy link
Contributor Author

Let me know if you think the latest push is OK. It's easier than before, but you still need to set each function explicitly (more complicated things are possible but seemed harder). It's a lot easier to read the definitions and make sure they are all consistent. The downside is that the signature is harder to understand.

@paulray
Copy link
Member

paulray commented Jun 14, 2023

Yeah, that looks good. It is nice to remove all the redundancy.

@dlakaplan
Copy link
Contributor Author

The other side of this is that the functions created with partial don't seem to be in the default RTD:
https://nanograv-pint--1591.org.readthedocs.build/en/1591/_autosummary/pint.event_toas.html

@paulray
Copy link
Member

paulray commented Jun 14, 2023

Oh, that's not optimal

@dlakaplan
Copy link
Contributor Author

Yes, I'll see if there's a quick fix.

@dlakaplan
Copy link
Contributor Author

Oddly, sphinx-doc/sphinx#5305 says it will add autodocs for partial functions, and I think our sphinx should be recent enough. But on the other hand I see people in the original issues trying with 1.8 and still having problems. I don't know if there were divergences between the sphinx 1.8 releases (which we use) and the 2.0/3.0/... releases. We are pinned to <2, but the current release is 7

@dlakaplan
Copy link
Contributor Author

@paulray : please look at the lated RTD build. I explicitly added the instrument-specific functions. It's still not perfect, as they don't collapse like normal. And now the instruments need to be included in 3 places. I still feel that something like this is useful, but maybe it's better to go back a couple of pushes and deal with this other stuff later.

@paulray
Copy link
Member

paulray commented Jun 15, 2023

I think this looks fine. My only suggestion would be to try to get the preferred get_XXX_TOAs functions to appear in the docs before the load_XXX_TOAs functions. Is that possible?

@dlakaplan
Copy link
Contributor Author

Changed

@dlakaplan
Copy link
Contributor Author

It is possible to define these functions dynamically. But I haven't found a nice way. The best I can do is:

for mission in ["RXTE", "NICER", "NuSTAR", "XMM", "Swift", "IXPE"]:
    exec(
        f"get_{mission}_TOAs = partial(get_event_TOAs, mission=mission.lower(), errors=_default_uncertainty[mission])"
    )
    exec(f"get_{mission}_TOAs.__doc__ = _get_event_docstring.format(mission)")

which seems too messy.

@paulray paulray merged commit febe889 into nanograv:master Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zero errors when loading Fermi TOAs
3 participants