Changeset 877


Ignore:
Timestamp:
Nov 20, 2012 1:24:11 PM (10 years ago)
Author:
srkline
Message:

minor changes to the event mode reader to allow for periods of oscillation longer than 6.7 seconds. Now T0 is explicitly identified and nRollover is reset if T0 is found. Appears to work, until something breaks it...

File:
1 edited

Legend:

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

    r875 r877  
    11#pragma rtGlobals=1             // Use modern global access method. 
    2 #pragma IgorVersion=6.1 
    3  
    4 //#include "TISANE" 
    5  
     2#pragma IgorVersion=6.22 
     3 
     4// vers 7.13d 
    65 
    76// TODO: 
    87// 
     8// -- Need to make sure that the rescaledTime and the differentiated time graphs are 
     9//     being properly updated when the data is processed, modified, etc. 
     10// 
     11// -- I need better nomenclature other than "stream" for the "continuous" data set. 
     12//     It's all a stream, just sometimes it's not oscillatory 
     13// 
    914// -- fix the log/lin display - it's not working correctly 
     15//                      I could use ModifyImage and log = 0|1 keyword for the log Z display 
     16//                      rather than creating a duplicate wave of log(data) 
     17//                      -- it's in the Function sliceSelectEvent_Proc() 
     18// 
     19// -- Do something withe the PP events. Currently, nothing is done (since I still need 
     20//     to find out what they realy mean) 
     21// 
     22// -- Add a switch to allow Sorting of the Stream data to remove the "time-reversed" data 
     23//     points. Maybe not kosher, but would clean things up. 
     24// 
     25// -- Is there any way to improve the speed of the loader? How could an XOP be structured 
     26//     for maximum flexibility? Leave the post processing to Igor, but how much for the XOP 
     27//     to do? And can it handle such large amounts of data to pass back and forth, or 
     28//     does it need to be written as an operation, rather than a function??? I'd really  
     29//     rather that Igor handles the memory management, not me, if I write the XOP. 
     30// 
    1031// X- add controls to show the bar graph 
    1132// x- add popup for selecting the binning type 
     
    2243// 
    2344// 
    24 // -- for the 19 MB file - the max time is reported as 67.108s, but the max rescaled time = 61 s 
    25 //    based on the last point... there are "spikes" in the time! -- look at the plot in the 
    26 //    data browser... (so waveMax() gives a different answer than the end point, and BinarySearch() 
    27 //    doesn't have a monotonic file to work with... ugh.) 
    28 // 
    29 // 
    30 // 
    31 // differentiate may be useful at some point, but not sure 
    32 //¥Differentiate rescaledTime/D=rescaledTime_DIF 
    33 //¥Display rescaledTime,rescaledTime_DIF 
    34 // 
    35 // 
     45 
     46 
     47// 
     48// These are currently defined in the TISANE procedure file. If that file becomes depricated 
     49// or is not loaded in, then these lines should be activated, and those in TISANE should also 
     50// be re-declared as Static, so they will be local to each procedure 
     51// 
     52//Static Constant ATXY = 0 
     53//Static Constant ATXYM = 2 
     54//Static Constant ATMIR = 1 
     55//Static Constant ATMAR = 3 
     56// 
     57//Static Constant USECSPERTICK=0.1 // microseconds 
     58//Static Constant TICKSPERUSEC=10 
     59//Static Constant XBINS=128 
     60//Static Constant YBINS=128 
     61// 
     62 
     63 
    3664 
    3765Proc Show_Event_Panel() 
     
    5987        Variable/G root:Packages:NIST:gEvent_tsdisp //Displayed slice 
    6088        Variable/G root:Packages:NIST:gEvent_nslices = 10  //Number of time slices 
    61         Variable/G root:Packages:NIST:gEvent_slicewidth  = 1000 // slice width (us) 
    62          
    63         Variable/G root:Packages:NIST:gEvent_prescan // Do we prescan the file? 
     89         
    6490        Variable/G root:Packages:NIST:gEvent_logint = 1 
    6591 
    66         Variable/G root:Packages:NIST:gEvent_Mode = 0           // ==0 for "stream", ==1 for Oscillatory 
     92        Variable/G root:Packages:NIST:gEvent_Mode = 0                           // ==0 for "stream", ==1 for Oscillatory 
    6793        Variable/G root:Packages:NIST:gRemoveBadEvents = 1              // ==1 to remove "bad" events, ==0 to read "as-is" 
    68  
     94        Variable/G root:Packages:NIST:gSortStreamEvents = 0             // ==1 to sort the event stream, a last resort for a stream of data 
     95         
    6996        NVAR nslices = root:Packages:NIST:gEvent_nslices 
    7097         
     
    247274        endif 
    248275         
     276         
    249277        return(0) 
    250278end 
     
    254282Function Osc_ProcessEventLog(ctrlName) 
    255283        String ctrlName 
    256  
    257284 
    258285        Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData 
     
    262289        Wave yLoc = root:Packages:NIST:Event:yLoc 
    263290 
    264         SetDataFolder root:Packages:NIST:Event 
    265         IndexForHistogram(xLoc,yLoc,binnedData) 
    266         SetDataFolder root: 
    267         Wave index = root:Packages:NIST:Event:SavedIndex 
    268          
    269         JointHistogram(xLoc,yLoc,binnedData,index)              // puts everything into one array 
    270  
    271  
    272291// now with the number of slices and max time, process the events 
    273         Osc_ProcessEvents(xLoc,yLoc,index) 
    274  
    275  
    276         SetDataFolder root:Packages:NIST:Event: 
    277  
    278         SetDataFolder root: 
    279  
    280         return(0) 
    281 End 
    282  
    283  
    284 Function Stream_ProcessEventLog(ctrlName) 
    285         String ctrlName 
    286  
    287 //      NVAR slicewidth = root:Packages:NIST:gTISANE_slicewidth 
    288  
    289          
    290         Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData 
    291          
    292         Wave binnedData = root:Packages:NIST:Event:binnedData 
    293         Wave xLoc = root:Packages:NIST:Event:xLoc 
    294         Wave yLoc = root:Packages:NIST:Event:yLoc 
    295  
    296         SetDataFolder root:Packages:NIST:Event 
    297         IndexForHistogram(xLoc,yLoc,binnedData) 
    298         SetDataFolder root: 
    299         Wave index = root:Packages:NIST:Event:SavedIndex 
    300          
    301         JointHistogram(xLoc,yLoc,binnedData,index)              // puts everything into one array 
    302  
    303  
    304 // now with the number of slices and max time, process the events 
    305         Stream_ProcessEvents(xLoc,yLoc,index) 
    306  
    307  
    308         SetDataFolder root:Packages:NIST:Event: 
    309  
    310         SetDataFolder root: 
    311  
    312         return(0) 
    313 End 
    314  
    315  
    316 Proc    UndoTheSorting() 
    317         Osc_UndoSort() 
    318 End 
    319  
    320 // for oscillatory mode 
    321 // 
    322 // -- this takes the previously generated index, and un-sorts the data to restore to the 
    323 // "as-collected" state 
    324 // 
    325 Function Osc_UndoSort() 
    326  
    327         SetDataFolder root:Packages:NIST:Event          //don't count on the folder remaining here 
    328         Wave rescaledTime = rescaledTime 
    329         Wave OscSortIndex = OscSortIndex 
    330         Wave yLoc = yLoc 
    331         Wave xLoc = xLoc 
    332         Wave timePt = timePt 
    333  
    334         Sort OscSortIndex OscSortIndex,yLoc,xLoc,timePt,rescaledTime 
    335  
    336         KillWaves/Z OscSortIndex 
    337          
    338         SetDataFolder root: 
    339         return(0) 
    340 End 
    341  
    342 // for oscillatory mode 
    343 // 
    344 //// use indexSort to be able to restore the original data 
    345 //¥Duplicate rescaledTime OscSortIndex 
    346 //¥MakeIndex rescaledTime OscSortIndex 
    347 //¥IndexSort OscSortIndex, yLoc,xLoc,timePt,rescaledTime 
    348 //¥Sort OscSortIndex OscSortIndex,yLoc,xLoc,timePt,rescaledTime 
    349 // 
    350 // sort the data by time, then do the binning 
    351 // save an index to be able to "undo" the sorting 
    352 // 
    353 Function Osc_ProcessEvents(xLoc,yLoc,index) 
    354         Wave xLoc,yLoc,index 
    355          
     292 
     293 
    356294        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
    357295        NVAR nslices = root:Packages:NIST:gEvent_nslices 
     
    408346                MakeIndex rescaledTime OscSortIndex 
    409347                IndexSort OscSortIndex, yLoc,xLoc,timePt,rescaledTime    
     348                //SetDataFolder root:Packages:NIST:Event 
     349                IndexForHistogram(xLoc,yLoc,binnedData)                 // index the events AFTER sorting 
     350                //SetDataFolder root: 
    410351        Endif 
    411352         
     353        Wave index = root:Packages:NIST:Event:SavedIndex                //this is the histogram index 
     354 
    412355        for(ii=0;ii<nslices;ii+=1) 
    413356                if(ii==0) 
     
    452395End 
    453396 
    454  
    455 // for the mode of "one continuous exposure" 
    456 // 
    457 Function Stream_ProcessEvents(xLoc,yLoc,index) 
    458         Wave xLoc,yLoc,index 
    459          
     397// for a "continuous exposure" 
     398// 
     399// if there is a sort of these events, I need to re-index the events for the histogram 
     400// - see the oscillatory mode  - and sort the events here, then immediately re-index for the histogram 
     401// - but with the added complication that I need to always remember to index for the histogram, every time 
     402// - since I don't know if I've sorted or un-sorted. Osc mode always forces a re-sort and a re-index 
     403// 
     404Function Stream_ProcessEventLog(ctrlName) 
     405        String ctrlName 
     406 
     407//      NVAR slicewidth = root:Packages:NIST:gTISANE_slicewidth 
     408 
     409         
     410        Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData 
     411         
     412        Wave binnedData = root:Packages:NIST:Event:binnedData 
     413        Wave xLoc = root:Packages:NIST:Event:xLoc 
     414        Wave yLoc = root:Packages:NIST:Event:yLoc 
     415 
     416// now with the number of slices and max time, process the events 
     417 
     418        NVAR yesSortStream = root:Packages:NIST:gSortStreamEvents               //do I sort the events? 
    460419        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
    461420        NVAR nslices = root:Packages:NIST:gEvent_nslices 
     
    498457                        SetLinearBins(binEndTime,nslices,t_longest) 
    499458        endswitch 
     459 
     460        if(yesSortStream == 1) 
     461                SortTimeData() 
     462        endif 
     463// index the events before binning 
     464// if there is a sort of these events, I need to re-index the events for the histogram 
     465//      SetDataFolder root:Packages:NIST:Event 
     466        IndexForHistogram(xLoc,yLoc,binnedData) 
     467//      SetDataFolder root: 
     468        Wave index = root:Packages:NIST:Event:SavedIndex                //the index for the histogram 
     469         
    500470         
    501471        for(ii=0;ii<nslices;ii+=1) 
     
    539509 
    540510 
     511Proc    UndoTheSorting() 
     512        Osc_UndoSort() 
     513End 
     514 
     515// for oscillatory mode 
     516// 
     517// -- this takes the previously generated index, and un-sorts the data to restore to the 
     518// "as-collected" state 
     519// 
     520Function Osc_UndoSort() 
     521 
     522        SetDataFolder root:Packages:NIST:Event          //don't count on the folder remaining here 
     523        Wave rescaledTime = rescaledTime 
     524        Wave OscSortIndex = OscSortIndex 
     525        Wave yLoc = yLoc 
     526        Wave xLoc = xLoc 
     527        Wave timePt = timePt 
     528 
     529        Sort OscSortIndex OscSortIndex,yLoc,xLoc,timePt,rescaledTime 
     530 
     531        KillWaves/Z OscSortIndex 
     532         
     533        SetDataFolder root: 
     534        return(0) 
     535End 
     536 
     537 
     538 
    541539Function SortTimeData() 
    542540 
     
    660658                Osc_LoadEventLog("") 
    661659        endif 
    662          
    663         DifferentiatedTime() 
    664          
     660 
     661        STRUCT WMButtonAction ba 
     662        ba.eventCode = 2 
     663        ShowEventDataButtonProc(ba) 
     664 
    665665        return(0) 
    666666End 
     
    674674 
    675675        SVAR filename = root:Packages:NIST:gEvent_logfile 
    676         NVAR prescan = root:Packages:NIST:gEvent_prescan 
    677 //      NVAR slicewidth = root:Packages:NIST:gEvent_slicewidth 
    678676        NVAR nslices = root:Packages:NIST:gEvent_nslices 
    679677        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
     
    713711 
    714712        SVAR filename = root:Packages:NIST:gEvent_logfile 
    715         NVAR prescan = root:Packages:NIST:gEvent_prescan 
    716 //      NVAR slicewidth = root:Packages:NIST:gEvent_slicewidth 
    717713        NVAR nslices = root:Packages:NIST:gEvent_nslices 
    718714        NVAR t_longest = root:Packages:NIST:gEvent_t_longest 
     
    734730        Duplicate/O timePt rescaledTime 
    735731        rescaledTime *= 1e-7                    //convert to seconds and that's all 
    736         t_longest = waveMax(rescaledTime)               //won't be the last point, so get it this way 
     732        t_longest = waveMax(rescaledTime)               //if oscillatory, won't be the last point, so get it this way 
    737733 
    738734        KillWaves/Z OscSortIndex                        //to make sure that there is no old index hanging around 
     
    778774 
    779775 
    780  
     776// this "fails" for data sets that have 3 or 4 slices, as the ModifyImage command 
     777// interprets the data as being RGB - and so does nothing. 
     778// need to find a way around this 
     779/// 
     780// I could modify this procedure to use the log = 0|1 keyword for the log Z display 
     781// rather than creating a duplicate wave of log(data) 
     782// 
    781783Function sliceSelectEvent_Proc(ctrlName, varNum, varStr, varName) : SetVariableControl 
    782784        String ctrlName 
     
    846848        Variable dataval,timeval,type,numLines,verbose,verbose3 
    847849        Variable xval,yval,rollBit,nRoll,roll_time,bit29,bit28,bit27 
    848         Variable ii,flaggedEvent,rolloverHappened,numBad=0,tmpPP=0 
     850        Variable ii,flaggedEvent,rolloverHappened,numBad=0,tmpPP=0,tmpT0=0 
    849851        Variable Xmax, yMax 
    850852         
     
    852854        yMax = 127 
    853855         
    854         verbose3 = 1                    //prints out the rollover events (type==3) 
     856        verbose3 = 0                    //prints out the rollover events (type==3) 
    855857        verbose = 0 
    856858        numLines = 0 
     
    859861        // what I really need is the number of XY events 
    860862        Variable numXYevents,num1,num2,num3,num0,totBytes,numPP,numT0,numDL,numFF,numZero 
     863        Variable numRemoved 
    861864        numXYevents = 0 
    862865        num0 = 0 
     
    869872        numFF = 0 
    870873        numZero = 0 
     874        numRemoved = 0 
    871875 
    872876//tic() 
     
    936940//              done counting the number of XY events 
    937941        toc() 
    938          
     942 
     943Print "numT0 = ",numT0   
    939944         
    940945// 
     
    975980//      Make/O/U/N=(totBytes/4) xLoc,yLoc               //too large, trim when done (bad idea) 
    976981//      Make/O/D/N=(totBytes/4) timePt 
    977         Make/O/D/N=1000 badTimePt,badEventNum,PPTime,PPEventNum 
     982        Make/O/D/N=1000 badTimePt,badEventNum,PPTime,PPEventNum,T0Time,T0EventNum 
    978983        badTimePt=0 
    979984        badEventNum=0 
    980985        PPTime=0 
    981986        PPEventNum=0 
     987        T0Time=0 
     988        T0EventNum=0 
    982989        xLoc=0 
    983990        yLoc=0 
     
    10351042                        else 
    10361043                                numBad += 1 
     1044                                numRemoved += 1 
    10371045                        endif 
    10381046                         
     
    10591067                type = (dataval & 0xC0000000)/1073741824                //right shift by 2^30 
    10601068                 
    1061 //              // if the first event, read the time_msw, since this is not always reset. if the first event is XYM, then it's OK, 
    1062 //              // but if the first event is XY, then the first few events will have msw=0 until an XYM forces a read of MSW in the 
    1063 //              // subsequent MIR event. 
    1064 //              // So do it now. 
    1065 //              if(ii==0 && RemoveBadEvents == 1) 
    1066 //                      time_msw =  (dataval & 536805376)/65536                 //13 bits, 28-16, right shift by 2^16 
    1067 //              endif 
    1068  
    10691069                // 
    10701070                //Constant ATXY = 0 
     
    10841084                                endif 
    10851085                                 
    1086                                 // if the datavalue is == 0, just skip it now (it can only be interpreted as type 0, obviously 
     1086                                // if the datavalue is == 0, just skip it now (it can only be interpreted as type 0, obviously) 
    10871087                                if(dataval == 0 && RemoveBadEvents == 1) 
     1088                                        numRemoved += 1 
    10881089                                        break           //don't increment ii 
    10891090                                endif 
     
    10951096                                        PPEventNum[tmpPP] = ii 
    10961097                                        tmpPP += 1 
     1098                                        numRemoved += 1 
    10971099                                        break           //don't increment ii 
    10981100                                endif 
     
    11211123                                                badEventNum[numBad] = ii 
    11221124                                                numBad +=1 
     1125                                                numRemoved += 1 
    11231126                                        else 
    11241127                                                // time_msw has been reset, points are good now, so keep this one 
     
    11661169                                // - but can I do this if this is an XY-time event? This will lead to a wrong time, and a time  
    11671170                                // assigned to an XY (0,0)... 
    1168                                 bit29 = (dataval & 0x20000000)/536870912                //bit 29 only , shift by 2^29 
    1169                                 if(bit29 == 1 && RemoveBadEvents == 1) 
    1170                                         Print "*****Bit 29 (PP) event set for Type==2, but not handled, ii = ",ii 
    1171 //                                      break           //don't increment ii 
    1172                                 endif 
     1171//                              bit29 = (dataval & 0x20000000)/536870912                //bit 29 only , shift by 2^29 
     1172//                              if(bit29 == 1 && RemoveBadEvents == 1) 
     1173//                                      Print "*****Bit 29 (PP) event set for Type==2, but not handled, ii = ",ii 
     1174////                                    break           //don't increment ii 
     1175//                              endif 
    11731176                                 
    11741177//                              xval = ~(dataval & ~(2^32 - 2^8)) & 127 
     
    12121215                                timePt[ii] = timeval 
    12131216 
    1214 //                              bit29 = (dataval & 0x20000000)/536870912                //bit 29 only , shift by 2^29 
    1215 //                              if(bit29 != 0) 
    1216 //                                      Printf "bit29 = 1 at ii = %d : type = %d\r",ii,type 
    1217 //                              endif 
     1217                                bit29 = (dataval & 0x20000000)/536870912                //bit 29 only , shift by 2^29 
     1218                                if(bit29 != 0)          // bit 29 set is a T0 event 
     1219                                        //Printf "bit29 = 1 at ii = %d : type = %d\r",ii,type 
     1220                                        T0Time[tmpT0] = timeval 
     1221                                        T0EventNum[tmpT0] = ii 
     1222                                        tmpT0 += 1 
     1223                                        // reset nRoll = 0 for calcluating the time 
     1224                                        nRoll = 0 
     1225                                endif 
    12181226                                                                 
    12191227                                ii+=1 
     
    12321240                                bit29 = (dataval & 0x20000000)/536870912                //bit 29 only , shift by 2^29 
    12331241                                nRoll += 1 
    1234 // not doing anything with these bits yet                                
     1242// not doing anything with these bits yet        
     1243                                bit28 = (dataval & 0x10000000)/268435456                //bit 28 only, shift by 2^28     
    12351244                                bit27 = (dataval & 0x08000000)/134217728        //bit 27 only, shift by 2^27 
    1236                                 bit28 = (dataval & 0x10000000)/268435456                //bit 28 only, shift by 2^28 
    12371245 
    12381246                                if(verbose3) 
    12391247                                        printf "d=%u : b29=%u : b28=%u : b27=%u : #Roll=%u \r",dataval,bit29, bit28, bit27,nRoll 
     1248                                endif 
     1249                                 
     1250                                if(bit29 != 0)          // bit 29 set is a T0 event 
     1251                                        //Printf "bit29 = 1 at ii = %d : type = %d\r",ii,type 
     1252                                        T0Time[tmpT0] = timeval 
     1253                                        T0EventNum[tmpT0] = ii 
     1254                                        tmpT0 += 1 
     1255                                        // reset nRoll = 0 for calcluating the time 
     1256                                        nRoll = 0 
    12401257                                endif 
    12411258                                 
     
    12551272         
    12561273        toc() 
     1274         
     1275        Print "Events removed = ",numRemoved 
    12571276         
    12581277        sPrintf tmpStr,"\rBad Events = numBad = %d (%g %% of events)",numBad,numBad/numXYevents*100 
Note: See TracChangeset for help on using the changeset viewer.