Ticket #9097: test_9097.py

File test_9097.py, 2.3 KB (added by Gesner Passos, 7 years ago)
Line 
1#Create a new 'calibration' file
2ws = LoadNexus('22024')
3MoveInstrumentComponent(ws, 'rear-detector(x=0)',Y=0.1)
4SaveNexus(ws, 'new_calibration_file.nxs')
5mtd.clear()
6
7
8#Update the Mask file to include the calibration file
9file_path = FileFinder.getFullPath('MaskSANS2DReductionGUI.txt')
10
11mask_file = open(file_path, 'r')
12mask_content = mask_file.read()
13mask_file.close()
14
15new_mask_file = open('sans2dmask.txt','w')
16new_mask_file.write(mask_content)
17new_mask_file.write('\nTUBECALIBFILE = new_calibration_file.nxs')
18new_mask_file.close()
19
20
21
22
23import ISISCommandInterface as ici
24import SANSBatchMode as batch
25import os
26
27# Function to check that the calibration file is being used.
28def checkWsCalibrated(ws):
29  det00 = ws.getInstrument().getComponentByName('rear-detector(x=0)/rear-detector(0,0)')
30  det10 = ws.getInstrument().getComponentByName('rear-detector(x=1)/rear-detector(1,0)')
31  #usually these two detectors have the same Y, but because we moved rear-detector(x=0) the calibration file, it will differ.
32  print det10.getPos().Y(), det00.getPos().Y(), abs(det10.getPos().Y() - det00.getPos().Y())
33  assert (0.1 - abs(det10.getPos().Y() - det00.getPos().Y()) < 0.0001)
34
35
36
37MASKFILE = FileFinder.getFullPath('sans2dmask.txt')
38if not os.path.isabs(MASKFILE):
39        MASKFILE = './'+MASKFILE
40
41
42# run reduction in single mode
43ici.SANS2D()
44ici.MaskFile(MASKFILE)
45ici.AssignSample('22048')
46#check calibrated
47checkWsCalibrated(mtd['22048_sans_nxs'])
48ici.AssignCan('22023')
49#check calibrated
50checkWsCalibrated(mtd['22023_sans_nxs'])
51ici.TransmissionSample('22041','22024')
52ici.TransmissionCan('22024', '22024')
53reduced = ici.WavRangeReduction()
54RenameWorkspace(reduced, OutputWorkspace='single_test_rear')
55
56# run reductin in batch mode
57ici.SANS2D()
58ici.MaskFile(MASKFILE)
59fit_settings = batch.BatchReduce(FileFinder.getFullPath('sans2d_reduction_gui_batch.csv'),
60                                '.nxs', combineDet='rear')
61# prove the result is the same
62result = CheckWorkspacesMatch('single_test_rear', 'trans_test_rear', 1.0e-10)
63assert (result == 'Success!')
64
65
66# run reduction in batch mode without the calibration
67ici.SANS2D()
68ici.MaskFile('MaskSANS2DReductionGUI.txt')
69fit_settings = batch.BatchReduce(FileFinder.getFullPath('sans2d_reduction_gui_batch.csv'),
70                                '.nxs', combineDet='rear')
71# prove the result is the same
72result = CheckWorkspacesMatch('single_test_rear', 'trans_test_rear', 1.0e-10)
73assert (result != 'Success!')
74