Changeset 4021 for trunk/GSASIIimage.py


Ignore:
Timestamp:
Jun 11, 2019 10:05:07 PM (2 years ago)
Author:
toby
Message:

implement filter for screen messages; start to replace print() with G2Print(); scripting changes for PDF

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIimage.py

    r4009 r4021  
    3434import GSASIIspc as G2spc
    3535import GSASIImath as G2mth
     36import GSASIIfiles as G2fil
    3637
    3738# trig functions in degrees
     
    566567    '''
    567568    import ImageCalibrants as calFile
    568     print ('Image recalibration:')
     569    G2fil.G2Print ('Image recalibration:')
    569570    time0 = time.time()
    570571    pixelSize = data['pixelSize']
     
    578579        data['DetDepth'] /= data['distance']
    579580    if not data['calibrant']:
    580         print ('no calibration material selected')
     581        G2fil.G2Print ('warning: no calibration material selected')
    581582        return []   
    582583    skip = data['calibskip']
    583584    dmin = data['calibdmin']
    584585    if data['calibrant'] not in calFile.Calibrants:
    585         print(' %s not in local copy of image calibrants file'%data['calibrant'])
     586        G2fil.G2Print('Warning: %s not in local copy of image calibrants file'%data['calibrant'])
    586587        return []
    587588    Bravais,SGs,Cells = calFile.Calibrants[data['calibrant']][:3]
     
    612613        tth = 2.0*asind(wave/(2.*dsp))
    613614        if tth+abs(data['tilt']) > 90.:
    614             print ('next line is a hyperbola - search stopped')
     615            G2fil.G2Print ('next line is a hyperbola - search stopped')
    615616            break
    616617        ellipse = GetEllipse(dsp,data)
     
    627628            continue
    628629    if not data['rings']:
    629         print ('no rings found; try lower Min ring I/Ib')
     630        G2fil.G2Print ('no rings found; try lower Min ring I/Ib',mode='warn')
    630631        return []   
    631632       
     
    644645        ellipse = GetEllipse(H[3],data)
    645646        data['ellipses'].append(copy.deepcopy(ellipse+('b',)))   
    646     print ('calibration time = %.3f'%(time.time()-time0))
     647    G2fil.G2Print ('calibration time = %.3f'%(time.time()-time0))
    647648    if G2frame:
    648649        G2plt.PlotImage(G2frame,newImage=True)       
     
    654655    '''
    655656    import ImageCalibrants as calFile
    656     print ('Image calibration:')
     657    G2fil.G2Print ('Image calibration:')
    657658    time0 = time.time()
    658659    ring = data['ring']
     
    664665    varyDict = data['varyList']
    665666    if varyDict['dist'] and varyDict['wave']:
    666         print ('ERROR - you can not simultaneously calibrate distance and wavelength')
     667        G2fil.G2Print ('ERROR - you can not simultaneously calibrate distance and wavelength')
    667668        return False
    668669    if len(ring) < 5:
    669         print ('ERROR - not enough inner ring points for ellipse')
     670        G2fil.G2Print ('ERROR - not enough inner ring points for ellipse')
    670671        return False
    671672       
     
    677678    fmt2 = '%s X: %.3f, Y: %.3f, phi: %.3f, R1: %.3f, R2: %.3f, chi**2: %.3f, Np: %d'
    678679    if outE:
    679         print (fmt%('start ellipse: ',outE[0][0],outE[0][1],outE[1],outE[2][0],outE[2][1]))
     680        G2fil.G2Print (fmt%('start ellipse: ',outE[0][0],outE[0][1],outE[1],outE[2][0],outE[2][1]))
    680681        ellipse = outE
    681682    else:
     
    690691        ellipse = FitEllipse(Ring)
    691692    else:
    692         print ('1st ring not sufficiently complete to proceed')
     693        G2fil.G2Print ('1st ring not sufficiently complete to proceed',mode='warn')
    693694        return False
    694695    if debug:
    695         print (fmt2%('inner ring:    ',ellipse[0][0],ellipse[0][1],ellipse[1],
     696        G2fil.G2Print (fmt2%('inner ring:    ',ellipse[0][0],ellipse[0][1],ellipse[1],
    696697            ellipse[2][0],ellipse[2][1],0.,len(Ring)))     #cent,phi,radii
    697698    data['ellipses'].append(ellipse[:]+('r',))
     
    702703    data['rings'] = []
    703704    if not data['calibrant']:
    704         print ('no calibration material selected')
     705        G2fil.G2Print ('Warning: no calibration material selected')
    705706        return True
    706707   
     
    715716            SGData = G2spc.SpcGroup(sg)[1]
    716717            hkl = G2pwd.getHKLpeak(dmin,SGData,A)
    717             print(hkl)
     718            G2fil.G2Print(hkl)
    718719            HKL += list(hkl)
    719720        else:
     
    724725    elcent,phi,radii = ellipse              #from fit of 1st ring
    725726    dsp = HKL[0][3]
    726     print ('1st ring: try %.4f'%(dsp))
     727    G2fil.G2Print ('1st ring: try %.4f'%(dsp))
    727728    if varyDict['dist']:
    728729        wave = data['wavelength']
     
    739740        tilt = npasind(np.sqrt(max(0.,1.-(radii[0]/radii[1])**2))*ctth)
    740741        if not tilt:
    741             print ('WARNING - selected ring was fitted as a circle')
    742             print (' - if detector was tilted we suggest you skip this ring - WARNING')
     742            G2fil.G2Print ('WARNING - selected ring was fitted as a circle')
     743            G2fil.G2Print (' - if detector was tilted we suggest you skip this ring - WARNING')
    743744    else:
    744745        tilt = data['tilt']
     
    763764        while fail:
    764765            dsp = HKL[i2][3]
    765             print ('2nd ring: try %.4f'%(dsp))
     766            G2fil.G2Print ('2nd ring: try %.4f'%(dsp))
    766767            tth = 2.0*asind(wave/(2.*dsp))
    767768            ellipsep = GetEllipse2(tth,0.,dist,centp,tilt,phi)
    768             print (fmt%('plus ellipse :',ellipsep[0][0],ellipsep[0][1],ellipsep[1],ellipsep[2][0],ellipsep[2][1]))
     769            G2fil.G2Print (fmt%('plus ellipse :',ellipsep[0][0],ellipsep[0][1],ellipsep[1],ellipsep[2][0],ellipsep[2][1]))
    769770            Ringp = makeRing(dsp,ellipsep,3,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    770771            parmDict = {'dist':dist,'det-X':centp[0],'det-Y':centp[1],
     
    780781                chip = 1e6
    781782            ellipsem = GetEllipse2(tth,0.,dist,centm,-tilt,phi)
    782             print (fmt%('minus ellipse:',ellipsem[0][0],ellipsem[0][1],ellipsem[1],ellipsem[2][0],ellipsem[2][1]))
     783            G2fil.G2Print (fmt%('minus ellipse:',ellipsem[0][0],ellipsem[0][1],ellipsem[1],ellipsem[2][0],ellipsem[2][1]))
    783784            Ringm = makeRing(dsp,ellipsem,3,cutoff,scalex,scaley,G2frame.ImageZ)[0]
    784785            if len(Ringm) > 10:
     
    817818        tth = 2.0*asind(wave/(2.*dsp))
    818819        if tth+abs(data['tilt']) > 90.:
    819             print ('next line is a hyperbola - search stopped')
     820            G2fil.G2Print ('next line is a hyperbola - search stopped')
    820821            break
    821822        if debug:   print ('HKLD:'+str(H[:4])+'2-theta: %.4f'%(tth))
     
    845846    fullSize = len(G2frame.ImageZ)/scalex
    846847    if 2*radii[1] < .9*fullSize:
    847         print ('Are all usable rings (>25% visible) used? Try reducing Min ring I/Ib')
     848        G2fil.G2Print ('Are all usable rings (>25% visible) used? Try reducing Min ring I/Ib')
    848849    N = len(data['ellipses'])
    849850    if N > 2:
     
    858859        ellipse = GetEllipse(H[3],data)
    859860        data['ellipses'].append(copy.deepcopy(ellipse+('b',)))
    860     print ('calibration time = %.3f'%(time.time()-time0))
     861    G2fil.G2Print ('calibration time = %.3f'%(time.time()-time0))
    861862    G2plt.PlotImage(G2frame,newImage=True)       
    862863    return True
     
    971972    'Integrate an image; called from OnIntegrateAll and OnIntegrate in G2imgGUI'    #for q, log(q) bins need data['binType']
    972973    import histogram2d as h2d
    973     print ('Begin image integration; image range: %d %d'%(np.min(image),np.max(image)))
     974    G2fil.G2Print ('Begin image integration; image range: %d %d'%(np.min(image),np.max(image)))
    974975    CancelPressed = False
    975976    LUtth = np.array(data['IOtth'])
     
    10451046            times[3] += time.time()-t0
    10461047#            print('done block %d %d %d %d %d %d %d %d'%(iBlk,iBeg,iFin,jBlk,jBeg,jFin,np.min(Block),np.max(Block)))
    1047     print('End integration loops')
     1048    G2fil.G2Print('End integration loops')
    10481049    t0 = time.time()
    10491050#    H2 = np.array([tth for tth in np.linspace(lutth[0],lutth[1],numChans+1)])
     
    10741075        H0 /= np.array([G2pwd.Polarization(data['PolaVal'][0],H2[:-1],Azm=azm-90.)[0] for azm in (H1[:-1]+np.diff(H1)/2.)])
    10751076    times[4] += time.time()-t0
    1076     print ('Step times: \n apply masks  %8.3fs xy->th,azm   %8.3fs fill map     %8.3fs \
     1077    G2fil.G2Print ('Step times: \n apply masks  %8.3fs xy->th,azm   %8.3fs fill map     %8.3fs \
    10771078        \n binning      %8.3fs cleanup      %8.3fs'%(times[0],times[1],times[2],times[3],times[4]))
    1078     print ("Elapsed time:","%8.3fs"%(time.time()-tbeg))
    1079     print ('Integration complete')
     1079    G2fil.G2Print ("Elapsed time:","%8.3fs"%(time.time()-tbeg))
     1080    G2fil.G2Print ('Integration complete')
    10801081    if returnN:     #As requested by Steven Weigand
    10811082        return H0,H1,H2,NST,CancelPressed
     
    11321133            ring['Ivar'] = np.var(ringint)
    11331134            ring['covMat'] = covMat
    1134             print ('Variance in normalized ring intensity: %.3f'%(ring['Ivar']))
     1135            G2fil.G2Print ('Variance in normalized ring intensity: %.3f'%(ring['Ivar']))
    11351136    CalcStrSta(StrSta,Controls)
    11361137   
     
    11511152            ringint = np.array([float(Image[int(x*scalex),int(y*scaley)]) for y,x in np.array(ringxy)[:,:2]])
    11521153            ringint /= np.mean(ringint)
    1153             print (' %s %.3f %s %.3f %s %d'%('d-spacing',ring['Dcalc'],'sig(MRD):',np.sqrt(np.var(ringint)),'# points:',len(ringint)))
     1154            G2fil.G2Print (' %s %.3f %s %.3f %s %d'%('d-spacing',ring['Dcalc'],'sig(MRD):',np.sqrt(np.var(ringint)),'# points:',len(ringint)))
    11541155            RingsAI.append(np.array(zip(ringazm,ringint)).T)
    11551156    return RingsAI
     
    12981299def AutoSpotMasks(Image,Masks,Controls):
    12991300   
    1300     print ('auto spot search')
     1301    G2fil.G2Print ('auto spot search')
    13011302    nxy = 15
    13021303    rollImage = lambda rho,roll: np.roll(np.roll(rho,roll[0],axis=0),roll[1],axis=1)
     
    13211322    mags = magind[2]
    13221323    size2 = mags.shape[0]
    1323     print ('Initial search done: %d -->%d %.2fs'%(size1,size2,time.time()-time0))
     1324    G2fil.G2Print ('Initial search done: %d -->%d %.2fs'%(size1,size2,time.time()-time0))
    13241325    nx,ny = Image.shape
    13251326    ImMax = np.max(Image)
     
    13321333        minM = mult*np.max(mags)
    13331334        num = ma.count(ma.array(mags,mask=mags<=minM))
    1334         print('try',mult,minM,num)
     1335        G2fil.G2Print('try',mult,minM,num)
    13351336    minM = mult*np.max(mags)
    1336     print ('Find biggest spots:',mult,num,minM)
     1337    G2fil.G2Print ('Find biggest spots:',mult,num,minM)
    13371338    for i,mag in enumerate(mags):
    13381339        if mag > minM:
    13391340            if (nxy2 < indx[0][i] < nx-nxy2-1) and (nxy2 < indx[1][i] < ny-nxy2-1):
    1340 #                    print ('try:%d %d %d %.2f'%(i,indx[0][i],indx[1][i],mags[i]))
     1341#                    G2fil.G2Print ('try:%d %d %d %.2f'%(i,indx[0][i],indx[1][i],mags[i]))
    13411342                peak = FitImageSpots(Image,ImMax,[indx[1][i],indx[0][i]],pixelSize,nxy)
    13421343                if peak and not any(np.isnan(np.array(peak))):
    13431344                    peaks.append(peak)
    1344 #                    print (' Spot found: %s'%str(peak))
     1345#                    G2fil.G2Print (' Spot found: %s'%str(peak))
    13451346    peaks = G2mth.sortArray(G2mth.sortArray(peaks,1),0)
    13461347    Peaks = [peaks[0],]
     
    13501351        if (peak[0]-Peaks[-1][0])**2+(peak[1]-Peaks[-1][1])**2 > peak[2]*Peaks[-1][2] :
    13511352            Peaks.append(peak)
    1352 #            print (' Spot found: %s'%str(peak))
    1353     print ('Spots found: %d time %.2fs'%(len(Peaks),time.time()-time0))
     1353#            G2fil.G2Print (' Spot found: %s'%str(peak))
     1354    G2fil.G2Print ('Spots found: %d time %.2fs'%(len(Peaks),time.time()-time0))
    13541355    Masks['Points'] = Peaks
    13551356    return None
Note: See TracChangeset for help on using the changeset viewer.