28
28
PropertyCriterion ,
29
29
StringArrayProperty ,
30
30
UnitParams ,
31
+ SpecialCoordinateSystem ,
31
32
)
32
33
from mantid .dataobjects import Workspace2D
33
34
from mantid .fitfunctions import FunctionWrapper , CompositeFunctionWrapper
42
43
)
43
44
from enum import Enum
44
45
from typing import Sequence , Tuple
46
+ from mantid .dataobjects import PeakShapeDetectorBin
45
47
46
48
47
49
class PEAK_STATUS (Enum ):
@@ -334,7 +336,7 @@ def PyExec(self):
334
336
for ipk , peak in enumerate (peaks ):
335
337
prog_reporter .report ("Integrating" )
336
338
peak_intens , peak_sigma = 0.0 , 0.0
337
- status = PEAK_STATUS .NO_PEAK
339
+ peak_status = PEAK_STATUS .NO_PEAK
338
340
339
341
detid = peak .getDetectorID ()
340
342
bank_name = peaks .column ("BankName" )[ipk ]
@@ -375,7 +377,7 @@ def PyExec(self):
375
377
continue # skip peak
376
378
377
379
# update peak mask based on I/sig from fit
378
- * _ , i_over_sigma = calc_intens_and_sigma_arrays (fit_result , error_strategy )
380
+ * _ , i_over_sigma , _ = calc_intens_and_sigma_arrays (fit_result , error_strategy )
379
381
non_bg_mask = np .zeros (peak_data .detids .shape , dtype = bool )
380
382
non_bg_mask .flat [initial_peak_mask ] = i_over_sigma > i_over_sig_threshold
381
383
peak_mask = find_peak_cluster_in_window (non_bg_mask , (peak_data .irow , peak_data .icol ))
@@ -384,7 +386,7 @@ def PyExec(self):
384
386
385
387
is_on_edge = np .any (np .logical_and (peak_mask , peak_data .det_edges ))
386
388
if is_on_edge :
387
- status = PEAK_STATUS .ON_EDGE
389
+ peak_status = PEAK_STATUS .ON_EDGE
388
390
if not integrate_on_edge :
389
391
self .delete_fit_result_workspaces (fit_result )
390
392
continue # skip peak
@@ -406,19 +408,21 @@ def PyExec(self):
406
408
peak_mask .flat [initial_peak_mask ] = fit_mask
407
409
408
410
# calculate intensity
409
- status = PEAK_STATUS .VALID
410
- intens , sigma , _ = calc_intens_and_sigma_arrays (fit_result , error_strategy )
411
+ peak_status = PEAK_STATUS .VALID
412
+ intens , sigma , _ , peak_limits = calc_intens_and_sigma_arrays (fit_result , error_strategy )
411
413
peak_intens = np .sum (intens [fit_mask ])
412
414
peak_sigma = np .sqrt (np .sum (sigma [fit_mask ] ** 2 ))
413
415
416
+ self ._set_peak_shape (peak , peak_data .detids [peak_mask ], peak_limits [fit_mask ])
417
+
414
418
if output_file :
415
419
intens_over_sig = peak_intens / peak_sigma if peak_sigma > 0 else 0.0
416
420
results .append (
417
421
LineProfileResult (
418
422
ipk ,
419
423
peak ,
420
424
intens_over_sig ,
421
- status ,
425
+ peak_status ,
422
426
peak_mask ,
423
427
fit_mask ,
424
428
func_generator .ysum ,
@@ -439,6 +443,15 @@ def PyExec(self):
439
443
# assign output
440
444
self .setProperty ("OutputWorkspace" , peaks )
441
445
446
+ def _set_peak_shape (self , peak , det_ids , fit_limits ):
447
+ det_bin_list = []
448
+ for detid , limits in zip (det_ids , fit_limits ):
449
+ if limits :
450
+ det_bin_list .append ((int (detid ), limits [0 ], limits [- 1 ]))
451
+ if len (det_bin_list ) > 0 :
452
+ peak_shape = PeakShapeDetectorBin (det_bin_list , SpecialCoordinateSystem .NONE , self .name (), self .version ())
453
+ peak .setPeakShape (peak_shape )
454
+
442
455
def exec_child_alg (self , alg_name , ** kwargs ):
443
456
alg = self .createChildAlgorithm (alg_name , enableLogging = False )
444
457
alg .initialize ()
@@ -478,7 +491,7 @@ def __init__(self, peak_params_to_fix: Sequence[str]):
478
491
self .cen_par_name : str = None
479
492
self .intens_par_name : str = None
480
493
self .width_par_name : str = None
481
- self .width_max : float = None
494
+ self .width_min : float = None
482
495
self .width_max : float = None
483
496
self .peak_params_to_fix : Sequence [str ] = peak_params_to_fix
484
497
self .peak_mask : np .ndarray [float ] = None
@@ -732,7 +745,7 @@ def calc_sigma_from_summation(xdat, edat_sq, ypeak, cutoff=0.025):
732
745
ilo = np .clip (np .argmin (abs (ypeak_cumsum - cutoff )), a_min = 0 , a_max = nbins // 2 )
733
746
ihi = np .clip (np .argmin (abs (ypeak_cumsum - (1 - cutoff ))), a_min = nbins // 2 , a_max = nbins - 1 ) + 1
734
747
bin_width = np .diff (xdat [ilo : ihi + 1 ])
735
- return np .sqrt (np .sum (edat_sq [ilo :ihi ] * (bin_width ** 2 )))
748
+ return np .sqrt (np .sum (edat_sq [ilo :ihi ] * (bin_width ** 2 ))), ( xdat [ ilo ], xdat [ ihi ])
736
749
737
750
738
751
def calc_intens_and_sigma_arrays (fit_result , error_strategy ):
@@ -741,6 +754,7 @@ def calc_intens_and_sigma_arrays(fit_result, error_strategy):
741
754
sigma = np .zeros (intens .shape )
742
755
intens_over_sig = np .zeros (intens .shape )
743
756
peak_func = FunctionFactory .Instance ().createPeakFunction (function [0 ][0 ].name ())
757
+ peak_limits = np .full (intens .shape , None )
744
758
for idom , comp_func in enumerate (function ):
745
759
[peak_func .setParameter (iparam , comp_func .getParameterValue (iparam )) for iparam in range (peak_func .nParams ())]
746
760
intens [idom ] = peak_func .intensity ()
@@ -749,10 +763,10 @@ def calc_intens_and_sigma_arrays(fit_result, error_strategy):
749
763
sigma [idom ] = peak_func .intensityError ()
750
764
else :
751
765
ws_fit = get_eval_ws (fit_result ["OutputWorkspace" ], idom )
752
- sigma [idom ] = calc_sigma_from_summation (ws_fit .readX (0 ), ws_fit .readE (0 ) ** 2 , ws_fit .readY (3 ))
766
+ sigma [idom ], peak_limits [ idom ] = calc_sigma_from_summation (ws_fit .readX (0 ), ws_fit .readE (0 ) ** 2 , ws_fit .readY (3 ))
753
767
ivalid = ~ np .isclose (sigma , 0 )
754
768
intens_over_sig [ivalid ] = intens [ivalid ] / sigma [ivalid ]
755
- return intens , sigma , intens_over_sig
769
+ return intens , sigma , intens_over_sig , peak_limits
756
770
757
771
758
772
def get_eval_ws (out_ws_name , idom ):
0 commit comments