Ignore:
Timestamp:
Oct 27, 2010 6:11:50 PM (12 years ago)
Author:
srkline
Message:

Fixing bugs associated with 2D fitting, making sure that smeared and unsmeared 2D models both fit correctly and report errors to the FitManager?.

Added "_v40" extension to the Raspberry models. These models still need to be added to the Procedure list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Common/Packages/PlotManager/PlotUtils2D_v40.ipf

    r754 r762  
    103103                w1 = CleanupName((S_fileName + "_qy"),0) 
    104104                w2 = CleanupName((S_fileName + "_i"),0) 
    105          
     105                w3 = CleanupName((S_fileName + "_iErr"),0)              //make a name for the error wave, to be generated here 
     106 
    106107                String baseStr=w1[0,strlen(w1)-4] 
    107108                if(DataFolderExists("root:"+baseStr)) 
     
    135136                Duplicate/O $("root:"+n1), $w1 
    136137                Duplicate/O $("root:"+n2), $w2 
     138         
     139 
     140 
     141                // generate my own error wave for I(qx,qy). This is exactly the same procedure that is used in the QxQy_Export function 
     142                Duplicate/O $("root:"+n0), $w3 
     143                $w3 = sqrt($w2)         //assumes Poisson statistics for each cell (counter) 
     144                //      sw = 0.05*sw            // uniform 5% error? tends to favor the low intensity too strongly 
     145                // get rid of the "bad" errorsby replacing the NaN, Inf, and zero with V_avg 
     146                // THIS IS EXTREMEMLY IMPORTANT - if this is not done, there are some "bad" values in the  
     147                // error wave (things that are not numbers) - and this wrecks the smeared model fitting. 
     148                // It appears to have no effect on the unsmeared model. 
     149                WaveStats/Q $w3 
     150                $w3 = numtype($w3[p]) == 0 ? $w3[p] : V_avg 
     151                $w3 = $w3[p] != 0 ? $w3[p] : V_avg 
    137152         
    138153        endif           //3-columns 
     
    569584// 
    570585// Currently the limitations are: 
    571 // - I have no error waves for the intensity 
    572 // - There is no smeared model 
     586// - I have no error waves for the intensity (fixed 10/2010) 
     587// - There is no smeared model (coming soon after 10/2010) 
    573588// - Cursors can't be used 
    574 // - the report *probably* won't work 
     589// - the report works OK, but I have little control over the graphics 
     590// - the mask is generated here with a default radius of 8 pixels around the beam center 
     591// 
    575592Function FitWrapper2D(folderStr,funcStr,coefStr,useCursors,useEps,useConstr) 
    576593        String folderStr,funcStr,coefStr 
    577594        Variable useCursors,useEps,useConstr 
    578595 
     596        //These only make sense for the 1D fits, but put them here so keep the look of the dispatching the same 
     597        Variable useResiduals, useTextBox 
     598        useResiduals = 0 
     599        useTextBox = 0 
     600         
    579601        String suffix=getModelSuffix(funcStr) 
    580602         
     
    596618         
    597619// fill a struct instance whether I need one or not 
     620// note that the resolution waves may or may not exist, and may or may not be used in the fitting 
    598621        String DF="root:"+folderStr+":"  
    599622         
     
    602625        WAVE qx=$(DF+folderStr+"_qx") 
    603626        WAVE qy=$(DF+folderStr+"_qy") 
    604         WAVE qz=$(DF+folderStr+"_qz") 
    605         WAVE sQpl=$(DF+folderStr+"_sQpl") 
    606         WAVE sQpp=$(DF+folderStr+"_sQpp") 
    607         WAVE shad=$(DF+folderStr+"_fs") 
     627        WAVE/Z qz=$(DF+folderStr+"_qz") 
     628        WAVE/Z sQpl=$(DF+folderStr+"_sQpl") 
     629        WAVE/Z sQpp=$(DF+folderStr+"_sQpp") 
     630        WAVE/Z shad=$(DF+folderStr+"_fs") 
    608631 
    609632//just a dummy - I shouldn't need this 
     
    616639        WAVE s.xw[0] = qx 
    617640        WAVE s.xw[1] = qy 
    618         WAVE s.qz = qz 
    619         WAVE s.sQpl = sQpl 
    620         WAVE s.sQpp = sQpp 
    621         WAVE s.fs = shad 
     641        WAVE/Z s.qz = qz 
     642        WAVE/Z s.sQpl = sQpl 
     643        WAVE/Z s.sQpp = sQpp 
     644        WAVE/Z s.fs = shad 
    622645         
    623646 
     
    637660 
    638661        //for now, use res will always be 0 for 2D functions     
    639         Variable useRes=0 
     662        Variable useResol=0 
    640663        if(stringmatch(funcStr, "Smear*"))              // if it's a smeared function, need a struct 
    641                 useRes=1 
     664                useResol=1 
    642665        endif 
    643666 
     
    648671                useConstr = 0 
    649672        endif    
     673        WAVE/Z constr=constr            //will be a null reference 
    650674         
    651675//      // do not construct constraints for any of the coefficients that are being held 
     
    671695//      endif 
    672696 
     697        if(useCursors) 
     698                Print "Cursors not yet implemented" 
     699                useCursors = 0 
     700        endif    
    673701///// NO CURSORS for 2D waves 
    674702        //if useCursors, and the data is USANS, need to feed a (reassigned) trimmed matrix to the fit 
    675 //      Variable pt1,pt2,newN 
     703        Variable pt1,pt2,newN 
     704        pt1 = 0 
     705        pt2 = numpnts(inten)-1 
    676706//      if(useCursors && (dimsize(resW,1) > 4) ) 
    677707//              if(pcsr(A) > pcsr(B)) 
     
    698728        //      FuncFit/H="11110111111"/NTHR=0 Cylinder2D_D :cyl2d_c_txt:coef_Cyl2D_D  :cyl2d_c_txt:cyl2d_c_txt_i /X={:cyl2d_c_txt:cyl2d_c_txt_qy,:cyl2d_c_txt:cyl2d_c_txt_qx} /W=:cyl2d_c_txt:sw /I=1 /M=:cyl2d_c_txt:mask /D  
    699729        Variable t1=StopMSTimer(-2) 
    700  
     730        Variable tb = 0         //no textbox 
    701731 
    702732// /NTHR=1 means just one thread for the fit (since the function itself is threaded) 
     733// NTHR = 0 == "Auto" mode, using as many processors as are available (not appropriate here since the function itself is threaded?) 
    703734 
    704735        do 
    705                 if(useRes && useEps && useCursors && useConstr)         //do it all 
    706                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /STRC=s 
     736         
     737                        // now useCursors, useEps, and useConstr are all handled w/ /NWOK, just like FitWrapper 
     738 
     739 
     740//              if(useResol && useResiduals && useTextBox)              //do it all 
     741//                      FuncFit/H=getHStr(hold) /NTHR=0 /TBOX=(tb) $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /STRC=s /R /NWOK 
     742//                      break 
     743//              endif 
     744//               
     745//              if(useResol && useResiduals)            //res + resid 
     746//                      FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /STRC=s /R /NWOK 
     747//                      break 
     748//              endif 
     749// 
     750//               
     751//              if(useResol && useTextBox)              //res + text 
     752//                      FuncFit/H=getHStr(hold) /NTHR=0 /TBOX=(tb) $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /STRC=s /NWOK 
     753//                      break 
     754//              endif 
     755                 
     756                if(useResol)            //res only 
     757                        Print "useRes only" 
     758                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /STRC=s /NWOK 
    707759                        break 
    708760                endif 
    709                  
    710                 if(useRes && useEps && useCursors)              //no constr 
    711                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /STRC=s 
     761                         
     762                                 
     763/////   same as above, but all without useResol (no /STRC flag) 
     764                if(useResiduals && useTextBox)          //resid+ text 
     765                        FuncFit/H=getHStr(hold) /NTHR=0 /TBOX=(tb) $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /R /NWOK 
    712766                        break 
    713767                endif 
    714768                 
    715                 if(useRes && useEps && useConstr)               //no crsr 
    716                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /STRC=s 
     769                if(useResiduals)                //resid 
     770                        FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /R /NWOK 
    717771                        break 
    718772                endif 
    719                  
    720                 if(useRes && useCursors && useConstr)           //no eps 
    721                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /C=constr /STRC=s 
     773 
     774                 
     775                if(useTextBox)          //text 
     776                        FuncFit/H=getHStr(hold) /NTHR=0 /TBOX=(tb) $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /NWOK 
    722777                        break 
    723778                endif 
    724779                 
    725                 if(useRes && useCursors)                //no eps, no constr 
    726                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /STRC=s 
    727                         break 
    728                 endif 
    729                  
    730                 if(useRes && useEps)            //no crsr, no constr 
    731                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /STRC=s 
    732                         break 
    733                 endif 
    734          
    735                 if(useRes && useConstr)         //no crsr, no eps 
    736                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /C=constr /STRC=s 
    737                         break 
    738                 endif 
    739                  
    740                 if(useRes)              //just res 
    741                         Print "useRes only" 
    742                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /STRC=s 
    743 //                      FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /W=sw /I=1 /STRC=s 
    744 //                      FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 
    745 //                      FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten_masked /X={Qx,Qy} /W=sw /I=1 /STRC=s 
    746                         break 
    747                 endif 
    748                  
    749 /////   same as above, but all without useRes (no /STRC flag) 
    750                 if(useEps && useCursors && useConstr)           //do it all 
    751                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr 
    752                         break 
    753                 endif 
    754                  
    755                 if(useEps && useCursors)                //no constr 
    756                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps 
    757                         break 
    758                 endif 
    759                  
    760                  
    761                 if(useEps && useConstr)         //no crsr 
    762                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr 
    763                         break 
    764                 endif 
    765                  
    766                 if(useCursors && useConstr)             //no eps 
    767                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 /C=constr 
    768                         break 
    769                 endif 
    770                  
    771                 if(useCursors)          //no eps, no constr 
    772                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten[pcsr(A),pcsr(B)] /X={Qx,Qy} /M=mask /W=sw /I=1 
    773                         break 
    774                 endif 
    775                  
    776                 if(useEps)              //no crsr, no constr 
    777                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps 
    778                         break 
    779                 endif 
    780          
    781                 if(useConstr)           //no crsr, no eps 
    782                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 /C=constr 
    783                         break 
    784                 endif 
    785                  
    786780                //just a plain vanilla fit 
    787                 print "unsmeared vanilla" 
    788                         FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /M=mask /W=sw /I=1 
    789 //                      FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten /X={Qx,Qy} /W=sw /I=1 
    790 //                      FuncFit/H=getHStr(hold) /NTHR=1 $funcStr cw, inten_masked /X={Qx,Qy} /W=sw /I=1 
    791          
     781 
     782                FuncFit/H=getHStr(hold) /NTHR=0 $funcStr cw, inten[pt1,pt2] /X={Qx,Qy} /M=mask /W=sw /I=1 /E=eps /C=constr /NWOK 
     783                 
    792784        while(0) 
    793785         
     
    814806        print w_sigma 
    815807        String resultStr="" 
     808         
     809        if(waveexists(W_sigma)) 
     810                //append it to the table, if it's not already there 
     811                CheckDisplayed/W=WrapperPanel#T0 W_sigma 
     812                if(V_flag==0) 
     813                        //not there, append it 
     814                        AppendtoTable/W=wrapperPanel#T0 W_sigma 
     815                else 
     816                        //remove it, and put it back on to make sure it's the right one (do I need to do this?) 
     817                        // -- not really, since any switch of the function menu takes W_Sigma off 
     818                endif 
     819        endif 
    816820                 
    817821        //now re-write the results 
Note: See TracChangeset for help on using the changeset viewer.