Changeset 5175 for trunk/GSASIIimage.py


Ignore:
Timestamp:
Feb 10, 2022 1:37:48 PM (14 months ago)
Author:
vondreele
Message:

Add a Calculate Rings menu item to Image/Calibrate?; useful for very difficult cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r5008 r5175  
    3636#import GSASIImath as G2mth
    3737import GSASIIfiles as G2fil
     38import ImageCalibrants as calFile
    3839
    3940# trig functions in degrees
     
    825826                tam[iBeg:iFin,jBeg:jFin] = True
    826827    return tam.T
    827    
     828
     829def CalcRings(G2frame,ImageZ,data,masks):
     830    pixelSize = data['pixelSize']
     831    scalex = 1000./pixelSize[0]
     832    scaley = 1000./pixelSize[1]
     833    data['rings'] = []
     834    data['ellipses'] = []
     835    if not data['calibrant']:
     836        G2fil.G2Print ('warning: no calibration material selected')
     837        return   
     838    skip = data['calibskip']
     839    dmin = data['calibdmin']
     840    if data['calibrant'] not in calFile.Calibrants:
     841        G2fil.G2Print('Warning: %s not in local copy of image calibrants file'%data['calibrant'])
     842        return
     843    calibrant = calFile.Calibrants[data['calibrant']]
     844    Bravais,SGs,Cells = calibrant[:3]
     845    HKL = []
     846    for bravais,sg,cell in zip(Bravais,SGs,Cells):
     847        A = G2lat.cell2A(cell)
     848        if sg:
     849            SGData = G2spc.SpcGroup(sg)[1]
     850            hkl = G2pwd.getHKLpeak(dmin,SGData,A,Inst=None,nodup=True)
     851            HKL += list(hkl)
     852        else:
     853            hkl = G2lat.GenHBravais(dmin,bravais,A)
     854            HKL += list(hkl)
     855    if len(calibrant) > 5:
     856        absent = calibrant[5]
     857    else:
     858        absent = ()
     859    HKL = G2lat.sortHKLd(HKL,True,False)
     860    wave = data['wavelength']
     861    frame = masks['Frames']
     862    tam = ma.make_mask_none(ImageZ.shape)
     863    if frame:
     864        tam = ma.mask_or(tam,MakeFrameMask(data,frame))
     865    for iH,H in enumerate(HKL):
     866        if debug:   print (H)
     867        dsp = H[3]
     868        tth = 2.0*asind(wave/(2.*dsp))
     869        if tth+abs(data['tilt']) > 90.:
     870            G2fil.G2Print ('next line is a hyperbola - search stopped')
     871            break
     872        ellipse = GetEllipse(dsp,data)
     873        if iH not in absent and iH >= skip:
     874            Ring = makeRing(dsp,ellipse,0,-1.,scalex,scaley,ma.array(ImageZ,mask=tam))[0]
     875        else:
     876            Ring = makeRing(dsp,ellipse,0,-1.,scalex,scaley,ma.array(ImageZ,mask=tam))[0]
     877        if Ring:
     878            if iH not in absent and iH >= skip:
     879                data['rings'].append(np.array(Ring))
     880        data['ellipses'].append(copy.deepcopy(ellipse+('r',)))   
     881   
    828882def ImageRecalibrate(G2frame,ImageZ,data,masks,getRingsOnly=False):
    829883    '''Called to repeat the calibration on an image, usually called after
     
    838892      or an empty list, in case of an error
    839893    '''
    840     import ImageCalibrants as calFile
    841894    if not getRingsOnly:
    842895        G2fil.G2Print ('Image recalibration:')
     
    937990    selected for the inner ring.
    938991    '''
    939     import ImageCalibrants as calFile
    940992    G2fil.G2Print ('Image calibration:')
    941993    time0 = time.time()
Note: See TracChangeset for help on using the changeset viewer.