Changeset 1245


Ignore:
Timestamp:
Mar 12, 2014 11:15:28 AM (8 years ago)
Author:
vondreele
Message:

Make SASD plot default to log & show errors
SASD MaxEnt? result now matches Irena result

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIplot.py

    r1244 r1245  
    699699        Plot = Page.figure.gca()          #get a fresh plot after clf()
    700700    except ValueError:
     701        if plottype == 'SASD':
     702            G2frame.logPlot = True
     703            G2frame.ErrorBars = True
    701704        newPlot = True
    702705        G2frame.Cmax = 1.0
  • trunk/GSASIIsasd.py

    r1244 r1245  
    105105    ''' Compute form factor for cylinders - can use numpy arrays
    106106    param float: Q Q value array (A-1)
    107     param float: L cylinder length (A)
    108     param float: D cylinder diameter (A)
     107    param float: L cylinder half length (A)
     108    param float: R cylinder diameter (A)
    109109    returns float: form factor
    110110    '''
    111     D = args[0]
    112     return CylinderFF(Q,D/2.,L)   
     111    R = args[0]
     112    return CylinderFF(Q,R,2.*L)   
    113113   
    114114def CylinderARFF(Q,R,args):
     
    205205    ''' Compute cylinder volume for length & diameter
    206206    - numpy array friendly
    207     param float: L length (A)
     207    param float: L half length (A)
    208208    param float: D diameter (A)
    209209    returns float:volume (A^3)
    210210    '''
    211     return CylinderVol(D/2.,L)
     211    return CylinderVol(D/2.,2.*L)
    212212   
    213213def CylinderARVol(R,AR):
     
    322322    '''
    323323       
    324     TEST_LIMIT        = 0.10                    # for convergence
     324    TEST_LIMIT        = 0.05                    # for convergence
    325325    CHI_SQR_LIMIT     = 0.01                    # maximum difference in ChiSqr for a solution
    326326    SEARCH_DIRECTIONS = 3                       # <10.  This code requires value = 3
     
    482482        chtarg = ctarg * chisq
    483483        return w, chtarg, loop, a_new, fx, beta
     484       
    484485#MaxEnt_SB starts here   
     486
    485487    if image_to_data == None:
    486488        image_to_data = opus
     
    583585
    584586        # calculate the normalized entropy
    585         S = -sum((f/fSum) * numpy.log(f/fSum))      # normalized entropy, S&B eq. 1
     587        S = sum((f/fSum) * numpy.log(f/fSum))      # normalized entropy, S&B eq. 1
    586588        z = (datum - image_to_data (f, G)) / sigma  # standardized residuals
    587589        chisq = sum(z*z)                            # report this ChiSq
    588590
    589591        if report:
    590             print "%3d/%3d" % ((iter+1), IterMax)
    591             print " %5.2lf%% %8lg" % (100*test, S)
     592            print " MaxEnt trial/max: %3d/%3d" % ((iter+1), IterMax)
     593            print " Residual: %5.2lf%% Entropy: %8lg" % (100*test, S)
    592594            if iter > 0:
    593595                value = 100*( math.sqrt(chisq/chtarg)-1)
    594596            else:
    595597                value = 0
    596             print " %12.5lg %10.4lf" % ( math.sqrt (chtarg/npt), value )
    597             print "%12.6lg %8.2lf\n" % (fSum, 100*fChange/fSum)
     598      #      print " %12.5lg %10.4lf" % ( math.sqrt(chtarg/npt), value )
     599            print " Function sum: %.6lg Change from last: %.2lf%%\n" % (fSum,100*fChange/fSum)
    598600
    599601        # See if we have finished our task.
    600602        # do the hardest test first
    601603        if (abs(chisq/chizer-1.0) < CHI_SQR_LIMIT) and  (test < TEST_LIMIT):
    602             return f,image_to_data (f, G)     # solution FOUND returns here
    603    
    604     return f,image_to_data (f, G)       # no solution after IterMax iterations
     604            print ' Convergence achieved.'
     605            return chisq,f,image_to_data(f, G)     # solution FOUND returns here
     606    print ' No convergence! Try increasing Error multiplier.'
     607    return chisq,f,image_to_data(f, G)       # no solution after IterMax iterations
    605608
    606609   
     
    658661    G = G_matrix(qVec,r,rhosq,SphereFF,SphereVol,args=())
    659662   
    660     f_dr,Ic = MaxEnt_SB(I - bkg, dI*errFac, b, IterMax, G, report=report)
     663    chisq,f_dr,Ic = MaxEnt_SB(I - bkg, dI*errFac, b, IterMax, G, report=report)
    661664    if f_dr is None:
    662665        print "no solution"
     
    698701    Qmax = Limits[1][1]
    699702    Contrast = Sample['Contrast'][1]
     703    wtFactor = ProfDict['wtFactor']
    700704    Ibeg = np.searchsorted(Q,Qmin)
    701705    Ifin = np.searchsorted(Q,Qmax)
     
    704708        Ic[Ibeg:Ifin] = Back[0]
    705709    Gmat = G_matrix(Q[Ibeg:Ifin],Bins,Contrast,shapes[Shape][0],shapes[Shape][1],args=Parms)
    706     BinMag,Ic[Ibeg:Ifin] = MaxEnt_SB(Io[Ibeg:Ifin]-Back[0],1./np.sqrt(wt[Ibeg:Ifin]),BinsBack,
    707         data['Size']['MaxEnt']['Niter'],Gmat)
    708     print BinMag.shape
    709     data['Size']['Distribution'] = [Bins,Dbins,BinMag]
    710     print np.sum(BinMag)
    711        
    712    
     710    chisq,BinMag,Ic[Ibeg:Ifin] = MaxEnt_SB(Io[Ibeg:Ifin]-Back[0],1./np.sqrt(wtFactor*wt[Ibeg:Ifin]),BinsBack,
     711        data['Size']['MaxEnt']['Niter'],Gmat,report=True)
     712    print ' Final chi^2: %.3f'%(chisq)
     713    Vols = shapes[Shape][1](Bins,Parms)
     714    data['Size']['Distribution'] = [Bins,Dbins,BinMag/(2.*Dbins)]
     715       
     716   
Note: See TracChangeset for help on using the changeset viewer.