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

Use xl, yl, zl for origin of diffraction calculation in PBP indexer #342

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

jadball
Copy link
Contributor

@jadball jadball commented Oct 23, 2024

@jonwright can you please double-check the maths behind this? I believe I am correctly modifying the distance but it'd be good to double-check: the new function get_local_gv does this for the indexer.

Copy link
Member

@jonwright jonwright left a comment

Choose a reason for hiding this comment

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

I didn't understand the mask arg. Otherwise, for the sign check I think the only way is just to plot the silicon data (dstar error vs omega) to check if it works.

eta_local = eta[m]

# mask g-vectors to [m & mr]
gv_local_mask = gv[local_mask[m], :]
Copy link
Member

Choose a reason for hiding this comment

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

The comment suggests this should be: gv[ m & mr , : ] or gv[ local_mask, : ]. Not sure why there is an [m] on the mask?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought process went like this:

We want to calculate the g-vectors for all the peaks at this pixel (mask m).
However, we want to index only the g-vectors that are also in isel (mask mr).

We compute gv (and gx, gy, gz) from peaks[m] (the dtyi, omega mask) so len(gv) = m.sum() != len(sinomega).

However mr has the wrong length to directly mask gv.
If we combine local_mask = m & mr first, then we can mask local_mask by m to get the mr mask for only the m-masked values, so the masks have the right lengths.
Therefore gv[local_mask[m], :] should be correct.

Copy link
Member

Choose a reason for hiding this comment

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

If you want the ring mask at this pixel I would expect to read that as mr[ local_mask ] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I see it is that we are creating a (ring and pixel) mask for all the peaks using local_mask = m & mr, then selecting a (pixel) subset of that with local_mask[m] which then has the same length to index gv (which was also created from peaks[m]).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps the problem is just unclear variable naming?

m: Mask on all peaks to select those that come from the pixel
mr: Mask on all peaks to select those on the ring (isel)
local_mask: Mask on all peaks to select those on the ring AND those from the pixel

Copy link
Member

Choose a reason for hiding this comment

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

It seems like it can also be gv[ mr[m] ] with a comment like # selection: mr = active on rings, [m] at this point in space.

The thing you have is:
gv[ ( m & mr )[m] ]

While I see this is mathematically equivalent, having the m in there twice meant I could not figure out what you were doing.

Feel free to merge and I can always change it later.

# ignore Numba dot product performance warnings?
import warnings

warnings.simplefilter('ignore', category=numba.core.errors.NumbaPerformanceWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Rather than suppressing the message, we should eventually fix the actual problem here

# compute g-vectors from xyz
ImageD11.cImageD11.compute_gv(xyz_local,
omega,
parglobal.get('omegasign'),
Copy link
Member

Choose a reason for hiding this comment

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

parglobal is not defined inside this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As parglobal is globally defined, I don't think it needs to be defined inside this function? It seems to run on my machine, anyway...

@@ -1,6 +1,10 @@
import os

import numba
# ignore Numba dot product performance warnings?
import warnings
warnings.simplefilter('ignore', category=numba.core.errors.NumbaPerformanceWarning)
Copy link
Member

Choose a reason for hiding this comment

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

I would like to understand why it gives the warning

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We see lots of console spam for the np.dot functions being run on non-contiguous arrays - mainly for the hkl calculations - I think this is unavoidable?

Copy link
Member

Choose a reason for hiding this comment

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

If we suppress the warning we should create an issue to come back to it sometime in the future. Like this I am afraid we lose all of the feedback on numba compilation for anything importing our code...

@jadball
Copy link
Contributor Author

jadball commented Oct 23, 2024

Otherwise, for the sign check I think the only way is just to plot the silicon data (dstar error vs omega) to check if it works.

This might be tricky - we're now directly computing the g-vectors from xl, yl, zl, so I'm not sure how we'd access the modified dstar values - unless we can compute dstar/tth back from the new g-vectors?

@jonwright
Copy link
Member

Dstar is the length of gv. I guess the function can be tested outside of the call here.

@jadball
Copy link
Contributor Author

jadball commented Oct 24, 2024

Just tested this against the previous version and it should be equivalent - should be good to merge

@jadball jadball merged commit d79b00b into FABLE-3DXRD:master Oct 24, 2024
6 checks passed
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.

2 participants