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

Merge pull request #20809 from mantidproject/20802_Python3DocTestLogToMaskPeaks

Python3 doctest compatibility: Logarithm to MaskPeaksWorkspace
parents a53ac0f3 1d141a10
No related branches found
No related tags found
No related merge requests found
......@@ -33,19 +33,20 @@ Usage
.. testcode:: ExLogarithm
dataX = range(0,10)*10 # define 10 x-spectra
dataX = list(range(0,10))*10 # define 10 x-spectra
dataY =([1]*10)*10 # with values 1
dataY[0]=-10 # make first value not suitable for logarithm
dataY[1]=10 # make second value different
dataE =([1]*10)*10 # define 10 error spectra with value 1
# create test workspace
ws = CreateWorkspace(dataX, dataY,dataE,NSpec=10)
# caluclate log10
ws = CreateWorkspace(dataX, dataY, dataE, NSpec=10)
# Calculate log10
ws = Logarithm(ws,Filler=-1,Natural='0')
#
# check results:
print 'Log10 for spectra 0: ',ws.readY(0)
print 'Log10 for Err spectra 0: ',ws.readE(0)[0:4]
print('Log10 for spectra 0: {}'.format(ws.readY(0)))
print('Log10 for Err spectra 0: {}'.format(ws.readE(0)[0:4]))
.. testcleanup:: ExLogarithm
......
......@@ -33,9 +33,9 @@ Usage
y = corrected.readY(2)
e = corrected.readE(2)
# print first corrected yvalues
print y[1:5]
print(y[1:5])
# print first corrected evalues
print e[1:5]
print(e[1:5])
Output:
......
......@@ -35,8 +35,8 @@ Usage
output = MDHistoToWorkspace2D(InputWorkspace='input')
# print 6th group of 4 bins in both input and output workspaces
print "part of MD workspace",input.getSignalArray()[1,1]
print "corresponding part of 2D workspace",output.dataY(5)
print("part of MD workspace {}".format(input.getSignalArray()[1,1]))
print("corresponding part of 2D workspace {}".format(output.dataY(5) ))
Output:
......
......@@ -22,17 +22,17 @@ Usage
.. testcode:: MaskAngle
#Load a workspace
ws=Load("CNCS_7860")
ws = Load("CNCS_7860")
#Do the masking for direct beam
mask=MaskAngle(ws,MinAngle=0,MaxAngle=10)
print "The algorithm has masked ",mask.size," detectors"
mask = MaskAngle(ws, MinAngle=0, MaxAngle=10)
print("The algorithm has masked {} detectors".format(mask.size))
#to test check a couple of detectors
inst=ws.getInstrument()
print "Is the minimum element in the mask list (detector ",mask.min(),") masked? ",inst.getDetector(int(mask.min())).isMasked()
print "Is the maximum element in the mask list (detector ",mask.max(),") masked? ",inst.getDetector(int(mask.max())).isMasked()
print "Is a detector outside the list masked (for example detector 100)? ", inst.getDetector(100).isMasked()
inst = ws.getInstrument()
print("Is the minimum element in the mask list (detector {}) masked? {}".format(mask.min(), inst.getDetector(int(mask.min())).isMasked()))
print("Is the maximum element in the mask list (detector {}) masked? {}".format(mask.max(), inst.getDetector(int(mask.max())).isMasked()))
print("Is a detector outside the list masked (for example detector 100)? {}".format(inst.getDetector(100).isMasked() ))
.. testcleanup:: MaskAngle
......@@ -42,9 +42,9 @@ Output:
.. testoutput:: MaskAngle
The algorithm has masked 1516 detectors
Is the minimum element in the mask list (detector 35126 ) masked? True
Is the maximum element in the mask list (detector 38601 ) masked? True
The algorithm has masked 1516 detectors
Is the minimum element in the mask list (detector 35126) masked? True
Is the maximum element in the mask list (detector 38601) masked? True
Is a detector outside the list masked (for example detector 100)? False
......
......@@ -41,19 +41,19 @@ Usage
a=MaskBTP(Instrument='CNCS',Tube='1-3')
b=MaskBTP(Workspace='CNCSMaskBTP',Instrument='CNCS',Bank='40-50',Pixel='1-10')
c=MaskBTP(Workspace='CNCSMaskBTP',Instrument='CNCS',Bank='42')
print "Detectors masked"
print "Step 1: 50 * 3 * 128 =", a.size
print "Step 2: 11 * 8 * 10 =", b.size
print "Step 3: 1 * 8 * 128 =", c.size
print("Detectors masked")
print("Step 1: 50 * 3 * 128 = {0.size}".format(a))
print("Step 2: 11 * 8 * 10 = {0.size}".format(b))
print("Step 3: 1 * 8 * 128 = {0.size}".format(c))
print "Here are some of the masked detectors:"
print("Here are some of the masked detectors:")
instrument=mtd['CNCSMaskBTP'].getInstrument()
print "A pixel Bank 42, detector 42700: ",instrument.getDetector(42700).isMasked()
print "Pixel 1 in Tube 4 in Bank 45, detector 45440: ",instrument.getDetector(45440).isMasked()
print "Pixel 100 in Tube 2 in Bank 45, detector 45283: ",instrument.getDetector(45283).isMasked()
print
print "And one that should not be masked"
print "Pixel 128 in Tube 8 in Bank 50, detector 51199: ",instrument.getDetector(51199).isMasked()
print("A pixel Bank 42, detector 42700: {}".format(instrument.getDetector(42700).isMasked()))
print("Pixel 1 in Tube 4 in Bank 45, detector 45440: {}".format(instrument.getDetector(45440).isMasked()))
print("Pixel 100 in Tube 2 in Bank 45, detector 45283: {}".format(instrument.getDetector(45283).isMasked()))
print("")
print("And one that should not be masked")
print("Pixel 128 in Tube 8 in Bank 50, detector 51199: {}".format(instrument.getDetector(51199).isMasked()))
.. testcleanup:: MaskBTP
......
......@@ -38,8 +38,8 @@ Usage
wsMasked = MaskBins(ws,XMin=16,XMax=32)
# Show Y values in workspaces
print "Before masking:", ws.readY(0)
print "After masking:",wsMasked.readY(0)
print("Before masking: {}".format(ws.readY(0)))
print("After masking: {}".format(wsMasked.readY(0)))
Output:
......
......@@ -41,8 +41,8 @@ Usage
wsMasked = MaskBinsFromTable(ws,MaskingInformation=mask_info)
# Show Y values in workspaces
print "Before masking:", ws.readY(0)
print "After masking:",wsMasked.readY(0)
print("Before masking: {}".format(ws.readY(0)))
print("After masking: {}".format(wsMasked.readY(0)))
Output:
......
......@@ -22,14 +22,14 @@ always returns first spectra present in the workspace.
The *Spectra Number* or *spectra ID* mean the number, assigned to a spectrum. This number is often equal to *WorkspaceIndex+1*, e.g. ::
print sp.getSpectrumNo()
print(sp.getSpectrumNo())
from the sample above will often print 1 but not always. The simplest case when this
number is different is when you load a second half of a workspace, when the first spectrum number still is **NumTotalSpectraInWorkspace/2+1**,
while *WorkspaceIndex* of this spectra becomes 0, i.e.: ::
sp = ws.getSpectrum(0)
print sp.getSpectrumNo()
print(sp.getSpectrumNo())
prints number equal to **NumTotalSpectraInWorkspace/2+1**. There are other ways to assign a random number to a spectrum.
......@@ -38,8 +38,8 @@ a first detector corresponds to the first spectra of a workspace, but it is not
the code: ::
ws = CreateSimulationWorkspace('MARI','-0.5,0.5,0.5')
sp=ws.getSpectrum(1)
print sp.getSpectrumNo(), sp.getDetectorIDs()
sp = ws.getSpectrum(1)
print("{} {}".format(sp.getSpectrumNo(), sp.getDetectorIDs()))
Will print: ::
......@@ -190,34 +190,34 @@ Example 1: specifying spectrum numbers
# Get the 1st spectrum in the workspace
spec = ws.getSpectrum(0)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
print('Spectrum number is {}'.format(spec.getSpectrumNo()))
print('Detector of this spectrum is masked: {}'.format(ws.getInstrument().getDetector(detid).isMasked()))
y = ws.readY(0)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
print('All counts in the spectrum are 0: {}'.format(np.all( y == 0.0 )))
# Get the 2nd spectrum in the workspace
spec = ws.getSpectrum(1)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
print('Spectrum number is {}'.format(spec.getSpectrumNo()))
print('Detector of this spectrum is masked: {}'.format(ws.getInstrument().getDetector(detid).isMasked()))
y = ws.readY(1)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
print('All counts in the spectrum are 0: {}'.format(np.all( y == 0.0 )))
# Get the 3rd spectrum in the workspace
spec = ws.getSpectrum(2)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
print('Spectrum number is {}'.format(spec.getSpectrumNo()))
print('Detector of this spectrum is masked: {}'.format(ws.getInstrument().getDetector(detid).isMasked()))
y = ws.readY(2)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
print('All counts in the spectrum are 0: {}'.format(np.all( y == 0.0 )))
# Get the 4th spectrum in the workspace
spec = ws.getSpectrum(3)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
print('Spectrum number is {}'.format(spec.getSpectrumNo()))
print('Detector of this spectrum is masked: {}'.format(ws.getInstrument().getDetector(detid).isMasked()))
y = ws.readY(3)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
print('All counts in the spectrum are 0: {}'.format(np.all( y == 0.0 )))
Output
^^^^^^
......@@ -252,19 +252,19 @@ Example 2: specifying detector IDs
# Check the 1st detector
det = ws.getInstrument().getDetector(101)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
# Check the 2nd detector
det = ws.getInstrument().getDetector(103)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
# Check some other detectors
det = ws.getInstrument().getDetector(100)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
det = ws.getInstrument().getDetector(102)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
det = ws.getInstrument().getDetector(105)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
Output
^^^^^^
......@@ -293,23 +293,23 @@ Example 3: specifying workspace indices
# Check the 1st spectrum
workspaceIndex = 0
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
print('Detector in spectrum with workspace index {} is masked: {}'.format(workspaceIndex, det.isMasked()))
# Check the 2nd spectrum
workspaceIndex = 2
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
print('Detector in spectrum with workspace index {} is masked: {}'.format(workspaceIndex, det.isMasked()))
# Check some other spectra
workspaceIndex = 1
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
print('Detector in spectrum with workspace index {} is masked: {}'.format(workspaceIndex, det.isMasked()))
workspaceIndex = 3
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
print('Detector in spectrum with workspace index {} is masked: {}'.format(workspaceIndex, det.isMasked()))
workspaceIndex = 4
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
print('Detector in spectrum with workspace index {} is masked: {}'.format(workspaceIndex, det.isMasked()))
Output
^^^^^^
......@@ -375,13 +375,13 @@ Example 5: specifying a masking workspace
# Extract created mask into specialised masking workspace
masking_ws,dummy = ExtractMask( tmp )
print 'A masking workspace has',masking_ws.blocksize(),'spectrum'
print 'Unmasked spectrum, value=',masking_ws.readY(0)[0]
print 'Masked spectrum, value=',masking_ws.readY(1)[0]
print 'Unmasked spectrum, value=',masking_ws.readY(2)[0]
print 'Masked spectrum, value=',masking_ws.readY(3)[0]
print 'Unmasked spectrum, value=',masking_ws.readY(4)[0]
print
print('A masking workspace has {} spectrum'.format(masking_ws.blocksize()))
print('Unmasked spectrum, value = {}'.format(masking_ws.readY(0)[0]))
print('Masked spectrum, value = {}'.format(masking_ws.readY(1)[0]))
print('Unmasked spectrum, value = {}'.format(masking_ws.readY(2)[0]))
print('Masked spectrum, value = {}'.format(masking_ws.readY(3)[0]))
print('Unmasked spectrum, value = {}'.format(masking_ws.readY(4)[0]))
print('')
# Create a data workspace
ws = CreateSampleWorkspace()
......@@ -390,15 +390,15 @@ Example 5: specifying a masking workspace
# Check masking of first 5 detectors
det = ws.getDetector(0)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
det = ws.getDetector(1)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
det = ws.getDetector(2)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
det = ws.getDetector(3)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
det = ws.getDetector(4)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
Output
......@@ -407,11 +407,11 @@ Output
.. testoutput:: ExMaskMask
A masking workspace has 1 spectrum
Unmasked spectrum, value= 0.0
Masked spectrum, value= 1.0
Unmasked spectrum, value= 0.0
Masked spectrum, value= 1.0
Unmasked spectrum, value= 0.0
Unmasked spectrum, value = 0.0
Masked spectrum, value = 1.0
Unmasked spectrum, value = 0.0
Masked spectrum, value = 1.0
Unmasked spectrum, value = 0.0
Detector 100 is masked: False
Detector 101 is masked: True
......@@ -430,9 +430,9 @@ Example 6: specifying a masking range
MaskDetectors(ws, StartWorkspaceIndex=2, EndWorkspaceIndex=4)
# Check masking of first 6 detectors
for ind in xrange(0,6):
for ind in range(0,6):
det = ws.getDetector(ind)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
Output
......@@ -461,13 +461,13 @@ Example 7: constraining the masking range
# Extract created mask into specialised masking workspace
masking_ws,_ = ExtractMask( tmp )
for ind in xrange(0,7):
for ind in range(0,7):
val = masking_ws.readY(ind)[0]
if val>0:
print 'Unmasked spectrum, value=',val
print('Unmasked spectrum, value= {}'.format(val))
else:
print 'Masked spectrum, value=',val
print
print('Masked spectrum, value= {}'.format(val))
print('')
# Create a data workspace
ws = CreateSampleWorkspace()
......@@ -475,10 +475,10 @@ Example 7: constraining the masking range
MaskDetectors(ws, MaskedWorkspace=masking_ws,StartWorkspaceIndex=4, EndWorkspaceIndex=5)
# Check masking of first 7 detectors
for ind in xrange(0,7):
for ind in range(0,7):
det = ws.getDetector(ind)
print 'Detector',det.getID(),'is masked:',det.isMasked()
print('Detector {} is masked: {}'.format(det.getID(), det.isMasked()))
Output
^^^^^^
......
......@@ -66,11 +66,11 @@ Usage
inside_dets.append( det.getID() )
# Print out the IDs
print masked_dets
print inside_dets
print(masked_dets)
print(inside_dets)
# Check that the two arrays are equal
print masked_dets == inside_dets
print(masked_dets == inside_dets)
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