Skip to content

Commit

Permalink
Merge pull request #913 from neutrons/include_monosetting_next
Browse files Browse the repository at this point in the history
added more information about mono setting to peaksummary export
  • Loading branch information
fanchercm authored Feb 4, 2025
2 parents 0a7ae72 + f2d175c commit 00365c6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pyrs/core/instrument_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(self, num_rows: int, num_columns: int,
self._pixel_size_y = to_float('Pixel size (y)', pixel_size_y, min_value=1E-7)
self._detector_rows = to_int('Number of rows in detector', num_rows, min_value=1)
self._detector_columns = to_int('Number of columns in detector', num_columns, min_value=1)
self._calibration_file = ''

checkdatatypes.check_bool_variable('Flag indicating instrument setup been calibrated', calibrated)

Expand All @@ -98,6 +99,7 @@ def apply_shift(self, geometry_shift):
"""
checkdatatypes.check_type('Detector geometry shift', geometry_shift, DENEXDetectorShift)

self._calibration_file = DENEXDetectorShift.calibration_file
self._arm_length += geometry_shift.center_shift_z

@property
Expand Down Expand Up @@ -127,7 +129,8 @@ class DENEXDetectorShift:
A class to handle and save instrument geometry calibration information
"""

def __init__(self, shift_x, shift_y, shift_z, rotation_x, rotation_y, rotation_z, tth_0):
def __init__(self, shift_x, shift_y, shift_z, rotation_x, rotation_y, rotation_z, tth_0,
calibration_file=''):
"""
Initialization of instrument geometry setup for 1 denex detector
:param shift_x: detector shift along x
Expand All @@ -137,6 +140,7 @@ def __init__(self, shift_x, shift_y, shift_z, rotation_x, rotation_y, rotation_z
:param rotation_y: detector rotation about y
:param rotation_z: detector rotation about z
:param tth_0: shift of detector tth reference frame
:param calibration_file: name of calibration file
"""

self._center_shift_x = shift_x
Expand All @@ -149,6 +153,8 @@ def __init__(self, shift_x, shift_y, shift_z, rotation_x, rotation_y, rotation_z

self._two_theta_0 = tth_0 # in rotation of detector arm about X

self.calibration_file = calibration_file

# Need data from client to finish this
self.calibrated_wave_length = {'Si001': 1.00}

Expand Down
4 changes: 3 additions & 1 deletion pyrs/core/summary_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
('item_number', 'Item number'), # BL11A:CS:ITEMS on powgen
('hkl', 'HKL phase'),
('StrainDirection', 'Strain direction'), # was suggested to be "strain_dir"
('mono_set', 'Monochromator wavelength'),
('mono_setting', 'Monochromator Setting'),
('mono_wavelength', 'Monochromator wavelength'),
('cal_wavelength', 'Calibrated wavelength'),
('cal_file', 'Calibration file'),
('project', 'Hidra project file'),
('reduction', 'Manual vs auto reduction')]
Expand Down
12 changes: 12 additions & 0 deletions pyrs/core/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def reduction_masks(self):
"""
return list(self._diff_data_set.keys())

@property
def calibration_file(self):
"""Name of the associated calibration file
Returns
-------
"""

try:
return self._instrument_geometry_shift._calibration_file
except AttributeError:
return ''

def _load_raw_counts(self, hidra_file):
""" Load raw detector counts from HIDRA file
:param hidra_file:
Expand Down
9 changes: 8 additions & 1 deletion pyrs/interface/peak_fitting/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pyrs.interface.gui_helper import browse_dir
from pyrs.core.summary_generator import SummaryGenerator
from pyrs.core import MonoSetting # type: ignore


class Export:
Expand Down Expand Up @@ -30,12 +31,18 @@ def create_csv(self):
try:
peaks = self.parent.fit_result.peakcollections
sample_logs = self.parent.hidra_workspace._sample_logs
monosetting = MonoSetting.getFromRotation(self.parent.hidra_workspace.get_sample_log_value('mrot', 1))

print("sample_log: {}".format(sample_logs))

generator = SummaryGenerator(self._csv_file_name,
log_list=sample_logs.keys())
generator.setHeaderInformation({'wavelength': self.parent.hidra_workspace.get_wavelength(False, False)})

generator.setHeaderInformation({'cal_wavelength': self.parent.hidra_workspace.get_wavelength(False, False),
'mono_wavelength': monosetting.value,
'mono_setting': monosetting.name,
'cal_file': self.parent.hidra_workspace.calibration_file})

generator.write_csv(sample_logs, peaks)

new_message = self.parent.current_root_statusbar_message + "\t\t\t\t Last Exported CSV: {}" \
Expand Down
3 changes: 2 additions & 1 deletion pyrs/utilities/calibration_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def read_calibration_json_file(calibration_file_name):
rotation_x=float(calib_dict['Rot_x']),
rotation_y=float(calib_dict['Rot_y']),
rotation_z=float(calib_dict['Rot_z']),
tth_0=float(calib_dict['two_theta_0']))
tth_0=float(calib_dict['two_theta_0']),
calibration_file=calibration_file_name)

except KeyError as key_error:
raise RuntimeError('Missing key parameter from JSON file {}: {}'.format(calibration_file_name, key_error))
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/test_peak_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ def test_write_csv():
# Item number
# HKL phase
# Strain direction
# Monochromator Setting
# Monochromator wavelength
# Calibrated wavelength
# Calibration file
# Hidra project file
# Manual vs auto reduction
Expand Down Expand Up @@ -373,7 +375,9 @@ def test_write_csv():
# Item number
# HKL phase
# Strain direction = Powder
# Monochromator Setting
# Monochromator wavelength
# Calibrated wavelength
# Calibration file
# Hidra project file = /some/place/random.h5
# Manual vs auto reduction
Expand All @@ -391,7 +395,9 @@ def test_write_csv():
# Item number
# HKL phase
# Strain direction = ND
# Monochromator Setting
# Monochromator wavelength
# Calibrated wavelength
# Calibration file
# Hidra project file = /some/place/random.h5
# Manual vs auto reduction
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/test_peak_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def handle_dialog(filename):
assert os.path.isfile("HB2B_1423.csv")
file_contents = open("HB2B_1423.csv").readlines()
# check number of lines
assert len(file_contents) == 127
assert len(file_contents) == 129
# check number of values in line
assert len(np.fromstring(file_contents[-1], dtype=np.float64, sep=',')) == 35

Expand Down Expand Up @@ -132,7 +132,7 @@ def handle_dialog(filename):
assert os.path.isfile("HB2B_1423.csv")
file_contents = open("HB2B_1423.csv").readlines()
# check number of lines
assert len(file_contents) == 127
assert len(file_contents) == 129
# check number of values in line
assert len(np.fromstring(file_contents[-1], dtype=np.float64, sep=',')) == 35

Expand Down

1 comment on commit 00365c6

@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-dev has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/pyrs-deploy/-/pipelines/669100"

Please sign in to comment.