#NEWLINE# def test_fit( ) : #NEWLINE# #INDENT# param = get_para ( ) #NEWLINE# pileup_peak = [ 'Si_Ka1-Si_Ka1' , 'Si_Ka1-Ce_La1' ] #NEWLINE# user_peak = [ 'user_peak1' ] #NEWLINE# elemental_lines = ( ( [ 'Ar_K' , 'Fe_K' , 'Ce_L' , 'Pt_M' ] + pileup_peak ) + user_peak ) #NEWLINE# x0 = np . arange ( 2000 ) #NEWLINE# y0 = synthetic_spectrum ( ) #NEWLINE# default_area = 100000.0 #NEWLINE# ( x , y ) = trim ( x0 , y0 , 100 , 1300 ) #NEWLINE# MS = ModelSpectrum ( param , elemental_lines ) #NEWLINE# MS . assemble_models ( ) #NEWLINE# result = MS . model_fit ( x , y , weights = ( 1 / np . sqrt ( ( y + 1 ) ) ) , maxfev = 200 ) #NEWLINE# for ( k , v ) in six . iteritems ( result . values ) : #NEWLINE# #INDENT# if ( 'area' in k ) : #NEWLINE# #INDENT# assert_true ( ( ( abs ( ( v - default_area ) ) / default_area ) < 1e-06 ) ) #NEWLINE# #UNINDENT# #UNINDENT# sum_Fe = sum_area ( 'Fe_K' , result ) #NEWLINE# assert_true ( ( sum_Fe > default_area ) ) #NEWLINE# sum_Ce = sum_area ( 'Ce_L' , result ) #NEWLINE# assert_true ( ( sum_Ce > default_area ) ) #NEWLINE# sum_Pt = sum_area ( 'Pt_M' , result ) #NEWLINE# assert_true ( ( sum_Pt > default_area ) ) #NEWLINE# PC = ParamController ( param , elemental_lines ) #NEWLINE# new_params = PC . params #NEWLINE# update_parameter_dict ( new_params , result ) #NEWLINE# for ( k , v ) in six . iteritems ( new_params ) : #NEWLINE# #INDENT# if ( 'area' in k ) : #NEWLINE# #INDENT# assert_equal ( v [ 'value' ] , result . values [ k ] )