Changeset 3313
- Timestamp:
- Mar 9, 2018 1:08:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r3304 r3313 2395 2395 LimitId = 0 2396 2396 if Pattern[1] is None: continue # skip over uncomputed simulations 2397 xye = np.array(ma.getdata(Pattern[1])) 2397 xye = np.array(ma.getdata(Pattern[1])) # strips mask 2398 xye0 = Pattern[1][0] # keeps mask 2398 2399 bxye = G2pdG.GetFileBackground(G2frame,xye,Pattern) 2399 2400 if PickId: … … 2401 2402 LimitId = G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId,'Limits') 2402 2403 limits = G2frame.GPXtree.GetItemPyData(LimitId) 2404 # recompute mask from excluded regions, in case they have changed 2403 2405 excls = limits[2:] 2406 xye0.mask = False # resets mask for xye0 & Pattern[1][0](!) 2404 2407 for excl in excls: 2405 xye[0] = ma.masked_inside(xye[0],excl[0],excl[1]) 2408 xye0 = ma.masked_inside(xye0,excl[0],excl[1]) # sets mask on xye0 but not Pattern[1][0] ! 2409 Pattern[1][0].mask = xye0.mask # transfer the mask 2406 2410 if G2frame.plotStyle['qPlot'] and 'PWDR' in plottype: 2407 X = 2.*np.pi/G2lat.Pos2dsp(Parms,xye [0])2411 X = 2.*np.pi/G2lat.Pos2dsp(Parms,xye0) 2408 2412 elif G2frame.plotStyle['dPlot'] and 'PWDR' in plottype: 2409 X = G2lat.Pos2dsp(Parms,xye [0])2413 X = G2lat.Pos2dsp(Parms,xye0) 2410 2414 else: 2411 X = xye [0]2415 X = xye0 2412 2416 if not lenX: 2413 2417 lenX = len(X) … … 2515 2519 DX = xlim[1]-xlim[0] 2516 2520 X += 0.002*offsetX*DX*N 2517 Xum = ma.getdata(X) 2521 Xum = ma.getdata(X) # unmasked version of X, use to plot data (only) 2518 2522 if ifpicked: 2519 2523 if G2frame.plotStyle['sqrtPlot']: … … 2795 2799 figure.clear() 2796 2800 plotOpt['fmtChoices'] = [fmtDict[j]+', '+j for j in sorted(fmtDict)] 2801 plotOpt['fmtChoices'].append('Data file with plot elements, csv') 2797 2802 if plotOpt['format'] is None: 2798 2803 if 'pdf' in fmtDict: … … 2834 2839 CopyRietveldPlot(G2frame,Pattern,Plot,Page,figure) 2835 2840 figure.canvas.draw() 2841 2842 def Write2csv(fil,dataItems,header=False): 2843 '''Write a line to a CSV file 2844 2845 :param object fil: file object 2846 :param list dataItems: items to write as row in file 2847 :param bool header: True if all items should be written with quotes (default is False) 2848 ''' 2849 line = '' 2850 for item in dataItems: 2851 if line: line += ',' 2852 item = str(item) 2853 if header or ' ' in item: 2854 line += '"'+item+'"' 2855 else: 2856 line += item 2857 fil.write(line+'\n') 2858 2859 def CopyRietveld2csv(Pattern,Plot,Page,filename): 2860 '''Copy the contents of the Rietveld graph from the plot window to 2861 .csv file 2862 ''' 2863 import itertools # delay this since not commonly called or needed 2864 2865 lblList = [] 2866 valueList = [] 2867 2868 lblList.append('Axis-limits') 2869 valueList.append(list(Plot.get_xlim())+list(Plot.get_ylim())) 2870 2871 tickpos = {} 2872 for i,l in enumerate(Plot.lines): 2873 lbl = l.get_label() 2874 if 'mag' in lbl: 2875 pass 2876 elif lbl[1:] in ('obs','calc','bkg','zero','diff'): 2877 if lbl[1:] == 'obs': 2878 lblList.append('x') 2879 valueList.append(l.get_xdata()) 2880 c = plotOpt['colors'].get(lbl[1:],l.get_color()) 2881 if sum(c) == 4.0: continue 2882 lblList.append(lbl) 2883 valueList.append(l.get_ydata()) 2884 elif l in Page.tickDict.values(): 2885 c = plotOpt['colors'].get(lbl,l.get_color()) 2886 if sum(c) == 4.0: continue 2887 tickpos[lbl] = l.get_ydata()[0] 2888 lblList.append(lbl) 2889 valueList.append(l.get_xdata()) 2890 if tickpos: 2891 lblList.append('tick-pos') 2892 valueList.append([]) 2893 for i in tickpos: 2894 valueList[-1].append(i) 2895 valueList[-1].append(tickpos[i]) 2896 # add (obs-calc)/sigma [=(obs-calc)*sqrt(weight)] 2897 lblList.append('diff/sigma') 2898 valueList.append(Pattern[1][5]*np.sqrt(Pattern[1][2])) 2899 if sum(Pattern[1][0].mask): # are there are excluded points? If so, add them too 2900 lblList.append('excluded') 2901 valueList.append(1*Pattern[1][0].mask) 2902 # magnifcation values 2903 for l in Plot.texts: 2904 lbl = l.get_label() 2905 if 'mag' not in lbl: continue 2906 if l.xycoords == 'axes fraction': 2907 lbl = 'initial-mag' 2908 lblList.append(lbl) 2909 valueList.append([l.get_text()]) 2910 else: 2911 lbl = 'mag' 2912 lblList.append(lbl) 2913 valueList.append([l.get_text(),l.get_position()[0]]) 2914 # invert lists into columns, use iterator for all values 2915 if hasattr(itertools,'zip_longest'): #Python 3+ 2916 invertIter = itertools.zip_longest(*valueList,fillvalue=' ') 2917 else: 2918 invertIter = itertools.izip_longest(*valueList,fillvalue=' ') 2919 fp = open(filename,'w') 2920 Write2csv(fp,lblList,header=True) 2921 for row in invertIter: 2922 Write2csv(fp,row) 2923 fp.close() 2924 2836 2925 def onSave(event): 2837 2926 '''Write the current plot to a file … … 2840 2929 hccanvas = hcCanvas(hcfigure) 2841 2930 CopyRietveldPlot(G2frame,Pattern,Plot,Page,hcfigure) 2842 longFormatName,typ e= plotOpt['format'].split(',')2843 fil = G2G.askSaveFile(G2frame,'','.'+typ e.strip(),longFormatName)2844 if fil:2845 hcfigure.savefig(fil,format=type.strip())2931 longFormatName,typ = plotOpt['format'].split(',') 2932 fil = G2G.askSaveFile(G2frame,'','.'+typ.strip(),longFormatName) 2933 if 'csv' in typ: 2934 CopyRietveld2csv(Pattern,Plot,Page,fil) 2846 2935 dlg.EndModal(wx.ID_OK) 2936 elif fil: 2937 hcfigure.savefig(fil,format=typ.strip()) 2938 dlg.EndModal(wx.ID_OK) 2939 2847 2940 def onTextSize(event): 2848 2941 '''Respond to a change in text size from the slider … … 2851 2944 plotOpt['labelsize'] = event.GetInt() 2852 2945 RefreshPlot() 2946 2853 2947 def OnSelectColour(event): 2854 2948 '''Respond to a change in color
Note: See TracChangeset
for help on using the changeset viewer.