def test_set_param(): param = get_para() elemental_lines = ['Ar_K', 'Fe_K', 'Ce_L', 'Pt_M'] MS = ModelSpectrum(param, elemental_lines) MS.assemble_models() # get compton model compton = MS.mod.components[0] input_param = {'bound_type': 'other', 'max': 13.0, 'min': 9.0, 'value': 11.0} _set_parameter_hint('coherent_sct_energy', input_param, compton)
def test_set_param_hint(): param = get_para() elemental_lines = ['Ar_K', 'Fe_K', 'Ce_L', 'Pt_M'] bound_options = ['none', 'lohi', 'fixed', 'lo', 'hi'] MS = ModelSpectrum(param, elemental_lines) MS.assemble_models() # get compton model compton = MS.mod.components[0] for v in bound_options: input_param = {'bound_type': v, 'max': 13.0, 'min': 9.0, 'value': 11.0} _set_parameter_hint('coherent_sct_energy', input_param, compton) p = compton.make_params() if v == 'fixed': assert_equal(p['coherent_sct_energy'].vary, False) else: assert_equal(p['coherent_sct_energy'].vary, True)
def test_fit(): param = get_para() pileup_peak = ['Si_Ka1-Si_Ka1', 'Si_Ka1-Ce_La1'] user_peak = ['user_peak1'] elemental_lines = (['Ar_K', 'Fe_K', 'Ce_L', 'Pt_M'] + pileup_peak + user_peak) x0 = np.arange(2000) y0 = synthetic_spectrum() default_area = 1e5 x, y = trim(x0, y0, 100, 1300) MS = ModelSpectrum(param, elemental_lines) MS.assemble_models() result = MS.model_fit(x, y, weights=1 / np.sqrt(y + 1), maxfev=200) # check area of each element for k, v in six.iteritems(result.values): if 'area' in k: # error smaller than 1e-6 assert abs(v - default_area) / default_area < 1e-6 # multiple peak sumed, so value should be larger than one peak area 1e5 sum_Fe = sum_area('Fe_K', result) assert sum_Fe > default_area sum_Ce = sum_area('Ce_L', result) assert sum_Ce > default_area sum_Pt = sum_area('Pt_M', result) assert sum_Pt > default_area # create full list of parameters PC = ParamController(param, elemental_lines) new_params = PC.params # update values update_parameter_dict(new_params, result) for k, v in six.iteritems(new_params): if 'area' in k: assert_equal(v['value'], result.values[k])
def test_fit(): param = get_para() pileup_peak = ['Si_Ka1-Si_Ka1', 'Si_Ka1-Ce_La1'] user_peak = ['user_peak1'] elemental_lines = (['Ar_K', 'Fe_K', 'Ce_L', 'Pt_M'] + pileup_peak + user_peak) x0 = np.arange(2000) y0 = synthetic_spectrum() default_area = 1e5 x, y = trim(x0, y0, 100, 1300) MS = ModelSpectrum(param, elemental_lines) MS.assemble_models() result = MS.model_fit(x, y, weights=1/np.sqrt(y+1), maxfev=200) # check area of each element for k, v in six.iteritems(result.values): if 'area' in k: # error smaller than 1e-6 assert_true(abs(v - default_area)/default_area < 1e-6) # multiple peak sumed, so value should be larger than one peak area 1e5 sum_Fe = sum_area('Fe_K', result) assert_true(sum_Fe > default_area) sum_Ce = sum_area('Ce_L', result) assert_true(sum_Ce > default_area) sum_Pt = sum_area('Pt_M', result) assert_true(sum_Pt > default_area) # create full list of parameters PC = ParamController(param, elemental_lines) new_params = PC.params # update values update_parameter_dict(new_params, result) for k, v in six.iteritems(new_params): if 'area' in k: assert_equal(v['value'], result.values[k])