Class methods for Phase based on Lattice/Crystal system#645
Conversation
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
|
@argerlt did you want to link the guidance on f strings in docs? I kind of agree that while things like f strings are nice for some developers it does make the code harder to read sometimes. |
|
Thanks for adding these methods, @argerlt! They make many things easier, as you say. I suggest we stick to the default lattices of
They're valid. They're also the ones used in MTEX.
I can print the string representation of the crystal vectors without issue. I'm using v0.15.dev2 (current develop branch). Which error do you get? |
| The name to give to the Phase. If None, a name will be inhereted | ||
| from *structure* if possible. If name is a Phase object, a copy | ||
| of that phase is returned instead, and all further arguments | ||
| are ignored. |
There was a problem hiding this comment.
I suggest to use regular language as much as we can. So I'd rephrase to something like:
The name to give the phase. If not given, a name will be inhereted from structure, if possible. If a phase is given, a copy of that phase is returned instead, and all further arguments are ignored.
So I'd not capitalize, and also not talk about "objects", and rather talk about a phase (Phase), an orientation (Orientation), a crystal vector (Miller) and so on. As long as it's not imprecise, of course, which I don't think it is here.
There was a problem hiding this comment.
Point of clarification: I still think docstrings like this one from Phase.structure are hugely helpful:
The unit cell is defined using the diffpy
:class:`~diffpy.structure.Structure` class. For reciprocal
space calculations, the structure must include a
:class:`~diffpy.structure.Lattice`. For atomic distance
calculations, the structure must include one or more
:class:`~diffpy.structure.atom.Atom`.
As long as you are still on board with this type of cross-linking when specific class types need to be referenced, yes, I agree, regular language is much better.
Actually, maybe a good rule is: if it's important enough to call out a specific class, it's also important enough to link to it's documentation.
There was a problem hiding this comment.
Yes, intersphinx references are very useful in the built docs and in at least VS Code's docstring preview.
| The list of known point group aliases can be seen using the | ||
| following command: | ||
| >>> import orix.quaternion as oqu | ||
| >>> [point_group.name for point_group in oqu.symmetry._groups] |
There was a problem hiding this comment.
This should be under an Examples section.
| value : str | ||
| Phase name. | ||
| """ | ||
| """The name of the phase.""" |
| """Return whether the crystal structure is hexagonal/trigonal or | ||
| not. | ||
| """ | ||
| """Returns True for hexagonal and trigonal crystal structures.""" |
There was a problem hiding this comment.
To better understand your changes here, could you say why the new docstring is better?
We should use "Return", not "Returns". Numpydoc will complain about "Returns". See e.g. the PEP 257 on one-line docstrings.
There was a problem hiding this comment.
The "... or not" should be removed, so I think the docstring should be:
Return whether the crystal structure is hexagonal/trigonal.
There was a problem hiding this comment.
My understanding from the numpydoc style guide was that every function should try to have a single line descriptor. This comment and the others like it were an attempt at sticking to that convention.
If you don't like it, we can revert it. If sticking to a convention dilutes the value of the docstring, it's not worth it.
There was a problem hiding this comment.
I think there are mainly two reasons to keep it short:
- When reading it, you get the gist right away
- It displays nicely in the Sphinx autosummary table: https://orix.readthedocs.io/en/stable/reference/generated/orix.quaternion.html#module-orix.quaternion
I interpret "single line" in that it must be a single sentence and it should be short, but it doesn't have to be a single line. A sentence over two-three lines can still be short, I think.
There was a problem hiding this comment.
That's reasonable. I recently switched to a Ruff linter that attempts to enforce it, but I think the linter is bad.
There was a problem hiding this comment.
I'm using Ruff in other projects (with a version controlled config file, (#568)), and there I don't experience this. Must be some setting, perhaps related to pydoclint settings?
|
After we agree on how to proceed based on my comments, is it OK if I push some commits? |
This sent me on a long journey. Quick summary though: the issue hasn't existed since this commit. Since then, the new if/then/else logic ensures
Fair. It bothers me that using a default cubic lattice for triclinic systems will produce impossible structure factors and symmetry relations, but an arbitrary dictionary of ad-hoc constants is also bad in retrospect. I'll revert this. |
@CSSFrancis, I don't think I do here, I'm not sure anyone is going to read and gain value from a comment on a style choice in a docstring. That said, it might be worth adding to the style guide page in a later PR. |
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
Yes, push whatever you want. My only concern is making sure we are on the same page w.r.t. this comment, but everything else is good. I'll also add, I'm not super attached to the updates I made to the docstrings. I felt some of the old ones read roughly and I wanted to try enforcing the one-line style suggestion from numpydoc, but I wont be bothered if you alter or revert several of them. |
Hm, this doesn't sound good. Can you provide an example snippet or two? |
|
To maybe summarize my point, I think
Is a solid reason to leave as-is. Maybe not crystallographically valid, but safer than the alternative. |
|
Thank you, I appreciate the effort to stress the fact that orix is useful in diffraction work and that we should consider this. You've convinced me that we can use different lattices for the default ones. The question is which. I'd prefer them to not be random. The options I see are:
Thoughts? |
|
I think option 2 makes more sense.
This side-steps.my worry of "making more arbitrary standards" as well. I like this option a lot. Wollastonite and Nickel seem like safe bets. I will look for others, but if you have good suggestions, drop them here as well. |
|
Of course, if we're returning a real phase, a valid question is then whether we should instead supply a small database of example phases via
The idea is that the former can be used to quickly create an arbitrary lattice. The latter provides a databse of real phases we can use for diffraction examples in diffsims, pyxem, kikuchupy, and so on. Sorry for the de-tour, here. |
Eh, it's a frustrating detour but an important one. Better to get it right now than fix it later. Your last suggestion is a good plan. As you said:
Which seems like good compromise of dealing with my concerns while also not deviating from the MTEX defaults or forcing assumptions about phase. Also, I didn't think about it until days later, but anecdotally, I've had considerable problems with HeXRD assuming Nickel as the default phase. The solution then was "force users to explicitly define everything", and this seems like a kinder but similar approach. |




Description of the change
With Regard to the Docstrings:
The docstrings in
Phasehave been updated to:The last point was done to clarify a common frustration I was hearing at TMS this year when discussing convention standards, as apparently a lot of synchrotron and neutron data uses a different convention, making it frustrating to align with EBSD.
With Regard to Class Methods:
Adds 7 new methods for creating
Phaseclasses, none of which require importing diffpy:This is a cleaned up version some commits I had in #623. In all seven cases, all or some of the lattice and symmetry information will be filled in, and the remainder will be filled in with defaults. This also means
Millerexamples can be done without having to import diffpy and then define a Lattice and Structure, which was an early on frustration for me when learning ORIX, and a complaint I've anecdotally heard from time to time from new users.With Regard to new defaults:
Previously, there was some oddity in how
Millerobjects worked wrt. a lazily definedPhaseattempting to print
m1throws an error, as does performing any rotation or plotting, butm2works just fine. this is becauseocm._phase.default_latticesets a default lattice for trigonal and hexagonal crystals, but not for any other systems. Furthermore, the defaults don't make sense for hexagonal, as a system where a=c would be trigonal.To fix this, I added defaults that make crystallographic sense for all values. This was also necessary to make class creation methods that don't require importing diffpy to operate properly.
With Regard to new examples:
I would prefer not to make examples for this functionality yet, as I think the better plan is to review/approve this PR, then some additional parts of #623 as a second PR, then handle the examples as part of the rewrite of the Phase tutorials. Writing some examples now just to redo them when we convert the tutorial section seems redundant.
Progress of the PR
For reviewers
__init__.py.section in
CHANGELOG.rst.__credits__inorix/__init__.pyand in.zenodo.json.