Changeset 2151
- Timestamp:
- Feb 16, 2016 4:19:48 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASII.py
r2150 r2151 1234 1234 returns: dict: Instrument parameter dictionary 1235 1235 ''' 1236 sind = lambda x: math.sin(x*math.pi/180.) 1237 tand = lambda x: math.tan(x*math.pi/180.) 1236 1238 import defaultIparms as dI 1237 1239 while True: # loop until we get a choice … … 1241 1243 for l in dI.defaultIparm_lbl: 1242 1244 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) 1245 res = rd.BlockSelector(choices,ParentFrame=self,title=head, 1246 header='Select default inst parms',useCancel=False) 1249 1247 if res is None: continue 1250 1248 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 1249 if 'Generic' in choices[res]: 1250 dlg = G2G.MultiFloatDialog(self,title='Generic TOF detector bank', 1251 prompts=['Total FP','2-theta',],values=[25.0,150.,], 1252 limits=[[6.,200.],[5.,175.],],formats=['%6.2f','%6.1f',]) 1253 if dlg.ShowModal() == wx.ID_OK: 1254 FP,tth = dlg.GetValues() 1255 difC = 252.816*2.*FP*sind(tth/2.) 1256 sig1 = 50.+2.5e-6*(difC/tand(tth/2.))**2 1257 rd.instmsg = 'default: '+dI.defaultIparm_lbl[res] 1258 Inst = self.ReadPowderInstprm(dI.defaultIparms[res],bank) 1259 Inst[0]['difC'] = [difC,difC,0] 1260 Inst[0]['sig-1'] = [sig1,sig1,0] 1261 return Inst #this is [Inst1,Inst2] a pair of dicts 1262 dlg.Destroy() 1263 else: 1264 rd.instmsg = 'default: '+dI.defaultIparm_lbl[res] 1265 return self.ReadPowderInstprm(dI.defaultIparms[res],bank) #this is [Inst1,Inst2] a pair of dicts 1253 1266 1254 1267 # stuff we might need from the reader … … 1260 1273 basename = os.path.splitext(filename)[0] 1261 1274 for ext in '.instprm','.prm','.inst','.ins': 1262 instfile = basename + ext 1275 if self.zipfile: 1276 instfile = G2IO.ExtractFileFromZip(self.zipfile, 1277 selection=os.path.split(basename + ext)[1],parent=self) 1278 else: 1279 instfile = basename + ext 1263 1280 if not os.path.exists(instfile): 1264 1281 continue … … 1293 1310 # for multiple reads of one data file, reuse the inst parm file 1294 1311 instfile = lastIparmfile 1312 if self.zipfile: 1313 instfile = G2IO.ExtractFileFromZip(self.zipfile, 1314 selection=os.path.split(instfile)[1],parent=self) 1295 1315 if os.path.exists(instfile): 1296 1316 #print 'debug: try read',instfile … … 1316 1336 self.ErrorDialog('Open Error','Error opening instrument parameter file ' 1317 1337 +str(instfile)+' requested by file '+ filename) 1318 # did we read the data file from a zip? If so, look there for a 1319 # instrument parameter file 1320 if self.zipfile: 1321 for ext in '.instprm','.prm','.inst','.ins': 1322 instfile = G2IO.ExtractFileFromZip(self.zipfile, 1323 selection=os.path.split(basename + ext)[1],parent=self) 1324 if instfile is not None and instfile != self.zipfile: 1325 print 'debug:',instfile,'created from ',self.zipfile 1326 Lines = self.OpenPowderInstprm(instfile) 1327 instParmList = None 1328 if Lines is not None: 1329 instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts 1330 if 'dict' in str(type(instParmList)): 1331 rd.instfile = instfile 1332 rd.instmsg = 'GSAS-II file '+instfile 1333 return instParmList 1334 else: 1335 rd.instmsg = instParmList #an error message 1336 print 'three',instParmList 1337 return GetDefaultParms(self,rd) 1338 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1339 if Iparm: 1340 rd.instfile = instfile 1341 rd.instmsg = instfile + ' bank ' + str(rd.instbank) 1342 return SetPowderInstParms(Iparm,rd) 1343 else: 1344 #print 'debug: open/read for',instfile,'from',self.zipfile,'failed' 1345 pass # fail silently 1346 1338 # # did we read the data file from a zip? If so, look there for a 1339 # # instrument parameter file 1340 # if self.zipfile: 1341 # for ext in '.instprm','.prm','.inst','.ins': 1342 # instfile = G2IO.ExtractFileFromZip(self.zipfile, 1343 # selection=os.path.split(basename + ext)[1],parent=self) 1344 # if instfile is not None and instfile != self.zipfile: 1345 # print 'debug:',instfile,'created from ',self.zipfile 1346 # Lines = self.OpenPowderInstprm(instfile) 1347 # instParmList = None 1348 # if Lines is not None: 1349 # instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts 1350 # if 'dict' in str(type(instParmList)): 1351 # rd.instfile = instfile 1352 # rd.instmsg = 'GSAS-II file '+instfile 1353 # return instParmList 1354 # else: 1355 # rd.instmsg = instParmList #an error message 1356 # print 'three',instParmList 1357 # return GetDefaultParms(self,rd) 1358 # Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1359 # if Iparm: 1360 # rd.instfile = instfile 1361 # rd.instmsg = instfile + ' bank ' + str(rd.instbank) 1362 # return SetPowderInstParms(Iparm,rd) 1363 # else: 1364 # #print 'debug: open/read for',instfile,'from',self.zipfile,'failed' 1365 # pass # fail silently 1366 # 1367 #Finally - ask user for Instrument parametrs file - seems it can't be in a zip file 1347 1368 while True: # loop until we get a file that works or we get a cancel 1348 1369 instfile = '' 1349 1370 pth = G2G.GetImportPath(self) 1350 1371 if not pth: pth = '.' 1351 dlg = wx.FileDialog( 1352 self, 1372 dlg = wx.FileDialog(self, 1353 1373 'Choose inst. param file for "'+rd.idstring+'" (or Cancel for default)', 1354 1374 pth, '', … … 1365 1385 if 'instprm' in instfile: 1366 1386 Lines = self.OpenPowderInstprm(instfile) 1367 print instfile,bank1368 1387 if Lines is not None: 1369 1388 instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts -
trunk/GSASIIctrls.py
r2133 r2151 1924 1924 def GetValue(self): 1925 1925 return self.value 1926 1927 def OnOk(self,event): 1928 parent = self.GetParent() 1929 parent.Raise() 1930 self.EndModal(wx.ID_OK) 1931 1932 def OnCancel(self,event): 1933 parent = self.GetParent() 1934 parent.Raise() 1935 self.EndModal(wx.ID_CANCEL) 1936 1937 ################################################################################ 1938 class MultiFloatDialog(wx.Dialog): 1939 'Dialog to obtain a multi float value from user' 1940 def __init__(self,parent,title,prompts,values,limits=[[0.,1.],],formats=['%.5g',]): 1941 wx.Dialog.__init__(self,parent,-1,title, 1942 pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE) 1943 self.panel = wx.Panel(self) #just a dummy - gets destroyed in Draw! 1944 self.limits = limits 1945 self.values = values 1946 self.prompts = prompts 1947 self.formats = formats 1948 self.Draw() 1949 1950 def Draw(self): 1951 1952 def OnValItem(event): 1953 Obj = event.GetEventObject() 1954 id,limits,format = Indx[Obj] 1955 try: 1956 val = float(Obj.GetValue()) 1957 if val < limits[0] or val > limits[1]: 1958 raise ValueError 1959 except ValueError: 1960 val = self.values[id] 1961 self.values[id] = val 1962 Obj.SetValue(format%(val)) 1963 1964 Indx = {} 1965 self.panel.Destroy() 1966 self.panel = wx.Panel(self) 1967 mainSizer = wx.BoxSizer(wx.VERTICAL) 1968 lineSizer = wx.FlexGridSizer(0,2,5,5) 1969 for id,[prompt,value,limits,format] in enumerate(zip(self.prompts,self.values,self.limits,self.formats)): 1970 lineSizer.Add(wx.StaticText(self.panel,label=prompt),0,wx.ALIGN_CENTER) 1971 valItem = wx.TextCtrl(self.panel,value=format%(value),style=wx.TE_PROCESS_ENTER) 1972 Indx[valItem] = [id,limits,format] 1973 lineSizer.Add(valItem,0,wx.ALIGN_CENTER) 1974 valItem.Bind(wx.EVT_TEXT_ENTER,OnValItem) 1975 valItem.Bind(wx.EVT_KILL_FOCUS,OnValItem) 1976 mainSizer.Add(lineSizer) 1977 OkBtn = wx.Button(self.panel,-1,"Ok") 1978 OkBtn.Bind(wx.EVT_BUTTON, self.OnOk) 1979 CancelBtn = wx.Button(self.panel,-1,'Cancel') 1980 CancelBtn.Bind(wx.EVT_BUTTON, self.OnCancel) 1981 btnSizer = wx.BoxSizer(wx.HORIZONTAL) 1982 btnSizer.Add((20,20),1) 1983 btnSizer.Add(OkBtn) 1984 btnSizer.Add(CancelBtn) 1985 btnSizer.Add((20,20),1) 1986 mainSizer.Add(btnSizer,0,wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 1987 self.panel.SetSizer(mainSizer) 1988 self.panel.Fit() 1989 self.Fit() 1990 1991 def GetValues(self): 1992 return self.values 1926 1993 1927 1994 def OnOk(self,event): -
trunk/GSASIIpwdGUI.py
r2147 r2151 1182 1182 data tree item. 1183 1183 ''' 1184 #patch 1185 if 'Bank' not in data: #get it from name 1184 if 'Bank' not in data: #get it from name; absent for default parms selection 1186 1185 hst = G2frame.PatternTree.GetItemText(G2frame.PatternId) 1187 1186 if 'Bank' in hst: 1188 bank = int(hst.split('Bank')[1] )1187 bank = int(hst.split('Bank')[1].split('_')[0]) 1189 1188 data['Bank'] = [bank,bank,0] 1190 1189 else: 1191 1190 data['Bank'] = [1,1,0] 1192 #end patch 1191 1193 1192 def keycheck(keys): 1194 1193 good = [] -
trunk/defaultIparms.py
r2133 r2151 103 103 'X:-1.80259010604;Y:4.47209435997\n', 104 104 ]) 105 106 defaultIparm_lbl.append('Generic TOF') 107 defaultIparms.append([ 108 '#GSAS-II instrument parameter file for Generic TOF\n', 109 'Type:PNT;fltPath:25.0;2-theta:150.;Azimuth:0.0\n', 110 'Zero:0.;difC:9000.;difA:0.;difB:0.\n', 111 'alpha:1.0\n', 112 'beta-0:0.;beta-1:0.005;beta-q:0.0\n', 113 'sig-0:0.;sig-1:-50.;sig-2:0.;sig-q:0.0\n', 114 'X:0.;Y:0.\n', 115 ])
Note: See TracChangeset
for help on using the changeset viewer.