Changeset 263


Ignore:
Timestamp:
Mar 13, 2011 2:02:45 PM (11 years ago)
Author:
vondreele
Message:

more tweaking of ellipse fitting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r262 r263  
    6060    if delta:
    6161        err,parms = FitEllipse(ring)
    62     errc,parmsc = FitCircle(ring)
    63     errc = errc[0]/(len(ring)*parmsc[2][0]**2)
    64 #    print 'Ellipse?',err,parms,len(ring)
    65 #    print 'Circle? ',errc,parmsc
    66     if not parms or errc < .1:
    67         parms = parmsc
     62        errc,parmsc = FitCircle(ring)
     63        errc = errc[0]/(len(ring)*parmsc[2][0]**2)
     64        if not parms or errc < .1:
     65            parms = parmsc
     66    else:
     67        err,parms = FitCircle(ring)
    6868    return parms
    6969       
     
    182182        X = (cphi*x-sphi*y+cent[0])*scalex      #convert mm to pixels
    183183        Y = (sphi*x+cphi*y+cent[1])*scaley
    184         X,Y,I,J = ImageLocalMax(image,pix,X,Y)     
     184        X,Y,I,J = ImageLocalMax(image,pix,X,Y)
    185185        if I and J and I/J > reject:
    186186            X += .5                             #set to center of pixel
     
    191191            amax = max(amax,a)
    192192            ring.append([X,Y,dsp])
     193    delt = amax-amin
    193194    if len(ring) < 20:             #want more than 20 deg
    194         return [],amax-amin
    195     return ring,amax-amin > 90
     195        return [],delt > 90
     196    return ring,delt > 90
    196197   
    197198def makeIdealRing(ellipse,azm=None):
     
    316317    else:
    317318        return image[::scale,::scale]
     319       
     320def checkEllipse(Zsum,distSum,xSum,ySum,dist,x,y):
     321    avg = np.array([distSum/Zsum,xSum/Zsum,ySum/Zsum])
     322    curr = np.array([dist,x,y])
     323    return abs(avg-curr)/avg < .02
     324
    318325       
    319326def ImageCalibrate(self,data):
     
    412419            dist = calcDist(radii,tth)
    413420            distR = 1.-dist/data['distance']
    414             if abs(distR) > 0.01:
    415                 continue
     421            if abs(distR) > 0.1:
     422                print dsp,dist,data['distance'],distR,len(Ring),delt
     423                break
    416424            if distR > 0.001:
    417425                print 'Wavelength too large?'
     
    420428            else:
    421429                ellipse = newellipse
    422                 if abs((radii[1]/radii[0]-ratio)/ratio) > 0.1:
    423                     print 'Bad fit for ring # %i. Try reducing Pixel search range'%(i)
    424                     return False
     430#                if abs((radii[1]/radii[0]-ratio)/ratio) > 0.1:
     431#                    print 'Bad fit for ring # %i. Try reducing Pixel search range'%(i)
     432#                    return False
    425433            zdis,cosB = calcZdisCosB(radius,tth,radii)
    426434            Tilt = acosd(cosB)          # 0 <= tilt <= 90
     
    442450                ySum += numZ*data['center'][1]
    443451                tiltSum += numZ*abs(Tilt)
     452                if not np.all(checkEllipse(Zsum,distSum,xSum,ySum,dist,data['center'][0],data['center'][1])):
     453                    print 'Bad ellipse. Try reducing Pixel search range'
    444454            cent = data['center']
    445             print ('for ring # %2i dist %.3f rotate %6.2f tilt %6.2f Xcent %.3f Ycent %.3f Npts %d'
    446                 %(i,dist,phi,Tilt,cent[0],cent[1],numZ))
     455            print ('for ring # %2i @ d-space %.4f: dist %.3f rotate %6.2f tilt %6.2f Xcent %.3f Ycent %.3f Npts %d'
     456                %(i,dsp,dist,phi,Tilt,cent[0],cent[1],numZ))
    447457            data['ellipses'].append(copy.deepcopy(ellipse+('r',)))
    448458        else:
Note: See TracChangeset for help on using the changeset viewer.