Changeset 2820


Ignore:
Timestamp:
May 4, 2017 4:06:25 PM (5 years ago)
Author:
vondreele
Message:

PWDR import now scriptable for single bank patterns

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2818 r2820  
    520520                if Start:   #clear old bank selections to allow new ones to be selected by user
    521521                    rd.selections = []
    522                     Start = False
     522                    rd.dnames = []
    523523                rd.ReInitialize() # purge anything from a previous read
    524524                fp.seek(0)  # rewind
     
    528528                    if rd.errors:
    529529                        errorReport += ': '+rd.errors
    530                     continue
     530                    continue
     531                if len(rd.selections)>1 and Start:
     532                    dlg = G2G.G2MultiChoiceDialog(self,'Dataset Selector','Select data to read from the list below',rd.dnames)
     533                    if dlg.ShowModal() == wx.ID_OK:
     534                        rd.selections = dlg.GetSelections()
     535                    Start = False
     536                    dlg.Destroy()
    531537                repeat = True
    532538                rdbuffer = {} # create temporary storage for file reader
     
    562568                                rd.Data['ImageTag'] = rd.repeatcount
    563569                            rd.Data['formatName'] = rd.formatName
    564 #                            print rd.readfilename
    565 #                            print rd.sumfile
    566 #                            print rd.Image.shape,rd.Image.dtype
    567570                            if rd.sumfile:
    568571                                rd.readfilename = rd.sumfile
     
    703706        header = 'Select histogram(s) to add to new phase(s):'
    704707        for phaseName in newPhaseList:
    705             header += '\n  '+str(phaseName)
     708            header += '\n  '+phaseName
    706709
    707710        notOK = True
     
    10921095          If the number of banks in the data and instrument parameter files
    10931096          agree, then the sets of banks are assumed to match up and bank
    1094           is used to select the instrument parameter file. If not, the user
    1095           is asked to make a selection.
     1097          is used to select the instrument parameter file. If not and not TOF,
     1098          the user is asked to make a selection.
    10961099        :param obj rd: the raw data (histogram) data object. This
    10971100          sets rd.instbank.
     
    11181121            rd.powderentry[2] = 1
    11191122            return Iparm
    1120 #        if 'PNT' in hType:  # not sure what this is about
    1121 #            rd.instbank = bank
    1122 #        elif ibanks != databanks or bank is None:
    1123         if (ibanks != databanks and databanks != 1) or bank is None:
    1124             # number of banks in data and prm file not not agree, need a
    1125             # choice from a human here
     1123        if 'PNT' in Iparm['INS   HTYPE ']:      #allow mismatch between banks in data  iparm file for TOF
     1124            rd.instbank = bank
     1125        elif ibanks != databanks or bank is None:
    11261126            choices = []
    11271127            for i in range(1,1+ibanks):
     
    11901190                    wave2 = G2IO.sfloat(s[10:20])
    11911191                v = (wave1,wave2,
    1192                      G2IO.sfloat(s[20:30]),G2IO.sfloat(s[55:65]),G2IO.sfloat(s[40:50])) #get lam1, lam2, zero, pola & ratio
     1192                     G2IO.sfloat(s[20:30])/100.,G2IO.sfloat(s[55:65]),G2IO.sfloat(s[40:50])) #get lam1, lam2, zero, pola & ratio
    11931193                if not v[1]:
    11941194                    names = ['Type','Lam','Zero','Polariz.','U','V','W','X','Y','SH/L','Azimuth']
     
    14351435                    return GetDefaultParms(self,rd)
    14361436            else:
    1437                 self.ErrorDialog('Open Error',
    1438                                  u'Error opening instrument parameter file '
    1439                                 +'{} requested by file '.format(instfile,filename))
     1437                self.ErrorDialog('Open Error',u'Error opening instrument parameter file '   \
     1438                    +'{} requested by file '.format(instfile,filename))
    14401439        #Finally - ask user for Instrument parametrs file - seems it can't be in a zip file
    14411440        while True: # loop until we get a file that works or we get a cancel
     
    15251524        lastdatafile = ''
    15261525        newHistList = []
    1527         lastVals = []
     1526#        lastVals = []
    15281527        self.EnablePlot = False
    15291528        for rd in rdlist:
     
    15321531            else:
    15331532                # get instrument parameters for each dataset, unless already set
    1534                 if lastIparmfile:  # is this histogram like previous?
    1535                     if lastVals != (rd.powderdata[0].min(),rd.powderdata[0].max(),len(rd.powderdata[0])):
    1536                         lastIparmfile = ''
     1533#                if lastIparmfile:  # is this histogram like previous?
     1534#                    if lastVals != (rd.powderdata[0].min(),rd.powderdata[0].max(),len(rd.powderdata[0])):
     1535#                        lastIparmfile = ''
    15371536                Iparms = self.GetPowderIparm(rd, Iparm, lastIparmfile, lastdatafile)
    15381537                if not Iparms:  #may have bailed out
     
    15421541                if rd.repeat_instparm:
    15431542                    lastIparmfile = rd.instfile
    1544                     lastVals = (rd.powderdata[0].min(),rd.powderdata[0].max(),len(rd.powderdata[0]))
     1543#                    lastVals = (rd.powderdata[0].min(),rd.powderdata[0].max(),len(rd.powderdata[0]))
    15451544                # override any keys in read instrument parameters with ones set in import
    15461545                for key in Iparm1: 
     
    32533252        sub = self.PatternTree.AppendItem(parent=sub,text=PhaseName)
    32543253        E,SGData = G2spc.SpcGroup('P 1')
    3255         self.PatternTree.SetItemPyData(sub,G2IO.SetNewPhase(Name=PhaseName,SGData=SGData))
     3254        self.PatternTree.SetItemPyData(sub,G2obj.SetNewPhase(Name=PhaseName,SGData=SGData))
    32563255        G2gd.SelectDataTreeItem(self,sub) #bring up new phase General tab
    32573256       
  • trunk/GSASIIimgGUI.py

    r2798 r2820  
    9393                if backImage is not None:
    9494                    sumImg += np.array(backImage*backScale,dtype='int32')
    95     if darkImg: del darkImg         #force cleanup
    96     if backImg: del backImg
     95#    if darkImg: del darkImg         #force cleanup
     96#    if backImg: del backImg
    9797    sumImg -= int(data.get('Flat Bkg',0))
    9898    Imax = np.max(sumImg)
  • trunk/GSASIIobj.py

    r2818 r2820  
    18121812        self.SciPy = False          #image reader needed scipy
    18131813        self.repeat = False
    1814         self.repeat = False
    18151814        self.repeatcount = 0
    18161815        self.readfilename = '?'
  • trunk/GSASIIpwdGUI.py

    r2817 r2820  
    3333import GSASIIpwd as G2pwd
    3434import GSASIIIO as G2IO
     35import GSASIIobj as G2obj
    3536import GSASIIlattice as G2lat
    3637import GSASIIspc as G2spc
     
    31583159                E,SGData = G2spc.SpcGroup(controls[13])
    31593160                G2frame.PatternTree.SetItemPyData(sub, \
    3160                     G2IO.SetNewPhase(Name=PhaseName,SGData=SGData,cell=cell[1:],Super=ssopt))
     3161                    G2obj.SetNewPhase(Name=PhaseName,SGData=SGData,cell=cell[1:],Super=ssopt))
    31613162                Status.SetStatusText('Change space group from '+str(controls[13])+' if needed')
    31623163        finally:
  • trunk/GSASIIscriptable.py

    r2817 r2820  
    1313import sys
    1414import cPickle
     15import imp
    1516import GSASIIpath
    1617import GSASIIobj as G2obj
     
    9697    print('project save successful')
    9798   
    98 def ImportPowder(filename,reader):
    99     print 'importer'
     99def ImportPowder(reader,filename,bankNo=0):
     100    rdfile,rdpath,descr = imp.find_module(reader)
     101    rdclass = imp.load_module(reader,rdfile,rdpath,descr)
     102    rd = rdclass.GSAS_ReaderClass()   
     103    fl = open(filename)
     104    if rd.ContentsValidator(fl):
     105        fl.seek(0)
     106        rd.selections = [bankNo,]
     107        if rd.Reader(filename,fl):
     108            return rd
     109    print rd.errors
     110    return None
    100111   
    101112
  • trunk/imports/G2pwd_GPX.py

    r2817 r2820  
    1616import numpy as np
    1717import GSASIIobj as G2obj
    18 import GSASIIIO as G2IO
    1918import GSASIIpath
    2019GSASIIpath.SetVersionNumber("$Revision$")
     
    4039            self.errors = 'This is not a valid .GPX file. Not recognized by cPickle'
    4140            return False
    42         return True
     41        filepointer.seek(0)
     42        nhist = 0
     43        while True:
     44            try:
     45                data = cPickle.load(filepointer)
     46            except EOFError:
     47                break
     48            if data[0][0][:4] == 'PWDR':
     49                nhist += 1
     50                self.dnames.append(data[0][0])
     51        if nhist:
     52            if not len(self.selections):    #no PWDR entries
     53                self.selections = range(nhist)
     54                return True
     55        self.errors = 'No powder entries found'
     56        return False
    4357
    4458    def Reader(self,filename,filepointer, ParentFrame=None, **kwarg):
     
    5165        # reload previously saved values
    5266        if self.repeat and rdbuffer is not None:
    53             selections = rdbuffer.get('selections')
     67            self.selections = rdbuffer.get('selections')
    5468            poslist = rdbuffer.get('poslist')
    5569            histnames = rdbuffer.get('histnames')
     
    7589        elif len(histnames) == 1: # one block, no choices
    7690            selblk = 0
    77         elif self.repeat and selections is not None:
     91        elif self.repeat and self.selections is not None:
    7892            # we were called to repeat the read
    7993            #print 'debug: repeat #',self.repeatcount,'selection',selections[self.repeatcount]
    80             selblk = selections[self.repeatcount]
     94            selblk = self.selections[self.repeatcount]
    8195            self.repeatcount += 1
    82             if self.repeatcount >= len(selections): self.repeat = False
     96            if self.repeatcount >= len(self.selections): self.repeat = False
    8397        else:                       # choose from options               
    84             selections = G2IO.MultipleBlockSelector(
    85                 histnames,
    86                 ParentFrame=ParentFrame,
    87                 title='Select histogram(s) to read from the list below',
    88                 size=(600,250),
    89                 header='Dataset Selector')
    90             if len(selections) == 0:
    91                 self.errors = 'No histogram selected'
    92                 return False
    93             selblk = selections[0] # select first in list
    94             if len(selections) > 1: # prepare to loop through again
     98            selblk = self.selections[0] # select first in list
     99            if len(self.selections) > 1: # prepare to loop through again
    95100                self.repeat = True
    96101                self.repeatcount = 1
     
    98103                    rdbuffer['poslist'] = poslist
    99104                    rdbuffer['histnames'] = histnames
    100                     rdbuffer['selections'] = selections
     105                    rdbuffer['selections'] = self.selections
    101106
    102107        fl = open(filename,'rb')
  • trunk/imports/G2pwd_fxye.py

    r2817 r2820  
    1717import numpy as np
    1818import GSASIIobj as G2obj
    19 import GSASIIIO as G2IO
    2019import GSASIIpath
    2120GSASIIpath.SetVersionNumber("$Revision$")
     
    3231        self.clockWd = {}
    3332        self.TimeMap = {}
     33        self.dnames = []
    3434
    3535    # Validate the contents -- look for a bank line
    3636    def ContentsValidator(self, filepointer):
    37         'Validate by checking to see if the file has BANK lines'
     37        'Validrate by checking to see if the file has BANK lines & count them'
    3838        #print 'ContentsValidator: '+self.formatName
     39        nBanks= 0
     40        fname = ospath.basename(filepointer.name)
    3941        for i,line in enumerate(filepointer):
    4042            self.GSAS = True
     
    4648            if line[0] == '#': continue
    4749            if line[:4] == 'BANK':
    48                 return True
     50                self.dnames.append(fname+' '+''.join(line.split()[:2]))
     51                nBanks += 1
     52                continue
    4953            elif line[:7] == 'Monitor': continue
    5054            elif line [:8] == 'TIME_MAP':          #LANSCE TOF data
    51                 return True
    52             else:
    53                 self.errors = 'Unexpected information in line: '+str(i+1)
    54                 if all([ord(c) < 128 and ord(c) != 0 for c in str(line)]): # show only if ASCII
    55                     self.errors += '  '+str(line)
    56                 else:
    57                     self.errors += '  (binary)'
    58                 return False
     55                continue
     56#            else:
     57#                if not all(c in ' 0123456789.eE+-' for c in line[:-1]):
     58#                    self.errors = 'Unexpected information in line: '+str(i+1)
     59#                    self.errors += '  '+str(line)
     60#                    return False
     61        if nBanks:
     62            if not len(self.selections):
     63                self.selections = range(nBanks)
     64            return True
     65        self.errors = 'No BANK records found'
    5966        return False # no bank records
    6067
     
    322329            if self.repeatcount >= len(self.selections): self.repeat = False
    323330        else:                       # choose from options
    324             if not len(self.selections):    #use previous selection, otherwise...
    325                 self.selections = G2IO.MultipleBlockSelector(
    326                     Banks,
    327                     ParentFrame=ParentFrame,
    328                     title='Select Bank(s) to read from the list below',
    329                     size=(600,300),
    330                     header='Dataset Selector')
    331             if len(self.selections) == 0:
    332                 self.errors = 'No banks selected'
    333                 return False
    334331            selblk = self.selections[0] # select first in list
    335332            if len(self.selections) > 1: # prepare to loop through again
Note: See TracChangeset for help on using the changeset viewer.