Skip to content

Commit

Permalink
added more information about mono setting to peaksummary export
Browse files Browse the repository at this point in the history
  • Loading branch information
fanchercm committed Feb 4, 2025
1 parent 7bf9642 commit 67b7d34
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
8 changes: 6 additions & 2 deletions 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 @@ -97,7 +98,7 @@ def apply_shift(self, geometry_shift):
:return:
"""
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 +128,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 @@ -152,6 +154,8 @@ def __init__(self, shift_x, shift_y, shift_z, rotation_x, rotation_y, rotation_z
# Need data from client to finish this
self.calibrated_wave_length = {'Si001': 1.00}

self.calibration_file = calibration_file

def __str__(self):
nice = '[Calibration]\nShift: {}, {}, {}\nRotation: {}, {}, {}\n' \
''.format(self.center_shift_x, self.center_shift_y, self.center_shift_z,
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'), # HB2B:CS:ITEMS
('hkl', 'HKL phase'),
('StrainDirection', 'Strain direction'), # was suggested to be "strain_dir"
('wavelength', '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
14 changes: 14 additions & 0 deletions pyrs/core/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ 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
10 changes: 8 additions & 2 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 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 Setting
# Monochromator wavelength
# Calibrated wavelength
# Calibration file
# Hidra project file = /some/place/random.h5
# Manual vs auto reduction
Expand Down

0 comments on commit 67b7d34

Please sign in to comment.