Ticket #11469: BuildSQW_splitting.py

File BuildSQW_splitting.py, 3.0 KB (added by Anton Piccardo-Selg, 6 years ago)
Line 
1###########################################################################
2##   Sample script to build Mantid's combined MD workspace               ##
3##    equivalent  of Horace sqw  object                                  ##
4###########################################################################
5data_path=os.path.dirname(os.path.realpath(__file__))
6config.appendDataSearchDir(data_path)
7
8config['defaultsave.directory']=data_path
9save_dir = config.getString('defaultsave.directory')
10print "Data will be saved into: ",save_dir
11
12#
13print 'Start converting \n'
14#
15preprocessedDetectorsWSName='preprDetMAPS'
16# List of the comma-separated file names to merge
17MDWS_FilesList='';
18
19#efix=34.96;
20
21# ConvertToMD parameters defined out of the loop
22pars = dict();
23pars['InputWorkspace']=''
24pars['QDimensions']='Q3D'
25pars['dEAnalysisMode']='Direct'
26pars['Q3DFrames']='HKL'
27pars['QConversionScales']='HKL'
28pars['PreprocDetectorsWS']=preprocessedDetectorsWSName;
29pars['MinValues']='-3,-3,-3,-2'
30pars['MaxValues']='3,3,3,23'
31pars['SplitInto']='50,50,50,60'
32pars['OverwriteExisting']=False
33# Currently works only with  1
34pars['MaxRecursionDepth']=1
35pars['MinRecursionDepth']=1
36pars['TopLevelSplitting']=1
37
38nFiles = 2
39print " processing {0} spe files".format(nFiles)
40
41for n in xrange(0,nFiles):
42    source = 'MAP0'+str(5935+n)+'_4to1_033.nxspe';
43    target  = 'MDMAP'+str(5935+n)+'_4to1_033.nxs';
44    #while not(os.path.exists(save_dir+source)):
45
46    if not(os.path.exists(save_dir+target)):
47        print 'Converting ',source
48        cur_ws=LoadNXSPE(Filename=source)
49
50        # save disk space, remove source file
51        # (it should  be stored somewhere) in archive
52        #os.remove(source);
53
54        # Add incident energy log.  May be not necessary for NXSPE or nxs files
55        #AddSampleLog(Workspace=cur_ws,LogName='Ei',LogText=str(efix),LogType='Number')
56        # Add rotation angle log.  May be not necessary for NXSPE or nxs files
57        #AddSampleLog(Workspace=cur_ws,LogName='Psi',LogText=str(psi[n])+'.',LogType='Number')
58
59        # Set projection matrix
60        SetUB(Workspace=cur_ws,a=4.2275,b=4.2275,c=4.2275,u='1,1,0',v='0,0,1')
61        # rotated by proper number of degrees around rotation axis, which in usual Horace set-up is parallel to  second projection axis
62        SetGoniometer(Workspace=cur_ws,Axis0='Psi,0,1,0,1')
63        print "Goniometer angles: ",cur_ws.getRun().getGoniometer().getEulerAngles('XYZ')
64
65
66        # set up source workspace
67        pars['InputWorkspace']=cur_ws;
68        # Convert To MD
69        target_MDws=ConvertToMD(**pars)
70
71        # Save data for future usage
72        SaveMD(target_MDws,Filename=target );
73        # Clear memory
74        DeleteWorkspace(target_MDws);
75        DeleteWorkspace(cur_ws);
76
77    if (len(MDWS_FilesList) == 0):
78        MDWS_FilesList = target;
79    else:
80        MDWS_FilesList=MDWS_FilesList+','+target;
81
82
83ws4D = MergeMDFiles(MDWS_FilesList,OutputFilename='RbMnF3_test.nxs', Parallel='0');
84
85######################################################################
86
87