Skip to content

Friedel horizontal - #687

Draft
jonwright wants to merge 6 commits into
FABLE-3DXRD:masterfrom
jonwright:friedel_horizontal
Draft

jonwright wants to merge 6 commits into
FABLE-3DXRD:masterfrom
jonwright:friedel_horizontal

Conversation

@jonwright

Copy link
Copy Markdown
Member

CLAUDE WRITTEN: Draft, this build on top of the previous one, after that is merged this one is easier to review.

Depends on the friedel_fixes PR; only the last commit is new. This is the pair-type part of #645. Merging the notebook helpers into the library is a separate PR.

A reflection g is seen at two omega solutions, left and right of the beam. This adds that relation next to the two existing ones:

pair_type relation column
omega (vertical) -hkl, omega + 180, eta -> 180 - eta omega_pair_id (unchanged)
eta (diagonal) -hkl, eta -> 180 + eta eta_pair_id (unchanged)
horizontal same hkl, eta -> -eta horizontal_pair_id (new)
  • match_friedel_pairs(pair_type='horizontal') splits the peaks by the sign of eta, as for eta pairs. The search space and the distance filters use g -> g and eta -> -eta.
  • match_friedel_pairs_by_chunks(chunk_type='minus_eta_bins') pairs eta bins (eta, -eta). It is built together with the (eta, eta+180) list and shares the eta-sorted lookup table, so switching pair type cannot leave stale subsets.
  • match_friedel_pairs.py accepts pair_type as "all", one type, or a list such as ["omega"]. Some methods only need the 180-degree omega pairs. Quadruplets run when both omega and eta are requested.
  • Results change: the script default goes from "omega" to "all" (omega, eta and horizontal). This adds two columns and takes longer. I have not measured the runtime on real data.

Test. Same simulation as in the fixes PR, with 3331 possible pairs per type and no wrong pairs:

global chunks
horizontal 3016 2999 (minus_eta_bins)
omega, eta unchanged unchanged

The two horizontal tests fail without the library change. Results are identical on Python 2.7 and 3. Not tested on real data.

Generated with Claude Code

jonwright and others added 4 commits November 6, 2026 16:50
Python 2.7 refuses to import friedel_pairs.py (non-ASCII in the module
header, no coding line). Replace the characters with ASCII equivalents
(deg, omega, theta, +-, ->, --, dy, Angstrom^-1) in friedel_pairs.py and
match_friedel_pairs.py. Comments, docstrings and log strings only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- from __future__ import division: py2 gave integer division, e.g. eta bin
  centres shifted by half a bin in _get_eta_bins.
- time.perf_counter and os.sched_getaffinity are missing on py2 (and the
  latter on macOS and Windows): fall back to time.time and
  multiprocessing.cpu_count.
- cKDTree.query(workers=1): the keyword is scipy >= 1.6; 1 is the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
match_friedel_pairs_by_chunks(chunk_type='frames') calibrated the search
space on the first frame pair with peaks on both sides. That pair can hold
a single peak: the pilot search keeps zero pairs, the median distances are
nan and cKDTree raises ValueError (scipy 1.2 instead returns no pairs).
Calibrate on a pair of scans, which holds the same omega pairs.

test_friedel_pairs.py simulates a scanning 3DXRD peaks_2d table (point
grains off the rotation axis, finite beam, one peak per dty row) and checks
omega and eta pairs, global and by chunks, against the true hkl and eta.
Possible pairs 3331; found (all correct): omega global 3331, scans 3263,
frames 3331 (was ValueError); eta global 3016, eta_bins 2998. Same counts
on python 2.7 (numpy 1.16.6, scipy 1.2.3) and 3 (numpy 2.5.4, scipy 1.18.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The script hardcoded IMAGED11_PATH = /home/esrf/jean1994b/ImageD11_jbjacob
and loaded that checkout through install_ImageD11_from_git. Remove that
block and follow nb_utils.prepare_mlem_bash: prepare_bash_script and
submit_to_slurm take id11_code_path (None -> the folder holding the
ImageD11 already imported) and write

    PYTHONPATH={id11_code_path} python {id11_code_path}/ImageD11/match_friedel_pairs.py

so the job on top of the jupyter-slurm module runs the same ImageD11 as
the notebook or shell that submitted it. nbGui/match_friedel_pairs.ipynb:
IMAGED11_PATH = None, as in the other notebooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

jonwright and others added 2 commits November 9, 2026 11:03
The module imported matplotlib.pyplot at the top. On python 2.7
(matplotlib 2.2) that selects the TkAgg backend, and the import fails
without _tkinter, as on the 2.7 CI runner. Import pyplot inside
check_symmetry and plot_pair_distances, the only two users.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add pair_type='horizontal': the same (h,k,l) at its two omega solutions,
left and right of the beam (g -> g, eta -> -eta). Results go in a new
column horizontal_pair_id; omega_pair_id and eta_pair_id are unchanged.

- match_friedel_pairs splits by the sign of eta, as for eta pairs.
- chunk_type='minus_eta_bins' pairs eta bins (eta, -eta). It is built with
  the (eta, eta+180) list and shares the eta-sorted lookup table.
- match_friedel_pairs.py: pair_type is 'all' (default, was 'omega'), one
  type, or a list such as ['omega']. 'all' runs omega, eta and horizontal.
  Quadruplets run when both omega and eta are requested.

Simulated peaks_2d, 3331 possible pairs per type, all found pairs correct:
horizontal global 3016, minus_eta_bins 2999 (omega and eta unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant