Ignore:
Timestamp:
Nov 25, 2014 3:10:21 PM (8 years ago)
Author:
srkline
Message:

adding new procedures for testing -- that will enable:

(1) automation of SANS data reduction, at least in some of the more standard cases. The more consistently the data files are named, the better this works.
(2) Much simpler scripting of experiment simulation. now a simulated experiment can be set up is the same way that a real experiemtn can -- by setting up a list of "runs"

Help files are to follow for all of these. Prelimiary help for the automation has been added to the SANS Reduction Help file. Videos to follow. Loaders for these two items have been added to the Macros menu so that all of the dependencies are satisfied.

More testing is still necessary to make sure that nothing has been broken, and that sufficient error catching has been done so that meaningful testing can be done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/MC_SimulationScripting.ipf

    r942 r950  
    9696// x- fill in the "RunSample" functions 
    9797// 
    98 //  -- I need a little panel to control all of this, and get the information, just  
     98//  x- I need a little panel to control all of this, and get the information, just  
    9999//     like setting up a real experiment. Or maybe not. Maybe better to keep some of this 
    100100//     hidden. 
     
    102102//     For some experiments it's quite useful to see the level of this contribution, rather than 
    103103//     the completely clean simulation. 
    104 //  -- in this file, clearly separate the examples from the utility functions 
     104//  x- in this file, clearly separate the examples from the utility functions 
    105105//  -- get a function list of everything, and document what each does (if not obvious) 
    106106//  -- step by step comments of one of the examples (1D and 2D) are probably the most useful 
    107 //  -- "dry run" function to estimate the total simulation time for 2D. (? set all monitor counts to 1000 
     107//  x- "dry run" function to estimate the total simulation time for 2D. (? set all monitor counts to 1000 
    108108//      or whatever I use to get other estimates, and then run through everything to get estimated times) 
    109109// 
     
    113113// 
    114114// 
    115 // ----- transmission really doesn't work in the simulation... 
    116 // -- add function to simulate transmission in 2D by saving a "Trans" configuration 
     115// ----- transmission really in the simulation... 
     116//  x- add function to simulate transmission in 2D by saving a "Trans" configuration 
    117117//     and automatically using that. Currently the trans is already written to the file 
    118 // x- would also need a function to simulate an empty beam measurement to rescale the  
     118//  x- would also need a function to simulate an empty beam measurement to rescale the  
    119119//     transmissions. (use the model given, set scale (w[0] to something really small) 
    120 //  -- or better, use the empty cell function that is guaranteed to have coefficients that are 
     120//  x- or better, use the empty cell function that is guaranteed to have coefficients that are 
    121121//     well behaved - and I can set/reset them to get a proper "empty beam" 
    122122// 
     
    128128 
    129129/// un-comment this by removing the "x" from the word xMenu. Then compile. 
     130// - note that no menu items will appear unless BOTH the Reduction and Analysis are loaded 
    130131Menu "Macros" 
    131132                Submenu "Simulation Scripting - Beta" 
    132                         ScriptItem(0),Sim_saveConfProc() 
    133                         ScriptItem(1),Sim_moveConfProc() 
    134                         ScriptItem(2),ListSASCALCConfigs() 
     133                        ScriptItem(0),ShowRunListPanel() 
     134//                      ScriptItem(0),Sim_StoreConfProc() 
     135//                      ScriptItem(1),Sim_moveConfProc() 
     136                        ScriptItem(1) 
     137//                      ScriptItem(2),ListSASCALCConfigs() 
    135138                        ScriptItem(3),DryRunProc_1D() 
    136                         ScriptItem(4),DryRunProc_2D() 
     139//                      ScriptItem(4),DryRunProc_2D() 
    137140                        ScriptItem(5),OptimalCountProc() 
    138141                        ScriptItem(6),MakeCombineTable_byName() 
     
    141144                        ScriptItem(9) 
    142145                        ScriptItem(10),Setup_Sim_Example() 
    143                         ScriptItem(11),Example_1DSim() 
    144                         ScriptItem(12),Example_2DSim() 
     146//                      ScriptItem(11),Example_1DSim() 
     147//                      ScriptItem(12),Example_2DSim() 
    145148                        ScriptItem(13) 
    146149                        ScriptItem(14),DisplayProcedure "Example_1DSim" 
     
    156159                switch(num)      
    157160                        case 0:  
    158                                 str = "Save Configuration" 
     161                                str = "Run List Panel" 
     162                                //str = "Save Configuration" 
    159163                                break 
    160164                        case 1: 
    161                                 str = "Move to Configuration" 
     165                                //str = "Move to Configuration" 
     166                                str = "-" 
    162167                                break 
    163168                        case 2: 
     
    236241Function Example_1DSim() 
    237242 
    238         String confList,ctTimeList,saveNameList,funcStr,titleStr 
     243        String confList,ctTimeList,saveNameList,funcStr,titleStrList 
    239244         
    240245 
     
    264269        ctTimeList = "100;300;900;" 
    265270        saveNameList = "sim_1m.abs;sim_4m.abs;sim_13m.abs;" 
    266         titleStr = "MySample 1" 
     271        titleStrList = "MySample 1 at 1m;MySample 1 at 4m;MySample 1 at 13m;" 
    267272 
    268273        // then this runs the samples as listed 
    269         Sim_RunSample_1D(confList,ctTimeList,titleStr,saveNameList) 
     274        Sim_RunSample_1D(confList,ctTimeList,titleStrList,saveNameList) 
    270275 
    271276        // no transmissions or empty beam measurements to make for 1D simulation 
     
    277282Function Example_2DSim() 
    278283 
    279         String confList,ctTimeList,titleStr,transConfList,transCtTimeList 
     284        String confList,ctTimeList,titleStrList,transConfList,transCtTimeList 
    280285        Variable runIndex,val,totalTime 
    281286        String funcStr 
     
    319324        transConfList = "Config_13m;"           // trans only @ 13m 
    320325        transCtTimeList = "1;"                          // trans count time = 1s 
    321         titleStr = "MySample 1" 
     326        titleStrList = "MySample 1 at 1m;MySample 1 at 4m;MySample 1 at 13m;" 
    322327 
    323328        // runIndex is PBR and updates as the number of files are written 
    324329         
    325330        // this runs the sample 
    326         totalTime += Sim_RunSample_2D(confList,ctTimeList,titleStr,runIndex) 
     331        totalTime += Sim_RunSample_2D(confList,ctTimeList,titleStrList,runIndex) 
    327332        // this runs the transmissions 
    328         totalTime += Sim_RunTrans_2D(transConfList,transCtTimeList,titleStr,runIndex) 
     333        totalTime += Sim_RunTrans_2D(transConfList,transCtTimeList,titleStrList,runIndex) 
    329334         
    330335        // run the empty beam at all configurations 
     
    332337        transConfList = "Config_1m;Config_4m;Config_13m;" 
    333338        transCtTimeList = "1;1;1;"       
    334         titleStr = "Empty Beam" 
    335         totalTime += Sim_RunEmptyBeamTrans_2D(transConfList,transCtTimeList,titleStr,runIndex) 
     339        titleStrList = "Empty Beam at 1m;Empty Beam at 4m;Empty Beam at 13m;" 
     340        totalTime += Sim_RunEmptyBeamTrans_2D(transConfList,transCtTimeList,titleStrList,runIndex) 
    336341         
    337342        Print "runIndex = ",runIndex 
     
    348353Function Example_Loop_1DSim() 
    349354 
    350         String confList,ctTimeList,saveNameList,funcStr,titleStr 
     355        String confList,ctTimeList,saveNameList,funcStr,titleStrList 
    351356         
    352357 
     
    376381        ctTimeList = ""         //filled in the loop 
    377382        saveNameList = "" 
    378         titleStr = "DAB versus count time t = " 
     383        titleStrList = "DAB versus count time t = "             //overwritten in loop 
    379384 
    380385        Make/O/D ctTime = {5,11,16,21,27,32,37,43,48,53,107,160,214,267,321,374,428,481,535,1604,5348,21390,53476} 
     
    384389        for(jj=0;jj<numpnts(ctTime);jj+=1)       
    385390                for(ii=0;ii<nTrials;ii+=1) 
    386                         titleStr = "DAB versus count time t = "+num2str(ctTime[jj]) 
     391                        titleStrList = "DAB versus count time t = "+num2str(ctTime[jj]) 
    387392                        saveNameList = "DAB_4m_t"+num2str(ctTime[jj])+"_"+num2str(ii)+".abs;" 
    388393                        ctTimeList = num2str(ctTime[jj])+";" 
    389394                        // then this runs the samples as listed 
    390                         Sim_RunSample_1D(confList,ctTimeList,titleStr,saveNameList) 
     395                        Sim_RunSample_1D(confList,ctTimeList,titleStrList,saveNameList) 
    391396                endfor 
    392397        endfor 
     
    411416Function Example_Loop_2DSim() 
    412417 
    413         String confList,ctTimeList,titleStr,transConfList,transCtTimeList 
     418        String confList,ctTimeList,titleStrList,transConfList,transCtTimeList 
    414419        Variable runIndex,val,totalTime 
    415420        String funcStr 
     
    454459        transConfList = "Config_1m;Config_4m;Config_13m;" 
    455460        transCtTimeList = "1;1;1;"       
    456         titleStr = "Empty Beam" 
    457         totalTime += Sim_RunEmptyBeamTrans_2D(transConfList,transCtTimeList,titleStr,runIndex) 
     461        titleStrList = "Empty Beam at 1m;Empty Beam at 4m;Empty Beam at 13m;" 
     462        totalTime += Sim_RunEmptyBeamTrans_2D(transConfList,transCtTimeList,titleStrList,runIndex) 
    458463         
    459464         
     
    464469        transConfList = "Config_13m"            // trans only @ 13m 
    465470        transCtTimeList = "1;"                          // trans count time = 1s 
    466         titleStr = "MySample 1" 
     471        titleStrList = "MySample 1" 
    467472 
    468473        // runIndex is PBR and updates as the number of files are written 
     
    483488 
    484489                confList = conf[ii] +";" 
    485                 titleStr = "DAB simulation, thick = "+num2str(thick[ii]) 
     490                titleStrList = "DAB simulation, thick = "+num2str(thick[ii]) 
    486491                ctTimeList = num2str(ctTime[ii])+";" 
    487492                 
    488493                // this runs the transmissions (only at 13m) 
    489494                if(cmpstr(conf[ii],"Config_13m")==0) 
    490                         totalTime += Sim_RunTrans_2D(transConfList,transCtTimeList,titleStr,runIndex) 
     495                        totalTime += Sim_RunTrans_2D(transConfList,transCtTimeList,titleStrList,runIndex) 
    491496                endif 
    492497                 
    493498                // this runs the sample 
    494                 totalTime += Sim_RunSample_2D(confList,ctTimeList,titleStr,runIndex) 
     499                totalTime += Sim_RunSample_2D(confList,ctTimeList,titleStrList,runIndex) 
    495500 
    496501        endfor 
     
    516521 
    517522// pass in a semicolon delimited list of configurations + corresponding count times + saved names 
    518 Function Sim_RunSample_1D(confList,ctTimeList,titleStr,saveNameList) 
    519         String confList,ctTimeList,titleStr,saveNameList 
     523Function Sim_RunSample_1D(confList,ctTimeList,titleStrList,saveNameList) 
     524        String confList,ctTimeList,titleStrList,saveNameList 
    520525         
    521526        Variable ii,num,ct,cr,numPt 
    522         String twStr,fname,type 
     527        String twStr,fname,type,titleStr 
    523528        NVAR g_estimateOnly = root:Packages:NIST:SAS:g_estimateOnly             // == 1 for just count rate, == 0 (default) to do the simulation and save 
    524529        WAVE/Z crWave = root:CR_1D 
     
    533538                ct = str2num(StringFromList(ii, ctTimeList,";")) 
    534539                fname = StringFromList(ii, saveNameList,";") 
     540                titleStr = StringFromList(ii, titleStrList,";") 
    535541                 
    536542                Sim_MoveToConfiguration(tw) 
     
    584590// of the model to something tiny so that there is no coherent scattering 
    585591// 
    586 Function Sim_RunTrans_2D(confList,ctTimeList,titleStr,runIndex) 
    587         String confList,ctTimeList,titleStr 
     592Function Sim_RunTrans_2D(confList,ctTimeList,titleStrList,runIndex) 
     593        String confList,ctTimeList,titleStrList 
    588594        Variable &runIndex 
    589595         
    590596        Variable ii,num,ct,index,totalTime 
    591         String twStr,type 
     597        String twStr,type,titleStr 
    592598 
    593599        NVAR g_estimateOnly = root:Packages:NIST:SAS:g_estimateOnly             // == 1 for just a time estimate, == 0 (default) to do the simulation 
     
    600606        for(ii=0;ii<num;ii+=1) 
    601607                twStr = StringFromList(ii, confList,";") 
     608                titleStr = StringFromList(ii, titleStrList,";") 
    602609                Wave/T tw=$("root:Packages:NIST:SAS:"+twStr) 
    603610                ct = str2num(StringFromList(ii, ctTimeList,";")) 
     
    628635//      Print "Sample Simulation (2D) CR = ",results[9]/ctTime 
    629636// -- for estimates, iMon is set to 1000, so time=1000/(root:Packages:NIST:SAS:gImon) 
    630 Function Sim_RunSample_2D(confList,ctTimeList,titleStr,runIndex) 
    631         String confList,ctTimeList,titleStr 
     637Function Sim_RunSample_2D(confList,ctTimeList,titleStrList,runIndex) 
     638        String confList,ctTimeList,titleStrList 
    632639        Variable &runIndex 
    633640 
    634641        Variable ii,num,ct,index,totalTime 
    635         String twStr,type 
     642        String twStr,type,titleStr 
    636643 
    637644        NVAR g_estimateOnly = root:Packages:NIST:SAS:g_estimateOnly             // == 1 for just a time estimate, == 0 (default) to do the simulation 
     
    645652        for(ii=0;ii<num;ii+=1) 
    646653                twStr = StringFromList(ii, confList,";") 
     654                titleStr = StringFromList(ii, titleStrList,";") 
    647655                Wave/T tw=$("root:Packages:NIST:SAS:"+twStr) 
    648656                ct = str2num(StringFromList(ii, ctTimeList,";")) 
     
    11321140End 
    11331141 
    1134 Proc Sim_saveConfProc(waveStr) 
     1142Proc Sim_StoreConfProc(waveStr) 
    11351143        String waveStr 
    11361144         
    1137         Sim_SaveConfiguration(waveStr) 
     1145        Sim_StoreConfiguration(waveStr) 
    11381146End 
    11391147// 
     
    11551163// 9 = offset 
    11561164// 
    1157 Function Sim_SaveConfiguration(waveStr) 
     1165Function Sim_StoreConfiguration(waveStr) 
    11581166        String waveStr 
    11591167         
     
    11621170        SetDataFolder root:Packages:NIST:SAS 
    11631171         
    1164         Make/O/T/N=20 $("Config_"+waveStr) 
    1165         Wave/T tw=$("Config_"+waveStr) 
     1172        waveStr = CleanupName("Config_"+waveStr,0) 
     1173 
     1174        Make/O/T/N=20 $(waveStr) 
     1175        Wave/T tw=$(waveStr) 
    11661176        tw = "" 
    11671177         
     
    12711281 
    12721282 
    1273 ///////////// a panel to (maybe) write to speed the setup of the runs 
    1274 // 
    1275 Function/S ListSASCALCConfigs() 
    1276         String str 
    1277         SetDataFolder root:Packages:NIST:SAS 
    1278         str = WaveList("Conf*",";","") 
    1279         SetDataFolder root: 
    1280         print str 
    1281         return(str) 
    1282 End 
    1283  
    1284 //Proc Sim_SetupRunPanel() : Panel 
    1285 //      PauseUpdate; Silent 1           // building window... 
    1286 //      NewPanel /W=(399,44,764,386) 
    1287 //      ModifyPanel cbRGB=(56639,28443,117) 
    1288 //      ShowTools/A 
    1289 //EndMacro 
Note: See TracChangeset for help on using the changeset viewer.