#NEWLINE# def test_pre_fit( ) : #NEWLINE# #INDENT# y0 = synthetic_spectrum ( ) #NEWLINE# x0 = np . arange ( len ( y0 ) ) #NEWLINE# item_list = [ 'Ar_K' , 'Fe_K' , 'compton' , 'elastic' ] #NEWLINE# param = get_para ( ) #NEWLINE# ( x , y_total , area_v ) = linear_spectrum_fitting ( x0 , y0 , param , weights = None ) #NEWLINE# for v in item_list : #NEWLINE# #INDENT# assert_true ( ( v in y_total ) ) #NEWLINE# #UNINDENT# sum1 = np . sum ( [ v for v in y_total . values ( ) ] , axis = 0 ) #NEWLINE# r1 = ( 1 - ( np . sum ( ( ( sum1 - y0 ) ** 2 ) ) / np . sum ( ( ( y0 - np . mean ( y0 ) ) ** 2 ) ) ) ) #NEWLINE# assert_true ( ( r1 > 0.85 ) ) #NEWLINE# w = ( 1 / np . sqrt ( ( y0 + 1 ) ) ) #NEWLINE# ( x , y_total , area_v ) = linear_spectrum_fitting ( x0 , y0 , param , weights = w ) #NEWLINE# for v in item_list : #NEWLINE# #INDENT# assert_true ( ( v in y_total ) ) #NEWLINE# #UNINDENT# sum2 = np . sum ( [ v for v in y_total . values ( ) ] , axis = 0 ) #NEWLINE# r2 = ( 1 - ( np . sum ( ( ( sum2 - y0 ) ** 2 ) ) / np . sum ( ( ( y0 - np . mean ( y0 ) ) ** 2 ) ) ) ) #NEWLINE# assert_true ( ( r2 > 0.85 ) )