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

Merge pull request #20819 from mantidproject/20818_Python3DocTestRemBackToResize

Python3 doctest compatibility: RemoveBackground to ResizeRectangularDetector
parents 2a1269ca 269c1743
No related merge requests found
Showing
with 61 additions and 60 deletions
......@@ -60,13 +60,13 @@ Proof of concept background removal algorithm::
wsParent = mtd[groupedFilename];
nHist = wsParent.getNumberHistograms();
print "Parent workspace contains {0:10} histograms".format(nHist)
print("Parent workspace contains {0:10} histograms".format(nHist))
# Get the energy binning correspondent to the binning produced by rebin function (not to re-implement the same function)
ws1s = ExtractSingleSpectrum(wsParent,0);
ws1s = ConvertUnits(ws1s,'DeltaE','Direct',Ei);
ws1s = Rebin(ws1s,Params=[e_min,dE,e_max]);
e_bins = ws1s.dataX(0);
nBins =e_bins.size;
nBins = e_bins.size;
x=[e_bins[i] for i in xrange(0,nBins)]
y=[0 for xx in xrange(0,len(x)-1)]*nHist
......@@ -102,7 +102,7 @@ Proof of concept background removal algorithm::
eGrid.setE(nspec, error)
else: # signal and error for background is 0 anyway.
pass
#print " bg at spectra {0} equal to : {1}".format(nspec,bg[0])
#print(" bg at spectra {0} equal to : {1}".format(nspec,bg[0]))
background = eGrid;
......@@ -206,9 +206,9 @@ Usage
ER = Result .dataE(0);
# print first spectra, Note invalid error calculations
print "| x sampl | x result | S sample | S no bg | Err samp | Err no_bg|"
for i in xrange(0,20):
print "|{0:10}|{1:10}|{2:10.4f}|{3:10.3f}|{4:10.3f}|{5:10.3f}|".format(XS[i],XR[i],YS[i],YR[i],ES[i],ER[i]);
print("| x sampl | x result | S sample | S no bg | Err samp | Err no_bg|")
for i in range(0,20):
print("|{0:10}|{1:10}|{2:10.4f}|{3:10.3f}|{4:10.3f}|{5:10.3f}|".format(XS[i],XR[i],YS[i],YR[i],ES[i],ER[i]))
.. testoutput:: ExFlatBkgRemoval
......
......@@ -69,8 +69,8 @@ Usage
OutputWorkspace = RemoveBins( ws, 20, 35)
# Show workspaces
print "Before RemoveBins",ws.readY(0)
print "After RemoveBins",OutputWorkspace.readY(0)
print("Before RemoveBins {}".format(ws.readY(0)))
print("After RemoveBins {}".format(OutputWorkspace.readY(0)))
Output:
......
......@@ -33,7 +33,7 @@ Usage
output = RemoveExpDecay(input)
print "Exp. decay removed:", output.readY(0)
print("Exp. decay removed: {}".format(output.readY(0)))
Output:
......
......@@ -17,15 +17,15 @@ Usage
# create some workspace with an instrument
ws = CreateSampleWorkspace()
print "Original logs: ", ws.run().keys()
print("Original logs: {}".format(ws.run().keys()))
# remove logs, but keep some
RemoveLogs(ws,KeepLogs="run_start, run_title")
print "Logs left: ", ws.run().keys()
print("Logs left: {}".format(ws.run().keys()))
# delete all logs
RemoveLogs(ws)
print "Logs left (should be empty): ", ws.run().keys()
print("Logs left (should be empty): {}".format(ws.run().keys()))
.. testcleanup:: RemoveLogs
......
......@@ -26,11 +26,11 @@ Usage
ws = CreateSampleWorkspace()
# Mask some detectors
MaskDetectors(ws,SpectraList=[10,20,30,40,50])
print 'Input workspace has %s spectra' % ws.getNumberHistograms()
print('Input workspace has {} spectra'.format(ws.getNumberHistograms()))
# Removed the 5 masked spectra
removed = RemoveMaskedSpectra(ws)
print 'Output workspace has %s spectra' % removed.getNumberHistograms()
print('Output workspace has {} spectra'.format(removed.getNumberHistograms()))
Output:
......
......@@ -31,10 +31,10 @@ Usage
x=w1.dataX(0)
y=w1.dataY(0)
print "Y(",x[100],") = ",y[100]
print "Y(",x[1000],") = ",y[1000]
print "Y(",x[4100],") = ",y[4100]
print "Y(",x[5000],") = ",y[5000]
print("Y( {} ) = {:.1f}".format(x[100], y[100]))
print("Y( {} ) = {:.1f}".format(x[1000], y[1000]))
print("Y( {} ) = {:.1f}".format(x[4100], y[4100]))
print("Y( {} ) = {:.1f}".format(x[5000], y[5000]))
.. testcleanup:: RemovePromptPulse
......
......@@ -21,9 +21,9 @@ Usage
def print_workspace_history(ws):
history = ws.getHistory()
print "Workspace %s has %i algorithms in it's history" %(ws,history.size())
print("Workspace {} has {} algorithms in it's history".format(ws,history.size()))
for alg in history.getAlgorithmHistories():
print " " + alg.name()
print(" " + alg.name())
# create histogram workspace
ws = CreateSampleWorkspace(NumBanks=1,BankPixelWidth=1)
......@@ -38,7 +38,7 @@ Usage
RemoveWorkspaceHistory(ws)
print "After RemoveWorkspaceHistory"
print("After RemoveWorkspaceHistory")
print_workspace_history(ws)
......
......@@ -42,35 +42,35 @@ Usage
myWs=CreateSampleWorkspace()
mon_ws = CreateSampleWorkspace()
myWs.setMonitorWorkspace(mon_ws)
print "*********************************************************************"
print "{0:20}|{1:>20}|{2:>20}|".format("Existing WS names: ",myWs.name(),mon_ws.name())
print("*********************************************************************")
print("{0:20}|{1:>20}|{2:>20}|".format("Existing WS names: ",myWs.name(),mon_ws.name()))
obj_inADS = AnalysisDataService.getObjectNames()
obj_inADS.sort()
print "{0:20}|{1:>6}| With Names: |{2:>20}|{3:>20}|".format("Exist in ADS: ",len(obj_inADS),obj_inADS[0],obj_inADS[1])
#
print("{0:20}|{1:>6}| With Names: |{2:>20}|{3:>20}|".format("Exist in ADS: ",len(obj_inADS),obj_inADS[0],obj_inADS[1]))
NameA = RenameWorkspace(myWs)
#
print "***** After simple rename:"
print "{0:20}|{1:>20}|{2:>20}|".format("Existing WS names: ",NameA.name(),mon_ws.name())
print("***** After simple rename:")
print("{0:20}|{1:>20}|{2:>20}|".format("Existing WS names: ",NameA.name(),mon_ws.name()))
obj_inADS = AnalysisDataService.getObjectNames()
obj_inADS.sort()
print "{0:20}|{1:>6}| With Names: |{2:>20}|{3:>20}|".format("Exist in ADS: ",len(obj_inADS),obj_inADS[0],obj_inADS[1])
print("{0:20}|{1:>6}| With Names: |{2:>20}|{3:>20}|".format("Exist in ADS: ",len(obj_inADS),obj_inADS[0],obj_inADS[1]))
print "Old pointer to myWs refers to workspace with new name: ",myWs.name()
print "*********************************************************************"
print "***** After renaming workspace and monitors workspace together:"
#
print("Old pointer to myWs refers to workspace with new name: {}".format(myWs.name()))
print("*********************************************************************")
print("***** After renaming workspace and monitors workspace together:")
NameB = RenameWorkspace(myWs,RenameMonitors=True)
#
print "{0:20}|{1:>20}|{2:>20}|".format("Existing WS names: ",NameB.name(),mon_ws.name())
print("{0:20}|{1:>20}|{2:>20}|".format("Existing WS names: ",NameB.name(),mon_ws.name()))
obj_inADS = AnalysisDataService.getObjectNames()
obj_inADS.sort()
print "{0:20}|{1:>6}| With Names: |{2:>20}|{3:>20}|".format("Exist in ADS: ",len(obj_inADS),obj_inADS[0],obj_inADS[1])
#
print("{0:20}|{1:>6}| With Names: |{2:>20}|{3:>20}|".format("Exist in ADS: ",len(obj_inADS),obj_inADS[0],obj_inADS[1]))
mon_ws1 = NameB.getMonitorWorkspace()
print "The name of the monitor workspace attached to workspace:{0:>6}| Is: {1:>10}|".\
format(NameB.name(),mon_ws1.name())
print "*********************************************************************"
print("The name of the monitor workspace attached to workspace:{0:>6}| Is: {1:>10}|".
format(NameB.name(),mon_ws1.name()))
print("*********************************************************************")
Output:
......@@ -104,16 +104,16 @@ Output:
CreateWorkspace([0], [0], OutputWorkspace="wsNew")
#This will fail telling us that 'wsOld' already exists
print 'Trying to rename with OverwriteExisting set to false.'
print('Trying to rename with OverwriteExisting set to false.')
try:
RenameWorkspace(InputWorkspace="wsNew", OutputWorkspace="wsOld", OverwriteExisting=False)
except RuntimeError:
print 'RuntimeError: The workspace wsOld already exists'
print('RuntimeError: The workspace wsOld already exists')
#This will succeed in renaming and 'wsOld' will be replaced with 'wsNew'
print 'Trying to rename with OverwriteExisting set to true.'
print('Trying to rename with OverwriteExisting set to true.')
RenameWorkspace(InputWorkspace="wsNew", OutputWorkspace="wsOld", OverwriteExisting=True)
print 'Succeeded'
print('Succeeded')
Output:
......
......@@ -50,13 +50,13 @@ Usage
ws_before_rename = mtd.getObjectNames()
ws_before_rename.sort()
print 'Workspaces in the ADS _before_ renaming:', ws_before_rename
print('Workspaces in the ADS _before_ renaming: {}'.format(ws_before_rename))
RenameWorkspaces(names, WorkspaceNames=['new_ws1', 'new_ws2', 'new_ws3'])
ws_after_rename = mtd.getObjectNames()
ws_after_rename.sort()
print 'Workspaces in the ADS _after_ renaming:', ws_after_rename
print('Workspaces in the ADS _after_ renaming: {}'.format(ws_after_rename))
Output:
......@@ -80,13 +80,13 @@ Output:
ws_before_rename = mtd.getObjectNames()
ws_before_rename.sort()
print 'Workspaces in the ADS _before_ renaming:', ws_before_rename
print('Workspaces in the ADS _before_ renaming: {}'.format(ws_before_rename))
RenameWorkspaces(names, Prefix='new_', Suffix='_name')
ws_after_rename = mtd.getObjectNames()
ws_after_rename.sort()
print 'Workspaces in the ADS _after_ renaming:', ws_after_rename
print('Workspaces in the ADS _after_ renaming: {}'.format(ws_after_rename))
Output:
......@@ -112,16 +112,16 @@ Output:
CreateWorkspace([0], [0], OutputWorkspace=name)
#This will fail telling us that 'new_ws1' already exists
print 'Trying to rename with OverwriteExisting set to false.'
print('Trying to rename with OverwriteExisting set to false.')
try:
RenameWorkspaces(names, Prefix='new_', OverwriteExisting=False)
except RuntimeError:
print 'RuntimeError: A workspace called new_ws1 already exists'
print('RuntimeError: A workspace called new_ws1 already exists')
#This will succeed in renaming and 'new_ws1' will be replaced with 'ws1'
print 'Trying to rename with OverwriteExisting set to true.'
print('Trying to rename with OverwriteExisting set to true.')
RenameWorkspaces(names, Prefix='new_', OverwriteExisting=True)
print 'Succeeded'
print('Succeeded')
Output:
......
......@@ -42,10 +42,10 @@ Usage
BigNumberThreshold=1000, BigNumberValue=1000,
SmallNumberThreshold=1e-6, SmallNumberValue=200)
print "i\tBefore\tAfter"
print "-\t------\t-----"
print("i\tBefore\tAfter")
print("-\t------\t-----")
for i in range(5):
print "%i\t%s\t%s" % (i, yArray[i],ws.readY(0)[i])
print("{}\t{}\t{}".format(i, yArray[i],ws.readY(0)[i]))
Output:
......@@ -75,7 +75,7 @@ Output:
ws = ReplaceSpecialValues(ws, SmallNumberThreshold=1e-6)
print("Before\t\t After")
print("{0}\t{1}".format(wsYArray[0], ws.readY(0)[0]))
print("{0:.11e}\t{1:.1f}".format(wsYArray[0], ws.readY(0)[0]))
Output:
......
......@@ -32,8 +32,8 @@ Usage
replicated = ReplicateMD(ShapeWorkspace=shape, DataWorkspace=data)
print 'Num dims:', replicated.getNumDims()
print 'Num points:', replicated.getNPoints()
print('Num dims: {}'.format(replicated.getNumDims()))
print('Num points: {}'.format(replicated.getNPoints()))
Output:
......
......@@ -50,8 +50,8 @@ Usage
bank1=i.getComponentByName('bank1')
bank2=i.getComponentByName('bank2')
print ("bank 1 was scaled and is now %.2f by %.2f" % (bank1.xsize(), bank1.ysize()))
print ("bank 2 was not scaled and remains %.2f by %.2f" % (bank2.xsize(), bank2.ysize()))
print ("bank 1 was scaled and is now {:.2f} by {:.2f}".format(bank1.xsize(), bank1.ysize()))
print ("bank 2 was not scaled and remains {:.2f} by {:.2f}".format(bank2.xsize(), bank2.ysize()))
Output:
......
......@@ -43,6 +43,7 @@ Usage
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:
......
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