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

Merge pull request #20828 from mantidproject/20827_Python3DocTestPDFToScaleX

Python3 doctest compatibility: SavePDFGui to ScaleX
parents e2aa4489 85452b42
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ Usage ...@@ -35,7 +35,7 @@ Usage
SavePDFGui(ws, path) SavePDFGui(ws, path)
# Check that the file exists # Check that the file exists
print os.path.isfile(path) print(os.path.isfile(path))
Output: Output:
......
...@@ -56,13 +56,13 @@ Usage ...@@ -56,13 +56,13 @@ Usage
# import os funcions to work with folders # import os funcions to work with folders
import os import os
# create sample workspace # create sample workspace
ws=CreateSampleWorkspace(); ws=CreateSampleWorkspace()
# test file name # test file name
file_name = os.path.join(config["defaultsave.directory"], "TestSavePhx.phx") file_name = os.path.join(config["defaultsave.directory"], "TestSavePhx.phx")
# save the file # save the file
SavePHX(ws,Filename=file_name); SavePHX(ws,Filename=file_name);
print "target file exists? {0}".format(os.path.exists(file_name)); print("target file exists? {0}".format(os.path.exists(file_name)))
.. testcleanup:: exSavePHX .. testcleanup:: exSavePHX
......
...@@ -37,7 +37,7 @@ Usage ...@@ -37,7 +37,7 @@ Usage
#Make sure the file was written successfully #Make sure the file was written successfully
if os.path.isfile(filename): if os.path.isfile(filename):
print "Parameters written successfully." print("Parameters written successfully.")
.. testcleanup:: .. testcleanup::
......
...@@ -72,7 +72,7 @@ Usage in autoreduction ...@@ -72,7 +72,7 @@ Usage in autoreduction
div = SavePlot1D(InputWorkspace='w1', OutputType='plotly') div = SavePlot1D(InputWorkspace='w1', OutputType='plotly')
from postprocessing.publish_plot import publish_plot from postprocessing.publish_plot import publish_plot
request = publish_plot('TESTINSTRUMENT', 12345, files={'file':div}) request = publish_plot('TESTINSTRUMENT', 12345, files={'file':div})
print "post returned %d" % request.status_code print("post returned {}".format(request.status_code))
To see what the result looks like on your local system, add the To see what the result looks like on your local system, add the
``Filename`` argument (``.html`` extension) and change to ``Filename`` argument (``.html`` extension) and change to
......
...@@ -38,7 +38,7 @@ Usage ...@@ -38,7 +38,7 @@ Usage
SaveRKH(out_ws, file_path) SaveRKH(out_ws, file_path)
in_ws = LoadRKH(file_path) in_ws = LoadRKH(file_path)
print "Contents of the file = " + str(in_ws.readY(0)) print("Contents of the file = " + str(in_ws.readY(0)))
.. testcleanup:: ExSimpleSavingRoundtrip .. testcleanup:: ExSimpleSavingRoundtrip
......
...@@ -104,7 +104,7 @@ Usage ...@@ -104,7 +104,7 @@ Usage
# perform the algorithm # perform the algorithm
SaveSPE(InputWorkspace=ws1,Filename=savefile) SaveSPE(InputWorkspace=ws1,Filename=savefile)
print "File Exists:", os.path.exists(savefile) print("File Exists: {}".format(os.path.exists(savefile)))
.. testcleanup:: ExSPESimple .. testcleanup:: ExSPESimple
......
...@@ -80,7 +80,7 @@ Usage ...@@ -80,7 +80,7 @@ Usage
# 13470,2.3,13463+13464,0.035,0.3,0.04,,0, # 13470,2.3,13463+13464,0.035,0.3,0.04,,0,
# 13462,2.3,13463+13464,0.035,0.3,0.04,,1,ProcessingInstruction="1:2" # 13462,2.3,13463+13464,0.035,0.3,0.04,,1,ProcessingInstruction="1:2"
# 13469,0.7,13463+13464,0.01,0.06,0.04,,1, # 13469,0.7,13463+13464,0.01,0.06,0.04,,1,
print "File Exists:", os.path.exists(savefile) print("File Exists: {}".format(os.path.exists(savefile)))
.. testcleanup:: ExTBLSimple .. testcleanup:: ExTBLSimple
......
...@@ -38,10 +38,10 @@ Usage ...@@ -38,10 +38,10 @@ Usage
lines = gfile.readlines() lines = gfile.readlines()
gfile.close() gfile.close()
print "[GSAS File Start]" print("[GSAS File Start]")
for i in xrange(11): for i in range(11):
print lines[i].rstrip() print(lines[i].rstrip())
print "... ..." print("... ...")
.. testcleanup:: ExSaveVulcanGSAS .. testcleanup:: ExSaveVulcanGSAS
......
...@@ -29,6 +29,7 @@ Usage ...@@ -29,6 +29,7 @@ Usage
import os import os
import numpy as np import numpy as np
from sys import stdout
# create x and y data # create x and y data
dataX = np.arange(12).reshape(3, 4) dataX = np.arange(12).reshape(3, 4)
...@@ -53,10 +54,9 @@ Usage ...@@ -53,10 +54,9 @@ Usage
# save file # save file
SaveYDA(ws, filename) SaveYDA(ws, filename)
with open(filename,'r') as f: with open(filename,'r') as f:
for i in range(12): for i in range(12):
print f.readline(), stdout.write(f.readline())
**Output:** **Output:**
...@@ -82,4 +82,4 @@ Usage ...@@ -82,4 +82,4 @@ Usage
.. categories:: .. categories::
.. sourcelink:: .. sourcelink::
\ No newline at end of file
...@@ -87,7 +87,7 @@ using :ref:`CreateMDWorkspace <algm-CreateMDWorkspace>`. ...@@ -87,7 +87,7 @@ using :ref:`CreateMDWorkspace <algm-CreateMDWorkspace>`.
import os import os
savefile = os.path.join(config["defaultsave.directory"], "ZODS.h5") savefile = os.path.join(config["defaultsave.directory"], "ZODS.h5")
SaveZODS(InputWorkspace=ws, FileName=savefile) SaveZODS(InputWorkspace=ws, FileName=savefile)
print "File created:", os.path.exists(savefile) print("File created: {}".format(os.path.exists(savefile)))
Output: Output:
......
...@@ -23,18 +23,18 @@ Usage ...@@ -23,18 +23,18 @@ Usage
.. testcode:: ExOffsetScale .. testcode:: ExOffsetScale
ws = CreateSampleWorkspace(BankPixelWidth=1) ws = CreateSampleWorkspace(BankPixelWidth=1)
print "Every 10th bin value of " + ws.name() print("Every 10th bin value of " + ws.name())
print ws.readY(0)[0:100:10] print(ws.readY(0)[0:100:10])
# Add 2 using scale # Add 2 using scale
wsOffset = Scale(ws,2,"Add") wsOffset = Scale(ws,2,"Add")
print "Every 10th bin value of " + wsOffset.name() print("Every 10th bin value of " + wsOffset.name())
print wsOffset.readY(0)[0:100:10] print(wsOffset.readY(0)[0:100:10])
# Add 2 using the workspace operator overloads # Add 2 using the workspace operator overloads
wsOffset2 = ws + 2 wsOffset2 = ws + 2
print "Every 10th bin value of " + wsOffset2.name() print("Every 10th bin value of " + wsOffset2.name())
print wsOffset2.readY(0)[0:100:10] print(wsOffset2.readY(0)[0:100:10])
Output: Output:
...@@ -52,18 +52,18 @@ Output: ...@@ -52,18 +52,18 @@ Output:
.. testcode:: ExOffsetScale .. testcode:: ExOffsetScale
ws = CreateSampleWorkspace(BankPixelWidth=1) ws = CreateSampleWorkspace(BankPixelWidth=1)
print "Every 10th bin value of " + ws.name() print("Every 10th bin value of " + ws.name())
print ws.readY(0)[0:100:10] print(ws.readY(0)[0:100:10])
# Multiply by 10 using scale # Multiply by 10 using scale
wsScaled = Scale(ws,10,"Multiply") wsScaled = Scale(ws,10,"Multiply")
print "Every 10th bin value of " + wsScaled.name() print("Every 10th bin value of " + wsScaled.name())
print wsScaled.readY(0)[0:100:10] print(wsScaled.readY(0)[0:100:10])
# Multiply by 10 using the workspace operator overloads # Multiply by 10 using the workspace operator overloads
wsScaled2 = ws * 10 wsScaled2 = ws * 10
print "Every 10th bin value of " + wsScaled2.name() print("Every 10th bin value of " + wsScaled2.name())
print wsScaled2.readY(0)[0:100:10] print(wsScaled2.readY(0)[0:100:10])
Output: Output:
......
...@@ -36,12 +36,12 @@ Usage ...@@ -36,12 +36,12 @@ Usage
# Center the Gaussian by shifting the X-axis, then find its average # Center the Gaussian by shifting the X-axis, then find its average
ws2 = ScaleX(ws, Factor=-mean, Operation='Add') ws2 = ScaleX(ws, Factor=-mean, Operation='Add')
print 'mean=%.2f'%abs(np.sum( ws2.dataX(0) *ws2.dataY(0) ) / np.sum( ws2.dataY(0) )) print('mean={:.2f}'.format(abs(np.sum( ws2.dataX(0) *ws2.dataY(0) ) / np.sum( ws2.dataY(0) ))))
# Decrease the standard deviation of the Gaussian by half via shrinkage of the X-axis, # Decrease the standard deviation of the Gaussian by half via shrinkage of the X-axis,
# then find its standard deviation # then find its standard deviation
ws3 = ScaleX(ws2, Factor=0.5, Operation='Multiply') ws3 = ScaleX(ws2, Factor=0.5, Operation='Multiply')
print 'sigma=%.2f'%np.sqrt( np.sum( ws3.dataX(0)**2 *ws3.dataY(0) ) / np.sum( ws3.dataY(0) ) ) print('sigma={:.2f}'.format(np.sqrt( np.sum( ws3.dataX(0)**2 *ws3.dataY(0) ) / np.sum( ws3.dataY(0) ) )))
Output: 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