Skip to content

Indexer cleanup#908

Closed
donald-e-boyce wants to merge 2 commits intoHEXRD:masterfrom
donald-e-boyce:indexer-cleanup
Closed

Indexer cleanup#908
donald-e-boyce wants to merge 2 commits intoHEXRD:masterfrom
donald-e-boyce:indexer-cleanup

Conversation

@donald-e-boyce
Copy link
Copy Markdown
Collaborator

@donald-e-boyce donald-e-boyce commented Mar 26, 2026

Overview

This cleans up the documentation for hexrd.hedm.indexer.py and adds python type hints.

This update was mostly done by Claude, with some minor adjustments by me. The documentation is way better, and the type hints are very good too.

I've run several problems on both the master and the indexer-cleanup branches, and all of the indexer output is identical for all of the problems, including accepted-orientations-ruby.dat, eta-ome-maps-ruby.npz, grains.out, and scored-orientations-ruby.npz.

Comparing the log files, howevers, shows a peculiar difference. If we strip the log files of their timestamp and diff, ignoring elapsed time differences, we get:

First, comparing new branch to current a recent master (2 or 3 days ago):

(hexrd-py-3.12) (MacBook-Pro-2023: single_GE) 1288. diff ruby/indexer/find-orientations-ruby.log.strip ruby/master.bak/
11c11
< hexrd.hedm.findorientations - 	mean reflections per grain: 486
---
> hexrd.hedm.findorientations - 	mean reflections per grain: 485

And also comparing the latest master branch (today) to the recent master:

(hexrd-py-3.12) (MacBook-Pro-2023: single_GE) 1289. diff ruby/master/find-orientations-ruby.log.strip ruby/master.bak/
< hexrd.hedm.findorientations - 	mean reflections per grain: 487
---
> hexrd.hedm.findorientations - 	mean reflections per grain: 485
15c15

The difference does not seem to be related to the changes in indexer.py, as the current master branch gives different results from a recent one. Also, the mean reflections per grain is calculated after the indexer is called, in the find_orientations.create_clustering_parameters() function.

Affected Workflows

This is part of the find-orientations workflow.

Documentation Changes

Only internal documentation has changed. No external documentation needs to be changed.

donald e. boyce added 2 commits March 25, 2026 15:39
@donald-e-boyce donald-e-boyce added the documentation Improvements or additions to documentation label Mar 26, 2026


def _meshgrid2d(x, y):
def _meshgrid2d(x: np.ndarray, y: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're sticking with the typing built into numpy, as using np.ndarray technically doesn't work the way we would like for typing.

Proposed:

from numpy.typing import NDArray

...

def _meshgrid2d(x: NDArray, y: NDArray) -> tuple[NDArray, NDArray]:
    ...

stops: np.ndarray,
offset: float,
ccw: bool = False,
) -> np.ndarray:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this section, the same comment about using numpy.typing.NDArray also applies.



def paintgrid_init(params):
def paintgrid_init(params: dict[str, Any]) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more appropriate type than Any to use here? It would also be preferable for us to use a typing.TypedDict for dictionary typing, as we've done here.

ome: int,
dpix_eta: int,
dpix_ome: int,
etaOmeMap: np.ndarray,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.ndarray -> numpy.typing.NDArray

Copy link
Copy Markdown
Collaborator

@ZackAttack614 ZackAttack614 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to others' judgement on the specific parameter documentation, but as far as typing goes, we can improve this using typing.TypedDict and numpy.typing.NDArray where appropriate. I'm happy to advise and assist as is useful.

@donald-e-boyce donald-e-boyce deleted the indexer-cleanup branch March 26, 2026 19:22
@donald-e-boyce
Copy link
Copy Markdown
Collaborator Author

Sorry again, Zack, I accidentally closed this. I had rebased the branch to the latest version, pushed it to my fork, where is 2 commits ahead and 2 behind. So I thought I could just delete the branch and push it up as a new branch. Unsurprisingly, it killed the PR.

Anyway, the NDArrays stuff I updated (38 instances). Now I am looking at the TypedDict.

I'll resubmit when the PR is ready again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants