Skip to content

Commit

Permalink
Refs #9584 Fix default directory path issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Jun 18, 2014
1 parent 9954881 commit 55cbd4e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 38 deletions.
11 changes: 7 additions & 4 deletions Code/Mantid/docs/source/algorithms/GeneratePythonScript-v1.rst
Expand Up @@ -46,7 +46,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand All @@ -58,15 +58,18 @@ Output:

.. testcode:: ExGeneratePythonScriptFile

import os

#create a workspace and run some operations on it
ws = CreateSampleWorkspace()
ws = CropWorkspace(ws, XMin=7828.162291, XMax=11980.906921)
ws = Power(ws, Exponent=1.5)
ws = RenameWorkspace(ws, OutputWorkspace="MyTestWorkspace")

GeneratePythonScript(ws, Filename='myscript.py')
path = os.path.join(os.path.expanduser("~"), 'myscript.py')
GeneratePythonScript(ws, Filename=path)

with open ('myscript.py', 'r') as script:
with open (path, 'r') as script:
print script.read().strip()

Output:
Expand All @@ -87,7 +90,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand Down
Expand Up @@ -25,6 +25,8 @@ Usage

.. testcode:: ExOSIRISDiffractionReductionSimple

import os

def createDummyOSIRISWorkspace(name, func, xmin, xmax, bin_width):
"""Creates a workspace that looks something like an OSIRIS diffraction run"""
#create workspace according to function
Expand Down Expand Up @@ -53,11 +55,12 @@ Usage

#OSIRISDiffractionReduction currently only support loading from file.
for ws in (samples + vanadium):
SaveNexus(ws, ws + ".nxs")
path = os.path.join(os.path.expanduser("~"), ws + ".nxs")
SaveNexus(ws, path)

#run OSIRISDiffractionReduction
samples = [sample + ".nxs" for sample in samples]
vanadium = [van + ".nxs" for van in vanadium]
samples = [os.path.join(os.path.expanduser("~"), sample + ".nxs") for sample in samples]
vanadium = [os.path.join(os.path.expanduser("~"), van + ".nxs") for van in vanadium]
ws = OSIRISDiffractionReduction(Sample=','.join(samples), Vanadium=','.join(vanadium), CalFile="osiris_041_RES10.cal")

print "Number of Spectra: %d, Number of bins: %d" % (ws.getNumberHistograms(), ws.blocksize())
Expand All @@ -74,7 +77,6 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
os.remove(path)
except:
pass
Expand Down
15 changes: 8 additions & 7 deletions Code/Mantid/docs/source/algorithms/SaveFocusedXYE-v1.rst
Expand Up @@ -40,9 +40,10 @@ Usage
ws = ExtractSingleSpectrum(ws, 0)

file_name = "myworkspace.ascii"
SaveFocusedXYE(ws, file_name)

path = os.path.join(config['defaultsave.directory'], "myworkspace-0.ascii")
path = os.path.join(os.path.expanduser("~"), "myworkspace.ascii")

SaveFocusedXYE(ws, path)
path = os.path.join(os.path.expanduser("~"), "myworkspace-0.ascii")
print os.path.isfile(path)

Output:
Expand All @@ -57,7 +58,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand All @@ -74,9 +75,9 @@ Output:
ws = CropWorkspace(ws, StartWorkspaceIndex=0, EndWorkspaceIndex=4)

file_name = "myworkspace.ascii"
SaveFocusedXYE(ws, file_name, SplitFiles=False, IncludeHeader=True, Format='MAUD')
path = os.path.join(os.path.expanduser("~"), file_name)

path = os.path.join(config['defaultsave.directory'], file_name)
SaveFocusedXYE(ws, path, SplitFiles=False, IncludeHeader=True, Format='MAUD')
print os.path.isfile(path)


Expand All @@ -92,7 +93,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand Down
14 changes: 8 additions & 6 deletions Code/Mantid/docs/source/algorithms/SaveGSS-v1.rst
Expand Up @@ -48,9 +48,11 @@ Usage
ws = CreateSampleWorkspace()
ws = ExtractSingleSpectrum(ws, WorkspaceIndex=0)
file_name = "myworkspace.ascii"
SaveGSS(ws, file_name)
path = os.path.join(os.path.expanduser("~"), file_name)

path = os.path.join(config['defaultsave.directory'], "myworkspace-0.ascii")
SaveGSS(ws, path)

path = os.path.join(os.path.expanduser("~"), "myworkspace-0.ascii")
print os.path.isfile(path)


