Changeset 835


Ignore:
Timestamp:
Feb 6, 2012 12:19:28 PM (11 years ago)
Author:
srkline
Message:

moving the Polarization routines to a temporary "beta" menu location on the macros menu, numbering the panels.

Created a loader for the polarization routines that will load the SANS reduction if needed.

Location:
sans/Dev/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_Igor_Procedures/NCNR_Package_Loader.ipf

    r828 r835  
    11#pragma rtGlobals=1             // Use modern global access method. 
    2 #pragma IgorVersion=6.1 
     2#pragma IgorVersion=6.2 
    33 
    44// load/unload courtesy of Jan Ilavsky 
     
    3131        // for testing ONLY 
    3232        "-" 
    33         "Load Polarization Reduction",Execute/P "INSERTINCLUDE \"Include_Polarization\"";Execute/P "COMPILEPROCEDURES " 
    34  
    35         "Load Batch Fitting",Execute/P "INSERTINCLUDE \"Auto_Fit\"";Execute/P "COMPILEPROCEDURES ";Execute/P "InitializeAutoFitPanel()" 
    36  
    37         "Load Real Space Modeling",Execute/P "INSERTINCLUDE \"FFT_Cubes_Includes\"";Execute/P "INSERTINCLUDE \"FFT_Fit_Includes\"";Execute/P "COMPILEPROCEDURES ";Execute/P "Init_FFT()" 
     33        "Load Polarization Reduction - Beta",PolarizationLoader() 
     34 
     35//      "Load Batch Fitting",Execute/P "INSERTINCLUDE \"Auto_Fit\"";Execute/P "COMPILEPROCEDURES ";Execute/P "InitializeAutoFitPanel()" 
     36 
     37        "Load Real Space Modeling - Beta",Execute/P "INSERTINCLUDE \"FFT_Cubes_Includes\"";Execute/P "INSERTINCLUDE \"FFT_Fit_Includes\"";Execute/P "COMPILEPROCEDURES ";Execute/P "Init_FFT()" 
    3838        "-" 
    3939 
     
    4343        String itemStr 
    4444                 
    45         if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.1) 
    46                 Abort "Your version of Igor is lower than 6.1, these macros need version 6.1 or higher.... " 
     45        if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.2) 
     46                Abort "Your version of Igor is lower than 6.2, these macros need version 6.2 or higher.... " 
    4747        endif 
    4848         
     
    127127        String itemStr 
    128128         
    129         if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.1) 
    130                 Abort "Your version of Igor is lower than 6.1, these macros need version 6.1 or higher.... " 
     129        if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.2) 
     130                Abort "Your version of Igor is lower than 6.2, these macros need version 6.2 or higher.... " 
    131131        endif 
    132132         
     
    198198        String itemStr 
    199199         
    200         if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.1) 
    201                 Abort "Your version of Igor is lower than 6.1, these macros need version 6.1 or higher.... " 
     200        if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.2) 
     201                Abort "Your version of Igor is lower than 6.2, these macros need version 6.2 or higher.... " 
    202202        endif 
    203203         
     
    283283        String itemStr 
    284284         
    285         if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.1) 
    286                 Abort "Your version of Igor is lower than 6.1, these macros need version 6.1 or higher.... " 
     285        if (str2num(stringByKey("IGORVERS",IgorInfo(0))) < 6.2) 
     286                Abort "Your version of Igor is lower than 6.2, these macros need version 6.2 or higher.... " 
    287287        endif 
    288288         
     
    405405        SetIgorOption poundUnDefine=ILL_D22 
    406406End 
     407 
     408Function PolarizationLoader() 
     409 
     410        // be sure that the SANS reduction is loaded and compiles 
     411        NCNR_SANSReductionLoader("Load NCNR SANS Reduction Macros") 
     412         
     413        // then the polarization 
     414        Execute/P "INSERTINCLUDE \"Include_Polarization\"";Execute/P "COMPILEPROCEDURES " 
     415        BuildMenu "Macros" 
     416 
     417        return(0) 
     418End 
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/NewModels_2006/SchulzSpheres_v40.ipf

    r570 r835  
    66// at low polydispersity (< 0.2), it is very similar to the Gaussian distribution 
    77// at larger polydispersities, it is more skewed and similar to log-normal 
     8// 
     9// 
     10// JAN 2012  
     11//-- added the functions to calculate the Beta factor for the decoupling approximation to 
     12// modify the S(q) calculation. A separate Sq_Beta.ipf file was created to hold all of the new P*S' combinations 
    813// 
    914 
     
    384389//End 
    385390// 
     391 
     392//AAO version, uses XOP if available 
     393// simply calls the original single point calculation with 
     394// a wave assignment (this will behave nicely if given point ranges) 
     395Function SchulzSpheresBeta(cw,yw,xw) : FitFunc 
     396        Wave cw,yw,xw 
     397         
     398#if exists("SchulzSpheresBetaX") 
     399        yw = SchulzSpheresBetaX(cw,xw) 
     400#else 
     401        yw = fSchulzSpheresBeta(cw,xw) 
     402#endif 
     403        return(0) 
     404End 
     405 
     406//use the analytic formula from Kotlarchyk & Chen, JCP 79 (1983) 2461 
     407//equations 26 + 23-30 
     408// 
     409// need to calculate in terms of logarithms to avoid numerical errors 
     410// this returns the Beta factor 
     411// 
     412Function fSchulzSpheresBeta(w,x) : FitFunc 
     413        Wave w 
     414        Variable x 
     415 
     416        Variable scale,ravg,pd,delrho,bkg,zz,rho,rhos,vpoly 
     417        scale = w[0] 
     418        ravg = w[1] 
     419        pd = w[2] 
     420        rho = w[3] 
     421        rhos = w[4] 
     422        bkg = w[5] 
     423         
     424        delrho=rho-rhos 
     425        zz = (1/pd)^2-1 
     426 
     427        Variable zp1,zp2,zp3,zp4,zp5,zp6,zp7 
     428        Variable aa,b1,b2,b3,at1,at2,rt1,rt2,rt3,t1,t2,t3 
     429        Variable v1,v2,v3,g1,g11,gd,pq,g2,g22,fBETA 
     430         
     431        ZP1 = zz + 1 
     432        ZP2 = zz + 2 
     433        ZP3 = zz + 3 
     434        ZP4 = zz + 4 
     435        ZP5 = zz + 5 
     436        ZP6 = zz + 6 
     437        ZP7 = zz + 7 
     438         
     439//      //small QR limit - use Guinier approx 
     440//      Variable i_zero,Rg2,zp8 
     441//      zp8 = zz+8 
     442//      if(x*ravg < 0.1) 
     443//              i_zero = scale*delrho*delrho*1e8*4*Pi/3*ravg^3 
     444//              i_zero *= zp6*zp5*zp4/zp1/zp1/zp1               //6th moment / 3rd moment 
     445//              Rg2 = 3*zp8*zp7/5/(zp1^2)*ravg*ravg 
     446//              pq = i_zero*exp(-x*x*Rg2/3) 
     447//              pq += bkg 
     448//              return(pq) 
     449//      endif 
     450// 
     451        aa = (zz+1)/x/Ravg 
     452 
     453        AT1 = atan(1/aa) 
     454        AT2 = atan(2/aa) 
     455// 
     456//  CALCULATIONS ARE PERFORMED TO AVOID  LARGE # ERRORS 
     457// - trick is to propogate the a^(z+7) term through the G1 
     458//  
     459        T1 = ZP7*log(aa) - zp1/2*log(aa*aa+4) 
     460        T2 = ZP7*log(aa) - zp3/2*log(aa*aa+4) 
     461        T3 = ZP7*log(aa) - zp2/2*log(aa*aa+4) 
     462//      Print T1,T2,T3 
     463        RT1 = alog(T1) 
     464        RT2 = alog(T2) 
     465        RT3 = alog(T3) 
     466        V1 = aa^6 - RT1*cos(zp1*at2) 
     467        V2 = ZP1*ZP2*( aa^4 + RT2*cos(zp3*at2) ) 
     468        V3 = -2*ZP1*RT3*SIN(zp2*at2) 
     469        G1 = (V1+V2+V3) 
     470         
     471        Pq = log(G1) - 6*log(ZP1) + 6*log(Ravg) 
     472        Pq = alog(Pq)*8*PI*PI*delrho*delrho 
     473         
     474// 
     475// beta factor is not used here, but could be for the  
     476// decoupling approximation 
     477//  
     478        G11 = G1 
     479        GD = -ZP7*log(aa) 
     480        G1 = log(G11) + GD 
     481                        
     482        T1 = ZP1*at1 
     483        T2 = ZP2*at1 
     484        G2 = SIN( T1 ) - ZP1/SQRT(aa*aa+1)*COS( T2 ) 
     485        G22 = G2*G2 
     486        fBETA = ZP1*log(aa) - ZP1*log(aa*aa+1) - G1 + log(G22)  
     487        fBETA = 2*alog(fBETA) 
     488         
     489        return(fBETA) 
     490         
     491//re-normalize by the average volume 
     492//      vpoly = 4*Pi/3*zp3*zp2/zp1/zp1*(ravg)^3 
     493//      Pq /= vpoly 
     494//scale, convert to cm^-1 
     495//      Pq *= scale * 1e8 
     496// add in the background 
     497//      Pq += bkg 
     498         
     499        //return (g1) 
     500//      Return (Pq) 
     501End 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_FlipperPanel.ipf

    r832 r835  
    2222// two waves per condition "Cond_Name_Cell" and "CondCalc_Name_Cell" 
    2323// 
    24 Macro ShowFlipperPanel() 
     24Proc ShowFlipperPanel() 
    2525         
    2626        // init folders 
     
    180180                        SetDataFolder root: 
    181181                         
     182                        // update the globals that are displayed from the wave note 
     183                        String nStr=Note(cond) 
     184                        SVAR gPsmPf = root:Packages:NIST:Polarization:Cells:gPsmPf 
     185                        SVAR gPsm = root:Packages:NIST:Polarization:Cells:gPsm 
     186                        sprintf gPsmPf, "%g +/- %g",NumberByKey("P_sm_f", nStr, "=",","),NumberByKey("err_P_sm_f", nStr, "=",",") 
     187                        sprintf gPsm, "%g +/- %g",NumberByKey("P_sm", nStr, "=",","),NumberByKey("err_P_sm", nStr, "=",",") 
     188                         
     189                         
    182190                        break 
    183191                case -1: // control being killed 
     
    215223        // generate the dummy wave note now, change as needed 
    216224        String cellStr = StringFromList(1, popStr,"_") 
    217         String testStr = "P_sm_f=2,err_P_sm_f=0,P_sm=0.6,err_P_sm=0,T0=asdf," 
     225        String testStr = "P_sm_f=0,err_P_sm_f=0,P_sm=0,err_P_sm=0,T0=undefined," 
    218226//      testStr = ReplaceStringByKey("Cell", testStr, cellStr ,"=", ",", 0) 
    219227        Note cond, testStr 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_PolarizationCorrection.ipf

    r829 r835  
    7575 
    7676// main entry to the PolCor Panel 
    77 Macro ShowPolCorSetup() 
     77Proc ShowPolCorSetup() 
    7878 
    7979        Variable restore=0 
     
    269269        Button button4,pos={620,18},size={30,20},proc=PolCorHelpParButtonProc,title="?" 
    270270        Button button12,pos={440,473},size={120,20},proc=Display4XSButton,title="Display 4 XS" 
     271        Button button13,pos={440,446},size={120,20},proc=ClearPolCorEntries,title="Clear Entries" 
    271272 
    272273        PopupMenu popup1,pos={210,24},size={102,20},title="Condition" 
     
    10151016         
    10161017        Variable row,Psm, PsmPf, PCell,err_Psm, err_PsmPf, err_PCell 
    1017         Variable ii,jj,muPo,err_muPo,gam,err_gam,monCts,t1,num 
     1018        Variable ii,jj,muPo,err_muPo,gam,err_gam,monCts,t1,num,fileCount 
    10181019 
    10191020        Variable ea_uu, ea_ud, ea_dd, ea_du 
     
    10571058 
    10581059        // loop over the (10) rows in the listWave 
     1060        fileCount=0 
    10591061        for(ii=0;ii<num;ii+=1) 
    10601062                runStr =        lb[ii][0]               //the run number 
    10611063                if(cmpstr(runStr, "" ) != 0) 
    1062                          
     1064                 
     1065                        fileCount += 1          //one more file is added 
    10631066                        // get run number (str) 
    10641067                        // get file name 
     
    10851088                        // get file info (monitor counts) 
    10861089                        monCts = getMonitorCount(fname) 
    1087                         monCts /= 1e8           //just to get reasonable values 
     1090                        monCts /= 1e8           //to get a normalized value to add proportionally 
    10881091                         
    10891092                        Variable err_monCts 
     
    12091212// can't take the SQRT here, since the matrix won't necessarily be full yet,  
    12101213         
    1211          
     1214// but now need to re-normalize the row based on the number of files that were added 
     1215// pType has only one value as passed in, so the row has already been set. It would be more correct 
     1216// to switch based on pType... 
     1217         
     1218        matA[row][0] /= fileCount 
     1219        matA[row][1] /= fileCount 
     1220        matA[row][2] /= fileCount 
     1221        matA[row][3] /= fileCount        
     1222         
     1223        matA_err[row][0] /= fileCount 
     1224        matA_err[row][1] /= fileCount 
     1225        matA_err[row][2] /= fileCount 
     1226        matA_err[row][3] /= fileCount    
     1227                                 
    12121228        SetDataFolder root: 
    12131229        return(0) 
     
    24492465End 
    24502466 
     2467// clear the entries for all 4 XS for the currently selected Tab only 
     2468// clears both the run numbers and the cell assignments 
     2469// 
     2470Function ClearPolCorEntries(ba) : ButtonControl 
     2471        STRUCT WMButtonAction &ba 
     2472 
     2473        switch( ba.eventCode ) 
     2474                case 2: // mouse up 
     2475                        // click code here 
     2476                        // 
     2477//                      String type 
     2478                        Variable tabNum 
     2479                        ControlInfo/W=PolCor_Panel PolCorTab 
     2480//                      type = S_value 
     2481//                      Print "selected data type = ",type,V_Value 
     2482                        tabNum = V_Value 
     2483                         
     2484                        WAVE/T twDD = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_DD") 
     2485                        WAVE/T twUU = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_UU") 
     2486                        WAVE/T twUD = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_UD") 
     2487                        WAVE/T twDU = $("root:Packages:NIST:Polarization:ListWave_"+num2str(tabNum)+"_DU") 
     2488                         
     2489                        twDD = "" 
     2490                        twUU = "" 
     2491                        twUD = "" 
     2492                        twDU = "" 
     2493                         
     2494                        break 
     2495                case -1: // control being killed 
     2496                        break 
     2497        endswitch 
     2498 
     2499        return 0 
     2500End 
    24512501 
    24522502 
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/Polarization/Pol_PolarizationPanels.ipf

    r832 r835  
    33 
    44// TODO: 
    5 // - on the decay panel. need to be able to manually enter a date that is to or an offset 
     5// x- on the decay panel. need to be able to manually enter a date that is to or an offset 
    66//              number of hours. currently it takes the first file as t=0, which is often not correct 
    77// 
     
    1616// -1- Fundamental Cell Parameters -- these are constants, generally not editable. (this file) 
    1717// -2- Decay Parameters -- these are fitted values based on transmission mearurements (this file) 
    18 // -3- Flipper Panel is in its own procedure (FlipperPanel.ipf) 
    19 // -4- PolCor_Panel is in PolarizationCorrection.ipf 
    20  
     18// -3- Flipper Panel is in its own procedure (Pol_FlipperPanel.ipf) 
     19// -4- PolCor_Panel is in Pol_PolarizationCorrection.ipf 
     20// 
    2121// 
    2222// Driven by 4 panels to get the necessary information from the users 
     
    7171//              - Polarization correction is done with one click (one per tab). "_pc" tags are added to the resulting names, 
    7272//                      and copies of all of the associated waves are again copied (wasteful), but makes switching display very easy 
    73 //              - Once all of the polariztion correction is done, then the UU_pc (etc.) data can be reduced as usual (xx_pc = 4 passes) 
     73//              - Once all of the polarization correction is done, then the UU_pc (etc.) data can be reduced as usual (xx_pc = 4 passes) 
    7474//              - protocol is built as ususal, from this panel only (since the SAM, EMP, and BGD need to be switched, rather than loaded 
    7575//              - protocols can be saved/recalled. 
     
    8484 
    8585 
     86// for the menu 
     87Menu "Macros" 
     88        "1 Fundamental Cell Parameters",ShowCellParamPanel() 
     89        "2 Cell Decay",ShowCellDecayPanel() 
     90        "3 Flipper States",ShowFlipperPanel() 
     91        "4 Polarization Correction",ShowPolCorSetup() 
     92End 
     93 
    8694 
    8795// 
     
    96104// Te=num 
    97105// err_Te=num 
    98 // mu=nnum 
     106// mu=num 
    99107// err_mu=num 
    100108// 
     
    103111// all of the strings start w/ "gCell_" 
    104112// 
    105 Macro ShowCellParamPanel() 
     113Proc ShowCellParamPanel() 
    106114         
    107115        // init folders 
     
    359367// all of the strings start w/ "gDecay_" 
    360368// 
    361 Macro ShowCellDecayPanel() 
     369Proc ShowCellDecayPanel() 
    362370         
    363371        // init folders 
     
    426434        Button button_6,pos={620,620},size={100,20},proc=WindowSnapshotButton,title="Snapshot" 
    427435        Button button_7,pos={620,580},size={130,20},proc=ManualEnterDecayButton,title="Manual Entry" 
    428  
     436        CheckBox check0,mode=0,pos={600,550},title="Overrride T0?",value=0 
    429437 
    430438 
     
    561569                        SetDataFolder root: 
    562570                         
     571                        // 
     572                        // now show the fit results, if any, from the wave note 
     573                        // 
     574                        SVAR gMuPo = root:Packages:NIST:Polarization:Cells:gMuPo 
     575                        SVAR gPo  = root:Packages:NIST:Polarization:Cells:gPo 
     576                        SVAR gGamma  = root:Packages:NIST:Polarization:Cells:gGamma 
     577                        SVAR gT0  = root:Packages:NIST:Polarization:Cells:gT0 
     578                        String nStr=note(decay) 
     579                         
     580 
     581                        // for the panel display 
     582                        sprintf gMuPo, "%g +/- %g",NumberByKey("muP", nStr, "=",","),NumberByKey("err_muP", nStr, "=",",") 
     583                        sprintf gPo, "%g +/- %g",NumberByKey("P0", nStr, "=",","),NumberByKey("err_P0", nStr, "=",",") 
     584                        sprintf gGamma, "%g +/- %g",NumberByKey("gamma", nStr, "=",","),NumberByKey("err_gamma", nStr, "=",",") 
     585                        gT0 = StringByKey("T0", nStr, "=",",") 
     586                 
     587                         
     588                        // clear the graph - force the user to update it manually 
     589                        // clear old data, and plot the new 
     590                        // 
     591                        SetDataFolder root:Packages:NIST:Polarization:Cells: 
     592 
     593                        CheckDisplayed/W=DecayPanel#G0 tmp_muP,tmp_muP2,fit_tmp_muP 
     594                        // if both present, bit 0 + bit 1 = 3 
     595                        if(V_flag & 2^0)                        //check bit 0 
     596                                RemoveFromGraph/W=DecayPanel#G0 tmp_muP 
     597                        endif 
     598                        if(V_flag & 2^1) 
     599                                RemoveFromGraph/W=DecayPanel#G0 tmp_muP2 
     600                        endif 
     601                        if(V_flag & 2^2) 
     602                                RemoveFromGraph/W=DecayPanel#G0 fit_tmp_muP 
     603                        endif 
     604                         
     605                        // kill the text box (name is hard-wired) 
     606                        TextBox/W=DecayPanel#G0/K/N=CF_tmp_muP 
     607                         
     608                        setDataFolder root: 
     609                         
    563610                        break 
    564611                case -1: // control being killed 
     
    588635         
    589636        // generate the dummy wave note now, change as needed 
    590         Note decay, "muP=2,err_muP=0,P0=0.6,err_P0=0,T0=asdf,gamma=200,err_gamma=0," 
     637        Note decay, "muP=0,err_muP=0,P0=0,err_P0=0,T0=undefined,gamma=0,err_gamma=0," 
    591638         
    592639        // to hold the results of the calculation 
     
    657704//                      selRow = V_startRow 
    658705 
    659                         Variable sum_muP, err_avg_muP, sum_Po, err_avg_Po, avg_muP, avg_Po 
     706                        Variable sum_muP, err_avg_muP, sum_Po, err_avg_Po, avg_muP, avg_Po, overrideT0 
    660707                        sum_muP = 0 
    661708                        sum_Po = 0 
     
    663710                        err_avg_Po = 0 
    664711                         
     712                        ControlInfo/W=DecayPanel check0 
     713                        overrideT0 = V_Value 
     714                         
    665715                        for(selRow=0;selRow<numRows;selRow+=1) 
    666716                                Print "calculate the row ",selRow 
    667717 
    668                                 if(selRow == 0) 
     718                                if(selRow == 0 && !overrideT0) 
    669719                                        //find T0 
    670720                                        fname = FindFileFromRunNumber(w[0][%Trans_He_In]) 
     
    677727                                        Note w, noteStr 
    678728                                        Print t0str 
    679                                         w[selRow][%elapsed_hr] = 0                      //by definition 
     729                                else 
     730                                        // manually entered on the panel to override the  
     731                                        SVAR gT0 = root:Packages:NIST:Polarization:Cells:gT0 
     732                                        t0Str = gT0 
     733                                        noteStr = note(w) 
     734                                        noteStr = ReplaceStringByKey("T0", noteStr, gT0  ,"=", ",", 0) 
     735                                        Note/K w 
     736                                        Note w, noteStr 
     737                                        Print t0str 
    680738                                endif 
    681739                                 
Note: See TracChangeset for help on using the changeset viewer.