Changeset 3825


Ignore:
Timestamp:
Feb 15, 2019 10:43:35 AM (6 years ago)
Author:
vondreele
Message:

create csv exporter for small angle data - includes size distribution histogram if any.
fix formatting issue with size distribution axis label
a bit different incomm. mag str fctr. math - still wrong

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIIO.py

    r3814 r3825  
    13431343        self.Histograms = {}
    13441344        self.powderDict = {}
     1345        self.sasdDict = {}
    13451346        self.xtalDict = {}
    13461347        self.parmDict = {}
     
    14781479            else:
    14791480                choices = sorted(self.powderDict.values())
     1481                hnum = G2G.ItemSelector(choices,self.G2frame)
     1482                if hnum is None: return True
     1483                self.histnam = [choices[hnum]]
     1484                numselected = len(self.histnam)
     1485        elif self.currentExportType == 'sasd':
     1486            if len(self.sasdDict) == 0:
     1487                self.G2frame.ErrorDialog(
     1488                    'Empty project',
     1489                    'Project does not contain any small angle data.')
     1490                return True
     1491            elif len(self.sasdDict) == 1:
     1492                self.histnam = self.sasdDict.values()
     1493            elif self.multiple:
     1494                choices = sorted(self.sasdDict.values())
     1495                hnum = G2G.ItemSelector(choices,self.G2frame,multiple=True)
     1496                if not hnum: return True
     1497                self.histnam = [choices[i] for i in hnum]
     1498                numselected = len(self.histnam)
     1499            else:
     1500                choices = sorted(self.sasdDict.values())
    14801501                hnum = G2G.ItemSelector(choices,self.G2frame)
    14811502                if hnum is None: return True
     
    16551676        self.OverallParms = {}
    16561677        self.powderDict = {}
     1678        self.sasdDict = {}
    16571679        self.xtalDict = {}
    16581680        self.Phases = {}
     
    16801702        elif self.currentExportType == 'image':
    16811703            histType = 'IMG'
     1704        elif self.currentExportType == 'sasd':
     1705            histType = 'SASD'
    16821706
    16831707        if histType: # Loading just one kind of tree entry
     
    17121736                elif hist.startswith("HKLF"):
    17131737                    d = self.xtalDict
     1738                elif hist.startswith("SASD"):
     1739                    d = self.sasdDict
    17141740                else:
    17151741                    return                   
     
    17371763            elif hist.startswith("HKLF"):
    17381764                self.xtalDict[i] = hist
     1765            elif hist.startswith("SASD"):
     1766                self.sasdDict[i] = hist
    17391767
    17401768    def dumpTree(self,mode='type'):
  • TabularUnified trunk/GSASIIdataGUI.py

    r3814 r3825  
    25512551        mapmenu = wx.Menu()
    25522552        item = menu.AppendSubMenu(mapmenu,'Maps as','Export density map(s)')
     2553       
     2554        sasdmenu = wx.Menu()
     2555        item = menu.AppendSubMenu(sasdmenu,'Small angle data as','Export small angle histogram(s)')
    25532556
    25542557        # sequential exports are handled differently; N.B. enabled in testSeqRefineMode
     
    25802583                elif typ == "map":
    25812584                    submenu = mapmenu
     2585                elif typ == "sasd":
     2586                    submenu = sasdmenu
    25822587                # elif typ == "pdf":
    25832588                #     submenu = pdfmenu
     
    50445049        for lbl,txt in (('Phase','Export selected phase(s)'),
    50455050                        ('Project','Export entire sequential fit'),
    5046                         ('Powder','Export selected powder histogram(s)')
     5051                        ('Powder','Export selected powder histogram(s)'),
     5052                        ('sasd','Export selected small angle histogram(s)')
    50475053                        ):
    50485054            objlist = []
  • TabularUnified trunk/GSASIIplot.py

    r3819 r3825  
    49824982    Plot.set_title('Size Distribution')
    49834983    Plot.set_xlabel(r'$D, \AA$',fontsize=14)
    4984     Plot.set_ylabel(r'$Volume distribution f(D)$',fontsize=14)
     4984    Plot.set_ylabel(r'$Volume\ distribution,\ f(D)$',fontsize=14)
    49854985    if data['Size']['logBins']:
    49864986        Plot.set_xscale("log",nonposx='mask')
  • TabularUnified trunk/GSASIIpy3.py

    r3136 r3825  
    111111    else: # in range where g formatting should do what I want
    112112        # used?
    113         decimals = digits[0] - 1
     113        decimals = digits[0] - 6
    114114        fmt = "{" + (":{:d}.{:d}g".format(digits[0],decimals))+"}"
    115115    try:
  • TabularUnified trunk/GSASIIstrMath.py

    r3821 r3825  
    16091609            fbm = (Q*TMcorr[nxs,:,nxs,nxs,:]*sinm[nxs,:,nxs,:,:]*SMag[nxs,nxs,:,:,:])
    16101610           
    1611             fas = np.sum(np.sum(fam,axis=-1)**2,axis=-1)      #xyz,Nref,ntau; sum ops & atoms
    1612             fbs = np.sum(np.sum(fbm,axis=-1)**2,axis=-1)      #ditto
     1611            fas = np.sum(np.sum(fam,axis=-1),axis=-1)/ngl      #xyz,Nref,ntau; sum ops & atoms
     1612            fbs = np.sum(np.sum(fbm,axis=-1),axis=-1)/ngl      #ditto
    16131613           
    1614             refl.T[10] = np.sum(np.sum(fas,axis=0)/ngl,axis=-1)+np.sum(np.sum(fbs,axis=0)/ngl,axis=-1)    #square of sums
     1614            refl.T[10] = np.sum(np.sum(fas,axis=-1),axis=0)**2+np.sum(np.sum(fbs,axis=-1),axis=0)**2    #square of sums
    16151615#            refl.T[11] = mphase[:,0,0]  #ignore f' & f"
    16161616           
  • TabularUnified trunk/exports/G2export_csv.py

    r3738 r3825  
    354354        print(hist+' reflections written to file '+self.fullpath)
    355355
     356class ExportSASDCSV(G2IO.ExportBaseclass):
     357    '''Used to create a csv file for a small angle data set
     358
     359    :param wx.Frame G2frame: reference to main GSAS-II frame
     360    '''
     361    def __init__(self,G2frame):
     362        super(self.__class__,self).__init__( # fancy way to say <parentclass>.__init__
     363            G2frame=G2frame,
     364            formatName = 'CSV file',
     365            extension='.csv',
     366            longFormatName = 'Export small angle data as comma-separated (csv) file'
     367            )
     368        self.exporttype = ['sasd']
     369        #self.multiple = False # only allow one histogram to be selected
     370        self.multiple = True
     371
     372    def Writer(self,TreeName,filename=None):
     373        self.OpenFile(filename)
     374        histblk = self.Histograms[TreeName]
     375        if len(self.Histograms[TreeName]['Models']['Size']['Distribution']):
     376            self.Write('"Size Distribution"')
     377            Distr = np.array(self.Histograms[TreeName]['Models']['Size']['Distribution'])
     378            WriteList(self,("bin_pos","bin_width","bin_value"))
     379            digitList = 2*((13,3),)+((13,4,'g'),)
     380            for bindata in Distr.T:
     381                line = ""
     382                for val,digits in zip(bindata,digitList):
     383                    if line: line += ','
     384                    line += G2py3.FormatValue(val,digits)
     385                self.Write(line)           
     386        self.Write('"Small angle data"')
     387        Parms = self.Histograms[TreeName]['Instrument Parameters'][0]
     388        for parm in Parms:
     389            if parm in ['Type','Source',]:
     390                line = '"Instparm: %s","%s"'%(parm,Parms[parm][0])
     391            elif parm in ['Lam',]:
     392                line = '"Instparm: %s",%10.6f'%(parm,Parms[parm][1])
     393            else:
     394                line = '"Instparm: %s",%10.2f'%(parm,Parms[parm][1])
     395            self.Write(line)
     396        WriteList(self,("q","y_obs","y_sig","y_calc","y_bkg"))
     397        digitList = 5*((13,5,'g'),)
     398        for vallist in zip(histblk['Data'][0],
     399                       histblk['Data'][1],
     400                       1./np.sqrt(histblk['Data'][2]),
     401                       histblk['Data'][3],
     402                       histblk['Data'][4],
     403                       ):
     404            line = ""
     405            for val,digits in zip(vallist,digitList):
     406                if line: line += ','
     407                line += G2py3.FormatValue(val,digits)
     408            self.Write(line)
     409        self.CloseFile()
     410       
     411    def Exporter(self,event=None):
     412        '''Export a set of small angle data as a csv file
     413        '''
     414        # the export process starts here
     415        self.InitExport(event)
     416        # load all of the tree into a set of dicts
     417        self.loadTree()
     418        if self.ExportSelect( # set export parameters
     419            AskFile='single' # get a file name/directory to save in
     420            ): return
     421        filenamelist = []
     422        for hist in self.histnam:
     423            if len(self.histnam) == 1:
     424                name = self.filename
     425            else:    # multiple files: create a unique name from the histogram
     426                name = self.MakePWDRfilename(hist)
     427            fileroot = os.path.splitext(G2obj.MakeUniqueLabel(name,filenamelist))[0]
     428            # create the file
     429            self.filename = os.path.join(self.dirname,fileroot + self.extension)
     430            self.Writer(hist)
     431            print('Histogram '+hist+' written to file '+self.fullpath)
     432
    356433class ExportSingleCSV(G2IO.ExportBaseclass):
    357434    '''Used to create a csv file with single crystal reflection data
Note: See TracChangeset for help on using the changeset viewer.