Changeset 2150 for trunk


Ignore:
Timestamp:
Feb 15, 2016 12:58:35 PM (9 years ago)
Author:
vondreele
Message:

incomplete mods to import powder - suggest not using until I fix it

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASII.py

    r2148 r2150  
    943943
    944944        '''
    945         if os.path.splitext(instfile)[1].lower() != '.instprm': # invalid file
    946             return None           
    947         if not os.path.exists(instfile): # no such file
    948             return None
    949945        File = open(instfile,'r')
    950946        lines = File.readlines()
     
    962958            when bank = n then use parameters; otherwise skip that set. Ignored if BANK n:
    963959            not present. NB: this kind of instprm file made by a Save all profile command in Instrument Parameters
    964 
     960        :return dict: Inst  instrument parameter dict if OK, or
     961                str: Error message if failed   
    965962        '''
    966963        if 'GSAS-II' not in instLines[0]: # not a valid file
     
    985982                            il += 1
    986983                            if il == len(instLines):
    987                                 return 'Bank %d not found in .instprm file'%(bank)
     984                                return 'Bank %d not found in instprm file'%(bank)
    988985                            S = instLines[il]
    989986                        continue
     
    1002999                    newVals.append(val)
    10031000            il += 1                       
    1004         return G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]),{}
     1001        return [G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]),{}]
    10051002       
    10061003    def ReadPowderIparm(self,instfile,bank,databanks,rd):
     
    10081005
    10091006        :param str instfile: name of instrument parameter file
    1010 
    10111007        :param int bank: the bank number read in the raw data file
    1012 
    10131008        :param int databanks: the number of banks in the raw data file.
    10141009          If the number of banks in the data and instrument parameter files
     
    10161011          is used to select the instrument parameter file. If not, the user
    10171012          is asked to make a selection.
    1018 
    10191013        :param obj rd: the raw data (histogram) data object. This
    10201014          sets rd.instbank.
     
    12331227                        Inst2['Icovar'] = Icovar
    12341228                return [Inst1,Inst2]
     1229               
     1230        def GetDefaultParms(self,rd):
     1231            '''Solicits from user a default set of parameters & returns Inst parm dict
     1232            param: self: refers to the GSASII main class
     1233            param: rd: importer data structure
     1234            returns: dict: Instrument parameter dictionary
     1235            '''       
     1236            import defaultIparms as dI
     1237            while True: # loop until we get a choice
     1238                choices = []
     1239                head = 'Select from default instrument parameters for '+rd.idstring
     1240   
     1241                for l in dI.defaultIparm_lbl:
     1242                    choices.append('Defaults for '+l)
     1243                res = rd.BlockSelector(
     1244                    choices,
     1245                    ParentFrame=self,
     1246                    title=head,
     1247                    header='Select default inst parms',
     1248                    useCancel=False)
     1249                if res is None: continue
     1250                rd.instfile = ''
     1251                rd.instmsg = 'default: '+dI.defaultIparm_lbl[res]
     1252                return self.ReadPowderInstprm(dI.defaultIparms[res],bank)    #this is [Inst1,Inst2] a pair of dicts
    12351253
    12361254        # stuff we might need from the reader
     
    12381256        bank = rd.powderentry[2]
    12391257        numbanks = rd.numbanks
    1240         # is there an instrument parameter file defined for the current data set?
    1241         # or if this is a read on a set of set of files, use the last one again
    1242         #if rd.instparm or (lastdatafile == filename and lastIparmfile):
    1243         if rd.instparm or lastIparmfile:
    1244             if rd.instparm:
    1245                 instfile = os.path.join(os.path.split(filename)[0],
    1246                                     rd.instparm)
    1247             else:
    1248                 # for multiple reads of one data file, reuse the inst parm file
    1249                 instfile = lastIparmfile
    1250             if os.path.exists(instfile):
    1251                 #print 'debug: try read',instfile
     1258        #1st priority: is there an instrument parameter file matching the current file
     1259        # with extension .instprm, .prm, .inst, or .ins? If so read it
     1260        basename = os.path.splitext(filename)[0]
     1261        for ext in '.instprm','.prm','.inst','.ins':
     1262            instfile = basename + ext
     1263            if not os.path.exists(instfile):
     1264                continue
     1265            if 'instprm' in instfile:
    12521266                Lines = self.OpenPowderInstprm(instfile)
    1253                 instParmList = None
    1254                 if Lines is not None:
    1255                     instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
     1267                instParmList = self.ReadPowderInstprm(Lines,bank)    #this is [Inst1,Inst2] a pair of dicts
    12561268                if 'list' in str(type(instParmList)):
    12571269                    rd.instfile = instfile
     
    12591271                    return instParmList
    12601272                else:
    1261                     rd.instmsg = instParmList   #an error message
    1262                     return None
     1273                    #print 'debug: open/read failed',instfile
     1274                    pass # fail silently
     1275            else:
    12631276                Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)
    12641277                if Iparm:
     
    12671280                    rd.instmsg = instfile + ' bank ' + str(rd.instbank)
    12681281                    return SetPowderInstParms(Iparm,rd)
     1282                else:
     1283                    #print 'debug: open/read failed',instfile
     1284                    pass # fail silently
     1285
     1286        #2nd priority: is there an instrument parameter file defined for the current data set?
     1287        # or if this is a read on a set of set of files, use the last one again
     1288        #if rd.instparm or (lastdatafile == filename and lastIparmfile):
     1289        if rd.instparm or lastIparmfile:
     1290            if rd.instparm:
     1291                instfile = os.path.join(os.path.split(filename)[0],rd.instparm)
     1292            else:
     1293                # for multiple reads of one data file, reuse the inst parm file
     1294                instfile = lastIparmfile
     1295            if os.path.exists(instfile):
     1296                #print 'debug: try read',instfile
     1297                if 'instprm' in instfile:   #GSAS-II file must have .instprm as extension
     1298                    Lines = self.OpenPowderInstprm(instfile)
     1299                    if Lines is not None:
     1300                        instParmList = self.ReadPowderInstprm(Lines,bank)   #this is [Inst1,Inst2] a pair of dicts
     1301                else:   #old GSAS style iparm file - could be named anything!
     1302                    Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)
     1303                    if Iparm:
     1304                        #print 'debug: success'
     1305                        rd.instfile = instfile
     1306                        rd.instmsg = instfile + ' bank ' + str(rd.instbank)
     1307                        instParmList = SetPowderInstParms(Iparm,rd)     #this is [Inst1,Inst2] a pair of dicts
     1308                if 'list' in str(type(instParmList)):   #record stuff & return stuff
     1309                    rd.instfile = instfile
     1310                    rd.instmsg = 'GSAS-II file '+instfile
     1311                    return instParmList
     1312                else:   #bad iparms - try default
     1313                    rd.instmsg = instParmList   #an error message
     1314                    return GetDefaultParms(self,rd)
    12691315            else:
    12701316                self.ErrorDialog('Open Error','Error opening instrument parameter file '
    12711317                    +str(instfile)+' requested by file '+ filename)
    1272         # is there an instrument parameter file matching the current file
    1273         # with extension .inst or .prm? If so read it
    1274         basename = os.path.splitext(filename)[0]
    1275         for ext in '.instprm','.prm','.inst','.ins':
    1276             instfile = basename + ext
    1277             Lines = self.OpenPowderInstprm(instfile)
    1278             instParmList = None
    1279             if Lines is not None:
    1280                 instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    1281             if instParmList is not None:
    1282                 rd.instfile = instfile
    1283                 rd.instmsg = 'GSAS-II file '+instfile
    1284                 return instParmList
    1285             Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)
    1286             if Iparm:
    1287                 #print 'debug: success'
    1288                 rd.instfile = instfile
    1289                 rd.instmsg = instfile + ' bank ' + str(rd.instbank)
    1290                 return SetPowderInstParms(Iparm,rd)
    1291             else:
    1292                 #print 'debug: open/read failed',instfile
    1293                 pass # fail silently
    1294 
    12951318        # did we read the data file from a zip? If so, look there for a
    12961319        # instrument parameter file
    12971320        if self.zipfile:
    12981321            for ext in '.instprm','.prm','.inst','.ins':
    1299                 instfile = G2IO.ExtractFileFromZip(
    1300                     self.zipfile,
    1301                     selection=os.path.split(basename + ext)[1],
    1302                     parent=self)
     1322                instfile = G2IO.ExtractFileFromZip(self.zipfile,
     1323                    selection=os.path.split(basename + ext)[1],parent=self)
    13031324                if instfile is not None and instfile != self.zipfile:
    13041325                    print 'debug:',instfile,'created from ',self.zipfile
     
    13061327                    instParmList = None
    13071328                    if Lines is not None:
    1308                         instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    1309                     if instParmList is not None:
     1329                        instParmList = self.ReadPowderInstprm(Lines,bank)    #this is [Inst1,Inst2] a pair of dicts
     1330                    if 'dict' in str(type(instParmList)):
    13101331                        rd.instfile = instfile
    13111332                        rd.instmsg = 'GSAS-II file '+instfile
    13121333                        return instParmList
     1334                    else:
     1335                        rd.instmsg = instParmList   #an error message
     1336                        print 'three',instParmList
     1337                        return GetDefaultParms(self,rd)
    13131338                    Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)
    13141339                    if Iparm:
     
    13361361                instfile = dlg.GetPath()
    13371362            dlg.Destroy()
    1338             if not instfile: break
    1339             Lines = self.OpenPowderInstprm(instfile)
    1340             instParmList = None
    1341             if Lines is not None:
    1342                 instParmList = self.ReadPowderInstprm(Lines,bank)    #know Bank - see above
    1343             if instParmList is not None:
    1344                 rd.instfile = instfile
    1345                 rd.instmsg = 'GSAS-II file '+instfile
    1346                 return instParmList
    1347             Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)
    1348             if Iparm:
    1349                 #print 'debug: success with',instfile
    1350                 rd.instfile = instfile
    1351                 rd.instmsg = instfile + ' bank ' + str(rd.instbank)
    1352                 return SetPowderInstParms(Iparm,rd)
     1363            if not instfile:
     1364                return GetDefaultParms(self,rd) #on Cancel/break
     1365            if 'instprm' in instfile:
     1366                Lines = self.OpenPowderInstprm(instfile)
     1367                print instfile,bank
     1368                if Lines is not None:
     1369                    instParmList = self.ReadPowderInstprm(Lines,bank)    #this is [Inst1,Inst2] a pair of dicts
     1370                if 'list' in str(type(instParmList)):
     1371                    rd.instfile = instfile
     1372                    rd.instmsg = 'GSAS-II file '+instfile
     1373                    return instParmList
     1374                else:
     1375                    rd.instmsg = instParmList   #an error message
     1376                    return GetDefaultParms(self,rd)
    13531377            else:
    1354                 self.ErrorDialog('Read Error',
    1355                                  'Error opening/reading file '+str(instfile))
    1356        
    1357         # still no success: offer user choice of defaults
    1358         import defaultIparms as dI
    1359         while True: # loop until we get a choice
    1360             choices = []
    1361             head = 'Select from default instrument parameters for '+rd.idstring
    1362 
    1363             for l in dI.defaultIparm_lbl:
    1364                 choices.append('Defaults for '+l)
    1365             res = rd.BlockSelector(
    1366                 choices,
    1367                 ParentFrame=self,
    1368                 title=head,
    1369                 header='Select default inst parms',
    1370                 useCancel=False)
    1371             if res is None: continue
    1372             rd.instfile = ''
    1373             rd.instmsg = 'default: '+dI.defaultIparm_lbl[res]
    1374             return self.ReadPowderInstprm(dI.defaultIparms[res],bank)    #know Bank - see above
    1375 
     1378                Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)
     1379                if Iparm:
     1380                    #print 'debug: success with',instfile
     1381                    rd.instfile = instfile
     1382                    rd.instmsg = instfile + ' bank ' + str(rd.instbank)
     1383                    return SetPowderInstParms(Iparm,rd)
     1384                else:
     1385                    self.ErrorDialog('Read Error',
     1386                                     'Error opening/reading file '+str(instfile))
     1387       
    13761388    def OnImportPowder(self,event):
    13771389        '''Called in response to an Import/Powder Data/... menu item
  • TabularUnified trunk/GSASIIIO.py

    r2109 r2150  
    14071407        dlg = wx.MultiChoiceDialog(ParentFrame,title, header,ChoiceList+['Select all'],
    14081408            wx.CHOICEDLG_STYLE)
    1409         dlg.CenterOnParent()
     1409        dlg.CenterOnScreen()
    14101410        if size: dlg.SetSize(size)
    14111411        if dlg.ShowModal() == wx.ID_OK:
Note: See TracChangeset for help on using the changeset viewer.