1515
1616from __future__ import print_function
1717
18+ import copy
1819import sys
1920from pathlib import Path
2021
@@ -747,6 +748,25 @@ def single_morph(
747748 refiner .refine (* rptemp )
748749 # Adjust all parameters
749750 unc = refiner .refine (* refpars , estimate_uncertainty = True )
751+ # If one parameter is causing trouble with uncertainty estimate
752+ # compute all uncertainties individually
753+ if unc is None :
754+ unc = {}
755+ for param in refpars :
756+ refiner_single_param = type (refiner )(
757+ refiner .chain ,
758+ refiner .x_morph ,
759+ refiner .y_morph ,
760+ refiner .x_target ,
761+ refiner .y_target ,
762+ tolerance = refiner .tolerance ,
763+ )
764+ refiner_single_param .chain .config = copy .deepcopy (config )
765+ unc_param = refiner_single_param .refine (
766+ * [param ], estimate_uncertainty = True
767+ )
768+ if unc_param is not None :
769+ unc .update (unc_param )
750770 except ValueError as e :
751771 parser .morph_error (str (e ), ValueError )
752772 # Smear is not being refined, but baselineslope needs to refined to apply
@@ -886,10 +906,12 @@ def single_morph(
886906 # Return different things depending on whether it is python interfaced
887907 if python_wrap :
888908 morph_info = morph_results
909+ if opts .estimate_uncertainty is not None and unc is not None :
910+ morph_info .update ({"Uncertainties" : unc })
889911 morph_table = numpy .array (xy_save ).T
890912 return morph_info , morph_table
891913 else :
892- return morph_results
914+ return morph_results , unc
893915
894916
895917def multiple_targets (parser , opts , pargs , stdout_flag = True , python_wrap = False ):
@@ -999,6 +1021,7 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False):
9991021
10001022 # Morph morph_file against all other files in target_directory
10011023 morph_results = {}
1024+ uncs = {}
10021025 for target_file in target_list :
10031026 if target_file .is_file :
10041027 # Set the save file destination to be a file within the SLOC
@@ -1008,13 +1031,11 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False):
10081031 opts .slocation = Path (save_morphs_here ).joinpath (save_as )
10091032 # Perform a morph of morph_file against target_file
10101033 pargs = [morph_file , target_file ]
1011- morph_results .update (
1012- {
1013- target_file .name : single_morph (
1014- parser , opts , pargs , stdout_flag = False
1015- ),
1016- }
1034+ morph_result , unc = single_morph (
1035+ parser , opts , pargs , stdout_flag = False
10171036 )
1037+ morph_results .update ({target_file .name : morph_result })
1038+ uncs .update ({target_file .name : unc })
10181039
10191040 target_file_names = []
10201041 for key in morph_results .keys ():
@@ -1036,6 +1057,7 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False):
10361057 morph_inputs ,
10371058 morph_results ,
10381059 target_file_names ,
1060+ uncertainties_dict = uncs ,
10391061 save_directory = save_directory ,
10401062 morph_file = morph_file ,
10411063 target_directory = target_directory ,
@@ -1193,6 +1215,7 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False):
11931215
11941216 # Morph morph_file against all other files in target_directory
11951217 morph_results = {}
1218+ uncs = {}
11961219 for morph_file in morph_list :
11971220 if morph_file .is_file :
11981221 # Set the save file destination to be a file within the SLOC
@@ -1202,13 +1225,11 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False):
12021225 opts .slocation = Path (save_morphs_here ).joinpath (save_as )
12031226 # Perform a morph of morph_file against target_file
12041227 pargs = [morph_file , target_file ]
1205- morph_results .update (
1206- {
1207- morph_file .name : single_morph (
1208- parser , opts , pargs , stdout_flag = False
1209- ),
1210- }
1228+ morph_result , unc = single_morph (
1229+ parser , opts , pargs , stdout_flag = False
12111230 )
1231+ morph_results .update ({morph_file .name : morph_result })
1232+ uncs .update ({morph_file .name : unc })
12121233
12131234 morph_file_names = []
12141235 for key in morph_results .keys ():
@@ -1230,6 +1251,7 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False):
12301251 morph_inputs ,
12311252 morph_results ,
12321253 morph_file_names ,
1254+ uncertainties_dict = uncs ,
12331255 save_directory = save_directory ,
12341256 morph_file = target_file ,
12351257 target_directory = morph_directory ,
0 commit comments