Ticket #10544: chk_WriteTitle.py

File chk_WriteTitle.py, 1.8 KB (added by Steve Miller, 6 years ago)
Line 
1#Basic python script to verify that changed workspace titles took effect
2
3import sys,os
4#Import Mantid computatinal modules
5sys.path.append(os.environ['MANTIDPATH'])
6from mantid.simpleapi import *     
7
8#Change path and file to point appropriately to the MD workspace you want to load
9path='C:\Users\mid\Documents\Mantid\Powder\CalcProj\\'  #will read input and save output to this directory
10file='zrh_1000_PCalcProj.nxs'
11print "*** Loading in Workspace: ",path+file
12ws=LoadMD(path+file)
13title_orig=ws.getTitle()
14print "  Original title: ",title_orig
15#change title
16title_new=title_orig+' this is a new title'
17print "  Title to be added to workspace: ",title_new
18ws.setTitle(title_new)
19#print new title
20title_current=ws.getTitle()
21print "  Title set in workspace: ",title_current
22
23if title_current == title_orig:
24    print "Setting workspace title did not take"
25elif title_current == title_new:
26    print "The new title was set properly in the workspace"
27    #in this case, save the workspace, then re-load it to see if the new title is still there
28    file='zrh_1000_PCalcProj_newTitle.nxs'
29    print "*** Saving workspace: ",path+file
30    SaveMD(ws,path+file)
31    print "*** Loading workspace: ",path+file
32    wsReload=Load(path+file)
33    title_reload=wsReload.getTitle()
34    if title_reload == title_new:
35        print "--> The new title was saved and recalled properly!"
36        print "  Title to be saved: ",title_new
37        print "  Title from reloaded workspace: "
38    else:
39        print "--> title mismatch between the workspace to be saved and the reloaded workspace...unlucky..."
40        print "  Title to be saved: ",title_new
41        print "  Title from reloaded workspace: ",title_reload
42else:
43    print "Problem: Title mismatch between original and that set"
44   
45
46