-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: allow passing coordinates to to_Vector*D #319
Conversation
Codecov ReportBase: 82.72% // Head: 82.87% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #319 +/- ##
==========================================
+ Coverage 82.72% 82.87% +0.15%
==========================================
Files 96 96
Lines 11366 11396 +30
==========================================
+ Hits 9402 9445 +43
+ Misses 1964 1951 -13
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good extension, with sufficient tests. I see that
- 2D → 3D
- 2D → 4D
- 3D → 4D
are all covered, and I believe this is a complete set.
I made some comments below about the error message and that more synonyms might be needed in the momentum cases. They're suggestions.
src/vector/_methods.py
Outdated
if sum(x is not None for x in (z, theta, eta)) > 1: | ||
raise TypeError("Only one non-None parameter allowed") | ||
raise TypeError("Only one non-None longitudinal coordinate allowed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above is helpful; maybe this is even more helpful (and it sets the tone for what the other to_Vector*D
should do).
raise TypeError("Only one non-None longitudinal coordinate allowed") | |
raise TypeError("At most one longitudinal coordinate (`z`, `theta`, or `eta`) may be assigned (non-None)") |
By the way, these to_Vector*D
functions maintain momentum-ness, right? For example, is it the case that Momentum2D.to_Vector3D
returns a Momentum3D
?
If so, then a user might justifiably expect to pass pz
instead or z
, but only in the momentum case. Just something to consider, at this point.
When this gets extended to to_Vector4D
, the time component has a lot of momentum synonyms. The geometric names for the two possible temporal coordinates are t
and tau
, but the momentum names are energy
and mass
, E
and M
, and (I think) e
and m
. There was a discussion once about including the lowercase as well as the uppercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they do maintain momentum-ness. Right now the generic coordinates are automatically converted to momentum coordinates, but yes, we can explicitly add momentum coordinates as arguments in the future -
In [1]: import vector
In [2]: vector.obj(px=1, py=2).to_Vector4D(z=3, t=4)
Out[2]: MomentumObject4D(px=1, py=2, pz=3, E=4)
In [3]: vector.obj(px=1, py=2).to_Vector4D(eta=3, tau=4)
Out[3]: MomentumObject4D(px=1, py=2, eta=3, mass=4)
src/vector/_methods.py
Outdated
if sum(x is not None for x in (z, theta, eta)) > 1: | ||
raise TypeError("Only one non-None longitudinal coordinate allowed") | ||
elif sum(x is not None for x in (t, tau)) > 1: | ||
raise TypeError("Only one non-None temporal coordinate allowed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar error messages: help the user by spelling out what the longitudinal and temporal coordinates are, since the user would more likely be familiar with concrete names like z
, theta
, eta
than "longitudinal".
src/vector/_methods.py
Outdated
if sum(x is not None for x in (t, tau)) > 1: | ||
raise TypeError("Only one non-None temporal coordinate allowed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing.
Co-authored-by: Jim Pivarski <jpivarski@users.noreply.github.com>
…nto pass-coords
Thanks for the review! I will merge this in and tag |
Description
Closes #276
Adds test and docs for #278
Checklist
$ pre-commit run --all-files
or$ nox -s lint
)$ pytest
or$ nox -s tests
)$ cd docs; make clean; make html
or$ nox -s docs
)$ xdoctest ./src/vector
or$ nox -s doctests
)Before Merging