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