Skip to content

Commit

Permalink
MNT #289 refactor reflection comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Nov 9, 2023
1 parent 00b1ba3 commit bf8e0bb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions hkl/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import datetime
import json
import math
import pathlib
import typing
from dataclasses import asdict
Expand All @@ -53,7 +54,7 @@
DEFAULT_WAVELENGTH = 1.54 # angstrom
EXPORT_FORMATS = "dict json yaml".split()

SIGNIFICANT_FIGURES = 7
EQUAL_TOLERANCE = 1.0e-7


# standard value checks, raise exception(s) when appropriate
Expand Down Expand Up @@ -218,17 +219,19 @@ def find(self, sample):
"""Find this reflection in the sample's reflections. Return None if not found."""

def equal(a, b):
return round(abs(a - b), SIGNIFICANT_FIGURES) == 0.0
return math.isclose(a, b, abs_tol=EQUAL_TOLERANCE)

for sref in sample._sample.reflections_get():
rdict = sample._get_reflection_dict(sref)
match = (
# fmt: off
matches = [
equal(rdict["reflection"][axis], self.reflection[axis])
for axis in self.reflection
] + [
equal(rdict["wavelength"], self.wavelength)
and equal(rdict["reflection"]["h"], self.reflection["h"])
and equal(rdict["reflection"]["k"], self.reflection["k"])
and equal(rdict["reflection"]["l"], self.reflection["l"])
)
if match:
]
# fmt: on
if False not in matches:
return sref


Expand Down

0 comments on commit bf8e0bb

Please sign in to comment.