Ignore:
Timestamp:
Mar 13, 2017 1:39:33 PM (6 years ago)
Author:
srkline
Message:

adding to the functionality of the data reduction protocol

getting the 1D plotting to work both as a standalone plot and part of the reduction protocol (where the choices are all made and fed in)

added log/lin toggle to 1D display. abc exponent scaling is fundamentally more messy, and has been shelved for now. Revisit if demand is there.

fixed bug in how raw data files are identified, to prevent .abs files from being incorrectly identified as raw (if same name before extension). Works correctly now, but may need tweak in future if naming scheme changes.

File:
1 edited

Legend:

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

    r1025 r1027  
    4747//              NAME=string             string from set {Auto,Manual} = Automatic name generation or Manual(dialog) 
    4848// 
     49//    BINTYPE=string (VSANS binning type) "One;Two;Four;Slit Mode;" 
    4950// 
    5051//              For work.DRK usage: 
     
    533534// -- decide on the way to locate the blocked beam files. Is the enumerated text of the intent 
    534535//    sufficiently unique to locate the file? 
     536// -- can I use the Data Catalog waves to locate the files  - faster? 
     537//    (fails if the catalog has not been read in recently enough) 
     538// 
    535539// 
    536540Function/S V_PickBGDButton(ctrlName) : ButtonControl 
     
    936940        String ctrlName 
    937941         
     942//      Execute "V_GetAvgInfo_Full()" 
    938943        Execute "V_GetAvgInfo()" 
    939944         
     
    944949End 
    945950 
     951// TODO 
     952// -- this is a trimmed down version of the "full" set of averaging options 
     953//    add to this as needed to add in functionality 
     954// 
    946955//procedure called by protocol panel to ask user for average type choices 
    947956// somewhat confusing and complex, but may be as good as it gets. 
    948957// 
    949 Proc V_GetAvgInfo(av_typ,autoSave,autoName,autoPlot,side,phi,dphi,width,QCtr,QDelta) 
     958//Proc V_GetAvgInfo(av_typ,autoSave,autoName,autoPlot,side,phi,dphi,width,QCtr,QDelta) 
     959Proc V_GetAvgInfo(av_typ,autoSave,autoName,binType) 
     960        String av_typ,autoSave,AutoName,binType 
     961//      Variable phi=0,dphi=10,width=10,Qctr = 0.01,qDelta=10 
     962 
     963//      Prompt av_typ, "Type of Average",popup,"Circular;Sector;Rectangular;Annular;2D_ASCII;QxQy_ASCII;PNG_Graphic;Sector_PlusMinus;" 
     964        Prompt av_typ, "Type of Average",popup,"Circular;" 
     965 
     966// comment out above line in DEMO_MODIFIED version, and uncomment the line below (to disable PNG save) 
     967//      Prompt av_typ, "Type of Average",popup,"Circular;Sector;Rectangular;Annular;2D_ASCII;QxQy_ASCII" 
     968        Prompt autoSave,"Save files to disk?",popup,"Yes;No" 
     969        Prompt autoName,"Auto-Name files?",popup,"Auto;Manual" 
     970//      Prompt autoPlot,"Plot the averaged Data?",popup,"Yes;No" 
     971//      Prompt side,"Include detector halves?",popup,"both;right;left" 
     972//      Prompt phi,"Orientation Angle (-90,90) degrees (Rectangular or Sector)" 
     973//      Prompt dphi, "Azimuthal range (0,45) degrees (Sector only)" 
     974//      Prompt width, "Width of Rectangular average (1,128)" 
     975//      Prompt Qctr, "q-value of center of annulus" 
     976//      Prompt Qdelta,"Pixel width of annulus" 
     977        Prompt binType,"Binning Type?",popup,"One;Two;Four;Slit Mode;" 
     978 
     979        //assign results of dialog to key=value string, semicolon separated 
     980        //do only what is necessary, based on av_typ 
     981        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr="" 
     982 
     983        // TODO: 
     984        // hard wired value 
     985        String autoPlot = "No" 
     986         
     987                 
     988        // all averages need these values 
     989        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "AVTYPE=" + av_typ + ";" 
     990        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SAVE=" + autoSave + ";" 
     991        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "NAME=" + autoName + ";" 
     992        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PLOT=" + autoPlot + ";" 
     993        root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "BINTYPE=" + binType + ";" 
     994         
     995//      if(cmpstr(av_typ,"Sector")==0 || cmpstr(av_typ,"Sector_PlusMinus")==0) 
     996//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SIDE=" + side + ";" 
     997//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";" 
     998//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "DPHI=" + num2str(dphi) + ";" 
     999//      Endif 
     1000//       
     1001//      if(cmpstr(av_typ,"Rectangular")==0) 
     1002//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "SIDE=" + side + ";" 
     1003//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "PHI=" + num2str(phi) + ";" 
     1004//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "WIDTH=" + num2str(width) + ";" 
     1005//      Endif 
     1006//       
     1007//      if(cmpstr(av_typ,"Annular")==0) 
     1008//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "QCENTER=" + num2str(QCtr) + ";" 
     1009//              root:Packages:NIST:VSANS:Globals:Protocols:gAvgInfoStr += "QDELTA=" + num2str(QDelta) + ";" 
     1010//      Endif 
     1011End 
     1012 
     1013 
     1014// TODO 
     1015// -- this is the original(SANS) version, and needs to be updated for VSANS as the averaging options are 
     1016//    worked out 
     1017// 
     1018//procedure called by protocol panel to ask user for average type choices 
     1019// somewhat confusing and complex, but may be as good as it gets. 
     1020// 
     1021Proc V_GetAvgInfo_Full(av_typ,autoSave,autoName,autoPlot,side,phi,dphi,width,QCtr,QDelta) 
    9501022        String av_typ,autoSave,AutoName,autoPlot,side 
    9511023        Variable phi=0,dphi=10,width=10,Qctr = 0.01,qDelta=10 
     
    9901062        Endif 
    9911063End 
    992  
    9931064 
    9941065 
     
    13351406        //returns the name of the newly created (= currently in use) protocol wave through a global 
    13361407        String/G root:Packages:NIST:VSANS:Globals:Protocols:gProtoStr = newProtoStr 
     1408         
     1409        //reset the panel based on the protocol textwave (currently a string) 
     1410        V_ResetToSavedProtocol(newProtoStr) 
     1411         
     1412        return(0) 
    13371413End 
    13381414 
     
    15731649                Endif 
    15741650        While(0) 
     1651        // TODO 
     1652        // -- this may not be the most reliable way to pas the file name 
     1653        SVAR file_name = root:file_Name 
     1654        String sameFileLoaded = file_name               //keep a copy of the sample file loaded 
     1655         
    15751656        //always update 
    15761657        V_UpdateDisplayInformation(ActiveType) 
     
    17591840//////////////////////////////////////////////////////// 
    17601841 
    1761          
     1842// TODO: 
     1843// -- calculation works, needs proper inputs (solid angle aware) 
     1844// --   Open beam method is only a stub - fill in calculation in V_AskForAbsoluteParams_Quest() 
    17621845        Variable c2,c3,c4,c5,kappa_err 
    17631846        //do absolute scaling if desired 
     
    17841867                Endif 
    17851868                //get the sample trans and thickness from the activeType folder 
    1786                 String destStr = "root:Packages:NIST:"+activeType+":realsread" 
    1787                 Wave dest = $destStr 
    1788                 Variable c0 = dest[4]           //sample transmission 
    1789                 Variable c1 = dest[5]           //sample thickness 
     1869                Variable c0 = V_getSampleTransmission(activeType)               //sample transmission 
     1870                Variable c1 = V_getSampleThickness(activeType)          //sample thickness 
    17901871                 
    17911872                err = V_Absolute_Scale(activeType,c0,c1,c2,c3,c4,c5,kappa_err) 
    17921873                if(err) 
    17931874                        SetDataFolder root: 
    1794                         Abort "Error in Absolute_Scale(), called from executeProtocol" 
     1875                        Abort "Error in V_Absolute_Scale(), called from V_ExecuteProtocol" 
    17951876                endif 
    17961877                activeType = "ABS" 
     
    17981879        Endif 
    17991880 
    1800  
     1881// 
    18011882// TODO -- incomplete 
    18021883//       
     1884//mask data if desired (this is done automatically  in the average step) and is 
     1885//not done explicitly here (if no mask in MSK folder, a null mask is created and "used") 
     1886         
    18031887        //check for mask 
    18041888        //add mask if needed 
     
    18321916        else 
    18331917                //if none desired, make sure that the old mask is deleted 
    1834                 //junkStr = GetDataFolder(1) 
    1835                 //SetDataFolder root:Packages:NIST:MSK 
    1836                 KillWaves/Z root:Packages:NIST:VSANS:MSK:data 
    1837                 //SetDataFolder junkStr 
    1838         Endif 
    1839          
    1840         //mask data if desired (this is done automatically  in the average step) and is 
    1841         //not done explicitly here (if no mask in MSK folder, a null mask is created and "used") 
    1842  
    1843  
    1844          
     1918// TODO 
     1919// x- clean out the data folder 
     1920// x- note that V_KillNamedDataFolder() points to RawVSANS, and won't work 
     1921// -- what happens if the kill fails? need error handling 
     1922// 
     1923                KillDataFolder/Z root:Packages:NIST:VSANS:MSK: 
     1924        Endif 
     1925         
     1926 
     1927 
     1928 
     1929 
    18451930        // average/save data as specified 
    18461931         
     
    18641949         
    18651950        //convert the folder to linear scale before averaging, then revert by calling the window hook 
    1866         // not needed for VSANS, data is always linear scale 
    1867  
    1868          
     1951        // (not needed for VSANS, data is always linear scale) 
     1952 
     1953// TODO 
     1954// -- this switch does nothing -- fill it in 
     1955//       
    18691956        strswitch(av_type)      //dispatch to the proper routine to average to 1D data 
    18701957                case "none":             
     
    18981985                        //do nothing 
    18991986        endswitch 
     1987        // bin and plot the data 
     1988        // TODO 
     1989        // x- currently this bins and plots based on the V_1D_Data panel, NOT the selections above 
     1990        // now takes the the binType from the protocol, and uses two steps to bin and average 
     1991        String binTypeStr = StringByKey("BINTYPE",prot[5],"=",";") 
     1992        // plotting is not really necessary, and the graph may not be open - so skip for now? 
     1993        Variable binType 
     1994        strswitch(binTypeStr)   // string switch 
     1995                case "One": 
     1996                        binType = 1 
     1997                        break           // exit from switch 
     1998                case "Two": 
     1999                        binType = 2 
     2000                        break           // exit from switch 
     2001                case "Four": 
     2002                        binType = 3 
     2003                        break           // exit from switch 
     2004                case "Slit Mode": 
     2005                        binType = 4 
     2006                        break           // exit from switch 
     2007 
     2008                default:                        // optional default expression executed 
     2009                        binType = 0 
     2010                        Abort "Binning mode not found in V_QBinAllPanels() "// when no case matches 
     2011        endswitch 
     2012         
     2013        V_PlotData_Panel(binType)               //this bins and plots the *currently displayed* data 
     2014        V_QBinAllPanels(activeType,binType)             //bin the active reduction data 
     2015 
     2016// TODO: 
     2017// x- "B" detector is currently skipped - Q is not yet calculated 
     2018        String str 
     2019        sprintf str,"(\"%s\",%d)",activeType,binType 
     2020         
     2021        Execute ("V_Back_IQ_Graph"+str) 
     2022//      Print "V_Back_IQ_Graph"+str 
     2023        Execute ("V_Middle_IQ_Graph"+str) 
     2024        Execute ("V_Front_IQ_Graph"+str) 
     2025 
     2026         
    19002027///// end of averaging dispatch 
    19012028 
    1902          
     2029 
     2030// TODO 
     2031// x- how do I get the sample file name? 
     2032//     sameFileLoaded is the file name loaded (contains the extension) 
     2033//       
    19032034        //save data if desired 
    19042035        String fullpath = "", newfileName="" 
     
    19062037        If( (cmpstr(item,"Yes")==0) && (cmpstr(av_type,"none") != 0) )           
    19072038                //then save 
    1908                 //get name from textwave of the activeType dataset 
    1909                 String textStr = "root:Packages:NIST:VSANS:"+activeType+":textread" 
    1910                 Wave/T textPath = $textStr 
    1911                 String tempFilename = samStr 
    1912                 If(WaveExists(textPath) == 1) 
    1913  
    1914                         newFileName = RemoveEnding("SAMFileName.nxs.ngv",".nxs.ngv")            //NCNR data drops here, trims to 8 chars 
    1915  
    1916                 else 
    1917                         newFileName = ""                        //if the header is missing? 
    1918                         //Print "can't read the header - newfilename is null" 
    1919                 Endif 
     2039                newFileName = RemoveEnding(sameFileLoaded,".nxs.ngv") 
    19202040                 
    19212041                //pick ABS or AVE extension 
     
    19412061                //Path is catPathName, symbolic path 
    19422062                //if this doesn't exist, a dialog will be presented by setting dialog = 1 
     2063                // 
     2064                // 
    19432065                Variable dialog = 0 
    19442066                PathInfo/S catPathName 
     
    19522074                        //auto-generate name and prepend path - won't put up any dialogs since it has all it needs 
    19532075                        //use autoname if present 
    1954                         if (cmpstr(autoname,"") != 0) 
    1955                                 fullPath = S_Path + autoname + "." +exten 
    1956                         else 
    1957                                 fullPath = S_Path + newFileName+"." + exten 
    1958                         endif    
     2076//                      if (cmpstr(autoname,"") != 0) 
     2077//                              fullPath = S_Path + autoname + "." +exten 
     2078//                      else 
     2079//                              fullPath = S_Path + newFileName+"." + exten 
     2080//                      endif    
    19592081                Endif 
    19602082                // 
     
    19782100//                                      WriteWaves_W_Protocol(activeType,fullpath,dialog) 
    19792101//                              endif 
     2102// 
     2103// TODO: 
     2104// -- fill in all of the cases, default is only the "standard" I(q) 
     2105                                V_ConcatenateForSave(activeType,binType) 
     2106                                V_Write1DData(activeType,newFileName+"."+exten)         //don't pass the full path, just the name 
     2107 
    19802108                endswitch 
    19812109                 
     
    19922120//values are passed back as a global string variable (keyword=value) 
    19932121// 
    1994 Proc V_AskForAbsoluteParams(c2,c3,c4,c5,err) 
    1995         Variable c2=0.95,c3=0.1,c4=1,c5=32.0,err=0 
     2122Proc V_AskForAbsoluteParams(c2,c3,c4,c5,I_err) 
     2123        Variable c2=0.95,c3=0.1,c4=1,c5=32.0,I_err=0.32 
    19962124        Prompt c2, "Standard Transmission" 
    19972125        Prompt c3, "Standard Thickness (cm)" 
    19982126        Prompt c4, "I(0) from standard fit (normalized to 1E8 monitor cts)" 
    19992127        Prompt c5, "Standard Cross-Section (cm-1)" 
    2000         Prompt err, "error in I(q=0) (one std dev)" 
     2128        Prompt I_err, "error in I(q=0) (one std dev)" 
    20012129         
    20022130        String/G root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr="" 
     
    20062134        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "IZERO="+num2str(c4) 
    20072135        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "XSECT="+num2str(c5) 
    2008         root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "SDEV="+num2str(err) 
     2136        root:Packages:NIST:VSANS:Globals:Protocols:gAbsStr +=  ";" + "SDEV="+num2str(I_err) 
    20092137         
    20102138End 
     
    20162144// 
    20172145//asks the user for absolute scaling information. the user can either 
    2018 //enter the 4 necessary values in manually (missing parameter dialog) 
     2146//enter the 5 necessary values in manually (missing parameter dialog) 
    20192147//or the user can select an empty beam file from a standard open dialog 
    20202148//if an empty beam file is selected, the "kappa" value is automatically calculated 
    20212149//in either case, the global keyword=value string is set. 
    20222150// 
    2023 //Proc AskForAbsoluteParams_Quest() 
    20242151Function V_AskForAbsoluteParams_Quest()  
    20252152         
    2026         Variable err, isNG5=0,loc,refnum 
     2153        Variable err,loc,refnum 
    20272154        //ask user if he wants to use a transmision file for absolute scaling 
    20282155        //or if he wants to enter his own information 
     
    20812208                // - obsucre bug if "ask" in ABS section of protocol clears RAW folder, then Q-axes can't be set from RAW:RealsRead 
    20822209 
    2083                 Printf "Kappa was successfully calculated as = %g +/- %g (%g %)\r",kappa,kappa_err,(kappa_err/kappa)*100 
     2210                Printf "Kappa was un-successfully calculated as = %g +/- %g (%g %)\r",kappa,kappa_err,(kappa_err/kappa)*100 
    20842211        Endif 
    20852212         
Note: See TracChangeset for help on using the changeset viewer.