Changeset 999 for sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS
- Timestamp:
- May 20, 2016 4:28:56 PM (7 years ago)
- 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 16 16 // 17 17 // -- 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 18 23 // -- see the proc DisplayForSlicing() that may aid in setting the bins properly by plotting the 19 24 // bins along with the differential collection rate … … 189 194 190 195 // for decimation 191 Variable/G root:Packages:NIST:Event:gEventFileTooLarge = 150 // 150 MB considered too large196 Variable/G root:Packages:NIST:Event:gEventFileTooLarge = 2500 // 2500 MB considered too large 192 197 Variable/G root:Packages:NIST:Event:gDecimation = 100 193 198 Variable/G root:Packages:NIST:Event:gEvent_t_longest_decimated = 0 … … 280 285 Button button16_1,pos={488,450},size={110,20},proc=AccumulateSlicesButton,title="Add Next Slice" 281 286 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" 282 288 283 289 CheckBox chkbox1_0,pos={25,34},size={69,14},title="Oscillatory",fSize=10 … … 584 590 // now before binning, sort the data 585 591 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, 587 593 // you'll never be able to undo the sort 588 594 // 595 // 596 // for a 500 MB hst, MakeIndex = 83s, everything else in this function totalled < 5s 597 // 589 598 SetDataFolder root:Packages:NIST:Event: 590 599 591 600 if(WaveExists($"root:Packages:NIST:Event:OscSortIndex") == 0 ) 592 601 Duplicate/O rescaledTime OscSortIndex 602 // tic() 593 603 MakeIndex rescaledTime OscSortIndex 604 // toc() 605 // tic() 594 606 IndexSort OscSortIndex, yLoc,xLoc,timePt,rescaledTime 607 // toc() 595 608 //SetDataFolder root:Packages:NIST:Event 609 // tic() 596 610 IndexForHistogram(xLoc,yLoc,binnedData) // index the events AFTER sorting 611 // toc() 597 612 //SetDataFolder root: 598 613 Endif … … 600 615 Wave index = root:Packages:NIST:Event:SavedIndex //this is the histogram index 601 616 617 // tic() 602 618 for(ii=0;ii<nslices;ii+=1) 603 619 if(ii==0) … … 634 650 endfor 635 651 652 // toc() 636 653 Duplicate/O slicedData,root:Packages:NIST:Event:dispsliceData,root:Packages:NIST:Event:logSlicedData 637 654 Wave logSlicedData = root:Packages:NIST:Event:logSlicedData … … 992 1009 993 1010 // 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 995 1020 // MODE_TOF 996 1021 if(mode == MODE_TOF) // TOF mode - don't adjust the times, we get periodic t0 to reset t=0 … … 1275 1300 totBytes = V_logEOF 1276 1301 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 1278 1306 //toc() 1279 1307 // … … 1768 1796 Print "total bytes = ", totBytes 1769 1797 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 1770 1802 // 1771 1803 // Print "scan only" … … 2436 2468 Wave xLoc = xLoc 2437 2469 Wave yLoc = yLoc 2438 Save/T xLoc,yLoc,timePt 2470 Save/T xLoc,yLoc,timePt,rescaledTime //will ask for a name 2439 2471 2440 2472 SetDataFolder root: … … 2464 2496 // load in the waves, saved as Igor text to preserve the data type 2465 2497 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 2468 2506 if(strlen(S_fileName) == 0) 2469 2507 //user cancelled … … 3047 3085 3048 3086 for(ii=0;ii<numSplit;ii+=1) 3049 outStr = (thePath+baseStr+num2str(ii) )3087 outStr = (thePath+baseStr+num2str(ii)+".hst") 3050 3088 // Print "outStr = ",outStr 3051 3089 Open outRef as outStr … … 3057 3095 3058 3096 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"+";" 3061 3099 endfor 3062 3100 3063 3101 Make/O/B/U/N=(frac) leftover 3064 3102 // ii was already incremented past the loop 3065 outStr = (thePath+baseStr+num2str(ii) )3103 outStr = (thePath+baseStr+num2str(ii)+".hst") 3066 3104 Open outRef as outStr 3067 3105 for(jj=0;jj<num;jj+=1) … … 3074 3112 Close outRef 3075 3113 // listStr += outStr+";" 3076 listStr += baseStr+num2str(ii)+" ;"3114 listStr += baseStr+num2str(ii)+".hst"+";" 3077 3115 3078 3116 FSetPos refNum,V_logEOF … … 3127 3165 End 3128 3166 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 // 3171 Function AccumulateSlices(mode,[skipAlert]) 3172 Variable mode,skipAlert 3173 3174 if(ParamIsDefault(skipAlert)) 3175 skipAlert = 0 3176 endif 3132 3177 SetDataFolder root:Packages:NIST:Event: 3133 3178 3134 3179 switch(mode) 3135 3180 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 3137 3184 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 3139 3188 break 3140 3189 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 3142 3193 Wave acc=accumulatedData 3143 3194 Wave cur=slicedData 3144 3195 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! 3145 3201 break 3146 3202 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 3148 3206 Duplicate/O accumulatedData slicedData 3149 3207 // do something to "touch" the display to force it to update … … 3413 3471 3414 3472 Variable fileref 3415 3473 Variable num,ii 3474 3416 3475 SVAR filename = root:Packages:NIST:Event:gEvent_logfile 3417 3476 NVAR t_longest = root:Packages:NIST:Event:gEvent_t_longest … … 3444 3503 3445 3504 //loop through everything in the list 3446 Variable num,ii3447 3505 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 3448 3510 3449 3511 for(ii=0;ii<num;ii+=1) … … 3451 3513 // (1) load the file, prepending the path 3452 3514 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 3454 3519 3455 3520 #if (exists("EventLoadWave")==4) … … 3555 3620 num = ItemsInList(listStr) 3556 3621 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 3557 3627 for(ii=0;ii<num;ii+=1) 3558 3628 3559 3629 // (1) load the file, prepending the path 3560 3630 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 3562 3635 SetDataFolder root:Packages:NIST:Event: 3563 3636 LoadWave/T/O fileName … … 3635 3708 Variable num,ii,jj 3636 3709 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 3639 3715 //////////////// 3640 3716 // declarations for the binning … … 3679 3755 // (1) load the file, prepending the path 3680 3756 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 3682 3761 SetDataFolder root:Packages:NIST:Event: 3683 3762 LoadWave/T/O fileName … … 3825 3904 end 3826 3905 ///////////////////////////// 3906 3907 Proc GetListofITXorSplitFiles(searchStr) 3908 String searchStr = ".itx" 3909 ShowList_ToLoad("") 3910 GetListofITXHST(searchStr) 3911 end 3912 3913 // needs SANS_Utilites.ipf 3914 Function 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) 3930 End 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 // 3938 Function 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) 4046 End 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 // 4056 Function 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) 4071 end 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 // 4077 Proc DecodeBinaryEvents(numToPrint) 4078 Variable numToPrint=10 4079 4080 DecodeEvents(numToPrint) 4081 end 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. 4086 Function 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 4157 toc() 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 4170 End -
sans/Dev/trunk/NCNR_User_Procedures/Reduction/SANS/Menu.ipf
r885 r999 50 50 "-" 51 51 "Split Large File",SplitBigFile() 52 "Get List of ITX or Split Files",GetListofITXorSplitFiles() 52 53 "Accumulate First Slice",AccumulateSlices(0) 53 54 "Add Current Slice",AccumulateSlices(1)
Note: See TracChangeset
for help on using the changeset viewer.