Skip to content
Snippets Groups Projects
Commit 2a1269ca authored by Savici, Andrei T.'s avatar Savici, Andrei T. Committed by GitHub
Browse files

Merge pull request #20821 from mantidproject/20820_Python3DoctTestRetToSaveAscii

Python3 doctest compatibility: RetrieveRunInfo to SaveAscii-v2
parents 3ad6741f 3ea1964e
No related merge requests found
Showing
with 46 additions and 46 deletions
......@@ -54,10 +54,10 @@ Usage
# Get the information for IRIS runs 21360 and 26173.
info_table = RetrieveRunInfo(Runs="IRS21360,IRS26173")
print "The table contains information about %i runs." % info_table.rowCount()
print "The first has run number %s." % info_table.cell("run_number", 0)
print "The second has run number %s." % info_table.cell("run_number", 1)
print "The title of the second run is \"%s.\"" % info_table.cell("run_title", 1).strip()
print("The table contains information about {} runs.".format(info_table.rowCount()))
print("The first has run number {}.".format(info_table.cell("run_number", 0)))
print("The second has run number {}.".format(info_table.cell("run_number", 1)))
print("The title of the second run is \"{}.\"".format(info_table.cell("run_title", 1).strip()))
.. testcleanup:: ExSingleRun
......
......@@ -71,7 +71,7 @@ Usage
ws = CreateSampleWorkspace("Histogram","Multiple Peaks")
wsOut = RingProfile(ws,Centre=[0,5,10],MaxRadius=5)
print ("The RingProfile has been calculated with %i bins" % wsOut.blocksize())
print("The RingProfile has been calculated with {} bins".format(wsOut.blocksize()))
Output:
......@@ -86,7 +86,7 @@ Output:
ws = CreateSampleWorkspace("Histogram","Multiple Peaks")
wsOut = RingProfile(ws,Centre=[0,5,10],MinRadius=1,MaxRadius=5,NumBins=200)
print ("The RingProfile has been calculated with %i bins" % wsOut.blocksize())
print("The RingProfile has been calculated with {} bins".format(wsOut.blocksize()))
Output:
......
......@@ -50,20 +50,20 @@ Example 1: Rotating a bank around the Y Axis
result = format_str.format(nz(pos.getX()), nz(pos.getY()), nz(pos.getZ()))
return result
print 'Original positions of detectors 1 and 2'
print('Original positions of detectors 1 and 2')
opos1 = ws.getInstrument().getDetector(1).getPos()
opos2 = ws.getInstrument().getDetector(2).getPos()
print 'Det 1: {0}'.format(pos3D_as_str(opos1))
print 'Det 2: {0}'.format(pos3D_as_str(opos2))
print('Det 1: {0}'.format(pos3D_as_str(opos1)))
print('Det 2: {0}'.format(pos3D_as_str(opos2)))
# Rotate bank 'back' around the Z axis by 90
RotateInstrumentComponent( ws, ComponentName='back', X=0,Y=1,Z=0, Angle=90.0 )
print 'Positions of detectors 1 and 2 after rotation'
print('Positions of detectors 1 and 2 after rotation')
pos1 = ws.getInstrument().getDetector(1).getPos()
pos2 = ws.getInstrument().getDetector(2).getPos()
print 'Det 1: {0}'.format(pos3D_as_str(pos1))
print 'Det 2: {0}'.format(pos3D_as_str(pos2))
print('Det 1: {0}'.format(pos3D_as_str(pos1)))
print('Det 2: {0}'.format(pos3D_as_str(pos2)))
Output
......@@ -108,19 +108,19 @@ Example 2: Rotating a bank around the Z Axis
result = format_str.format(nz(pos.getX()), nz(pos.getY()), nz(pos.getZ()))
return result
print 'Original positions of detectors 1 and 4'
print('Original positions of detectors 1 and 4')
opos1 = ws.getInstrument().getDetector(1).getPos()
opos4 = ws.getInstrument().getDetector(4).getPos()
print 'Det 1: {0}'.format(pos3D_as_str(opos1))
print 'Det 4: {0}'.format(pos3D_as_str(opos4))
print('Det 1: {0}'.format(pos3D_as_str(opos1)))
print('Det 4: {0}'.format(pos3D_as_str(opos4)))
# Rotate bank 'back' around the Z axis by 3 detectors.
RotateInstrumentComponent( ws, ComponentName='back', X=0,Y=0,Z=1, Angle=3*360.0 / 32 )
print 'Positions of detector 1 after rotation'
print('Positions of detector 1 after rotation')
pos1 = ws.getInstrument().getDetector(1).getPos()
print 'Det 1: {0}'.format(pos3D_as_str(pos1))
print 'Detector 1 took place of detector 4'
print('Det 1: {0}'.format(pos3D_as_str(pos1)))
print('Detector 1 took place of detector 4')
Output
^^^^^^
......@@ -156,7 +156,7 @@ Example 3: Rotating a single detector
# Rotating a detector doesn't change its position, just its orientation
# Original position of detector 33
print ws.getInstrument().getDetector(33).getPos()
print(ws.getInstrument().getDetector(33).getPos())
# Caclulate the solid angles for all detectors in the instrument
# The result is a single-bin workspace with solid angles for all spectra in ws
......@@ -169,7 +169,7 @@ Example 3: Rotating a single detector
RotateInstrumentComponent( ws, DetectorID=33, X=0,Y=0,Z=1, Angle=90 )
# Check the position of detector 33 stays unchanged
print ws.getInstrument().getDetector(33).getPos()
print(ws.getInstrument().getDetector(33).getPos())
# Calculate the solid angles after rotation
saws = SolidAngle( ws )
......@@ -177,8 +177,8 @@ Example 3: Rotating a single detector
# Take element by element difference of the solid angles
diff = sa2 - sa1
print diff
print 'The non-zero difference',diff[32] ,'is due to detector', ws.getDetector(32).getID()
print(diff)
print('The non-zero difference {:.13f} is due to detector {}'.format(diff[32], ws.getDetector(32).getID()))
Output
^^^^^^
......
......@@ -45,8 +45,8 @@ Usage
result = format_str.format(nz(pos.getX()), nz(pos.getY()), nz(pos.getZ()))
return result
print "Original position of the sample: {0}".format(pos3D_as_str(samplePos))
print "Original position of the source: {0}".format(pos3D_as_str(sourcePos))
print("Original position of the sample: {0}".format(pos3D_as_str(samplePos)))
print("Original position of the source: {0}".format(pos3D_as_str(sourcePos)))
# Move (rotate) the source around X axis
RotateSource(ws, -90)
......@@ -54,8 +54,8 @@ Usage
# New positions
samplePos = ws.getInstrument().getSample().getPos()
sourcePos = ws.getInstrument().getSource().getPos()
print "New position of the sample: {0}".format(pos3D_as_str(samplePos))
print "New position of the source: {0}".format(pos3D_as_str(sourcePos))
print("New position of the sample: {0}".format(pos3D_as_str(samplePos)))
print("New position of the source: {0}".format(pos3D_as_str(sourcePos)))
Output:
......
......@@ -41,7 +41,7 @@ Usage
RunPythonScript(InputWorkspace=ws,Code=script,OutputWorkspace="wsOut")
wsOut = mtd["wsOut"]
print "The workspace contained a total of %i counts" % wsOut.readY(0)[0]
print("The workspace contained a total of {:d} counts".format(int(wsOut.readY(0)[0])))
Output:
......
......@@ -41,8 +41,8 @@ Usage
# Do the correction, dragging in the file which contains the reference flux spectrum.
corrected = SANSBeamFluxCorrection(ws, InputMonitorWorkspace=monitor, ReferenceFluxFilename="SANSBeamFluxCorrectionMonitor.nxs")
print "The expected value of each bin should be %s." % (0.1/(49152*0.1)/(49152*0.1))
print "The actual value of the first bin is %s." % corrected[0].readY(0)[0]
print("The expected value of each bin should be {:.11e}.".format(0.1/(49152*0.1)/(49152*0.1)))
print("The actual value of the first bin is {:.11e}.".format(corrected[0].readY(0)[0]))
Output:
......
......@@ -48,8 +48,8 @@ Usage
in_y = ws_sample.dataY(0)
out_y = out_ws.dataY(0)
print "The first bin of the first spectrum of the input was " + str(in_y[0])
print "After the dark run correction it is " + str(out_y[0])
print("The first bin of the first spectrum of the input was {:.1f}".format(in_y[0]))
print("After the dark run correction it is {:.2f}".format(out_y[0]))
Output:
......
......@@ -35,8 +35,8 @@ Usage
scale, shift = SANSFitShiftScale(HABWorkspace = hab_ws, LABWorkspace =lab_ws, Mode='ShiftOnly', ScaleFactor=1.0)
print scale
print shift
print("{:.1f}".format(scale))
print("{:.1f}".format(shift))
Output:
......
......@@ -73,8 +73,8 @@ Usage
LABNormSample=lab_norm,
Mode='ShiftOnly', ScaleFactor=1.0 )
print scale
print shift
print("{:.1f}".format(scale))
print("{:.1f}".format(shift))
Output:
......
......@@ -149,7 +149,7 @@ Usage
corrected_data = SANSWideAngleCorrection(sample, transmission)
print "%f was corrected to %f." % (sample.readY(19)[0], corrected_data.readY(19)[0])
print("{:.6f} was corrected to {:.6f}.".format(sample.readY(19)[0], corrected_data.readY(19)[0]))
Output:
......
......@@ -89,7 +89,7 @@ Usage
det1 = mtd['MANDI_801_event_DetCal'].getInstrument().getDetector(327680)
det2 = mtd['MANDI_801_event_xml'].getInstrument().getDetector(327680)
if det1.getPos() == det2.getPos():
print "matches"
print("matches")
.. testcleanup:: SCDCalibratePanels
......
......@@ -70,7 +70,7 @@ Usage
ws = LoadSassena("loadSassenaExample.h5", TimeUnit=1.0)
SassenaFFT(ws, FFTonlyRealPart=1, Temp=1000, DetailedBalance=1)
print('workspaces instantiated: ', ', '.join(ws.getNames()))
print('workspaces instantiated: {}'.format(', '.join(ws.getNames())))
sqt = ws[3] # S(Q,E)
# I(Q,t) is a Gaussian, thus S(Q,E) is a Gaussian too (at high temperatures)
......@@ -88,10 +88,10 @@ Usage
paramTable = fit_output.OutputParameters # table containing the optimal fit parameters
fitWorkspace = fit_output.OutputWorkspace
print("The fit was: " + fit_output.OutputStatus)
print("Fitted Height value is: %.1f" % paramTable.column(1)[0])
print("Fitted centre value is: %.1f" % abs(paramTable.column(1)[1]))
print("Fitted sigma value is: %.4f" % paramTable.column(1)[2])
print("The fit was: " + str(fit_output.OutputStatus))
print("Fitted Height value is: {:.1f}".format(paramTable.column(1)[0]))
print("Fitted centre value is: {:.1f}".format(abs(paramTable.column(1)[1])))
print("Fitted sigma value is: {:.4f}".format(paramTable.column(1)[2]))
# fitWorkspace contains the data, the calculated and the difference patterns
print("Number of spectra in fitWorkspace is: " + str(fitWorkspace.getNumberHistograms()))
......
......@@ -40,7 +40,7 @@ Usage
# perform the algorithm
SaveANSTOAscii(InputWorkspace=ws1,Filename=savefile)
print "File Exists:", os.path.exists(savefile)
print("File Exists: {}".format(os.path.exists(savefile)))
.. testcleanup:: ExANSTOSimple
......
......@@ -44,7 +44,7 @@ Usage
# perform the algorithm
SaveAscii(InputWorkspace=ws1,Filename=savefile)
print "File Exists:", os.path.exists(savefile)
print("File Exists: {}".format(os.path.exists(savefile)))
.. testcleanup:: ExSaveASCIISimple
......@@ -77,7 +77,7 @@ Output:
# perform the algorithm
SaveAscii(InputWorkspace=ws1,Filename=savefile,Separator="Space")
print "File Exists:", os.path.exists(savefile)
print("File Exists: {}".format(os.path.exists(savefile)))
.. testcleanup:: ExSaveASCIIDelimiter
......@@ -112,7 +112,7 @@ Output:
# CommentIndicator can be changed, but when read back in must be specified
SaveAscii(InputWorkspace=ws1,Filename=savefile,CommentIndicator="!")
print "File Exists:", os.path.exists(savefile)
print("File Exists: {}".format(os.path.exists(savefile)))
.. testcleanup:: ExSaveASCIIComment
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment