-
Notifications
You must be signed in to change notification settings - Fork 101
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
Remove u.cycle units from phases #685
Conversation
@mhvk We had a discussion about the u.cycle for pulse phase. I remember you tried to improve the |
Indeed, I constructed a precise |
* nanograv/master: Update CHANGELOG Update CHANGELOG Make import pint not update IERS immediately Fix README Remove deprecated pytest-runner from setup.cfg
Just a note that @champagne-cmd is starting to work on a set of unit tests for the |
For the unit tests, you may be able to use quite a bit from https://github.com/mhvk/scintillometry/blob/master/scintillometry/tests/test_phase_class.py My original intent was to push the phase class up to PINT, and I'm quite happy to help if people are interested. I do think it is the right way in terms of a |
Thanks @mhvk, those are some extensive examples of unit tests! In the big picture, we need to consider what to do for PINT. At the moment, we have 3 options, I think: To decide, we need to consider how I started looking back at the code I had to change to remove
This thus forces you to either use the equivalency or pull out p1.value. This negates any value of the unit. So, if we decide we must use the u.cycle unit, I think we should change our frequencies to be in u.cycle/u.s instead if u.Hz. For this and some of the other reasons we've talked about, I favor stripping the u.cycle unit from Phases, as done by this PR. |
@paulray - I think there are two separate questions: (i) what unit to use, and (ii) how to keep precision. On (ii), PINT doesn't seem to use its own On the unit, I can see p.s. |
p.s. Are you going to remove the unit from orbital phase too? I ask since that will likely break a few custom scripts that students wrote here (well, @luojing1211 can tell: does this affect things like Ashley's scripts?), and hence you may want to consider also whether phases more generally are used outside PINT. |
It is only for the rotational phase. The major API should be as same as possible. |
It is strange that PINT uses its Phase class so little. The phase functions of a TimingModel don't even return Phases! They are converted to Phase in TimingModel.phase() like this:
Since (at least if we merge this PR) our phases are fractions of a cycle, not angles, I guess we'd have to write On orbital phase, I'll have to check on that... |
Yeah, it looks like orbital phases are normal quantities with units of |
@paulray - thanks! Obviously, in the end it is up to all of you, but I would use at least equivalent units between orbital and rotational phase. Aside: how should one test these days? I thought I would rebase my phase-class PR and tried |
@mhvk sorry, that is annoying. As far as I know |
yes, it may be that somehow some local matplotlib setting manages to get through (I do use KDE which uses qt) ... |
OK, clearly a different issue, so #694... |
So, at the telecon, we decided to merge this PR. But, we are very interested in studying @mhvk's Phase class as well. We are wondering if a version of it that kept many of the nice features (that are missing in our simple Phase class) but didn't use the u.cycle unit might be worthwhile? |
@paulray - I think it would not be particularly difficult for the class itself have the equivalency between cycles and dimensionless built-in. Indeed, the example I pushed in #695 already did that for initialization, and that could be extended to the unit-conversion methods I do think that the same phase class (or a lower-precision version) should be used for orbital phase as well. |
p.s. I repeated the above in #695 and it is probably good to move further discussion there - merged PRs are not the right place! |
Should have realized this while discussing above, but unsurprisingly this broke our use of PINT phases for folding in |
Yeah, sorry! I suspect that others might have the same issue, like @matteobachetti with HENDRICS. Now that we have tagged the version to go with the paper, I hope that we can keep these kind of significant API changes to a minimum! |
@paulray thanks for the warning, I'll check |
OK this was easier than I expected, at least so far.
I change Phases to be u.dimensionless_unscaled (which is a synonym for u.Units("") and Quantity(x)), so Phases are still Quantities, they just are dimensionless. I think this is the right choice rather than trying to make them bare np.arrays.
I removed all the
u.cycle
references and many dimensionless_cycle equivalencies. In nearly all cases, this was a simplification of the code, which gives me confidence that this is the right way to go.All the tests pass, but this will need review and people to test it with their downstream code.