- Timestamp:
- Jun 4, 2014 4:01:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/Dev/trunk/NCNR_User_Procedures/Analysis/Alpha/Tinker/FFT_KR_Parser.ipf
r940 r941 373 373 // sld = SLD of cylinder 374 374 // 375 //376 //377 375 // Put this into a panel with the table and the data 378 376 // and fields for all of the inputs … … 414 412 415 413 414 415 416 416 Function KR_Plot1DButtonProc(ba) : ButtonControl 417 417 STRUCT WMButtonAction &ba … … 613 613 614 614 ///////////////////////////////////// 615 // 616 // 617 // for the "manual" fitting 618 // 619 620 Proc Vary_One_Cyl_Param(waveStr,row,percent,numStep) 621 // pick the wave and row and % 622 String waveStr="xx" 623 Variable row=1 624 Variable percent = 105 625 Variable numStep = 10 626 Prompt waveStr,"wave",popup,"xx;yy;zz;rri;hti;rotx;roty;sld;" 627 628 print waveStr 629 630 // dispatch to calculation 631 MultiCyl_Loop($waveStr,row,percent,numStep) 632 633 // plot the chi2_map 634 DoWindow/F MultiCyl_ChiMap 635 if(V_flag==0) 636 MultiCyl_ChiMap() 637 endif 638 639 end 640 641 Function MultiCyl_Loop(w,row,percent,numStep) 642 Wave w 643 Variable row,percent,numStep 644 645 Variable loLim,hiLim,ii,minIndex,minChiSq 646 String folderStr 647 648 Make/O/D/N=(numStep) chi2_map,testVals 649 Wave chi2_map=chi2_map 650 Wave testVals=testVals 651 652 loLim = w[row] - percent*w[row]/100 653 hiLim = w[row] + percent*w[row]/100 654 testVals = loLim + x*(hiLim-loLim)/numStep 655 656 // the experimental data 657 ControlInfo/W=WrapperPanel popup_0 658 folderStr=S_Value 659 // wave references for the data (to pass) 660 String DF="root:"+folderStr+":" 661 662 WAVE yw=$(DF+folderStr+"_i") 663 WAVE xw=$(DF+folderStr+"_q") 664 WAVE sw=$(DF+folderStr+"_s") 665 666 duplicate/o yw, interpCalc,chi2_data 667 Wave chi2_data=chi2_data 668 Wave interpCalc=interpCalc 669 670 STRUCT WMButtonAction ba 671 ba.eventCode = 2 672 673 // loop 674 for(ii=0;ii<numStep;ii+=1) 675 // set the value 676 w[row] = testVals[ii] 677 // generate the structure 678 // 679 KR_GenerateButtonProc(ba) 680 681 // do the calculation 682 KR_DoCalcButtonProc(ba) 683 684 WAVE ival_KR=ival_KR 685 WAVE qval_KR=qval_KR 686 687 interpCalc = interp(xw, qval_KR, ival_KR ) 688 689 // calculate chi-squared 690 chi2_data = (yw-interpCalc)^2 691 chi2_data /= sw^2 692 693 694 Wavestats/Q chi2_data 695 chi2_map[ii] = V_avg * V_npnts 696 // end loop 697 endfor 698 699 // find the best chi squared 700 WaveStats/Q chi2_map 701 // reset the value to the best 702 minIndex = V_minRowLoc 703 w[row] = testVals[minIndex] 704 705 minChiSq = chi2_map[minIndex] 706 print "Minimum chi2 = ",minChiSq 707 708 709 // and then recalculate at the best solution 710 KR_GenerateButtonProc(ba) 711 712 // do the calculation 713 KR_DoCalcButtonProc(ba) 714 715 return(0) 716 End 717 718 Proc MultiCyl_ChiMap() 719 PauseUpdate; Silent 1 // building window... 720 Display /W=(35,44,466,414) chi2_map vs testVals 721 DoWindow/C MultiCyl_ChiMap 722 ModifyGraph mode=4 723 ModifyGraph marker=19 724 ModifyGraph msize=2 725 Label left "chi-squared" 726 Label bottom "test values" 727 end 728 729 //Function testKRPar() 730 // 731 // Variable row, col 732 // String wStr 733 // 734 // getParamFromKRSetup(row,col,wStr) 735 // Print row, col, wStr 736 // 737 // wStr = StringFromList(0, wStr) // some wave "xx.d" 738 // wStr = StringFromList(0, wStr, ".") // removes the ".d" 739 // Wave w=$wStr 740 // print w[row] 741 // 742 // Variable numStep,loLim,hiLim,percent 743 // numStep = 25 744 // percent = 50 745 // 746 // loLim = w[row] - percent*w[row]/100 747 // hiLim = w[row] + percent*w[row]/100 748 // 749 // 750 // Make/O/D/N=(numStep) testKRVals 751 // testKRVals = loLim + x*(hiLim-loLim)/numStep 752 // 753 // print testKRvals 754 // return(0) 755 // 756 //End 757 // 758 //Function getParamFromKRSetup(row,col,wStr) 759 // Variable &row,&col 760 // String &wStr 761 // 762 // Variable parNum 763 // 764 // GetSelection table, MultiCyl#T0, 3 765 // row = V_startRow 766 // col = V_startCol 767 // Print S_Selection 768 // wStr = S_Selection 769 // 770 // 771 // return(0) 772 //End 773 774 Proc Vary_Two_Cyl_Param(waveStr,row,waveStr2,row2,percent,percent2,numStep) 775 // pick the wave and row and % 776 String waveStr="xx" 777 Variable row=1 778 String waveStr2="rri" 779 Variable row2=0 780 Variable percent = 105 781 Variable percent2 = 50 782 Variable numStep=5 783 Prompt waveStr,"wave",popup,"xx;yy;zz;rri;hti;rotx;roty;sld;" 784 Prompt waveStr2,"wave2",popup,"xx;yy;zz;rri;hti;rotx;roty;sld;" 785 786 // dispatch to calculation 787 MultiCyl_Loop_2D($waveStr,row,$waveStr2,row2,percent,percent2,numStep) 788 789 // plot the chi2_map 790 DoWindow/F MultiCyl_ChiMap_2D 791 if(V_flag==0) 792 MultiCyl_ChiMap_2D() 793 else 794 //V_min*1.01 = the 1% neighborhood around the solution 795 WaveStats/Q chi2_Map_2D 796 ModifyImage/W=MultiCyl_ChiMap_2D chi2_Map_2D ctab= {(V_min*1.01),*,ColdWarm,0} 797 ModifyImage/W=MultiCyl_ChiMap_2D chi2_Map_2D minRGB=(0,65535,0),maxRGB=(0,65535,0) 798 endif 799 800 end 801 802 803 Function MultiCyl_Loop_2D(w,row,w2,row2,percent,percent2,numStep) 804 Wave w 805 Variable row 806 Wave w2 807 Variable row2,percent,percent2,numStep 808 809 Variable loLim,hiLim,ii,jj,minIndex,minChiSq 810 String folderStr 811 812 Make/O/D/N=(numStep,numStep) chi2_Map_2D 813 Make/O/D/N=(numStep) testVals,testVals2 814 Wave chi2_Map_2D=chi2_Map_2D 815 Wave testVals=testVals 816 Wave testVals2=testVals2 817 818 testVals = 0 819 testVals2 = 0 820 chi2_Map_2D = 0 821 822 823 loLim = w[row] - percent*w[row]/100 824 hiLim = w[row] + percent*w[row]/100 825 testVals = loLim + x*(hiLim-loLim)/(numStep-1) 826 // Print lolim,hilim 827 828 SetScale/I x LoLim,HiLim,"", chi2_Map_2D 829 830 loLim = w2[row2] - percent2*w2[row2]/100 831 hiLim = w2[row2] + percent2*w2[row2]/100 832 testVals2 = loLim + x*(hiLim-loLim)/(numStep-1) 833 // Print lolim,hilim 834 835 SetScale/I y LoLim,HiLim,"", chi2_Map_2D 836 837 838 // the experimental data 839 ControlInfo/W=WrapperPanel popup_0 840 folderStr=S_Value 841 // wave references for the data (to pass) 842 String DF="root:"+folderStr+":" 843 844 WAVE yw=$(DF+folderStr+"_i") 845 WAVE xw=$(DF+folderStr+"_q") 846 WAVE sw=$(DF+folderStr+"_s") 847 848 duplicate/o yw, interpCalc,chi2_data 849 Wave chi2_data=chi2_data 850 Wave interpCalc=interpCalc 851 852 STRUCT WMButtonAction ba 853 ba.eventCode = 2 854 855 // double loop 856 for(ii=0;ii<numStep;ii+=1) 857 Print " Outer Loop Index = ",ii," out of ",numStep 858 //set the value from the outer loop 859 w[row] = testVals[ii] 860 861 for(jj=0;jj<numStep;jj+=1) 862 863 // set the inner value 864 w2[row2] = testVals2[jj] 865 // generate the structure 866 // 867 KR_GenerateButtonProc(ba) 868 869 // do the calculation 870 KR_DoCalcButtonProc(ba) 871 872 WAVE ival_KR=ival_KR 873 WAVE qval_KR=qval_KR 874 875 interpCalc = interp(xw, qval_KR, ival_KR ) 876 877 // calculate chi-squared 878 chi2_data = (yw-interpCalc)^2 879 chi2_data /= sw^2 880 881 Wavestats/Q chi2_data 882 chi2_Map_2D[ii][jj] = V_avg * V_npnts 883 884 endfor 885 endfor 886 887 888 // find the best chi squared 889 WaveStats/Q chi2_Map_2D 890 // reset the value to the best 891 w[row] = V_MinRowLoc 892 w2[row2] = V_MinColLoc 893 894 minChiSq = V_Min 895 print "Minimum chi2 = ",minChiSq 896 897 // and then recalculate at the best solution 898 KR_GenerateButtonProc(ba) 899 900 // do the calculation 901 KR_DoCalcButtonProc(ba) 902 903 return(0) 904 End 905 906 Proc MultiCyl_ChiMap_2D() 907 PauseUpdate; Silent 1 // building window... 908 Display /W=(35,44,466,414) 909 AppendImage chi2_Map_2D 910 DoWindow/C MultiCyl_ChiMap_2D 911 ModifyImage chi2_Map_2D ctab= {*,*,ColdWarm,0} 912 913 //V_min*1.01 = the 1% neighborhood around the solution 914 WaveStats/Q chi2_Map_2D 915 ModifyImage/W=MultiCyl_ChiMap_2D chi2_Map_2D ctab= {(V_min*1.01),*,ColdWarm,0} 916 ModifyImage/W=MultiCyl_ChiMap_2D chi2_Map_2D minRGB=(0,65535,0),maxRGB=(0,65535,0) 917 918 Label bottom "test values" 919 Label left "test values" 920 end
Note: See TracChangeset
for help on using the changeset viewer.