Skip to content

Commit

Permalink
Merge pull request #899 from neutrons/fix_test_warning_main
Browse files Browse the repository at this point in the history
Fix test warning main
  • Loading branch information
fanchercm authored Dec 3, 2024
2 parents 81fe7be + b1eab6c commit bdcb80c
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 39 deletions.
38 changes: 19 additions & 19 deletions pyrs/calibration/mantid_peakfit_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -643,37 +643,37 @@ def get_tth0(self):
return np.array([self._calib[6]])

def set_shift(self, out):
self._calib[0:3] = out[0]
self._calib[0:3] = out[0][:]
self._calibstatus = out[2]
self._caliberr[0:3] = out[1]
self._caliberr[0:3] = out[1][:]

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

def set_rotation(self, out):
self._calib[3:6] = out[0]
self._calib[3:6] = out[0][:]
self._calibstatus = out[2]
self._caliberr[3:6] = out[1]
self._caliberr[3:6] = out[1][:]

return

def set_geo(self, out):
self._calib[0:7] = out[0]
self._calib[0:7] = out[0][:]
self._calibstatus = out[2]
self._caliberr[0:7] = out[1]
self._caliberr[0:7] = out[1][:]

return

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion pyrs/core/monosetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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)
if -41.0 < mrot < -38.0:
return MonoSetting.Si333
elif -1.0 < mrot < 1.0:
Expand Down
4 changes: 2 additions & 2 deletions pyrs/core/nexus_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions pyrs/core/reduce_hb2b_pyrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion pyrs/core/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,11 @@ def set_reduced_diffraction_data(self, sub_run: int, mask_id: Optional[str],
dtype=intensity_array.dtype)

if variances_array is None:
variances_array = numpy.sqrt(intensity_array)
temp_intensity_array = intensity_array.copy()
temp_intensity_array[temp_intensity_array < 1] = 1
variances_array = numpy.sqrt(temp_intensity_array)
del temp_intensity_array

# END-IF

# set the diffraction data (2D) array with new dimension
Expand Down
1 change: 1 addition & 0 deletions pyrs/dataobjects/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def __init__(self, name: str,
z: Union[List[float], np.ndarray]) -> None:
all_lengths = [len(values), len(errors), len(x), len(y), len(z)]
assert len(set(all_lengths)) == 1, 'input lists must all have the same lengths'

self._sample = unumpy.uarray(values, errors)
self._point_list = PointList([x, y, z])
self._name = name
Expand Down
1 change: 1 addition & 0 deletions pyrs/peaks/mantid_fit_peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def convert_from_table_to_arrays(table_ws): # TODO put this in mantid_helper
# get fitted parameter value
for col_index, param_name in enumerate(table_col_names):
# get value from column in value table

struct_array[param_name] = table_ws.column(col_index)

return struct_array
Expand Down
7 changes: 5 additions & 2 deletions pyrs/peaks/peak_fit_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ def _guess_center(self, x_min, x_max):
y_vals = self._mtd_wksp.readY(wksp_index)[i_min:i_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:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_powder_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

1 comment on commit bdcb80c

@github-actions
Copy link

Choose a reason for hiding this comment

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

GitLab pipeline for pyrs-qa has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/pyrs-deploy/-/pipelines/644163"

Please sign in to comment.