@@ -332,28 +332,12 @@ def get_config(self, dgroup=None):
332
332
if conf .get ('edge_step' , None ) is None :
333
333
conf ['edge_step' ] = getattr (dgroup , 'edge_step' , 1 )
334
334
335
- atsym = '?'
336
- if hasattr (dgroup , 'element' ):
337
- elem = getattr (dgroup , 'element' , '?' )
338
- try :
339
- z = int (elem )
340
- atsym = ATSYMS [z ]
341
- except :
342
- pass
343
- if elem in ATSYMS [1 :]:
344
- atsym = elem
345
- else :
346
- try :
347
- if elem .lower () in ATOM_NAMES :
348
- z = 1 + ATOM_NAMES .index (eleme .lower ())
349
- atsym = ATSYMS [z ]
350
- except :
351
- pass
352
-
353
- conf ['atsym' ] = atsym
354
- if atsym == '?' :
355
- conf ['atsym' ] = getattr (dgroup , 'atsym' , atsym )
356
- conf ['edge' ] = getattr (dgroup ,'edge' , conf ['edge' ])
335
+ conf ['atsym' ] = getattr (dgroup , 'atsym' , '?' )
336
+ conf ['edge' ] = getattr (dgroup ,'edge' , 'K' )
337
+ # print("Conf 1 ", dgroup.groupname, conf['atsym'], getattr(dgroup, 'e0', 'no e0'))
338
+ if hasattr (dgroup , 'e0' ) and conf ['atsym' ] == '?' :
339
+ self .set_atom_edge ('?' , '?' )
340
+
357
341
try :
358
342
conf ['e0_nominal' ] = e0_nom = xray_edge (conf ['atsym' ] , conf ['edge' ]).energy
359
343
self .wids ['e0_nominal' ].SetLabel (f'nominal E0={ e0_nom :.2f} eV' )
@@ -374,25 +358,17 @@ def get_config(self, dgroup=None):
374
358
conf ['energy_ref' ] = fname
375
359
376
360
conf ['energy_shift' ] = getattr (dgroup ,'energy_shift' , conf ['energy_shift' ])
377
- if hasattr (dgroup , 'e0' ) and conf ['atsym' ] == '?' :
378
- atsym , edge = guess_edge (dgroup .e0 )
379
- conf ['atsym' ] = atsym
380
- conf ['edge' ] = edge
381
- try :
382
- conf ['e0_nominal' ] = e0_nom = xray_edge (atsym , edge ).energy
383
- self .wids ['e0_nominal' ].SetLabel (f'nominal E0={ e0_nom :.2f} eV' )
384
- except :
385
- conf ['e0_nominal' ] = - 1
386
-
387
- if hasattr (dgroup , 'mback_params' ):
388
- conf ['atsym' ] = getattr (dgroup .mback_params , 'atsym' , conf ['atsym' ])
389
- conf ['edge' ] = getattr (dgroup .mback_params , 'edge' , conf ['edge' ])
390
- try :
391
- conf ['e0_nominal' ] = e0_nom = xray_edge (conf ['atsym' ], conf ['edge' ]).energy
392
- self .wids ['e0_nominal' ].SetLabel (f'nominal E0={ e0_nom :.2f} eV' )
393
- except :
394
- conf ['e0_nominal' ] = - 1
395
361
362
+ # if hasattr(dgroup, 'mback_params'):
363
+ # dgroup.atsym = conf['atsym'] = getattr(dgroup.mback_params, 'atsym', conf['atsym'])
364
+ # dgroup.edge = conf['edge'] = getattr(dgroup.mback_params, 'edge', conf['edge'])
365
+ # print("Got config from MBACK ", conf['atsym'], conf['edge'])
366
+ # try:
367
+ # conf['e0_nominal'] = e0_nom = xray_edge(conf['atsym'], conf['edge']).energy
368
+ # self.wids['e0_nominal'].SetLabel(f'nominal E0={e0_nom:.2f} eV')
369
+ # except:
370
+ # conf['e0_nominal'] = -1
371
+ # print("Get config ", conf['atsym'], conf['edge'], conf['e0_nominal'])
396
372
setattr (dgroup .config , self .configname , conf )
397
373
return conf
398
374
@@ -411,15 +387,8 @@ def fill_form(self, dgroup):
411
387
412
388
self .wids ['e0' ].SetValue (opts .get ('e0' , - 1 ))
413
389
edge_step = opts .get ('edge_step' , 1.0 )
414
-
415
- if hasattr (dgroup , 'e0' ) and opts ['atsym' ] == '?' :
416
- atsym , edge = guess_edge (dgroup .e0 )
417
- opts ['atsym' ] = atsym
418
- opts ['edge' ] = edge
419
- try :
420
- opts ['e0_nominal' ] = xray_edge (atsym , edge ).energy
421
- except :
422
- opts ['e0_nominal' ] = - 1
390
+ if opts ['atsym' ] == '?' and hasattr (dgroup , 'atsym' ):
391
+ self .set_atom_edge (dgroup .atsym , getattr (dgroup , 'edge' , 'K' ))
423
392
424
393
self .wids ['step' ].SetValue (edge_step )
425
394
autoset_fs_increment (self .wids ['step' ], edge_step )
@@ -500,20 +469,31 @@ def read_form(self, who='x'):
500
469
return form_opts
501
470
502
471
def onAtSymEdge (self , event = None ):
503
- atsym = self .wids ['atsym' ].GetStringSelection ().title ()
504
- edge = self .wids ['edge' ].GetStringSelection ().title ()
472
+ self .set_atom_edge ( self . wids ['atsym' ].GetStringSelection ().title (),
473
+ self .wids ['edge' ].GetStringSelection ().title () )
505
474
475
+ def set_atom_edge (self , atsym , edge ):
476
+ "set atom symbol and edge, aiming for consistency"
506
477
dgroup = self .controller .get_group ()
507
- if dgroup is not None :
508
- conf = getattr (dgroup .config , self .configname )
509
- dgroup .atsym = conf ['atsym' ] = atsym
510
- dgroup .edge = conf ['edge' ] = edge
511
- try :
512
- e0_nom = xray_edge (atsym , edge ).energy
513
- conf ['e0_nominal' ] = e0_nom
514
- self .wids ['e0_nominal' ].SetLabel (f'nominal E0={ e0_nom :.2f} eV' )
515
- except :
516
- pass
478
+ if dgroup is None :
479
+ return
480
+ conf = self .get_config ()
481
+ if atsym == '?' and getattr (dgroup , 'e0' , None ) is not Noe :
482
+ atsym , edge = guess_edge (dgroup .e0 )
483
+
484
+ dgroup .atsym = conf ['atsym' ] = atsym
485
+ dgroup .edge = conf ['edge' ] = edge
486
+
487
+ try :
488
+ e0_nom = xray_edge (atsym , edge ).energy
489
+ conf ['e0_nominal' ] = e0_nom
490
+ self .wids ['e0_nominal' ].SetLabel (f'nominal E0={ e0_nom :.2f} eV' )
491
+ except :
492
+ pass
493
+ if hasattr (dgroup , 'mback_params' ):
494
+ dgroup .mback_params .atsym = atsym
495
+ dgroup .mback_params .edge = edge
496
+ # print("End of Set Atom ", atsym, edge)
517
497
518
498
519
499
def onNNormChoice (self , evt = None ):
@@ -536,11 +516,10 @@ def onNormMethod(self, evt=None):
536
516
if method .startswith ('mback' ):
537
517
dgroup = self .controller .get_group ()
538
518
cur_elem = self .wids ['atsym' ].GetStringSelection ()
539
- if hasattr (dgroup , 'e0' ) and cur_elem == 'H' :
540
- atsym , edge = guess_edge (dgroup .e0 )
519
+ if hasattr (dgroup , 'e0' ) and cur_elem in ('H' , '?' ):
541
520
self .wids ['edge' ].SetStringSelection (edge )
542
521
self .wids ['atsym' ].SetStringSelection (atsym )
543
- self .update_config ({ 'edge' : edge , 'atsym' : atsym } )
522
+ # self.set_atom_edge('?' , '?' )
544
523
time .sleep (0.002 )
545
524
self .onReprocess ()
546
525
@@ -752,6 +731,8 @@ def onReprocess(self, evt=None, value=None, **kws):
752
731
dgroup = self .controller .get_group ()
753
732
except TypeError :
754
733
return
734
+ if dgroup is None :
735
+ return
755
736
if not hasattr (dgroup .config , self .configname ):
756
737
return
757
738
self .process (dgroup = dgroup )
@@ -770,9 +751,10 @@ def process(self, dgroup=None, force_mback=False, force=False, use_form=True, **
770
751
dgroup = self .controller .get_group ()
771
752
if dgroup is None :
772
753
return
773
-
754
+ # print("Process ", dgroup, getattr(dgroup, 'atsym', '?'))
774
755
self .skip_process = True
775
756
conf = self .get_config (dgroup )
757
+ # print("Process got conf ", conf['atsym'], getattr(dgroup, 'atsym', '?'))
776
758
form = self .read_form ('process' )
777
759
if not use_form :
778
760
form .update (self .get_defaultconfig ())
@@ -785,7 +767,6 @@ def process(self, dgroup=None, force_mback=False, force=False, use_form=True, **
785
767
if eref_sel in (val , key ):
786
768
self .wids ['energy_ref' ].SetStringSelection (key )
787
769
788
-
789
770
en_units = getattr (dgroup , 'energy_units' , None )
790
771
if en_units is None :
791
772
en_units = guess_energy_units (dgroup .energy )
@@ -806,15 +787,8 @@ def process(self, dgroup=None, force_mback=False, force=False, use_form=True, **
806
787
807
788
if not hasattr (dgroup , 'e0' ):
808
789
e0 = find_e0 (dgroup )
809
- if form ['atsym' ] == '?' and conf .get ('atsym' , '?' ) != '?' :
810
- form ['atsym' ] = conf ['atsym' ]
811
- form ['edge' ] = conf .get ('edge' , 'K' )
812
-
813
790
if form ['atsym' ] == '?' :
814
- form ['atsym' ], form ['edge' ] = guess_edge (dgroup .e0 )
815
- dgroup .atsym = form ['atsym' ]
816
- dgroup .edge = form ['edge' ]
817
-
791
+ self .set_atom_edge ('?' , '?' )
818
792
819
793
cmds = []
820
794
# test whether the energy shift is 0 or is different from the current energy shift:
@@ -920,6 +894,8 @@ def process(self, dgroup=None, force_mback=False, force=False, use_form=True, **
920
894
atsym , edge = guess_edge (dgroup .e0 )
921
895
conf ['atsym' ] = dgroup .atsym = atsym
922
896
conf ['edge' ] = dgroup .edge = edge
897
+ # conf['atsym'] = atsym
898
+ # conf['edge'] = edge
923
899
self .wids ['atsym' ].SetStringSelection (dgroup .atsym )
924
900
self .wids ['edge' ].SetStringSelection (dgroup .edge )
925
901
@@ -935,9 +911,6 @@ def process(self, dgroup=None, force_mback=False, force=False, use_form=True, **
935
911
if val is not None :
936
912
self .wids [attr ].SetValue (val )
937
913
938
- if hasattr (dgroup , 'mback_params' ): # from mback
939
- conf ['atsym' ] = getattr (dgroup .mback_params , 'atsym' )
940
- conf ['edge' ] = getattr (dgroup .mback_params , 'edge' )
941
914
self .update_config (conf , dgroup = dgroup )
942
915
943
916
self .skip_process = False
0 commit comments