Changeset 3906
- Timestamp:
- Apr 16, 2019 9:39:40 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r3900 r3906 2751 2751 PlotList = [Pattern,] 2752 2752 PId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background') 2753 Pattern[0]['BackFile'] = ['',-1.0 ]2753 Pattern[0]['BackFile'] = ['',-1.0,False] 2754 2754 if PId: 2755 Pattern[0]['BackFile'] = G2frame.GPXtree.GetItemPyData(PId)[1].get('background PWDR',['',-1.0 ])2755 Pattern[0]['BackFile'] = G2frame.GPXtree.GetItemPyData(PId)[1].get('background PWDR',['',-1.0,False]) 2756 2756 Parms,Parms2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame, 2757 2757 G2frame.PatternId, 'Instrument Parameters')) … … 2786 2786 Page.plotStyle.update({'Offset':[0.0,0.0],'delOffset':0.02*Ymax,'refOffset':-0.1*Ymax,'refDelt':0.1*Ymax,}) 2787 2787 PId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Background') 2788 Pattern[0]['BackFile'] = ['',-1.0 ]2788 Pattern[0]['BackFile'] = ['',-1.0,False] 2789 2789 if PId: 2790 Pattern[0]['BackFile'] = G2frame.GPXtree.GetItemPyData(PId)[1].get('background PWDR',['',-1.0 ])2790 Pattern[0]['BackFile'] = G2frame.GPXtree.GetItemPyData(PId)[1].get('background PWDR',['',-1.0,False]) 2791 2791 PlotList.append(Pattern) 2792 2792 ParmList.append(G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame, … … 2805 2805 for ip,Pattern in enumerate(PlotList): 2806 2806 xye = Pattern[1] 2807 bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern)2807 #bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern) 2808 2808 if xye[1] is None: continue 2809 if Ymax is None: Ymax = max(xye[1] +bxye)2810 Ymax = max(Ymax,max(xye[1] +bxye))2809 if Ymax is None: Ymax = max(xye[1]) 2810 Ymax = max(Ymax,max(xye[1])) 2811 2811 if Ymax is None: return # nothing to plot 2812 2812 offsetX = Page.plotStyle['Offset'][1] … … 2880 2880 xye = np.array(ma.getdata(Pattern[1])) # strips mask 2881 2881 xye0 = Pattern[1][0] # keeps mask 2882 bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern)2882 #bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern) 2883 2883 if PickId: 2884 2884 ifpicked = Pattern[2] == G2frame.GPXtree.GetItemText(PatternId) … … 2953 2953 if Page.plotStyle['sqrtPlot']: 2954 2954 olderr = np.seterr(invalid='ignore') #get around sqrt(-ve) error 2955 Y = np.where(xye[1] +bxye>=0.,np.sqrt(xye[1]+bxye),-np.sqrt(-xye[1]-bxye))+bxye+NoffY*Ymax/100.02955 Y = np.where(xye[1]>=0.,np.sqrt(xye[1]),-np.sqrt(-xye[1]))+NoffY*Ymax/100.0 2956 2956 np.seterr(invalid=olderr['invalid']) 2957 2957 elif 'PWDR' in plottype and G2frame.SinglePlot and not ( 2958 2958 Page.plotStyle['logPlot'] or Page.plotStyle['sqrtPlot'] or G2frame.Contour): 2959 Y = xye[1]*multArray+ bxye+NoffY*Ymax/100.02959 Y = xye[1]*multArray+NoffY*Ymax/100.0 2960 2960 else: 2961 Y = xye[1]+ bxye+NoffY*Ymax/100.02961 Y = xye[1]+NoffY*Ymax/100.0 2962 2962 elif plottype in ['SASD','REFD']: 2963 2963 if plottype == 'SASD': -
trunk/GSASIIpwd.py
r3848 r3906 716 716 return intens*Df(xdata)*DX/dx 717 717 718 def getBackground(pfx,parmDict,bakType,dataType,xdata): 719 'needs a doc string' 718 def getBackground(pfx,parmDict,bakType,dataType,xdata,fixedBkg={}): 719 '''Computes the background from vars pulled from gpx file or tree. 720 ''' 720 721 if 'T' in dataType: 721 722 q = 2.*np.pi*parmDict[pfx+'difC']/xdata … … 837 838 except ValueError: 838 839 print ('**** WARNING - backround peak '+str(iD)+' sigma is negative; fix & try again ****') 839 break 840 break 841 # fixed background from file 842 if len(fixedBkg) >= 3: 843 mult = fixedBkg.get('_fixedMult',0.0) 844 if len(fixedBkg.get('_fixedValues',[])) != len(yb): 845 print('Lengths of backgrounds do not agree: yb={}, fixed={}'.format( 846 len(yb),len(fixedBkg.get('_fixedValues',[])))) 847 elif mult: 848 yb -= mult*fixedBkg.get('_fixedValues',[]) # N.B. mult is negative 849 sumBk[0] = sum(yb) 840 850 return yb,sumBk 841 851 … … 1087 1097 1088 1098 def getPeakProfile(dataType,parmDict,xdata,varyList,bakType): 1089 ' needs a doc string'1099 'Computes the profile for a powder pattern' 1090 1100 1091 1101 yb = getBackground('',parmDict,bakType,dataType,xdata)[0] … … 1404 1414 1405 1415 def SetBackgroundParms(Background): 1406 ' needs a doc string'1416 'Loads background parameters into dicts/lists to create varylist & parmdict' 1407 1417 if len(Background) == 1: # fix up old backgrounds 1408 1418 Background.append({'nDebye':0,'debyeTerms':[]}) … … 1442 1452 peaksVary.append(item[0]) 1443 1453 backDict.update(peaksDict) 1444 backVary += peaksVary 1454 backVary += peaksVary 1445 1455 return bakType,backDict,backVary 1446 1456 … … 1867 1877 if dlg: dlg.Destroy() 1868 1878 sigDict = dict(zip(varyList,sig)) 1869 yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])[0] 1870 yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],varyList,bakType) 1871 yd[xBeg:xFin] = (y+fixback)[xBeg:xFin]-yc[xBeg:xFin]1879 yb[xBeg:xFin] = getBackground('',parmDict,bakType,dataType,x[xBeg:xFin])[0]-fixback[xBeg:xFin] 1880 yc[xBeg:xFin] = getPeakProfile(dataType,parmDict,x[xBeg:xFin],varyList,bakType)-fixback[xBeg:xFin] 1881 yd[xBeg:xFin] = y[xBeg:xFin]-yc[xBeg:xFin] 1872 1882 GetBackgroundParms(parmDict,Background) 1873 1883 if bakVary: BackgroundPrint(Background,sigDict) … … 2848 2858 fplot.plot(xdata,getBackground('',parmDict1,bakType,'PXC',xdata)[0]) 2849 2859 fplot.plot(xdata,getPeakProfile(parmDict1,xdata,varyList,bakType)) 2850 2860 2851 2861 def test1(): 2852 2862 if NeedTestData: TestData() -
trunk/GSASIIpwdGUI.py
r3886 r3906 286 286 bxye = np.zeros(len(xye[1])) 287 287 if 'BackFile' in Pattern[0]: 288 backfile,mult = Pattern[0]['BackFile'] 288 backfile,mult = Pattern[0]['BackFile'][:2] 289 289 if backfile: 290 290 bId = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,backfile) … … 1565 1565 def OnBackPWDR(event): 1566 1566 data[1]['background PWDR'][0] = back.GetValue() 1567 if data[1]['background PWDR'][0]: 1568 curHist = G2frame.GPXtree.GetItemPyData(G2frame.PatternId) 1569 Id = G2gd.GetGPXtreeItemId(G2frame,G2frame.root,data[1]['background PWDR'][0]) 1570 if not Id: 1571 G2G.G2MessageBox(G2frame,'Histogram not found -- how did this happen?','Missing histogram') 1572 back.SetValue('') 1573 data[1]['background PWDR'][0] = back.GetValue() 1574 return 1575 bkgHist = G2frame.GPXtree.GetItemPyData(Id) 1576 if len(bkgHist[1][0]) != len(curHist[1][0]): 1577 G2G.G2MessageBox(G2frame,'Histogram have different lengths','Mismatched histograms') 1578 back.SetValue('') 1579 data[1]['background PWDR'][0] = back.GetValue() 1580 return 1567 1581 G2plt.PlotPatterns(G2frame,plotType='PWDR') 1568 1582 … … 1570 1584 fileSizer.Add(wx.StaticText(G2frame.dataWindow,-1,' Fixed background file:'),0,WACV) 1571 1585 if 'background PWDR' not in data[1]: 1572 data[1]['background PWDR'] = ['',-1. ]1586 data[1]['background PWDR'] = ['',-1.,False] 1573 1587 backSizer = wx.BoxSizer(wx.HORIZONTAL) 1574 1588 Choices = ['',]+G2gd.GetGPXtreeDataNames(G2frame,['PWDR',]) -
trunk/GSASIIstrIO.py
r3887 r3906 510 510 print('For phase "'+phase+ 511 511 '" unresolved reference to histogram "'+hist+'"') 512 # load the fix background info into the histograms 513 for hist in Histograms: 514 fixedBkg = Histograms[hist]['Background'][1].get('background PWDR') 515 if fixedBkg: 516 if not fixedBkg[0]: continue 517 # patch: add refinement flag, if needed 518 if len(fixedBkg) == 2: fixedBkg += [False] 519 h = Histograms[hist]['Background'][1] 520 try: 521 Limits = Histograms[hist]['Limits'][1] 522 x = Histograms[hist]['Data'][0] 523 xB = np.searchsorted(x,Limits[0]) 524 xF = np.searchsorted(x,Limits[1])+1 525 h['_fixedValues'] = allHistograms[fixedBkg[0]]['Data'][1][xB:xF] 526 h['_fixedMult'],h['_fixedVary'] = fixedBkg[1:] 527 except KeyError: # would happen if a referenced histogram were renamed or deleted 528 print('For hist "{}" unresolved background reference to hist "{}"' 529 .format(hist,fixedBkg[0])) 512 530 G2obj.IndexAllIds(Histograms=Histograms,Phases=Phases) 513 531 return Histograms,Phases … … 604 622 for datus in data[1:]: 605 623 # print ' read: ',datus[0] 606 if datus[0] in [' Background','Instrument Parameters','Sample Parameters','Reflection Lists']:624 if datus[0] in ['Instrument Parameters','Sample Parameters','Reflection Lists']: 607 625 datus[1] = histogram[datus[0]] 626 if datus[0] == 'Background': # remove fixed background from file 627 d1 = {key:histogram['Background'][1][key] 628 for key in histogram['Background'][1] 629 if not key.startswith('_fixed')} 630 datus[1] = copy.deepcopy(histogram['Background']) 631 datus[1][1] = d1 608 632 except KeyError: 609 633 pass … … 711 735 'Sample Parameters','Reflection Lists'): 712 736 xfer_dict[key] = hist[key] 737 if key == 'Background': # remove fixed background from file 738 xfer_dict['Background'][1] = {k:hist['Background'][1][k] 739 for k in hist['Background'][1] 740 if not k.startswith('_fixed')} 713 741 del hist[key] 714 742 # xform into a gpx-type entry -
trunk/GSASIIstrMath.py
r3882 r3906 3152 3152 hfx = ':%d:'%(hId) 3153 3153 bakType = calcControls[hfx+'bakType'] 3154 yb,Histogram['sumBk'] = G2pwd.getBackground(hfx,parmDict,bakType,calcControls[hfx+'histType'],x) 3154 fixedBkg = {i:Histogram['Background'][1][i] for i in Histogram['Background'][1] if i.startswith("_")} 3155 yb,Histogram['sumBk'] = G2pwd.getBackground(hfx,parmDict,bakType,calcControls[hfx+'histType'],x,fixedBkg) 3155 3156 yc = np.zeros_like(yb) 3156 3157 cw = np.diff(ma.getdata(x))
Note: See TracChangeset
for help on using the changeset viewer.