Changeset 4830 for trunk


Ignore:
Timestamp:
Feb 26, 2021 4:49:53 PM (2 years ago)
Author:
vondreele
Message:

show more places in Absorb output
improve image absorption calcs for cylinders now seems to work OK
reorganize Image controls GUI & add option for vertical samples
hide printing of LS cycles if Rrint=False in HessianLSQ
implement (& not use) Klein-Nishina PDF correction
Fix bug in if importer

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Absorb.py

    r4672 r4830  
    463463       
    464464        if self.Volume:
    465             Text += "%s %s%10.2f %s" % ("Total",' '+Gkmu+'=',self.Pack*muT/self.Volume,'cm'+Pwrm1+', ')
    466             Text += "%s%10.2f%s" % ('Total '+Gkmu+'R=',self.Radius*self.Pack*muT/(10.0*self.Volume),', ')
     465            Text += "%s %s%10.4g %s" % ("Total",' '+Gkmu+'=',self.Pack*muT/self.Volume,'cm'+Pwrm1+', ')
     466            Text += "%s%10.4g%s" % ('Total '+Gkmu+'R=',self.Radius*self.Pack*muT/(10.0*self.Volume),', ')
    467467            Text += "%s%10.4f%s\n" % ('Transmission exp(-2'+Gkmu+'R)=', \
    468468                100.0*math.exp(-2*self.Radius*self.Pack*muT/(10.0*self.Volume)),'%')
  • trunk/GSASIIimage.py

    r4820 r4830  
    12621262    return useMask
    12631263
    1264 def MakeGainMap(image,Ix,Iy,data,blkSize=128):
     1264def MakeGainMap(image,Ix,Iy0,data,blkSize=128):
    12651265    import scipy.ndimage.filters as sdif
     1266    Iy = sdif.gaussian_filter1d(Iy0,3.)
    12661267    Iy *= npcosd(Ix[:-1])**3       #undo parallax
    12671268    Iy *= (1000./data['distance'])**2    #undo r^2 effect
     
    12701271        Iy *= G2pwd.Oblique(data['Oblique'][0],Ix[:-1])     #undo penetration
    12711272    IyInt = scint.interp1d(Ix[:-1],Iy[0],bounds_error=False)
     1273    muT = data.get('SampleAbs',[0.0,''])[0]
    12721274    GainMap = np.zeros_like(image,dtype=float)
    12731275    #do interpolation on all points - fills in the empty bins; leaves others the same
     
    12821284            jFin = min(jBeg+blkSize,Nx)
    12831285            TA = Make2ThetaAzimuthMap(data,(iBeg,iFin),(jBeg,jFin))           #2-theta & azimuth arrays & create position mask
     1286            tabs = np.ones_like(TA[3])
     1287            if data.get('SampleAbs',[0.0,False])[1]:
     1288                if 'Cylind' in data['SampleShape']:
     1289                    if 'horiz' in data['orientation']:
     1290                        muR = muT*(1.+0.5*npsind(TA[0])*npsind(TA[1])**2)      #adjust for additional thickness off sample normal
     1291                    else:   #vertical
     1292                        muR = muT*(1.+0.5*npsind(TA[0])*npcosd(TA[1])**2)
     1293                    tabs = G2pwd.Absorb(data['SampleShape'],muR,TA[1])
     1294            elif 'Fixed' in data['SampleShape']:    #assumes flat plate sample normal to beam
     1295                tabs = G2pwd.Absorb('Fixed',muT,TA[1])
    12841296            Ipix = IyInt(TA[0])
    1285             GainMap[iBeg:iFin,jBeg:jFin] = image[iBeg:iFin,jBeg:jFin]/(Ipix*TA[3])
     1297            GainMap[iBeg:iFin,jBeg:jFin] = image[iBeg:iFin,jBeg:jFin]/(tabs*Ipix*TA[3])
    12861298    GainMap = np.nan_to_num(GainMap,1.0)
    12871299    GainMap = sdif.gaussian_filter(GainMap,3.,order=0)
     
    13501362            tax = np.where(tax > LRazm[1],tax-360.,tax)                 #put azm inside limits if possible
    13511363            tax = np.where(tax < LRazm[0],tax+360.,tax)
    1352             if data.get('SampleAbs',[0.0,''])[1]:
     1364            if data.get('SampleAbs',[0.0,False])[1]:
    13531365                if 'Cylind' in data['SampleShape']:
    1354                     muR = muT*(1.+npsind(tax)**2/2.)/(npcosd(tay))      #adjust for additional thickness off sample normal
     1366                    if 'horiz' in data['orientation']:
     1367                        muR = muT*(1.+0.5*npsind(tax)*npsind(tay)**2)      #adjust for additional thickness off sample normal
     1368                    else:   #vertical
     1369                        muR = muT*(1.+0.5*npsind(tax)*npcosd(tay)**2)
    13551370                    tabs = G2pwd.Absorb(data['SampleShape'],muR,tay)
    13561371                elif 'Fixed' in data['SampleShape']:    #assumes flat plate sample normal to beam
  • trunk/GSASIIimgGUI.py

    r4820 r4830  
    157157       
    158158    def OnMakeGainMap(event):
     159        import scipy.ndimage.filters as sdif
    159160        sumImg = GetImageZ(G2frame,data)
    160161        masks = copy.deepcopy(G2frame.GPXtree.GetItemPyData(
     
    166167        Data['LRazimuth'] = [0.,360.]
    167168        Data['outChannels'] = 5000
    168         Data['SampleAbs'] = [0.0,False]
    169169        Data['binType'] = '2-theta'
    170170        Data['color'] = 'gray'
     
    182182            Data['formatName'] = 'GSAS-II image'
    183183            Data['range'] = [(500,2000),[800,1200]]
    184             GainMap = np.where(GainMap > 1200,1200,GainMap)
    185             GainMap = np.where(GainMap < 800,800,GainMap)
     184            GainMap = np.where(GainMap > 2000,2000,GainMap)
     185            GainMap = np.where(GainMap < 500,500,GainMap)
     186            masks['Thresholds'] = [(500.,2000.),[800.,1200.]]
    186187            G2IO.PutG2Image(newimagefile,[],data,Npix,GainMap)
    187188            GMname = 'IMG '+os.path.split(newimagefile)[1]
     
    284285    if 'det2theta' not in data:
    285286        data['det2theta'] = 0.0
     287    if 'orientation' not in data:
     288        data['orientation'] = 'horizontal'
    286289#end patch
    287290
     
    646649                    'tilt','rotation','azmthOff','fullIntegrate','LRazimuth','setdist',
    647650                    'IOtth','outChannels','outAzimuths','invert_x','invert_y','DetDepth',
    648                     'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList',
     651                    'calibskip','pixLimit','cutoff','calibdmin','Flat Bkg','varyList','orientation',
    649652                    'binType','SampleShape','PolaVal','SampleAbs','dark image','background image']
    650653        keyList.sort(key=lambda s: s.lower())
     
    11861189        def OnSamAbs(event):
    11871190            data['SampleAbs'][1] = not data['SampleAbs'][1]
     1191            wx.CallLater(100,UpdateImageControls,G2frame,data,masks)
    11881192                           
    11891193        def OnShowLines(event):
     
    12191223        def OnIfPink(event):
    12201224            data['IfPink'] = not data['IfPink']
     1225           
     1226        def OnOchoice(event):
     1227            data['orientation'] = ochoice.GetValue()
    12211228               
    12221229        dataSizer = wx.FlexGridSizer(0,2,5,3)
     
    12701277        outAzim = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data,'outAzimuths',nDig=(10,4),xmin=1,typeHint=int,OnLeave=OnNumOutAzms)
    12711278        littleSizer.Add(outAzim,0,WACV)
    1272         dataSizer.Add(littleSizer,0,)
    1273         samplechoice = ['Cylinder','Fixed flat plate',]
    1274         dataSizer.Add(wx.StaticText(G2frame.dataWindow,label='Select sample shape'),0,WACV)
    1275         samShape = wx.ComboBox(G2frame.dataWindow,value=data['SampleShape'],choices=samplechoice,
    1276             style=wx.CB_READONLY|wx.CB_DROPDOWN)
    1277         samShape.Bind(wx.EVT_COMBOBOX,OnSampleShape)
    1278         dataSizer.Add(samShape,0,WACV)
     1279        dataSizer.Add(littleSizer)
     1280        showLines = wx.CheckBox(parent=G2frame.dataWindow,label='Show integration limits?')
     1281        dataSizer.Add(showLines,0,WACV)
     1282        showLines.Bind(wx.EVT_CHECKBOX, OnShowLines)
     1283        showLines.SetValue(data['showLines'])
     1284        fullIntegrate = wx.CheckBox(parent=G2frame.dataWindow,label='Do full integration?')
     1285        dataSizer.Add(fullIntegrate,0,WACV)
     1286        fullIntegrate.Bind(wx.EVT_CHECKBOX, OnFullIntegrate)
     1287        fullIntegrate.SetValue(data['fullIntegrate'])
     1288        setDefault = wx.CheckBox(parent=G2frame.dataWindow,label='Use for all new images?')
     1289        dataSizer.Add(setDefault,0,WACV)
     1290        setDefault.Bind(wx.EVT_CHECKBOX, OnSetDefault)
     1291        setDefault.SetValue(data['setDefault'])
     1292        centerAzm = wx.CheckBox(parent=G2frame.dataWindow,label='Azimuth at bin center?')
     1293        dataSizer.Add(centerAzm,0,WACV)
     1294        centerAzm.Bind(wx.EVT_CHECKBOX, OnCenterAzm)
     1295        centerAzm.SetValue(data['centerAzm'])
    12791296        #SampleShape - cylinder or flat plate choice?
    12801297        littleSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    12841301        samabs.SetValue(data['SampleAbs'][1])
    12851302        minmax = [0.,2.]
    1286         if 'Cylind' in data['SampleShape']: #cylinder mu*R; flat plate transmission
    1287             littleSizer.Add(wx.StaticText(G2frame.dataWindow,label='mu*R (0.00-2.0) '),0,WACV)
    1288         elif 'Fixed' in data['SampleShape']:
    1289             littleSizer.Add(wx.StaticText(G2frame.dataWindow,label='transmission '),0,WACV) #for flat plate
    1290             minmax = [.05,1.0]
    1291         samabsVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data['SampleAbs'],0,nDig=(10,3),
    1292             typeHint=float,xmin=minmax[0],xmax=minmax[1])
    1293         littleSizer.Add(samabsVal,0,WACV)
    1294         dataSizer.Add(littleSizer,0,)       
     1303        if data['SampleAbs'][1]:
     1304            samplechoice = ['Cylinder','Fixed flat plate',]
     1305            littleSizer.Add(wx.StaticText(G2frame.dataWindow,label='Select shape '),0,WACV)
     1306            samShape = wx.ComboBox(G2frame.dataWindow,value=data['SampleShape'],choices=samplechoice,
     1307                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     1308            samShape.Bind(wx.EVT_COMBOBOX,OnSampleShape)
     1309            littleSizer.Add(samShape,0,WACV)
     1310        dataSizer.Add(littleSizer)
     1311        if data['SampleAbs'][1]:
     1312            littleSizer = wx.BoxSizer(wx.HORIZONTAL)
     1313            if 'Cylind' in data['SampleShape']: #cylinder mu*R; flat plate transmission
     1314                littleSizer.Add(wx.StaticText(G2frame.dataWindow,label='mu*R (0.00-2.0) '),0,WACV)
     1315            elif 'Fixed' in data['SampleShape']:
     1316                littleSizer.Add(wx.StaticText(G2frame.dataWindow,label='transmission '),0,WACV) #for flat plate
     1317                minmax = [.05,1.0]
     1318            samabsVal = G2G.ValidatedTxtCtrl(G2frame.dataWindow,data['SampleAbs'],0,nDig=(10,3),
     1319                typeHint=float,xmin=minmax[0],xmax=minmax[1])
     1320            littleSizer.Add(samabsVal,0,WACV)
     1321            dataSizer.Add(littleSizer,0,WACV)
     1322        if 'Cylind' in data['SampleShape'] and data['SampleAbs'][1]:
     1323            littleSizer = wx.BoxSizer(wx.HORIZONTAL)
     1324            littleSizer.Add(wx.StaticText(G2frame.dataWindow,label='Select orientation '),0,WACV)
     1325            choice = ['horizontal','vertical']
     1326            ochoice = wx.ComboBox(G2frame.dataWindow,value=data['orientation'],choices=choice,
     1327                style=wx.CB_READONLY|wx.CB_DROPDOWN)
     1328            ochoice.Bind(wx.EVT_COMBOBOX,OnOchoice)
     1329            littleSizer.Add(ochoice,0,WACV)
     1330            dataSizer.Add(littleSizer)
     1331        if 'flat' in data['SampleShape'] and data['SampleAbs'][1]:
     1332            dataSizer.Add((5,5),0)
    12951333        if 'PWDR' in data['type']:
    12961334            littleSizer = wx.BoxSizer(wx.HORIZONTAL)
     
    13141352            dataSizer.Add(littleSizer,0,)
    13151353       
    1316         showLines = wx.CheckBox(parent=G2frame.dataWindow,label='Show integration limits?')
    1317         dataSizer.Add(showLines,0,WACV)
    1318         showLines.Bind(wx.EVT_CHECKBOX, OnShowLines)
    1319         showLines.SetValue(data['showLines'])
    1320         fullIntegrate = wx.CheckBox(parent=G2frame.dataWindow,label='Do full integration?')
    1321         dataSizer.Add(fullIntegrate,0,WACV)
    1322         fullIntegrate.Bind(wx.EVT_CHECKBOX, OnFullIntegrate)
    1323         fullIntegrate.SetValue(data['fullIntegrate'])
    1324         setDefault = wx.CheckBox(parent=G2frame.dataWindow,label='Use for all new images?')
    1325         dataSizer.Add(setDefault,0,WACV)
    1326         setDefault.Bind(wx.EVT_CHECKBOX, OnSetDefault)
    1327         setDefault.SetValue(data['setDefault'])
    1328         centerAzm = wx.CheckBox(parent=G2frame.dataWindow,label='Azimuth at bin center?')
    1329         dataSizer.Add(centerAzm,0,WACV)
    1330         centerAzm.Bind(wx.EVT_CHECKBOX, OnCenterAzm)
    1331         centerAzm.SetValue(data['centerAzm'])
    13321354        return dataSizer
    13331355       
     
    16301652    mainSizer.Add((5,5),0)           
    16311653    mainSizer.Add(BackSizer(),0)
    1632     mainSizer.Add(wx.StaticText(parent=G2frame.dataWindow,label=' Calibration controls:'),0,WACV)
     1654    mainSizer.Add(wx.StaticText(parent=G2frame.dataWindow,label=' Calibration controls:'),0)
    16331655    mainSizer.Add((5,5),0)
    1634     mainSizer.Add(CalibSizer(),0,WACV)
     1656    mainSizer.Add(CalibSizer(),0)
    16351657    mainSizer.Add((5,5),0)
    1636     mainSizer.Add(GonioSizer(),0,WACV)   
     1658    mainSizer.Add(GonioSizer(),0)   
    16371659    G2frame.dataWindow.SetDataSize()
    16381660   
     
    21042126    delbtn.Bind(wx.EVT_BUTTON,OnDelBtn)
    21052127    spotSizer.Add(delbtn,0,WACV)
    2106     mainSizer.Add(spotSizer,0,WACV)
     2128    mainSizer.Add(spotSizer,0)
    21072129    if len(Spots):
    21082130        lbl = wx.StaticText(parent=G2frame.dataWindow,label=' Spot masks(on plot LB drag to move, shift-LB drag to resize, RB to delete)')
  • trunk/GSASIImath.py

    r4819 r4830  
    338338        # complete current cycle
    339339        deltaChi2 = (chisq0-chisq1)/chisq0
    340         if n-len(indices):
    341             G2fil.G2Print(
    342                 'Cycle %d: %.2fs Chi2: %.5g; Obs: %d; Lam: %.3g Del: %.3g; drop=%d, SVD=%d'%
    343                 (icycle,time.time()-time0,chisq1,Nobs,lamMax,deltaChi2,n-len(indices),Nzeros))
    344         else:
    345             G2fil.G2Print(
    346                 'Cycle %d: %.2fs, Chi**2: %.5g for %d obs., Lambda: %.3g,  Delta: %.3g, SVD=%d'%
    347                 (icycle,time.time()-time0,chisq1,Nobs,lamMax,deltaChi2,Nzeros))
     340        if Print:
     341            if n-len(indices):
     342                G2fil.G2Print(
     343                    'Cycle %d: %.2fs Chi2: %.5g; Obs: %d; Lam: %.3g Del: %.3g; drop=%d, SVD=%d'%
     344                    (icycle,time.time()-time0,chisq1,Nobs,lamMax,deltaChi2,n-len(indices),Nzeros))
     345            else:
     346                G2fil.G2Print(
     347                    'Cycle %d: %.2fs, Chi**2: %.5g for %d obs., Lambda: %.3g,  Delta: %.3g, SVD=%d'%
     348                    (icycle,time.time()-time0,chisq1,Nobs,lamMax,deltaChi2,Nzeros))
    348349        Histograms = args[0][0]
    349350        if refPlotUpdate is not None: refPlotUpdate(Histograms,icycle)   # update plot
    350351        if deltaChi2 < ftol:
    351352            ifConverged = True
    352             G2fil.G2Print("converged")
     353            if Print:
     354                G2fil.G2Print("converged")
    353355            break
    354356        icycle += 1
  • trunk/GSASIIpwd.py

    r4821 r4830  
    6868npT2stl = lambda tth, wave: 2.0*npsind(tth/2.0)/wave    #=d*
    6969npT2q = lambda tth,wave: 2.0*np.pi*npT2stl(tth,wave)    #=2pi*d*
     70npq2T = lambda Q,wave: 2.0*npasind(0.25*Q*wave/np.pi)
    7071ateln2 = 8.0*math.log(2.0)
    7172sateln2 = np.sqrt(ateln2)
     
    248249    C = 2.9978e8
    249250    D = 1.5e-3
    250     hmc = 0.024262734687
     251    hmc = 0.024262734687    #Compton wavelength in A
    251252    sinth2 = (Q*wave/(4.0*np.pi))**2
    252253    dlam = (wave**2)*Compton*Q/C
    253254    dlam_c = 2.0*hmc*sinth2-D*wave**2
    254255    return 1.0/((1.0+dlam/RulCoff)*(1.0+(np.pi*dlam_c/(dlam+RulCoff))**2))
     256
     257def KleinNishina(wave,Q):
     258    hmc = 0.024262734687    #Compton wavelength in A
     259    TTh = npq2T(Q,wave)
     260    P = 1./(1.+(1.-npcosd(TTh)*(hmc/wave)))
     261    KN = (P**3-(P*npsind(TTh))**2+P)/(1.+npcosd(TTh)**2)
     262    return KN
    255263   
    256264def LorchWeight(Q):
     
    383391#    auxPlot.append([Q,np.copy(CF),'CF-unCorr'])
    384392    if 'XC' in inst['Type'][0]:
     393#        CF *= KleinNishina(wave,Q)
    385394        ruland = Ruland(data['Ruland'],wave,Q,CF)
    386395#        auxPlot.append([Q,ruland,'Ruland'])     
  • trunk/imports/G2phase_CIF.py

    r4659 r4830  
    598598                isodistort_warnings += '\nRepeated atom labels prevents ISODISTORT decode'
    599599            for lbl in phasenamefields: # get a name for the phase
    600                 name = blk.get(lbl)
     600                name = blk.get(lbl)[0]
    601601                if name is None:
    602602                    continue
Note: See TracChangeset for help on using the changeset viewer.