Ignore:
Timestamp:
Feb 19, 2016 4:37:30 PM (7 years ago)
Author:
srkline
Message:

more changes, filling in functionality of the initial data correction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_DetectorCorrections.ipf

    r979 r981  
    7676end 
    7777 
     78// 
     79// Non-linear data correction 
     80//  
     81// input is the data array (N tubes x M pixels) 
     82// input of N x M array of quadratic coefficients 
     83// 
     84// output is wave of corrected real space distance corresponding to each pixel of the data 
     85// 
     86// 
     87// TODO 
     88// -- verify the direction of the tubes and indexing 
     89// -- be sure I'm working in the right data folder 
     90// -- clean up when done 
     91// -- calculate + return the error contribution? 
     92// -- do I want this to return a wave? 
     93// -- do I need to write a separate function that returns the distance wave for later calculations? 
     94// -- do I want to make the distance array 2D to keep the x and y dims together? Calculate them all right now? 
     95// -- what else do I need to pass to the function? (fname=folder? detStr?) 
     96// 
     97// 
     98// 
     99Function NonLinearCorrection(dataW,data_errW,coefW) 
     100        Wave dataW,data_errW,coefW 
     101         
     102        // do I count on the orientation as an input, or do I just figure it out on my own? 
     103        String orientation 
     104        Variable dimX,dimY 
     105        dimX = DimSize(dataW,0) 
     106        dimY = DimSize(dataw,1) 
     107        if(dimX > dimY) 
     108                orientation = "horizontal" 
     109        else 
     110                orientation = "vertical" 
     111        endif 
     112 
     113        // make a wave of the same dimensions, in the same data folder for the distance 
     114        // ?? or a 2D wave? 
     115         
     116        // then per tube, do the quadratic calculation to get the real space distance along the tube 
     117        // the distance perpendicular to the tube is n*(8.4mm) per tube index 
     118         
     119        if(cmpstr(orientation,"vertical")==0) 
     120                //      this is data dimensioned as (Ntubes,Npix) 
     121                 
     122 
     123        elseif(cmpstr(orientation,"horizontal")==0) 
     124                //      this is data (horizontal) dimensioned as (Npix,Ntubes) 
     125 
     126         
     127        else             
     128                DoAlert 0,"Orientation not correctly passed in NonLinearCorrection(). No correction done." 
     129        endif 
     130         
     131        return(0) 
     132end 
    78133 
    79134 
     
    101156//// 
    102157 
    103  
    104  
     158// TODO 
     159// get rid of this in the real data 
     160// 
     161// TESTING ONLY 
     162Macro MakeFakeCalibrationWaves() 
     163        // make these in the RAW data folder, before converting to a work folder 
     164        // - then they will be "found" by get() 
     165        // -- only for the tube, not the Back det 
     166         
     167        DoAlert 0, "re-do this and do a better job of filling the fake data" 
     168         
     169        fMakeFakeCalibrationWaves() 
     170End 
     171 
     172 
     173 
     174// TODO 
     175// get rid of this in the real data 
     176// 
     177// TESTING ONLY 
     178// 
     179// orientation does not matter, there are 48 tubes in each bank 
     180// so dimension (3,48) for everything. 
     181// 
     182// -- but the orientation does indicate TB vs LR, which has implications for  
     183//  the (fictional) dimension of the pixel along the tube axis, at least as far 
     184// as for making the fake coefficients. 
     185// 
     186Function fMakeFakeCalibrationWaves() 
     187 
     188        Variable ii,pixSize 
     189        String detStr,fname="RAW",orientation 
     190         
     191        for(ii=0;ii<ItemsInList(ksDetectorListNoB);ii+=1) 
     192                detStr = StringFromList(ii, ksDetectorListNoB, ";") 
     193//              Wave w = V_getDetectorDataW(fname,detStr) 
     194                Make/O/D/N=(3,48) $("root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_"+detStr+":spatial_calibration") 
     195                Wave calib = $("root:Packages:NIST:VSANS:RAW:entry:entry:instrument:detector_"+detStr+":spatial_calibration") 
     196                // !!!! this overwrites what is there 
     197 
     198                orientation = V_getDet_tubeOrientation(fname,detStr) 
     199                if(cmpstr(orientation,"vertical")==0) 
     200                //      this is vertical tube data dimensioned as (Ntubes,Npix) 
     201                        pixSize = 8                     //V_getDet_y_pixel_size(fname,detStr) 
     202                elseif(cmpstr(orientation,"horizontal")==0) 
     203                //      this is data (horizontal) dimensioned as (Npix,Ntubes) 
     204                        pixSize = 4                     //V_getDet_x_pixel_size(fname,detStr) 
     205                else             
     206                        DoAlert 0,"Orientation not correctly passed in NonLinearCorrection(). No correction done." 
     207                endif 
     208                 
     209                calib[0][] = -64 
     210                calib[1][] = pixSize 
     211                calib[2][] = 2e-4 
     212                 
     213        endfor 
     214         
     215        return(0) 
     216End 
    105217 
    106218 
     
    543655//check before re-implementing 
    544656// 
    545 Proc DIV_a_Workfile(type) 
     657Macro DIV_a_Workfile(type) 
    546658        String type 
    547         Prompt type,"WORK data type",popup,"COR;SAM;EMP;BGD" 
     659        Prompt type,"WORK data type",popup,"SAM;EMP;BGD;ADJ;" 
    548660         
    549661        //macro will take whatever is in SELECTED folder and DIVide it by the current 
    550662        //contents of the DIV folder - the function will check for existence  
    551663        //before proceeding 
     664 
     665//DoAlert 0,"This has not yet been updated for VSANS" 
    552666         
    553667        Variable err 
    554         err = Divide_work(type)         //returns err = 1 if data doesn't exist in specified folders 
     668        err = DIVCorrection(type)               //returns err = 1 if data doesn't exist in specified folders 
    555669         
    556670        if(err) 
    557                 Abort "error in Divide_work" 
    558         endif 
    559          
    560         //contents are always dumped to CAL 
    561         type = "CAL" 
     671                Abort "error in DIVCorrection()" 
     672        endif 
     673         
     674        //contents are NOT always dumped to CAL, but are in the new type folder 
    562675         
    563676        String newTitle = "WORK_"+type 
    564         DoWindow/F SANS_Data 
    565         DoWindow/T SANS_Data, newTitle 
     677        DoWindow/F VSANS_Data 
     678        DoWindow/T VSANS_Data, newTitle 
    566679        KillStrings/Z newTitle 
    567680         
    568681        //need to update the display with "data" from the correct dataFolder 
    569682        //reset the current displaytype to "type" 
    570         String/G root:myGlobals:gDataDisplayType=Type 
    571          
    572         fRawWindowHook() 
    573          
    574 End 
     683        String/G root:Packages:NIST:VSANS:Globals:gCurDispType=Type 
     684         
     685        UpdateDisplayInformation(type) 
     686         
     687End 
     688 
    575689 
    576690// 
     
    578692//   --         DoAlert 0,"This has not yet been updated for VSANS" 
    579693// 
    580 //function will divide the contents of "type" folder with the contents of  
    581 //the DIV folder 
    582 // all data is converted to linear scale for the calculation 
    583 // 
    584 Function Divide_work(type) 
    585         String type 
    586  
    587         DoAlert 0,"This has not yet been updated for VSANS" 
     694//function will divide the contents of "workType" folder with the contents of  
     695//the DIV folder + detStr 
     696// all data is linear scale for the calculation 
     697// 
     698Function DIVCorrection(data,data_err,detStr,workType) 
     699        Wave data,data_err 
     700        String detStr,workType 
    588701         
    589702        //check for existence of data in type and DIV 
    590         // if the desired workfile doesn't exist, let the user know, and abort 
     703        // if the desired data doesn't exist, let the user know, and abort 
    591704        String destPath="" 
    592705 
    593         if(WaveExists($("root:Packages:NIST:"+Type + ":data")) == 0) 
    594                 Print "There is no work file in "+type+"--Aborting" 
     706        if(WaveExists(data) == 0) 
     707                Print "The data wave does not exist in DIVCorrection()" 
    595708                Return(1)               //error condition 
    596709        Endif 
     710         
    597711        //check for DIV 
    598712        // if the DIV workfile doesn't exist, let the user know,and abort 
    599713 
    600         if(WaveExists($"root:Packages:NIST:DIV:data") == 0) 
    601                 Print "There is no work file in DIV --Aborting" 
     714        WAVE/Z div_data = $("root:Packages:NIST:VSANS:DIV:entry:entry:instrument:detector_"+detStr+":data") 
     715        if(WaveExists(div_data) == 0) 
     716                Print "The DIV wave does not exist in DIVCorrection()" 
    602717                Return(1)               //error condition 
    603718        Endif 
    604719        //files exist, proceed 
    605          
    606         //check for log-scaling of the "DIV" data and adjust if necessary 
    607         // should not be needed now - using display flag instead 
    608 //      ConvertFolderToLinearScale("DIV") 
    609          
    610         //copy type information to CAL, wiping out the old contents of the CAL folder first 
    611          
    612         //destPath = "root:Packages:NIST:CAL" 
    613         //SetDataFolder destPath 
    614         //KillWaves/A/Z                 //get rid of the old data in CAL folder 
    615  
    616         //check for log-scaling of the "type" data and adjust if necessary 
    617         // should not be needed now - using display flag instead 
    618 //      ConvertFolderToLinearScale(type) 
    619         //then continue 
    620  
    621         //copy from current dir (type)=destPath to CAL, overwriting CAL contents 
    622         destPath = "root:Packages:NIST:" + type 
    623         Duplicate/O $(destPath + ":data"),$"root:Packages:NIST:CAL:data" 
    624         Duplicate/O $(destPath + ":linear_data"),$"root:Packages:NIST:CAL:linear_data" 
    625         Duplicate/O $(destPath + ":linear_data_error"),$"root:Packages:NIST:CAL:linear_data_error" 
    626 //      Duplicate/O $(destPath + ":vlegend"),$"root:Packages:NIST:CAL:vlegend" 
    627         Duplicate/O $(destPath + ":textread"),$"root:Packages:NIST:CAL:textread" 
    628         Duplicate/O $(destPath + ":integersread"),$"root:Packages:NIST:CAL:integersread" 
    629         Duplicate/O $(destPath + ":realsread"),$"root:Packages:NIST:CAL:realsread" 
    630         //need to save a copy of filelist string too (from the current type folder) 
    631         SVAR oldFileList = $(destPath + ":fileList") 
    632  
    633         //now switch to reference waves in CAL folder 
    634         destPath = "root:Packages:NIST:CAL" 
    635         //make appropriate wave references 
    636         Wave data=$(destPath + ":linear_data")                                  // these wave references point to the data in CAL 
    637 //      Wave data_err=$(destPath + ":linear_data_err")                                  // these wave references point to the data in CAL 
    638         Wave data_copy=$(destPath + ":data")                                    // these wave references point to the data in CAL 
    639         Wave/t textread=$(destPath + ":textread")                       //that are to be directly operated on 
    640         Wave integersread=$(destPath + ":integersread") 
    641         Wave realsread=$(destPath + ":realsread") 
    642         Variable/G $(destPath + ":gIsLogScale")=0                       //make new flag in CAL folder, data is linear scale 
    643         //need to copy filelist string too 
    644         String/G $(destPath + ":fileList") = oldFileList 
    645  
    646         Wave div_data = $"root:Packages:NIST:DIV:data"          //hard-wired in.... 
    647         //do the division, changing data in CAL 
     720 
    648721        data /= div_data 
    649722         
    650723//      data_err /= div_data 
    651724         
    652         // keep "data" in sync with linear_data 
    653         data_copy = data 
    654          
    655         //update CAL header 
    656         textread[1] = date() + " " + time()             //date + time stamp 
    657          
    658725        Return(0) 
    659726End 
Note: See TracChangeset for help on using the changeset viewer.