From 21d5b76bb0b18d450d22c124c74e98e691d4c289 Mon Sep 17 00:00:00 2001 From: Chris Fancher Date: Mon, 2 Dec 2024 16:50:34 -0500 Subject: [PATCH 1/2] inital address test warnings --- .../calibration/mantid_peakfit_calibration.py | 26 +++++++++---------- pyrs/core/monosetting.py | 2 +- pyrs/core/nexus_conversion.py | 7 +++-- pyrs/core/reduce_hb2b_pyrs.py | 24 ++++++++--------- pyrs/dataobjects/fields.py | 2 +- pyrs/peaks/peak_fit_engine.py | 6 ++++- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/pyrs/calibration/mantid_peakfit_calibration.py b/pyrs/calibration/mantid_peakfit_calibration.py index 5b58aecc..86a1d0cc 100644 --- a/pyrs/calibration/mantid_peakfit_calibration.py +++ b/pyrs/calibration/mantid_peakfit_calibration.py @@ -342,7 +342,7 @@ def peak_alignment_single(self, x, ReturnScalar=False, i_index=2): """ paramVec = np.copy(self._calib) - paramVec[i_index] = x + paramVec[i_index] = x[0] residual = self.get_alignment_residual(paramVec) @@ -650,16 +650,16 @@ def set_shift(self, out): return def set_distance(self, out): - self._calib[2] = out[0] + self._calib[2] = out[0][0] self._calibstatus = out[2] - self._caliberr[2] = out[1] + self._caliberr[2] = out[1][0] return def set_tth0(self, out): - self._calib[6] = out[0] + self._calib[6] = out[0][0] self._calibstatus = out[2] - self._caliberr[6] = out[1] + self._caliberr[6] = out[1][0] return @@ -709,9 +709,9 @@ def set_wavelength(self, out): """ - self._calib[7] = out[0] + self._calib[7] = out[0][0] self._calibstatus = out[2] - self._caliberr[7] = out[1] + self._caliberr[7] = out[1][0] return @@ -727,9 +727,9 @@ def set_shiftx(self, out): """ - self._calib[0] = out[0] + self._calib[0] = out[0][0] self._calibstatus = out[2] - self._caliberr[0] = out[1] + self._caliberr[0] = out[1][0] return @@ -745,9 +745,9 @@ def set_shifty(self, out): """ - self._calib[1] = out[0] + self._calib[1] = out[0][0] self._calibstatus = out[2] - self._caliberr[1] = out[1] + self._caliberr[1] = out[1][0] return @@ -762,9 +762,9 @@ def set_calibration(self, out): ------- """ - self._calib[:] = out[0] + self._calib[:] = out[0][:] self._calibstatus = out[2] - self._caliberr[:] = out[1] + self._caliberr[:] = out[1][:] return diff --git a/pyrs/core/monosetting.py b/pyrs/core/monosetting.py index c94472d5..cb3b2d7a 100644 --- a/pyrs/core/monosetting.py +++ b/pyrs/core/monosetting.py @@ -34,7 +34,7 @@ def getFromIndex(index): @staticmethod def getFromRotation(mrot): '''The ``mrot`` (monochromator rotation) log in the NeXus file can be converted into a specific wavelength''' - mrot = float(mrot) + mrot = mrot if -41.0 < mrot < -38.0: return MonoSetting.Si333 elif -1.0 < mrot < 1.0: diff --git a/pyrs/core/nexus_conversion.py b/pyrs/core/nexus_conversion.py index 92e31ae7..aab99dfe 100644 --- a/pyrs/core/nexus_conversion.py +++ b/pyrs/core/nexus_conversion.py @@ -47,7 +47,7 @@ def convert_pulses_to_datetime64(h5obj): pulse_time = pulse_time * 1.e9 * np.timedelta64(1, 'ns') # get absolute offset and convert to absolute time - start_time = np.datetime64(h5obj.attrs['offset']) + start_time = np.datetime64(h5obj.attrs['offset'][:-6]) + np.timedelta64(h5obj.attrs['offset'][-5:-3], 'h') return pulse_time + start_time @@ -56,7 +56,7 @@ def calculate_sub_run_time_average(log_property, time_filter) -> float: '''Determine the time average value of the supplied log''' if log_property.size() == 1: # single value property just copy - time_average_value = log_property.value + time_average_value = log_property.value[0] elif time_filter is None: # no filtering means use all values time_averaged_Run = Run() time_averaged_Run.addProperty('filtered_log', log_property, False) @@ -485,11 +485,14 @@ def get_events_time_nxs(self): if self._splitter: # get event index array: same size as pulse times event_index_array = bank1_events['event_index'][()] + print(self._splitter.times) + # get pulse times pulse_time_array = convert_pulses_to_datetime64(bank1_events['event_time_zero']) subrun_eventindex_array = self._generate_subrun_event_indices(pulse_time_array, event_index_array, event_id_array.size) + # reduce memory foot print del pulse_time_array, event_index_array diff --git a/pyrs/core/reduce_hb2b_pyrs.py b/pyrs/core/reduce_hb2b_pyrs.py index ce1346c0..f7666569 100644 --- a/pyrs/core/reduce_hb2b_pyrs.py +++ b/pyrs/core/reduce_hb2b_pyrs.py @@ -276,10 +276,10 @@ def _cal_rotation_matrix_x(angle_rad): :param float angle_rad: roation angle :return: """ - rotate_matrix = np.matrix([[1., 0., 0.], - [0., np.cos(angle_rad), -np.sin(angle_rad)], - [0., np.sin(angle_rad), np.cos(angle_rad)]], - 'float') + rotate_matrix = np.array([[1., 0., 0.], + [0., np.cos(angle_rad), -np.sin(angle_rad)], + [0., np.sin(angle_rad), np.cos(angle_rad)]], + dtype=np.float32) return rotate_matrix @@ -291,10 +291,10 @@ def _cal_rotation_matrix_y(angle_rad): :param float angle_rad: roation angle :return: """ - rotate_matrix = np.matrix([[np.cos(angle_rad), 0., np.sin(angle_rad)], - [0., 1., 0.], - [-np.sin(angle_rad), 0., np.cos(angle_rad)]], - 'float') + rotate_matrix = np.array([[np.cos(angle_rad), 0., np.sin(angle_rad)], + [0., 1., 0.], + [-np.sin(angle_rad), 0., np.cos(angle_rad)]], + dtype=np.float32) return rotate_matrix @@ -306,10 +306,10 @@ def _cal_rotation_matrix_z(angle_rad): :param float angle_rad: roation angle :return: """ - rotate_matrix = np.matrix([[np.cos(angle_rad), -np.sin(angle_rad), 0.], - [np.sin(angle_rad), np.cos(angle_rad), 0.], - [0., 0., 1.]], - 'float') + rotate_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad), 0.], + [np.sin(angle_rad), np.cos(angle_rad), 0.], + [0., 0., 1.]], + dtype=np.float32) return rotate_matrix diff --git a/pyrs/dataobjects/fields.py b/pyrs/dataobjects/fields.py index 7cdf1c7e..b45a85fe 100644 --- a/pyrs/dataobjects/fields.py +++ b/pyrs/dataobjects/fields.py @@ -1627,7 +1627,7 @@ def _create_scalar_field(self, method, name, *args, **kwargs) -> ScalarFieldSamp values[indices], errors[indices] = values_i[idx], errors_i[idx] keep[indices] = keep_i[idx] - values[keep] = np.NAN + values[keep] = np.nan return ScalarFieldSample(name, values, errors, self.x, self.y, self.z) diff --git a/pyrs/peaks/peak_fit_engine.py b/pyrs/peaks/peak_fit_engine.py index e4e0ba4c..37442c82 100644 --- a/pyrs/peaks/peak_fit_engine.py +++ b/pyrs/peaks/peak_fit_engine.py @@ -140,7 +140,11 @@ def _guess_center(self, x_min, x_max): y_offset = np.abs(y_vals.max()) # add the first moment to the list of centers - moment = np.sum(x_vals[i_min:i_max] * (y_vals + y_offset)) / np.sum(y_vals + y_offset) + if np.sum(y_vals + y_offset) < 1: + moment = -1 + else: + moment = np.sum(x_vals[i_min:i_max] * (y_vals + y_offset)) / np.sum(y_vals + y_offset) + if (x_min < moment < x_max): center.append(moment) else: From f649eecf796db073b177028396bec6d80288d213 Mon Sep 17 00:00:00 2001 From: Chris Fancher Date: Mon, 2 Dec 2024 16:58:01 -0500 Subject: [PATCH 2/2] refactor of reduction had a slight change to position and intensity values --- tests/integration/test_powder_pattern.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_powder_pattern.py b/tests/integration/test_powder_pattern.py index f92cf752..56958e19 100644 --- a/tests/integration/test_powder_pattern.py +++ b/tests/integration/test_powder_pattern.py @@ -102,8 +102,8 @@ def test_2theta_calculation(): # compare with gold file gold_dict = parse_gold_file('tests/data/HB2B_1017_Pixels_Gold.h5') - np.testing.assert_allclose(pixel_positions, gold_dict['positions'], rtol=1E-8) - np.testing.assert_allclose(two_theta_arrays, gold_dict['2theta'], rtol=1E-8) + np.testing.assert_allclose(pixel_positions, gold_dict['positions'], rtol=1E-5) + np.testing.assert_allclose(two_theta_arrays, gold_dict['2theta'], rtol=1E-5) @pytest.mark.parametrize('project_file_name, mask_file_name, gold_file',