Expand All @@ -66,7 +68,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand All @@ -83,9 +85,9 @@ Output:
#GSAS file cannot have more than 99 entries
ws = CropWorkspace(ws, StartWorkspaceIndex=0, EndworkspaceIndex=98)
file_name = "myworkspace.ascii"
SaveGSS(ws, file_name, SplitFiles=False, ExtendedHeader=True, UseSpectrumNumberAsBankID=True)
path = os.path.join(os.path.expanduser("~"), file_name)
SaveGSS(ws, path, SplitFiles=False, ExtendedHeader=True, UseSpectrumNumberAsBankID=True)

path = os.path.join(config['defaultsave.directory'], file_name)
print os.path.isfile(path)

Output:
Expand All @@ -100,7 +102,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand Down
13 changes: 7 additions & 6 deletions Code/Mantid/docs/source/algorithms/SaveHKL-v1.rst
Expand Up @@ -49,11 +49,12 @@ Usage

import os

path = os.path.join(os.path.expanduser("~"), "MyPeaks.hkl")

#load a peaks workspace from file
peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
SaveHKL(peaks, "MyPeaks.hkl")
SaveHKL(peaks, path)

path = os.path.join(config['defaultsave.directory'], "MyPeaks.hkl")
print os.path.isfile(path)

Output:
Expand All @@ -68,7 +69,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand All @@ -85,9 +86,9 @@ Output:
peaks = LoadIsawPeaks(Filename=r'Peaks5637.integrate')
print "Number of peaks in table %d" % peaks.rowCount()

SaveHKL(peaks, "MyPeaks.hkl", MinWavelength=0.5, MaxWavelength=2,MinDSpacing=0.2, SortBy='Bank')
path = os.path.join(os.path.expanduser("~"), "MyPeaks.hkl")
SaveHKL(peaks, path, MinWavelength=0.5, MaxWavelength=2,MinDSpacing=0.2, SortBy='Bank')

path = os.path.join(config['defaultsave.directory'], "MyPeaks.hkl")
peaks = LoadHKL(path)
print "Number of peaks in table %d" % peaks.rowCount()

Expand All @@ -104,7 +105,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand Down
22 changes: 11 additions & 11 deletions Code/Mantid/docs/source/algorithms/SaveNexusProcessed-v1.rst
Expand Up @@ -55,9 +55,9 @@ Usage

ws = CreateSampleWorkspace()
file_name = "myworkspace.nxs"
SaveNexusProcessed(ws, file_name)
path = os.path.join(os.path.expanduser("~"), file_name)
SaveNexusProcessed(ws, path)

path = os.path.join(config['defaultsave.directory'], file_name)
print os.path.isfile(path)

Output:
Expand All @@ -72,7 +72,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand All @@ -88,12 +88,12 @@ Output:

ws = CreateSampleWorkspace()
file_name = "myworkspace.nxs"
SaveNexusProcessed(ws, file_name, Title="MyWorkspace", WorkspaceIndexMin=0, WorkspaceIndexMax=9)
path = os.path.join(os.path.expanduser("~"), file_name)
SaveNexusProcessed(ws, path, Title="MyWorkspace", WorkspaceIndexMin=0, WorkspaceIndexMax=9)

path = os.path.join(config['defaultsave.directory'], file_name)
print os.path.isfile(path)

ws = Load(file_name)
ws = Load(path)
print "Saved workspace has %d spectra" % ws.getNumberHistograms()

Output:
Expand All @@ -109,7 +109,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand All @@ -124,12 +124,12 @@ Output:

ws = CreateSampleWorkspace("Event")
file_name = "myworkspace.nxs"
SaveNexusProcessed(ws, file_name, CompressNexus=True, PreserveEvents=True)
path = os.path.join(os.path.expanduser("~"), file_name)
SaveNexusProcessed(ws, path, CompressNexus=True, PreserveEvents=True)

path = os.path.join(config['defaultsave.directory'], file_name)
print os.path.isfile(path)

ws = Load(file_name)
ws = Load(path)
print "Saved workspace has %d spectra" % ws.getNumberHistograms()

Output:
Expand All @@ -145,7 +145,7 @@ Output:
def removeFiles(files):
for ws in files:
try:
path = os.path.join(config['defaultsave.directory'], ws)
path = os.path.join(os.path.expanduser("~"), ws)
os.remove(path)
except:
pass
Expand Down

0 comments on commit 55cbd4e

Please sign in to comment.