diff --git a/hexrd/core/instrument/hedm_instrument.py b/hexrd/core/instrument/hedm_instrument.py index 7ee65be73..a2cfde6bc 100644 --- a/hexrd/core/instrument/hedm_instrument.py +++ b/hexrd/core/instrument/hedm_instrument.py @@ -1120,7 +1120,11 @@ def extract_polar_maps( raise TypeError("active_hkls must be an iterable with __len__") # these are all active reflection unique hklIDs - active_hklIDs = plane_data.getHKLID(plane_data.hkls, master=True) + # np.asarray: getHKLID may return a list, and `list == int` below is + # a scalar bool -> np.where(scalar) raises "0d array nonzero". + active_hklIDs = np.asarray( + plane_data.getHKLID(plane_data.hkls, master=True) + ) # find indices idx = np.zeros_like(active_hkls, dtype=int) diff --git a/hexrd/hedm/xrdutil/utils.py b/hexrd/hedm/xrdutil/utils.py index 77c9c4502..5d6fe1ae0 100644 --- a/hexrd/hedm/xrdutil/utils.py +++ b/hexrd/hedm/xrdutil/utils.py @@ -1060,7 +1060,15 @@ def apply_correction_to_wavelength( ind = 1 if energy_correction['axis'] == 'y' else 0 # Correct wavelength according to grain position. Position is in mm. - position = tvec_c[ind] + tvec_s[ind] - energy_correction['intercept'] + # tvec_c/tvec_s may be shaped (3, 1) (e.g. objFuncFitGrain reshapes tVec_c + # to (3, 1)); ravel so `position` is a scalar. A stray (1,) here makes the + # corrected wavelength a length-1 array, which oscill_angles_of_hkls then + # treats as a per-reflection wavelength array (1 value vs N hkls) -> NaN -> + # "Infeasible parameters for hkls". + position = ( + np.ravel(tvec_c)[ind] + np.ravel(tvec_s)[ind] + - energy_correction['intercept'] + ) # The slope is in eV/mm. Convert to keV. adjustment = position * energy_correction['slope'] / 1e3 diff --git a/tests/core/fitting/test_fitting_grains.py b/tests/core/fitting/test_fitting_grains.py index 329404bf6..b1d8c0839 100644 --- a/tests/core/fitting/test_fitting_grains.py +++ b/tests/core/fitting/test_fitting_grains.py @@ -16,6 +16,9 @@ def env(): det1 = MagicMock(distortion=None) instr.detectors = {'det1': det1} instr.detector_parameters = {'det1': MagicMock()} + # Real arrays (not bare MagicMocks) for values that flow into numpy ops + # such as apply_correction_to_wavelength (np.ravel(instr.tvec)). + instr.tvec = np.zeros(3) return { 'inst': instr,