@@ -133,40 +133,37 @@ def main():
133133 # Find the index where cooling commences
134134 pivot_index = 0
135135 n = 30
136- for i in range (2 , len (data )):
136+ for i in range (n , len (data )):
137137 if len (data ) <= i + n :
138- # No pivot found at all
139- break ;
138+ # No pivot found at all
139+ break
140140 # Check whether a significant descent starts within the next n entries
141- if np .mean ([ x [ 1 ] for x in data [ i + 1 :i + 1 + n ]] ) < np .mean ([ x [ 1 ] for x in data [ i - n :i ] ]):
141+ if np .mean (T [ i + 1 :i + 1 + n ]) < np .mean (T [ i - n :i ]):
142142 # Check the next n entries in reverse order, until we find the first local maximum
143143 for j in reversed (range (i ,i + n )):
144144 if data [j ] < data [j + 1 ]:
145145 pivot_index = j
146146 break
147147 break
148148
149- for s , temp in data :
150- data
151-
152149 curve = lambda x , a , b , c : a * np .log (b * x ) + c
153150
154151 params_heat = curve_fit (curve , t [0 :pivot_index or - 1 ], T [0 :pivot_index or - 1 ])
155- print ('Heating curve:\n T = {a } log({b }x) + {c }' .format (a = params_heat [0 ][ 0 ], b = params_heat [ 0 ][ 1 ], c = params_heat [ 0 ][ 2 ]))
152+ print ('Heating curve:\n T = {} log({}x) + {}' .format (* params_heat [0 ]))
156153 t_heat = range (0 ,data [pivot_index or - 1 ][0 ])
157154 heating_curve = [curve (x , params_heat [0 ][0 ], params_heat [0 ][1 ], params_heat [0 ][2 ]) for x in t_heat ]
158155 #print(heating_curve)
159156 axis .plot (t_heat , heating_curve )
160157
161158 if pivot_index > 0 :
162159 params_cool = curve_fit (curve , t [pivot_index :- 1 ], T [pivot_index :- 1 ])
163- print ('Cooling curve:\n T = {a } log({b }x) + {c }' .format (a = params_cool [0 ][ 0 ], b = params_cool [ 0 ][ 1 ], c = params_cool [ 0 ][ 2 ]))
160+ print ('Cooling curve:\n T = {} log({}x) + {}' .format (* params_cool [0 ]))
164161 t_cool = range (data [pivot_index ][0 ], data [- 1 ][0 ])
165162 cooling_curve = [curve (x , params_cool [0 ][0 ], params_cool [0 ][1 ], params_cool [0 ][2 ]) for x in t_cool ]
166163 #print(cooling_curve)
167164 axis .plot (t_cool , cooling_curve )
168165
169- plt .show (fig )
166+ plt .show ()
170167
171168if __name__ == '__main__' :
172- main ()
169+ main ()
0 commit comments