@@ -70,15 +70,27 @@ def flatten(arr):
7070 )
7171
7272
73- def pretty_print_values (popt , pcov , params , extra_decimal_places = 0 ):
73+ def pretty_string_values (popt , pcov , extra_decimal_places = 0 ):
7474 """
7575 Takes a numpy array of parameters, the corresponding covariance matrix
76- and a set of parameter names and prints the parameters and
77- principal 1-s.d.uncertainties (np.sqrt(pcov[i][i]))
78- in a nice text based format.
76+ and a set of parameter names and returns the scaled variables and
77+ principal 1-s.d.uncertainties (np.sqrt(pcov[i][i])) and scaling factor
78+ as three separate lists of strings.
79+
80+ :param popt: Parameter values
81+ :type popt: numpy array
82+ :param pcov: Variance-covariance matrix
83+ :type pcov: 2D numpy array
84+ :param extra_decimal_places: extra precision for values, defaults to 0
85+ :type extra_decimal_places: int, optional
86+ :return: values, uncertainties and the scaling factors
87+ :rtype: tuple of 3 lists
7988 """
80- for i , p in enumerate (params ):
81- p_rnd = round_to_n (popt [i ], np .sqrt (pcov [i ][i ]), 1 + extra_decimal_places )
89+ pval = []
90+ psig = []
91+ pscale = []
92+ for i , p in enumerate (popt ):
93+ p_rnd = round_to_n (p , np .sqrt (pcov [i ][i ]), 1 + extra_decimal_places )
8294 c_rnd = round_to_n (
8395 np .sqrt (pcov [i ][i ]), np .sqrt (pcov [i ][i ]), 1 + extra_decimal_places
8496 )
@@ -90,11 +102,29 @@ def pretty_print_values(popt, pcov, params, extra_decimal_places=0):
90102
91103 scale = np .power (10.0 , p_expnt )
92104 nd = p_expnt - np .floor (np .log10 (np .abs (c_rnd ))) + extra_decimal_places
93- print (
94- "{0:s}: ({1:{4}{5}f} +/- {2:{4}{5}f}) x {3:.0e}" .format (
95- p , p_rnd / scale , c_rnd / scale , scale , 0 , (nd ) / 10.0
96- )
97- )
105+ pval .append (f"{ p_rnd / scale :0{nd / 10.0 }f} " )
106+ psig .append (f"{ c_rnd / scale :0{nd / 10.0 }f} " )
107+ pscale .append (f"{ scale :.0e} " )
108+ return (pval , psig , pscale )
109+
110+
111+ def pretty_print_values (popt , pcov , params , extra_decimal_places = 0 ):
112+ """
113+ Takes a numpy array of parameters, the corresponding covariance matrix
114+ and a set of parameter names and prints the scaled variables and
115+ principal 1-s.d.uncertainties (np.sqrt(pcov[i][i])) and scaling factor
116+ in an easy to read format.
117+
118+ :param popt: Parameter values
119+ :type popt: numpy array
120+ :param pcov: Variance-covariance matrix
121+ :type pcov: 2D numpy array
122+ :param extra_decimal_places: extra precision for values, defaults to 0
123+ :type extra_decimal_places: int, optional
124+ """
125+ pval , psig , pscale = pretty_string_values (popt , pcov , extra_decimal_places )
126+ for i , p in enumerate (params ):
127+ print (f"{ p :s} : ({ pval [i ]} +/- { psig [i ]} ) x { pscale [i ]} " )
98128
99129
100130def pretty_print_table (table , use_tabs = False ):
0 commit comments