Ignore:
Timestamp:
Apr 12, 2016 2:30:46 PM (7 years ago)
Author:
srkline
Message:

more additions to HDF reader to work with the Nexus definition

Additions to SANS event mode processing to allow proper processing of large data streams. Data was inproperly saved after decimation without correcting for the decimation. Instead, use decimation for screening, and bin the full data (splits) on the fly.

File:
1 edited

Legend:

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

    r969 r989  
    1313// 
    1414// -- examples? 
     15// 
     16// 
     17// -- NEW 2016 
     18//  -- see the proc DisplayForSlicing() that may aid in setting the bins properly by plotting the  
     19//     bins along with the differential collection rate 
    1520// 
    1621// -- ?? need way to get correspondence between .hst files and VAX files? Names are all different. See 
     
    3641// -- Add a switch to allow Sorting of the Stream data to remove the "time-reversed" data 
    3742//     points. Maybe not kosher, but would clean things up. 
     43// 
     44// -- when a large stream file is split, and each segment is edited, it is re-loaded from a list and is currently 
     45//    NOT decimated, and there is no option. There could be an option for this, especially for these 
     46//    large files. The issue is that the data segments are concatentated (adjusting the time) and can 
     47//    be too large to handle (a 420 MB event file split and edited and re-loaded becomes a 1.6 GB Igor experiment!!) 
     48// 
     49//    -- so allow the option of either decimation of the segments as they are loaded, or create the option to  
     50//       bin on the fly so that the full concatentated set does not need to be stored. Users could be  
     51//       directed to determine the binning and manipulate the data of a sufficiently decimated data set 
     52//       first to set the binning, then only process the full set. 
    3853// 
    3954/////////////////////////////// 
     
    177192        Variable/G root:Packages:NIST:Event:gDecimation = 100 
    178193        Variable/G root:Packages:NIST:Event:gEvent_t_longest_decimated = 0 
     194        Variable/G root:Packages:NIST:Event:gEvent_t_segment_start = 0 
     195        Variable/G root:Packages:NIST:Event:gEvent_t_segment_end = 0 
    179196 
    180197// for large file splitting 
     
    205222        NewPanel /W=(82,44,884,664)/N=EventModePanel/K=2 
    206223        DoWindow/C EventModePanel 
    207         ModifyPanel fixedSize=1,noEdit =1 
     224//      ModifyPanel fixedSize=1,noEdit =1 
    208225 
    209226        SetDrawLayer UserBack 
    210227        DrawText 479,345,"Stream Data" 
    211228        DrawLine 563,338,775,338 
    212         DrawText 479,419,"Oscillatory or Stream Data" 
    213         DrawLine 647,411,775,411 
     229        DrawText 479,419,"Oscillatory Data" 
     230        DrawLine 580,411,775,411 
    214231 
    215232//      ShowTools/A 
     
    250267 
    251268        Button button10,pos={488,305},size={100,20},proc=SplitFileButtonProc,title="Split Big File" 
    252         Button button14,pos={488,350},size={120,20},proc=Stream_LoadDecim,title="Load Split List" 
    253         Button button19,pos={649,350},size={120,20},proc=Stream_LoadAdjustedList,title="Load Edited List" 
    254         Button button20,pos={680,376},size={90,20},proc=ShowList_ToLoad,title="Show List" 
     269        Button button14,pos={488,350},size={120,20},proc=Stream_LoadDecim,title="Load+Decimate" 
     270        Button button19,pos={639,350},size={130,20},proc=Stream_LoadAdjustedList,title="Load+Concatenate" 
     271        Button button20,pos={680,305},size={90,20},proc=ShowList_ToLoad,title="Show List" 
     272 
     273        Button button21,pos={649,378},size={120,20},proc=Stream_LoadAdjList_BinOnFly,title="Load+Accumulate" 
     274 
    255275        SetVariable setvar3,pos={487,378},size={150,16},title="Decimation factor" 
    256276        SetVariable setvar3,fSize=10 
     
    11991219// 
    12001220// This is duplicated by the XOP, but the Igor code allows quick access to print out 
    1201 // all of the gorey details of the events and every little bit of them. the print 
     1221// all of the gory details of the events and every little bit of them. the print 
    12021222// statements and flags are kept for this reason, so the code is a bit messy. 
    12031223// 
     
    19251945                Display /W=(25,44,486,356)/K=1/N=RescaledTimeGraph rescaledTime 
    19261946                SetDataFolder fldrSav0 
    1927                 ModifyGraph mode=4 
     1947                ModifyGraph mode=0 
    19281948                ModifyGraph marker=19 
    19291949                ModifyGraph rgb(rescaledTime)=(0,0,0) 
     
    21722192                Display /W=(35,44,761,533)/K=2 rescaledTime 
    21732193                DoWindow/C EventCorrectionPanel 
    2174                 ModifyGraph mode=4 
     2194                ModifyGraph mode=0 
    21752195                ModifyGraph marker=19 
    21762196                ModifyGraph rgb=(0,0,0) 
     
    21872207                Button button3,pos={153,64},size={90,20},proc=EC_TrimPointsButtonProc,title="Trim points" 
    21882208                Button button4,pos={295+150,12},size={90,20},proc=EC_SaveWavesButtonProc,title="Save Waves" 
    2189                 Button button5,pos={295,64},size={100,20},proc=EC_FindOutlierButton,title="Find Outlier" 
     2209                Button button5,pos={285,64},size={100,20},proc=EC_FindOutlierButton,title="Find Outlier" 
    21902210                Button button6,pos={18,38},size={80,20},proc=EC_ShowAllButtonProc,title="All Data" 
    21912211                Button button7,pos={683,12},size={30,20},proc=EC_HelpButtonProc,title="?" 
    21922212                Button button8,pos={658,72},size={60,20},proc=EC_DoneButtonProc,title="Done" 
    21932213         
    2194                 Button button9,pos={295,12},size={110,20},proc=EC_FindStepButton_down,title="Find Step Down" 
    2195                 Button button10,pos={295,38},size={110,20},proc=EC_FindStepButton_up,title="Find Step Up" 
     2214                Button button9,pos={285,12},size={110,20},proc=EC_FindStepButton_down,title="Find Step Down" 
     2215                Button button10,pos={285,38},size={110,20},proc=EC_FindStepButton_up,title="Find Step Up" 
    21962216                Button button11,pos={295+150,38},size={110,20},proc=EC_DoDifferential,title="Differential" 
    2197                  
     2217                Button button12,pos={295+150,64},size={110,20},proc=EC_AddFindNext,title="Add Find Next" 
     2218                Button button13,pos={285+120,12},size={20,20},proc=EC_NudgeCursor,title=">" 
    21982219                 
    21992220        else 
     
    22042225         
    22052226EndMacro 
     2227 
     2228 
     2229Function EC_NudgeCursor(ba) 
     2230        STRUCT WMButtonAction &ba 
     2231 
     2232        switch( ba.eventCode ) 
     2233                case 2: // mouse up 
     2234                        // click code here 
     2235                        // nudge the leftmost cursor to the right two points 
     2236                        // presumably to bypass a desired time step 
     2237                        // 
     2238         
     2239                        Wave rescaledTime = root:Packages:NIST:Event:rescaledTime 
     2240                        Variable ptA,ptB,lo 
     2241                        ptA = pcsr(A) 
     2242                        ptB = pcsr(B) 
     2243                        lo=min(ptA,ptB) 
     2244 
     2245                        if(lo == ptA) 
     2246                                Cursor/P A rescaledTime ptA+2   //at the point + 2 
     2247                                Print "Nudged cursor A two points right" 
     2248                        else 
     2249                                Cursor/P B rescaledTime ptB+2   //at the point + 2 
     2250                                Print "Nudged cursor B two points right" 
     2251                        endif 
     2252                         
     2253                        break 
     2254                case -1: // control being killed 
     2255                        break 
     2256        endswitch 
     2257                 
     2258        return(0) 
     2259End 
     2260 
     2261Function EC_AddFindNext(ba) 
     2262        STRUCT WMButtonAction &ba 
     2263 
     2264        switch( ba.eventCode ) 
     2265                case 2: // mouse up 
     2266                        // click code here 
     2267                        // add time      
     2268                        EC_AddTimeButtonProc(ba) 
     2269                         
     2270                // re-do the differential 
     2271                        EC_DoDifferential("") 
     2272                         
     2273                // find the next step down 
     2274                        EC_FindStepButton_down("") 
     2275                         
     2276                        break 
     2277                case -1: // control being killed 
     2278                        break 
     2279        endswitch 
     2280                 
     2281        return(0) 
     2282End 
     2283 
     2284 
    22062285 
    22072286Function EC_AddCursorButtonProc(ba) : ButtonControl 
     
    24612540 
    24622541//upDown 5 or -5 looks for spikes +5 or -5 std deviations from mean 
     2542// 
     2543// will search from the leftmost cursor to the end. this allows skipping of oscillations 
     2544// that are not timing errors. It may introduce other issues, but we'll see what happens 
     2545// 
    24632546Function PutCursorsAtStep(upDown) 
    24642547        Variable upDown 
     
    24692552        Wave rescaledTime_DIF=rescaledTime_DIF 
    24702553        Variable avg,pt,zoom 
    2471          
     2554        Variable ptA,ptB,startPt 
     2555                 
    24722556        zoom = 200              //points in each direction 
    24732557         
    24742558        WaveStats/M=1/Q rescaledTime_DIF 
    24752559        avg = V_avg 
    2476                  
    2477         FindLevel/P/Q rescaledTime_DIF avg*upDown 
     2560         
     2561        ptA = pcsr(A) 
     2562        ptB = pcsr(B) 
     2563        startPt = min(ptA,ptB) 
     2564         
     2565        FindLevel/P/Q/R=[startPt] rescaledTime_DIF avg*upDown 
    24782566        if(V_flag==0) 
    24792567                pt = V_levelX 
    2480                 WaveStats/Q/R=[pt-zoom,pt+zoom] rescaledTime            // find the max/min y-vallues within the point range 
     2568                WaveStats/Q/R=[pt-zoom,pt+zoom] rescaledTime            // find the max/min y-values within the point range 
    24812569        else 
    24822570                Print "Level not found" 
    2483                 return(0) 
     2571//              return(0) 
    24842572        endif 
    24852573         
     
    28832971        Variable splitSize = 100 
    28842972        String baseStr="split" 
    2885         Prompt splitSize,"Target file size, in MB" 
     2973        Prompt splitSize,"Target file size, in MB (< 150 MB!!)" 
    28862974        Prompt baseStr,"File prefix, number will be appended" 
    28872975         
     2976        if(splitSize > root:Packages:NIST:Event:gEventFileTooLarge) 
     2977                Abort "File split must be less than 150 MB. Please try again" 
     2978        endif 
    28882979         
    28892980        fSplitBigFile(splitSize, baseStr) 
     
    32473338 
    32483339 
     3340Macro DisplayForSlicing() 
     3341 
     3342        // plot the EventBarGraph? 
     3343                SetDataFolder root:Packages:NIST:Event: 
     3344                Display /W=(110,705,610,1132)/N=SliceGraph /K=1 binCount vs binEndTime 
     3345                ModifyGraph mode=5 
     3346                ModifyGraph marker=19 
     3347                ModifyGraph lSize=2 
     3348                ModifyGraph rgb=(0,0,0) 
     3349                ModifyGraph msize=2 
     3350                ModifyGraph hbFill=2 
     3351                ModifyGraph gaps=0 
     3352                ModifyGraph usePlusRGB=1 
     3353                ModifyGraph toMode=1 
     3354                ModifyGraph useBarStrokeRGB=1 
     3355                ModifyGraph standoff=0 
     3356 
     3357                SetDataFolder root: 
     3358 
     3359// append the differential 
     3360        AppendToGraph/R root:Packages:NIST:Event:rescaledTime_DIF vs root:Packages:NIST:Event:rescaledTime 
     3361        ModifyGraph rgb(rescaledTime_DIF)=(1,16019,65535) 
     3362 
     3363End 
     3364 
     3365 
    32493366 
    32503367// unused, old testing procedure 
     
    33673484                 
    33683485 
    3369 // (3) concatenate 
     3486// (3) concatenate the files + adjust the time 
    33703487                fConcatenateButton(ii+1)                //passes 1 for the first time, >1 each other time 
    33713488         
     
    34673584 
    34683585 
    3469 // (3) concatenate 
     3586// (3) concatenate the files + adjust the time 
    34703587                fConcatenateButton(ii+1)                //passes 1 for the first time, >1 each other time 
    34713588         
     
    34783595        return(0) 
    34793596End 
     3597 
     3598// 
     3599// loads a list of files that have been adjusted and saved 
     3600// -- does not decimate 
     3601// -- bins as they are loaded 
     3602// 
     3603Function Stream_LoadAdjList_BinOnFly(ctrlName) 
     3604        String ctrlName 
     3605         
     3606        Variable fileref 
     3607 
     3608        SVAR filename = root:Packages:NIST:Event:gEvent_logfile 
     3609        SVAR listStr = root:Packages:NIST:Event:gSplitFileList 
     3610 
     3611        String pathStr 
     3612        PathInfo catPathName 
     3613        pathStr = S_Path 
     3614 
     3615// if "stream" mode is not checked - abort 
     3616        NVAR gEventModeRadioVal= root:Packages:NIST:Event:gEvent_mode 
     3617        if(gEventModeRadioVal != MODE_STREAM) 
     3618                Abort "The mode must be 'Stream' to use this function" 
     3619                return(0) 
     3620        endif 
     3621 
     3622// if the list has been edited, turn it into a list 
     3623        WAVE/T/Z tw = root:Packages:NIST:Event:SplitFileWave 
     3624        if(WaveExists(tw)) 
     3625                listStr = TextWave2SemiList(tw) 
     3626        else 
     3627                ShowSplitFileTable() 
     3628                DoAlert 0,"Enter the file names in the table, then click 'Load From List' again." 
     3629                return(0) 
     3630        endif 
     3631         
     3632 
     3633        //loop through everything in the list 
     3634        Variable num,ii,jj 
     3635        num = ItemsInList(listStr) 
     3636 
     3637 
     3638//////////////// 
     3639// declarations for the binning 
     3640// for the first pass, do all of this 
     3641        Make/O/D/N=(128,128) root:Packages:NIST:Event:binnedData 
     3642         
     3643        Wave binnedData = root:Packages:NIST:Event:binnedData 
     3644        Wave xLoc = root:Packages:NIST:Event:xLoc 
     3645        Wave yLoc = root:Packages:NIST:Event:yLoc 
     3646 
     3647// now with the number of slices and max time, process the events 
     3648 
     3649        NVAR yesSortStream = root:Packages:NIST:Event:gSortStreamEvents         //do I sort the events? 
     3650        NVAR t_longest = root:Packages:NIST:Event:gEvent_t_longest 
     3651        NVAR nslices = root:Packages:NIST:Event:gEvent_nslices 
     3652//      NVAR t_longest_dec = root:Packages:NIST:Event:gEvent_t_longest_decimated 
     3653        NVAR t_segment_start = root:Packages:NIST:Event:gEvent_t_segment_start 
     3654        NVAR t_segment_end = root:Packages:NIST:Event:gEvent_t_segment_end 
     3655                 
     3656        SetDataFolder root:Packages:NIST:Event          //don't count on the folder remaining here 
     3657         
     3658        Make/D/O/N=(128,128,nslices) slicedData 
     3659         
     3660        Wave slicedData = slicedData 
     3661        Wave rescaledTime = rescaledTime 
     3662        Make/O/D/N=(128,128) tmpData 
     3663        Make/O/D/N=(nslices+1) binEndTime,binCount//,binStartTime 
     3664        Make/O/D/N=(nslices) timeWidth 
     3665        Wave binEndTime = binEndTime 
     3666        Wave timeWidth = timeWidth 
     3667        Wave binCount = binCount 
     3668 
     3669        slicedData = 0 
     3670        binCount = 0 
     3671 
     3672        variable p1,p2,t1,t2 
     3673 
     3674        t_segment_start = 0 
     3675// start w/file 1??      
     3676        for(jj=0;jj<num;jj+=1) 
     3677 
     3678// (1) load the file, prepending the path                
     3679                filename = pathStr + StringFromList(jj, listStr  ,";") 
     3680                 
     3681                SetDataFolder root:Packages:NIST:Event: 
     3682                LoadWave/T/O fileName 
     3683 
     3684                SetDataFolder root:Packages:NIST:Event:                 //LoadEvents sets back to root: ?? 
     3685 
     3686// this is what is loaded --  
     3687                Wave timePt=timePt 
     3688                Wave xLoc=xLoc 
     3689                Wave yLoc=yLoc 
     3690                Wave rescaledTime=rescaledTime 
     3691 
     3692                if(jj==0) 
     3693                        timePt -= timePt[0]                     //make sure the first point is zero 
     3694                        t_segment_start = 0 
     3695                        t_segment_end = rescaledTime[numpnts(rescaledTime)-1] 
     3696                else 
     3697                        t_segment_start = t_segment_end 
     3698                        t_segment_end += rescaledTime[numpnts(rescaledTime)-1] 
     3699                         
     3700                        rescaledTime += t_segment_start          
     3701                endif 
     3702                 
     3703                Printf "jj=%g\t\tt_segment_start=%g\tt_segment_end=%g\r",jj,t_segment_start,t_segment_end 
     3704                 
     3705// this is the binning-- 
     3706 
     3707//              del = t_longest/nslices 
     3708         
     3709        // TODO 
     3710        // the global exists for this switch, but it is not implemented - not sure whether 
     3711        // it's correct to implement this at all -- 
     3712        // 
     3713                if(yesSortStream == 1) 
     3714                        SortTimeData() 
     3715                endif 
     3716                 
     3717        // index the events before binning 
     3718        // if there is a sort of these events, I need to re-index the events for the histogram 
     3719        //      SetDataFolder root:Packages:NIST:Event 
     3720                IndexForHistogram(xLoc,yLoc,binnedData) 
     3721        //      SetDataFolder root: 
     3722                Wave index = root:Packages:NIST:Event:SavedIndex                //the index for the histogram 
     3723                 
     3724                for(ii=0;ii<nslices;ii+=1) 
     3725                        if(ii==0) 
     3726        //                      t1 = ii*del 
     3727        //                      t2 = (ii+1)*del 
     3728                                p1 = BinarySearch(rescaledTime,0) 
     3729                                p2 = BinarySearch(rescaledTime,binEndTime[ii+1]) 
     3730                        else 
     3731        //                      t2 = (ii+1)*del 
     3732                                p1 = p2+1               //one more than the old one 
     3733                                p2 = BinarySearch(rescaledTime,binEndTime[ii+1])                 
     3734                        endif 
     3735         
     3736                        if(p1 == -1) 
     3737                                Printf "p1 = -1 Binary search off the end %15.10g <?? %15.10g\r", 0, rescaledTime[0] 
     3738                                p1 = 0          //set to the first point if it's off the end 
     3739                        Endif 
     3740                        if(p2 == -2) 
     3741                                Printf "p2 = -2 Binary search off the end %15.10g >?? %15.10g\r", binEndTime[ii+1], rescaledTime[numpnts(rescaledTime)-1] 
     3742                                p2 = numpnts(rescaledTime)-1            //set to the last point if it's off the end 
     3743                        Endif 
     3744        //              Print p1,p2 
     3745         
     3746                        tmpData=0 
     3747                        JointHistogramWithRange(xLoc,yLoc,tmpData,index,p1,p2) 
     3748        //              slicedData[][][ii] = tmpData[p][q] 
     3749                        slicedData[][][ii] += tmpData[p][q] 
     3750                         
     3751//                      Duplicate/O tmpData,$("tmpData_"+num2str(ii)+"_"+num2str(jj)) 
     3752                         
     3753        //              binEndTime[ii+1] = t2 
     3754        //              binCount[ii] = sum(tmpData,-inf,inf) 
     3755                        binCount[ii] += sum(tmpData,-inf,inf) 
     3756                endfor 
     3757         
     3758        endfor  //end loop over the file list 
     3759 
     3760// after all of the files have been loaded 
     3761        t_longest = t_segment_end               //this is the total time 
     3762 
     3763        Duplicate/O slicedData,root:Packages:NIST:Event:dispsliceData,root:Packages:NIST:Event:logSlicedData 
     3764        Wave logSlicedData = root:Packages:NIST:Event:logSlicedData 
     3765        logslicedData = log(slicedData) 
     3766         
     3767                 
     3768        SetDataFolder root: 
     3769 
     3770        return(0) 
     3771End 
     3772 
    34803773 
    34813774///////////////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.