| 1 | #Basic python script to verify that changed workspace titles took effect |
|---|
| 2 | |
|---|
| 3 | import sys,os |
|---|
| 4 | #Import Mantid computatinal modules |
|---|
| 5 | sys.path.append(os.environ['MANTIDPATH']) |
|---|
| 6 | from mantid.simpleapi import * |
|---|
| 7 | |
|---|
| 8 | #Change path and file to point appropriately to the MD workspace you want to load |
|---|
| 9 | path='C:\Users\mid\Documents\Mantid\Powder\CalcProj\\' #will read input and save output to this directory |
|---|
| 10 | file='zrh_1000_PCalcProj.nxs' |
|---|
| 11 | print "*** Loading in Workspace: ",path+file |
|---|
| 12 | ws=LoadMD(path+file) |
|---|
| 13 | title_orig=ws.getTitle() |
|---|
| 14 | print " Original title: ",title_orig |
|---|
| 15 | #change title |
|---|
| 16 | title_new=title_orig+' this is a new title' |
|---|
| 17 | print " Title to be added to workspace: ",title_new |
|---|
| 18 | ws.setTitle(title_new) |
|---|
| 19 | #print new title |
|---|
| 20 | title_current=ws.getTitle() |
|---|
| 21 | print " Title set in workspace: ",title_current |
|---|
| 22 | |
|---|
| 23 | if title_current == title_orig: |
|---|
| 24 | print "Setting workspace title did not take" |
|---|
| 25 | elif 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 |
|---|
| 42 | else: |
|---|
| 43 | print "Problem: Title mismatch between original and that set" |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|