Ignore:
Timestamp:
May 20, 2016 4:28:56 PM (7 years ago)
Author:
srkline
Message:

changes to a few analysis models to make these Igor 7-ready

adding mask editing utilities

many changes to event mode for easier processing of split lists

updated event mode help file

+ lots more!

Location:
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
Files:
2 edited

Legend:

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

    r990 r999  
    1616// 
    1717// -- NEW 2016 
     18// 
     19// -- see the Procedure DecodeBinaryEvents(numToPrint) for a first implementation of a "viewer" 
     20//    for the binary events. Prints out the decoded 32-bit binary to the command window for inspection 
     21//    Could be modified as needed to flag events, see what bad events really look like, etc. (May 2016) 
     22 
    1823//  -- see the proc DisplayForSlicing() that may aid in setting the bins properly by plotting the  
    1924//     bins along with the differential collection rate 
     
    189194 
    190195// for decimation 
    191         Variable/G root:Packages:NIST:Event:gEventFileTooLarge = 150            // 150 MB considered too large 
     196        Variable/G root:Packages:NIST:Event:gEventFileTooLarge = 2500           // 2500 MB considered too large 
    192197        Variable/G root:Packages:NIST:Event:gDecimation = 100 
    193198        Variable/G root:Packages:NIST:Event:gEvent_t_longest_decimated = 0 
     
    280285        Button button16_1,pos={488,450},size={110,20},proc=AccumulateSlicesButton,title="Add Next Slice" 
    281286        Button button17_2,pos={620,425},size={110,20},proc=AccumulateSlicesButton,title="Display Total" 
     287        Button button22,pos={620,450},size={120,20},proc=Osc_LoadAdjList_BinOnFly,title="Load+Accumulate" 
    282288 
    283289        CheckBox chkbox1_0,pos={25,34},size={69,14},title="Oscillatory",fSize=10 
     
    584590// now before binning, sort the data 
    585591 
    586         //this is slow - undoing the sorting and starting over, but if you don't, 
     592        //MakeIndex is REALLY SLOW - this is slow - to allow undoing the sorting and starting over, but if you don't, 
    587593        // you'll never be able to undo the sort 
    588594        // 
     595        // 
     596        // for a 500 MB hst, MakeIndex = 83s, everything else in this function totalled < 5s 
     597        // 
    589598        SetDataFolder root:Packages:NIST:Event: 
    590599 
    591600        if(WaveExists($"root:Packages:NIST:Event:OscSortIndex") == 0 ) 
    592601                Duplicate/O rescaledTime OscSortIndex 
     602//              tic() 
    593603                MakeIndex rescaledTime OscSortIndex 
     604//              toc() 
     605//              tic() 
    594606                IndexSort OscSortIndex, yLoc,xLoc,timePt,rescaledTime    
     607//              toc() 
    595608                //SetDataFolder root:Packages:NIST:Event 
     609//              tic() 
    596610                IndexForHistogram(xLoc,yLoc,binnedData)                 // index the events AFTER sorting 
     611//              toc() 
    597612                //SetDataFolder root: 
    598613        Endif 
     
    600615        Wave index = root:Packages:NIST:Event:SavedIndex                //this is the histogram index 
    601616 
     617//      tic() 
    602618        for(ii=0;ii<nslices;ii+=1) 
    603619                if(ii==0) 
     
    634650        endfor 
    635651 
     652//      toc() 
    636653        Duplicate/O slicedData,root:Packages:NIST:Event:dispsliceData,root:Packages:NIST:Event:logSlicedData 
    637654        Wave logSlicedData = root:Packages:NIST:Event:logSlicedData 
     
    9921009 
    9931010// MODE_TISANE 
    994  
     1011//TODO -- tisane doesn't do anything different than oscillatory. Is this really correct?? 
     1012        if(mode == MODE_TISANE)         // TISANE mode - don't adjust the times, we get periodic t0 to reset t=0 
     1013                Duplicate/O timePt rescaledTime 
     1014                rescaledTime *= 1e-7                    //convert to seconds and that's all 
     1015                t_longest = waveMax(rescaledTime)               //if oscillatory, won't be the last point, so get it this way 
     1016         
     1017                KillWaves/Z OscSortIndex                        //to make sure that there is no old index hanging around 
     1018        endif 
     1019         
    9951020// MODE_TOF 
    9961021        if(mode == MODE_TOF)            // TOF mode - don't adjust the times, we get periodic t0 to reset t=0 
     
    12751300        totBytes = V_logEOF 
    12761301        Print "total bytes = ", totBytes 
    1277          
     1302        if(EventDataType(filePathStr) != 1)             //if not hst extension of raw data 
     1303                Abort "Data must be raw event data with file extension .hst for this operation" 
     1304                return(0) 
     1305        endif    
    12781306//toc() 
    12791307// 
     
    17681796        Print "total bytes = ", totBytes 
    17691797         
     1798        if(EventDataType(filePathStr) != 1)             //if not hst extension of raw data 
     1799                Abort "Data must be raw event data with file extension .hst for this operation" 
     1800                return(0) 
     1801        endif 
    17701802// 
    17711803//      Print "scan only" 
     
    24362468                        Wave xLoc = xLoc 
    24372469                        Wave yLoc = yLoc 
    2438                         Save/T xLoc,yLoc,timePt ,rescaledTime           //will ask for a name 
     2470                        Save/T xLoc,yLoc,timePt,rescaledTime            //will ask for a name 
    24392471                         
    24402472                        SetDataFolder root: 
     
    24642496                        // load in the waves, saved as Igor text to preserve the data type 
    24652497                        PathInfo/S catPathName          //should set the next dialog to the proper path... 
    2466                         LoadWave/T/O/P=catPathName 
    2467                         filePathStr = S_fileName 
     2498                        filePathStr = PromptForPath("Pick the edited event data") 
     2499                        if(EventDataType(filePathStr) != 2)             //if not itx extension of edited data 
     2500                                Abort "Data must be edited data with file extension .itx for this operation" 
     2501                                return(0) 
     2502                        endif 
     2503                        LoadWave/T/O/P=catPathName filePathStr 
     2504//                      filePathStr = S_fileName 
     2505 
    24682506                        if(strlen(S_fileName) == 0) 
    24692507                                //user cancelled 
     
    30473085         
    30483086        for(ii=0;ii<numSplit;ii+=1) 
    3049                 outStr = (thePath+baseStr+num2str(ii)) 
     3087                outStr = (thePath+baseStr+num2str(ii)+".hst") 
    30503088//              Print "outStr = ",outStr 
    30513089                Open outRef as outStr 
     
    30573095 
    30583096                Close outRef 
    3059 //              listStr += outStr+";" 
    3060                 listStr += baseStr+num2str(ii)+";" 
     3097//              listStr += outStr+";"           //no, this is the FULL path 
     3098                listStr += baseStr+num2str(ii)+".hst"+";" 
    30613099        endfor 
    30623100 
    30633101        Make/O/B/U/N=(frac) leftover 
    30643102        // ii was already incremented past the loop 
    3065         outStr = (thePath+baseStr+num2str(ii)) 
     3103        outStr = (thePath+baseStr+num2str(ii)+".hst") 
    30663104        Open outRef as outStr 
    30673105        for(jj=0;jj<num;jj+=1) 
     
    30743112        Close outRef 
    30753113//      listStr += outStr+";" 
    3076         listStr += baseStr+num2str(ii)+";" 
     3114        listStr += baseStr+num2str(ii)+".hst"+";" 
    30773115 
    30783116        FSetPos refNum,V_logEOF 
     
    31273165End 
    31283166 
    3129 Function AccumulateSlices(mode) 
    3130         Variable mode 
    3131          
     3167// added an extra (optional) parameter for silent operation - to be used when a list of 
     3168// files are processed - so the user can walk away as it works. Using the buttons from the 
     3169// panel will still present the alerts 
     3170// 
     3171Function AccumulateSlices(mode,[skipAlert]) 
     3172        Variable mode,skipAlert 
     3173         
     3174        if(ParamIsDefault(skipAlert)) 
     3175                skipAlert = 0 
     3176        endif 
    31323177        SetDataFolder root:Packages:NIST:Event: 
    31333178 
    31343179        switch(mode)     
    31353180                case 0: 
    3136                         DoAlert 0,"The current data has been copied to the accumulated set. You are now ready to add more data." 
     3181                        if(!skipAlert) 
     3182                                DoAlert 0,"The current data has been copied to the accumulated set. You are now ready to add more data." 
     3183                        endif 
    31373184                        KillWaves/Z accumulatedData 
    3138                         Duplicate/O slicedData accumulatedData           
     3185                        Duplicate/O slicedData accumulatedData   
     3186                        KillWaves/Z accum_BinCount              // the accumulated BinCount 
     3187                        Duplicate/O binCount accum_binCount      
    31393188                        break 
    31403189                case 1: 
    3141                         DoAlert 0,"The current data has been added to the accumulated data. You can add more data." 
     3190                        if(!skipAlert) 
     3191                                DoAlert 0,"The current data has been added to the accumulated data. You can add more data." 
     3192                        endif 
    31423193                        Wave acc=accumulatedData 
    31433194                        Wave cur=slicedData 
    31443195                        acc += cur 
     3196                        Wave binCount = binCount 
     3197                        Wave accum_binCount = accum_BinCount 
     3198                        accum_BinCount += binCount 
     3199                        binCount = accum_binCount                       // !! NOTE - the bin count wave is now the total 
     3200//                      AccumulateSlices(2,skipAlert=skipAlert)                                         // and a recursive call to show the total! 
    31453201                        break 
    31463202                case 2: 
    3147                         DoAlert 0,"The accumulated data is now the display data and is ready for display or export." 
     3203                        if(!skipAlert) 
     3204                                DoAlert 0,"The accumulated data is now the display data and is ready for display or export." 
     3205                        endif 
    31483206                        Duplicate/O accumulatedData slicedData 
    31493207                        // do something to "touch" the display to force it to update 
     
    34133471         
    34143472        Variable fileref 
    3415  
     3473        Variable num,ii 
     3474         
    34163475        SVAR filename = root:Packages:NIST:Event:gEvent_logfile 
    34173476        NVAR t_longest = root:Packages:NIST:Event:gEvent_t_longest 
     
    34443503 
    34453504        //loop through everything in the list 
    3446         Variable num,ii 
    34473505        num = ItemsInList(listStr) 
     3506        if(num == 0) 
     3507                DoAlert 0,"Enter the file names in the table, then click 'Load From List' again." 
     3508                return (0) 
     3509        endif 
    34483510         
    34493511        for(ii=0;ii<num;ii+=1) 
     
    34513513// (1) load the file, prepending the path                
    34523514                filename = pathStr + StringFromList(ii, listStr  ,";") 
    3453                  
     3515                if(EventDataType(filename) != 1)                //if not hst extension of raw data 
     3516                        Abort "Data must be raw event data with file extension .hst for this operation" 
     3517                        return(0) 
     3518                endif            
    34543519 
    34553520#if (exists("EventLoadWave")==4) 
     
    35553620        num = ItemsInList(listStr) 
    35563621         
     3622        if(num == 0) 
     3623                DoAlert 0,"Enter the file names in the table, then click 'Load From List' again." 
     3624                return(0) 
     3625        endif 
     3626         
    35573627        for(ii=0;ii<num;ii+=1) 
    35583628 
    35593629// (1) load the file, prepending the path                
    35603630                filename = pathStr + StringFromList(ii, listStr  ,";") 
    3561                  
     3631                if(EventDataType(filename) != 2)                //if not itx extension of edited data 
     3632                        Abort "Data must be edited data with file extension .itx for this operation" 
     3633                        return(0) 
     3634                endif            
    35623635                SetDataFolder root:Packages:NIST:Event: 
    35633636                LoadWave/T/O fileName 
     
    36353708        Variable num,ii,jj 
    36363709        num = ItemsInList(listStr) 
    3637  
    3638  
     3710        if(num == 0) 
     3711                DoAlert 0,"Enter the file names in the table, then click 'Load From List' again." 
     3712                return(0) 
     3713        endif 
     3714         
    36393715//////////////// 
    36403716// declarations for the binning 
     
    36793755// (1) load the file, prepending the path                
    36803756                filename = pathStr + StringFromList(jj, listStr  ,";") 
    3681                  
     3757                if(EventDataType(filename) != 2)                //if not itx extension of edited data 
     3758                        Abort "Data must be edited data with file extension .itx for this operation" 
     3759                        return(0) 
     3760                endif            
    36823761                SetDataFolder root:Packages:NIST:Event: 
    36833762                LoadWave/T/O fileName 
     
    38253904end 
    38263905///////////////////////////// 
     3906 
     3907Proc GetListofITXorSplitFiles(searchStr) 
     3908        String searchStr = ".itx" 
     3909        ShowList_ToLoad("") 
     3910        GetListofITXHST(searchStr) 
     3911end 
     3912 
     3913// needs SANS_Utilites.ipf 
     3914Function GetListofITXHST(searchStr) 
     3915        String searchStr 
     3916         
     3917        String fullList = IndexedFile(catpathName, -1, "????" ) 
     3918         
     3919        // list is currently everything -- trim it 
     3920        searchStr = "*" + searchStr + "*" 
     3921        String list = ListMatch(fullList, searchStr ) 
     3922         
     3923        Print "searchString = ",searchStr 
     3924        // 
     3925        Wave/T tw = root:Packages:NIST:Event:SplitFileWave 
     3926        List2TextWave(list,tw) 
     3927        Sort/A tw,tw                    //alphanumeric sort 
     3928        Edit tw 
     3929        return(0) 
     3930End 
     3931 
     3932// 
     3933// loads a list of files that have been adjusted and saved 
     3934// -- MUST run one through first manually to set the bin sapcing, then this 
     3935//    won't touch that, just process all of the files 
     3936// -- bins as they are loaded 
     3937// 
     3938Function Osc_LoadAdjList_BinOnFly(ctrlName) 
     3939        String ctrlName 
     3940         
     3941        Variable fileref 
     3942 
     3943        SVAR filename = root:Packages:NIST:Event:gEvent_logfile 
     3944        SVAR listStr = root:Packages:NIST:Event:gSplitFileList 
     3945 
     3946        String pathStr,fileStr,tmpStr 
     3947        PathInfo catPathName 
     3948        pathStr = S_Path 
     3949 
     3950// if "Osc" mode is not checked - abort 
     3951        NVAR gEventModeRadioVal= root:Packages:NIST:Event:gEvent_mode 
     3952        if(gEventModeRadioVal != MODE_OSCILL) 
     3953                Abort "The mode must be 'Oscillatory' to use this function" 
     3954                return(0) 
     3955        endif 
     3956 
     3957// if the list has been edited, turn it into a list 
     3958        WAVE/T/Z tw = root:Packages:NIST:Event:SplitFileWave 
     3959        if(WaveExists(tw)) 
     3960                listStr = TextWave2SemiList(tw) 
     3961        else 
     3962                ShowSplitFileTable() 
     3963                DoAlert 0,"Enter the file names in the table, then click 'Load From List' again." 
     3964                return(0) 
     3965        endif 
     3966         
     3967 
     3968        //loop through everything in the list 
     3969        Variable num,ii,jj 
     3970        num = ItemsInList(listStr) 
     3971 
     3972//handle the first file differently 
     3973//(1) load (import edited) 
     3974        jj=0 
     3975        filename = pathStr + StringFromList(jj, listStr  ,";") 
     3976        if(EventDataType(filename) != 2)                //if not itx extension of edited data 
     3977                Abort "Data must be edited data with file extension .itx for this operation" 
     3978                return(0) 
     3979        endif 
     3980         
     3981        SetDataFolder root:Packages:NIST:Event: 
     3982        LoadWave/T/O fileName 
     3983        SetDataFolder root:Packages:NIST:Event:                 //LoadEvents sets back to root: ?? 
     3984 
     3985        // clear out the old sort index, if present, since new data is being loaded 
     3986        KillWaves/Z OscSortIndex         
     3987        SVAR dispStr = root:Packages:NIST:Event:gEventDisplayString 
     3988        sprintf tmpStr, "%s: a user-modified event file\r",StringFromList(jj, listStr  ,";") 
     3989        dispStr = tmpStr         
     3990         
     3991//(2) bin 
     3992        Osc_ProcessEventLog("") 
     3993         
     3994//(3) display bin details 
     3995        Execute "ShowBinTable()" 
     3996        Execute "BinEventBarGraph()" 
     3997         
     3998//(4) add first 
     3999        AccumulateSlices(0,skipAlert=1)         //bypass the dialog 
     4000 
     4001        // with remaining files 
     4002        // load 
     4003        // bin 
     4004        // add next 
     4005 
     4006// start w/file 1, since "0th" file was already processed 
     4007        for(jj=1;jj<num;jj+=1) 
     4008         
     4009        //(1) load (import edited) 
     4010                filename = pathStr + StringFromList(jj, listStr  ,";") 
     4011                if(EventDataType(filename) != 2)                //if not itx extension of edited data 
     4012                        Abort "Data must be edited data with file extension .itx for this operation" 
     4013                        return(0) 
     4014                endif 
     4015                SetDataFolder root:Packages:NIST:Event: 
     4016                LoadWave/T/O fileName 
     4017                SetDataFolder root:Packages:NIST:Event:                 //LoadEvents sets back to root: ?? 
     4018         
     4019                // clear out the old sort index, if present, since new data is being loaded 
     4020                KillWaves/Z OscSortIndex         
     4021                SVAR dispStr = root:Packages:NIST:Event:gEventDisplayString 
     4022                sprintf tmpStr, "%s: a user-modified event file\r",StringFromList(jj, listStr  ,";") 
     4023                dispStr = tmpStr         
     4024                 
     4025        //(2) bin 
     4026                Osc_ProcessEventLog("") 
     4027                 
     4028        //(3) display bin details 
     4029                Execute "ShowBinTable()" 
     4030                Execute "BinEventBarGraph()" 
     4031                 
     4032        //(4) add next 
     4033                AccumulateSlices(1,skipAlert=1) 
     4034         
     4035        endfor  //end loop over the file list 
     4036 
     4037         
     4038        //display total 
     4039        AccumulateSlices(2,skipAlert=1) 
     4040 
     4041        // let user know we're done 
     4042        DoAlert 0,"The list has been processed and is ready for export" 
     4043        SetDataFolder root: 
     4044 
     4045        return(0) 
     4046End 
     4047 
     4048 
     4049//returns 0 for unknown data 
     4050// 1 for raw hst files 
     4051// 2 for edited ITX files 
     4052// 
     4053//  TODO 
     4054//  -- currently, this blindly assumes an .hst extension for raw HST data, and .itx for edited data 
     4055// 
     4056Function EventDataType(filename) 
     4057        string filename 
     4058         
     4059        Variable type 
     4060        Variable offset = strsearch(filename,".",Inf,1)         //work backwards 
     4061        String extension = filename[offset+1,strlen(filename)-1] 
     4062        //Print extension 
     4063        type = 0 
     4064        if(cmpstr(extension,"hst") == 0) 
     4065                type = 1 
     4066        endif 
     4067        if(cmpstr(extension,"itx") == 0) 
     4068                type = 2 
     4069        endif 
     4070        return(type) 
     4071end 
     4072 
     4073//////////// 
     4074// this could be jazzed up quite a bit, but it is a first pass at 
     4075// figuring out what is going on with the events 
     4076// 
     4077Proc DecodeBinaryEvents(numToPrint) 
     4078        Variable numToPrint=10 
     4079         
     4080        DecodeEvents(numToPrint) 
     4081end 
     4082 
     4083//      sscanf %x takes hex input and gives a real value output 
     4084// printf %d val gives the integer representation of the sscanf output 
     4085// printf %b val gives the binary representation. 
     4086Function DecodeEvents(numToPrint) 
     4087        Variable numToPrint 
     4088 
     4089        String filePathStr,buffer 
     4090        Variable fileRef,type,dataval,num0,num1,num2,num3 
     4091        Variable numT0,numPP,numZero,numXYevents,bit29 
     4092        Variable ii 
     4093 
     4094        ii=0 
     4095        Open/R fileref 
     4096        tic() 
     4097        do 
     4098                do 
     4099                        FReadLine fileref, buffer                       //skip the "blank" lines that have one character 
     4100                while(strlen(buffer) == 1)               
     4101 
     4102                if (strlen(buffer) == 0) 
     4103                        break 
     4104                endif 
     4105                 
     4106                sscanf buffer,"%x",dataval 
     4107                if(ii<numToPrint) 
     4108                        printf "%s  %0.32b  ",buffer[0,7],dataval 
     4109                endif 
     4110                 
     4111                // two most sig bits (31-30) 
     4112                type = (dataval & 0xC0000000)/1073741824                //right shift by 2^30 
     4113 
     4114                if(ii<numToPrint) 
     4115                        printf "%0.2b  ",type 
     4116                endif 
     4117                                                 
     4118                if(type == 0) 
     4119                        num0 += 1 
     4120                        numXYevents += 1 
     4121                endif 
     4122                if(type == 2) 
     4123                        num2 += 1 
     4124                        numXYevents += 1 
     4125                endif 
     4126                if(type == 1) 
     4127                        num1 += 1 
     4128                endif 
     4129                if(type == 3) 
     4130                        num3 += 1 
     4131                endif    
     4132                 
     4133                bit29 = (dataval & 0x20000000)/536870912                //bit 29 only , shift by 2^29 
     4134                if(ii<numToPrint) 
     4135                        printf "%0.1b  ",bit29 
     4136                endif 
     4137                                 
     4138                if(type==0 || type==2) 
     4139                        numPP += round(bit29) 
     4140                endif 
     4141                 
     4142                if(type==1 || type==3) 
     4143                        numT0 += round(bit29) 
     4144                endif 
     4145                 
     4146                if(dataval == 0) 
     4147                        numZero += 1 
     4148                endif 
     4149                 
     4150                if(ii<numToPrint) 
     4151                        printf "\r" 
     4152                        ii += 1 
     4153                endif 
     4154                 
     4155        while(1) 
     4156        Close fileref 
     4157toc() 
     4158 
     4159        Print "(Igor) numT0 = ",numT0    
     4160        Print "num0 = ",num0     
     4161        Print "num1 = ",num1     
     4162        Print "num2 = ",num2     
     4163        Print "num3 = rollover = ",num3 
     4164        Print "numXY = ",numXYevents 
     4165        Print "numZero = ",numZero 
     4166        Print "numPP = ",numPP 
     4167         
     4168        return(0) 
     4169 
     4170End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Menu.ipf

    r885 r999  
    5050                "-" 
    5151                "Split Large File",SplitBigFile() 
     52                "Get List of ITX or Split Files",GetListofITXorSplitFiles() 
    5253                "Accumulate First Slice",AccumulateSlices(0) 
    5354                "Add Current Slice",AccumulateSlices(1) 
Note: See TracChangeset for help on using the changeset viewer.