Commit fb9f6b6c authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Make groups have different positions

parent 1abd7893
......@@ -20,7 +20,7 @@ def cc_calibrate_groups(data_ws,
# skip group 0 because this is eveything that wasn't included in a group
group_list = np.unique(group_ws.extractY())
for n, group in enumerate(group_list):
for group in group_list:
indexes = np.where(group_ws.extractY().flatten() == group)[0]
ExtractSpectra(data_d, WorkspaceIndexList=indexes, OutputWorkspace=f'_tmp_group_{group}')
ExtractUnmaskedSpectra(f'_tmp_group_{group}', OutputWorkspace=f'_tmp_group_{group}')
......@@ -74,6 +74,7 @@ def pdcalibration_groups(data_ws,
OutputCalibrationTable=f'{output_basename}_pd_diffcal',
DiagnosticWorkspaces=f'{output_basename}_pd_diag')
# Everything below will all be replaced by be the new CombineDiffCal algorithm
pd_diffcal = mtd[f'{output_basename}_pd_diffcal']
cc_and_pd_diffcal = CloneWorkspace(f'{output_basename}_pd_diffcal', OutputWorkspace=f'{output_basename}_cc_pd_diffcal')
......@@ -81,23 +82,23 @@ def pdcalibration_groups(data_ws,
cc_det_to_difc = dict(zip(cc_diffcal.column('detid'), cc_diffcal.column('difc')))
grouped = mtd['_tmp_data_aligned_focussed']
si = grouped.spectrumInfo()
specInfo = grouped.spectrumInfo()
grouped_det_to_difc = {}
for detid in cc_and_pd_diffcal.column('detid'):
ind = list(grouped.getIndicesFromDetectorIDs([1]))
ind = list(grouped.getIndicesFromDetectorIDs([detid]))
if ind:
grouped_det_to_difc[detid] = si.difcUncalibrated(ind[0])
grouped_det_to_difc[detid] = specInfo.difcUncalibrated(ind[0])
if previous_calibration:
previous_calibration_det_to_difc = dict(zip(previous_calibration.column('detid'), previous_calibration.column('difc')))
eng_det_to_difc = {}
si = data_ws.spectrumInfo()
eng_det_to_difc = {}
specInfo = data_ws.spectrumInfo()
for detid in cc_and_pd_diffcal.column('detid'):
ind = list(data_ws.getIndicesFromDetectorIDs([1]))
ind = list(data_ws.getIndicesFromDetectorIDs([detid]))
if ind:
eng_det_to_difc[detid] = si.difcUncalibrated(ind[0])
eng_det_to_difc[detid] = specInfo.difcUncalibrated(ind[0])
for n, detid in enumerate(cc_and_pd_diffcal.column('detid')):
if detid in cc_det_to_difc and detid in grouped_det_to_difc:
......
......@@ -19,8 +19,10 @@ def create_test_ws_and_group():
"name=Gaussian, PeakCentre=4, Height=100, Sigma=0.01"
ws = CreateSampleWorkspace("Event","User Defined", myFunc, BankPixelWidth=1,
XUnit='dSpacing', XMax=5, BinWidth=0.001, NumEvents=100000, NumBanks=8)
for n in range(1,9):
for n in range(1,5):
MoveInstrumentComponent(ws, ComponentName=f'bank{n}', X=1, Y=0, Z=1, RelativePosition=False)
for n in range(5,9):
MoveInstrumentComponent(ws, ComponentName=f'bank{n}', X=2, Y=0, Z=2, RelativePosition=False)
MaskDetectors(ws, WorkspaceIndexList=[3,7])
......@@ -57,8 +59,9 @@ class TestGroupCalibration(unittest.TestCase):
output_workspace_basename = 'test_from_eng'
# same for all spectra
starting_difc = ws.spectrumInfo().difcUncalibrated(0)
# same for all spectra in group
starting_difc1 = ws.spectrumInfo().difcUncalibrated(0)
starting_difc2 = ws.spectrumInfo().difcUncalibrated(4)
cc_diffcal = group_calibration.cc_calibrate_groups(ws,
groups,
......@@ -69,12 +72,12 @@ class TestGroupCalibration(unittest.TestCase):
Xmax=2.25)
assert_allclose(cc_diffcal.column('difc'),
[starting_difc,
starting_difc/0.95,
starting_difc/1.05,
starting_difc,
starting_difc/0.98,
starting_difc/1.02], rtol=0.005)
[starting_difc1,
starting_difc1/0.95,
starting_difc1/1.05,
starting_difc2,
starting_difc2/0.98,
starting_difc2/1.02], rtol=0.005)
diffcal = group_calibration.pdcalibration_groups(ws,
groups,
......@@ -84,13 +87,13 @@ class TestGroupCalibration(unittest.TestCase):
PeakWindow=0.4)
assert_allclose(diffcal.column('difc'),
[starting_difc,
starting_difc/0.95,
starting_difc/1.05,
[starting_difc1,
starting_difc1/0.95,
starting_difc1/1.05,
0,
starting_difc/0.95,
starting_difc/(0.95*0.98),
starting_difc/(0.95*1.02),
starting_difc2/0.95,
starting_difc2/(0.95*0.98),
starting_difc2/(0.95*1.02),
0], rtol=0.005)
def test_from_prev_cal(self):
......@@ -99,8 +102,9 @@ class TestGroupCalibration(unittest.TestCase):
output_workspace_basename = 'test_from_eng_prev_cal'
# same for all spectra
starting_difc = ws.spectrumInfo().difcUncalibrated(0)
# same for all spectra in group
starting_difc1 = ws.spectrumInfo().difcUncalibrated(0)
starting_difc2 = ws.spectrumInfo().difcUncalibrated(4)
previous_diffcal = CreateEmptyTableWorkspace()
......@@ -109,14 +113,14 @@ class TestGroupCalibration(unittest.TestCase):
previous_diffcal.addColumn("double", "difa")
previous_diffcal.addColumn("double", "tzero")
previous_diffcal.addRow([1, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([2, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([3, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([4, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([5, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([6, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([7, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([8, starting_difc*1.01, 0, 0])
previous_diffcal.addRow([1, starting_difc1*1.01, 0, 0])
previous_diffcal.addRow([2, starting_difc1*1.01, 0, 0])
previous_diffcal.addRow([3, starting_difc1*1.01, 0, 0])
previous_diffcal.addRow([4, starting_difc1*1.01, 0, 0])
previous_diffcal.addRow([5, starting_difc2*1.01, 0, 0])
previous_diffcal.addRow([6, starting_difc2*1.01, 0, 0])
previous_diffcal.addRow([7, starting_difc2*1.01, 0, 0])
previous_diffcal.addRow([8, starting_difc2*1.01, 0, 0])
cc_diffcal = group_calibration.cc_calibrate_groups(ws,
groups,
......@@ -128,14 +132,14 @@ class TestGroupCalibration(unittest.TestCase):
Xmax=2.25)
assert_allclose(cc_diffcal.column('difc'),
[starting_difc*1.01,
starting_difc*1.01/0.95,
starting_difc*1.01/1.05,
starting_difc*1.01,
starting_difc*1.01,
starting_difc*1.01/0.98,
starting_difc*1.01/1.02,
starting_difc*1.01], rtol=0.005)
[starting_difc1*1.01,
starting_difc1*1.01/0.95,
starting_difc1*1.01/1.05,
starting_difc1*1.01,
starting_difc2*1.01,
starting_difc2*1.01/0.98,
starting_difc2*1.01/1.02,
starting_difc2*1.01], rtol=0.005)
diffcal = group_calibration.pdcalibration_groups(ws,
groups,
......@@ -146,14 +150,14 @@ class TestGroupCalibration(unittest.TestCase):
PeakWindow=0.4)
assert_allclose(diffcal.column('difc'),
[starting_difc,
starting_difc/0.95,
starting_difc/1.05,
starting_difc*1.01,
starting_difc/0.95,
starting_difc/(0.95*0.98),
starting_difc/(0.95*1.02),
starting_difc*1.01], rtol=0.005)
[starting_difc1,
starting_difc1/0.95,
starting_difc1/1.05,
starting_difc1*1.01,
starting_difc2/0.95,
starting_difc2/(0.95*0.98),
starting_difc2/(0.95*1.02),
starting_difc2*1.01], rtol=0.005)
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment